blob: bb2bff7b56b46e2f759ae15b0ea85eafbc198c93 [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 Smart128bdda2018-01-30 15:59:03 -08004 * Copyright (C) 2017-2018 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>
Maurizio Lombardi286871a2017-08-23 16:55:48 -070040#include <linux/bitops.h>
dea31012005-04-17 16:05:31 -050041
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040042#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050043#include <scsi/scsi_device.h>
44#include <scsi/scsi_host.h>
45#include <scsi/scsi_transport_fc.h>
James Smart86c67372017-04-21 16:05:04 -070046#include <scsi/scsi_tcq.h>
47#include <scsi/fc/fc_fs.h>
48
49#include <linux/nvme-fc-driver.h>
dea31012005-04-17 16:05:31 -050050
James Smartda0436e2009-05-22 14:51:39 -040051#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050052#include "lpfc_hw.h"
53#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040054#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040055#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050056#include "lpfc_disc.h"
dea31012005-04-17 16:05:31 -050057#include "lpfc.h"
James Smart895427b2017-02-12 13:52:30 -080058#include "lpfc_scsi.h"
59#include "lpfc_nvme.h"
James Smart86c67372017-04-21 16:05:04 -070060#include "lpfc_nvmet.h"
dea31012005-04-17 16:05:31 -050061#include "lpfc_logmsg.h"
62#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050063#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050064#include "lpfc_version.h"
James Smart12f44452016-07-06 12:36:03 -070065#include "lpfc_ids.h"
dea31012005-04-17 16:05:31 -050066
James Smart81301a92008-12-04 22:39:46 -050067char *_dump_buf_data;
68unsigned long _dump_buf_data_order;
69char *_dump_buf_dif;
70unsigned long _dump_buf_dif_order;
71spinlock_t _dump_buf_lock;
72
James Smart7bb03bb2013-04-17 20:19:16 -040073/* Used when mapping IRQ vectors in a driver centric manner */
James Smartb246de12013-05-31 17:03:07 -040074uint16_t *lpfc_used_cpu;
75uint32_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);
dea31012005-04-17 16:05:31 -050096
97static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050098static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -050099static DEFINE_IDR(lpfc_hba_index);
James Smartf358dd02017-02-12 13:52:34 -0800100#define LPFC_NVMET_BUF_POST 254
dea31012005-04-17 16:05:31 -0500101
James Smarte59058c2008-08-24 21:49:00 -0400102/**
James Smart3621a712009-04-06 18:47:14 -0400103 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
James Smarte59058c2008-08-24 21:49:00 -0400104 * @phba: pointer to lpfc hba data structure.
105 *
106 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
107 * mailbox command. It retrieves the revision information from the HBA and
108 * collects the Vital Product Data (VPD) about the HBA for preparing the
109 * configuration of the HBA.
110 *
111 * Return codes:
112 * 0 - success.
113 * -ERESTART - requests the SLI layer to reset the HBA and try again.
114 * Any other value - indicates an error.
115 **/
dea31012005-04-17 16:05:31 -0500116int
James Smart2e0fef82007-06-17 19:56:36 -0500117lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500118{
119 lpfc_vpd_t *vp = &phba->vpd;
120 int i = 0, rc;
121 LPFC_MBOXQ_t *pmb;
122 MAILBOX_t *mb;
123 char *lpfc_vpd_data = NULL;
124 uint16_t offset = 0;
125 static char licensed[56] =
126 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -0400127 static int init_key = 1;
dea31012005-04-17 16:05:31 -0500128
129 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
130 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500131 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500132 return -ENOMEM;
133 }
134
James Smart04c68492009-05-22 14:52:52 -0400135 mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -0500136 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -0500137
138 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -0400139 if (init_key) {
140 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -0500141
James Smart65a29c12006-07-06 15:50:50 -0400142 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
143 *ptext = cpu_to_be32(*ptext);
144 init_key = 0;
145 }
dea31012005-04-17 16:05:31 -0500146
147 lpfc_read_nv(phba, pmb);
148 memset((char*)mb->un.varRDnvp.rsvd3, 0,
149 sizeof (mb->un.varRDnvp.rsvd3));
150 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
151 sizeof (licensed));
152
153 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
154
155 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500156 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400157 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500158 "error, mbxCmd x%x READ_NVPARM, "
159 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500160 mb->mbxCommand, mb->mbxStatus);
161 mempool_free(pmb, phba->mbox_mem_pool);
162 return -ERESTART;
163 }
164 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500165 sizeof(phba->wwnn));
166 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
167 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500168 }
169
James Smart92d7f7b2007-06-17 19:56:38 -0500170 phba->sli3_options = 0x0;
171
dea31012005-04-17 16:05:31 -0500172 /* Setup and issue mailbox READ REV command */
173 lpfc_read_rev(phba, pmb);
174 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
175 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500176 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400177 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500178 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500179 mb->mbxCommand, mb->mbxStatus);
180 mempool_free( pmb, phba->mbox_mem_pool);
181 return -ERESTART;
182 }
183
James Smart92d7f7b2007-06-17 19:56:38 -0500184
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500185 /*
186 * The value of rr must be 1 since the driver set the cv field to 1.
187 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500188 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500189 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500190 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500191 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400192 "0440 Adapter failed to init, READ_REV has "
193 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500194 mempool_free(pmb, phba->mbox_mem_pool);
195 return -ERESTART;
dea31012005-04-17 16:05:31 -0500196 }
197
James Smart495a7142008-06-14 22:52:59 -0400198 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
199 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500200 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400201 }
James Smarted957682007-06-17 19:56:37 -0500202
dea31012005-04-17 16:05:31 -0500203 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500204 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500205 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500206 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
207 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
208 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
209 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500210 vp->rev.biuRev = mb->un.varRdRev.biuRev;
211 vp->rev.smRev = mb->un.varRdRev.smRev;
212 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
213 vp->rev.endecRev = mb->un.varRdRev.endecRev;
214 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
215 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
216 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
217 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
218 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
219 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
220
James Smart92d7f7b2007-06-17 19:56:38 -0500221 /* If the sli feature level is less then 9, we must
222 * tear down all RPIs and VPIs on link down if NPIV
223 * is enabled.
224 */
225 if (vp->rev.feaLevelHigh < 9)
226 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
227
dea31012005-04-17 16:05:31 -0500228 if (lpfc_is_LC_HBA(phba->pcidev->device))
229 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
230 sizeof (phba->RandomData));
231
dea31012005-04-17 16:05:31 -0500232 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500233 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
234 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400235 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500236 do {
James Smarta0c87cb2009-07-19 10:01:10 -0400237 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
dea31012005-04-17 16:05:31 -0500238 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
239
240 if (rc != MBX_SUCCESS) {
241 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400242 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500243 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500244 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500245 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500246 }
James Smart04c68492009-05-22 14:52:52 -0400247 /* dump mem may return a zero when finished or we got a
248 * mailbox error, either way we are done.
249 */
250 if (mb->un.varDmp.word_cnt == 0)
251 break;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500252 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
253 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400254 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
255 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500256 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500257 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500258 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
259 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500260
261 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500262out_free_mbox:
263 mempool_free(pmb, phba->mbox_mem_pool);
264 return 0;
265}
266
James Smarte59058c2008-08-24 21:49:00 -0400267/**
James Smart3621a712009-04-06 18:47:14 -0400268 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
James Smarte59058c2008-08-24 21:49:00 -0400269 * @phba: pointer to lpfc hba data structure.
270 * @pmboxq: pointer to the driver internal queue element for mailbox command.
271 *
272 * This is the completion handler for driver's configuring asynchronous event
273 * mailbox command to the device. If the mailbox command returns successfully,
274 * it will set internal async event support flag to 1; otherwise, it will
275 * set internal async event support flag to 0.
276 **/
James Smart57127f12007-10-27 13:37:05 -0400277static void
278lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
279{
James Smart04c68492009-05-22 14:52:52 -0400280 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
James Smart57127f12007-10-27 13:37:05 -0400281 phba->temp_sensor_support = 1;
282 else
283 phba->temp_sensor_support = 0;
284 mempool_free(pmboxq, phba->mbox_mem_pool);
285 return;
286}
287
James Smarte59058c2008-08-24 21:49:00 -0400288/**
James Smart3621a712009-04-06 18:47:14 -0400289 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
James Smart97207482008-12-04 22:39:19 -0500290 * @phba: pointer to lpfc hba data structure.
291 * @pmboxq: pointer to the driver internal queue element for mailbox command.
292 *
293 * This is the completion handler for dump mailbox command for getting
294 * wake up parameters. When this command complete, the response contain
295 * Option rom version of the HBA. This function translate the version number
296 * into a human readable string and store it in OptionROMVersion.
297 **/
298static void
299lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
300{
301 struct prog_id *prg;
302 uint32_t prog_id_word;
303 char dist = ' ';
304 /* character array used for decoding dist type. */
305 char dist_char[] = "nabx";
306
James Smart04c68492009-05-22 14:52:52 -0400307 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
James Smart9f1e1b52008-12-04 22:39:40 -0500308 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500309 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500310 }
James Smart97207482008-12-04 22:39:19 -0500311
312 prg = (struct prog_id *) &prog_id_word;
313
314 /* word 7 contain option rom version */
James Smart04c68492009-05-22 14:52:52 -0400315 prog_id_word = pmboxq->u.mb.un.varWords[7];
James Smart97207482008-12-04 22:39:19 -0500316
317 /* Decode the Option rom version word to a readable string */
318 if (prg->dist < 4)
319 dist = dist_char[prg->dist];
320
321 if ((prg->dist == 3) && (prg->num == 0))
James Smarta2fc4aef2014-09-03 12:57:55 -0400322 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
James Smart97207482008-12-04 22:39:19 -0500323 prg->ver, prg->rev, prg->lev);
324 else
James Smarta2fc4aef2014-09-03 12:57:55 -0400325 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
James Smart97207482008-12-04 22:39:19 -0500326 prg->ver, prg->rev, prg->lev,
327 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500328 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500329 return;
330}
331
332/**
James Smart05580562011-05-24 11:40:48 -0400333 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
334 * cfg_soft_wwnn, cfg_soft_wwpn
335 * @vport: pointer to lpfc vport data structure.
336 *
337 *
338 * Return codes
339 * None.
340 **/
341void
342lpfc_update_vport_wwn(struct lpfc_vport *vport)
343{
James Smartaeb3c812017-04-21 16:05:02 -0700344 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
345 u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0];
346
James Smart05580562011-05-24 11:40:48 -0400347 /* If the soft name exists then update it using the service params */
348 if (vport->phba->cfg_soft_wwnn)
349 u64_to_wwn(vport->phba->cfg_soft_wwnn,
350 vport->fc_sparam.nodeName.u.wwn);
351 if (vport->phba->cfg_soft_wwpn)
352 u64_to_wwn(vport->phba->cfg_soft_wwpn,
353 vport->fc_sparam.portName.u.wwn);
354
355 /*
356 * If the name is empty or there exists a soft name
357 * then copy the service params name, otherwise use the fc name
358 */
359 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
360 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
361 sizeof(struct lpfc_name));
362 else
363 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
364 sizeof(struct lpfc_name));
365
James Smartaeb3c812017-04-21 16:05:02 -0700366 /*
367 * If the port name has changed, then set the Param changes flag
368 * to unreg the login
369 */
370 if (vport->fc_portname.u.wwn[0] != 0 &&
371 memcmp(&vport->fc_portname, &vport->fc_sparam.portName,
372 sizeof(struct lpfc_name)))
373 vport->vport_flag |= FAWWPN_PARAM_CHG;
374
375 if (vport->fc_portname.u.wwn[0] == 0 ||
376 vport->phba->cfg_soft_wwpn ||
377 (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) ||
378 vport->vport_flag & FAWWPN_SET) {
James Smart05580562011-05-24 11:40:48 -0400379 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
380 sizeof(struct lpfc_name));
James Smartaeb3c812017-04-21 16:05:02 -0700381 vport->vport_flag &= ~FAWWPN_SET;
382 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR)
383 vport->vport_flag |= FAWWPN_SET;
384 }
James Smart05580562011-05-24 11:40:48 -0400385 else
386 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
387 sizeof(struct lpfc_name));
388}
389
390/**
James Smart3621a712009-04-06 18:47:14 -0400391 * lpfc_config_port_post - Perform lpfc initialization after config port
James Smarte59058c2008-08-24 21:49:00 -0400392 * @phba: pointer to lpfc hba data structure.
393 *
394 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
395 * command call. It performs all internal resource and state setups on the
396 * port: post IOCB buffers, enable appropriate host interrupt attentions,
397 * ELS ring timers, etc.
398 *
399 * Return codes
400 * 0 - success.
401 * Any other value - error.
402 **/
dea31012005-04-17 16:05:31 -0500403int
James Smart2e0fef82007-06-17 19:56:36 -0500404lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500405{
James Smart2e0fef82007-06-17 19:56:36 -0500406 struct lpfc_vport *vport = phba->pport;
James Smarta257bf92009-04-06 18:48:10 -0400407 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500408 LPFC_MBOXQ_t *pmb;
409 MAILBOX_t *mb;
410 struct lpfc_dmabuf *mp;
411 struct lpfc_sli *psli = &phba->sli;
412 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500413 int i, j;
414 int rc;
dea31012005-04-17 16:05:31 -0500415
James Smart7af67052007-10-27 13:38:11 -0400416 spin_lock_irq(&phba->hbalock);
417 /*
418 * If the Config port completed correctly the HBA is not
419 * over heated any more.
420 */
421 if (phba->over_temp_state == HBA_OVER_TEMP)
422 phba->over_temp_state = HBA_NORMAL_TEMP;
423 spin_unlock_irq(&phba->hbalock);
424
dea31012005-04-17 16:05:31 -0500425 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
426 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500427 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500428 return -ENOMEM;
429 }
James Smart04c68492009-05-22 14:52:52 -0400430 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500431
dea31012005-04-17 16:05:31 -0500432 /* Get login parameters for NID. */
James Smart9f1177a2010-02-26 14:12:57 -0500433 rc = lpfc_read_sparam(phba, pmb, 0);
434 if (rc) {
435 mempool_free(pmb, phba->mbox_mem_pool);
436 return -ENOMEM;
437 }
438
James Smarted957682007-06-17 19:56:37 -0500439 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500440 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500441 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400442 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500443 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500444 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500445 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500446 mp = (struct lpfc_dmabuf *) pmb->context1;
James Smart9f1177a2010-02-26 14:12:57 -0500447 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500448 lpfc_mbuf_free(phba, mp->virt, mp->phys);
449 kfree(mp);
450 return -EIO;
451 }
452
453 mp = (struct lpfc_dmabuf *) pmb->context1;
454
James Smart2e0fef82007-06-17 19:56:36 -0500455 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500456 lpfc_mbuf_free(phba, mp->virt, mp->phys);
457 kfree(mp);
458 pmb->context1 = NULL;
James Smart05580562011-05-24 11:40:48 -0400459 lpfc_update_vport_wwn(vport);
James Smarta257bf92009-04-06 18:48:10 -0400460
461 /* Update the fc_host data structures with new wwn. */
462 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
463 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart21e9a0a2009-05-22 14:53:21 -0400464 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smarta257bf92009-04-06 18:48:10 -0400465
dea31012005-04-17 16:05:31 -0500466 /* If no serial number in VPD data, use low 6 bytes of WWNN */
467 /* This should be consolidated into parse_vpd ? - mr */
468 if (phba->SerialNumber[0] == 0) {
469 uint8_t *outptr;
470
James Smart2e0fef82007-06-17 19:56:36 -0500471 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500472 for (i = 0; i < 12; i++) {
473 status = *outptr++;
474 j = ((status & 0xf0) >> 4);
475 if (j <= 9)
476 phba->SerialNumber[i] =
477 (char)((uint8_t) 0x30 + (uint8_t) j);
478 else
479 phba->SerialNumber[i] =
480 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
481 i++;
482 j = (status & 0xf);
483 if (j <= 9)
484 phba->SerialNumber[i] =
485 (char)((uint8_t) 0x30 + (uint8_t) j);
486 else
487 phba->SerialNumber[i] =
488 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
489 }
490 }
491
dea31012005-04-17 16:05:31 -0500492 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500493 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500494 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500495 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400496 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500497 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500498 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500499 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500500 mempool_free( pmb, phba->mbox_mem_pool);
501 return -EIO;
502 }
503
James Smarta0c87cb2009-07-19 10:01:10 -0400504 /* Check if the port is disabled */
505 lpfc_sli_read_link_ste(phba);
506
dea31012005-04-17 16:05:31 -0500507 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -0400508 i = (mb->un.varRdConfig.max_xri + 1);
509 if (phba->cfg_hba_queue_depth > i) {
510 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
511 "3359 HBA queue depth changed from %d to %d\n",
512 phba->cfg_hba_queue_depth, i);
513 phba->cfg_hba_queue_depth = i;
514 }
515
516 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
517 i = (mb->un.varRdConfig.max_xri >> 3);
518 if (phba->pport->cfg_lun_queue_depth > i) {
519 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
520 "3360 LUN queue depth changed from %d to %d\n",
521 phba->pport->cfg_lun_queue_depth, i);
522 phba->pport->cfg_lun_queue_depth = i;
523 }
dea31012005-04-17 16:05:31 -0500524
525 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500526
527 /* Get the default values for Model Name and Description */
528 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
529
James Smart2e0fef82007-06-17 19:56:36 -0500530 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500531
James Smart0b727fe2007-10-27 13:37:25 -0400532 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smart895427b2017-02-12 13:52:30 -0800533 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
534 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
535 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
536 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500537
538 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500539 if (phba->sli_rev != 3)
540 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500541
James Smart93996272008-08-24 21:50:30 -0400542 /*
543 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
544 */
545 if (phba->intr_type == MSIX) {
546 rc = lpfc_config_msi(phba, pmb);
547 if (rc) {
548 mempool_free(pmb, phba->mbox_mem_pool);
549 return -EIO;
550 }
551 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
552 if (rc != MBX_SUCCESS) {
553 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
554 "0352 Config MSI mailbox command "
555 "failed, mbxCmd x%x, mbxStatus x%x\n",
James Smart04c68492009-05-22 14:52:52 -0400556 pmb->u.mb.mbxCommand,
557 pmb->u.mb.mbxStatus);
James Smart93996272008-08-24 21:50:30 -0400558 mempool_free(pmb, phba->mbox_mem_pool);
559 return -EIO;
560 }
561 }
562
James Smart04c68492009-05-22 14:52:52 -0400563 spin_lock_irq(&phba->hbalock);
James Smart93996272008-08-24 21:50:30 -0400564 /* Initialize ERATT handling flag */
565 phba->hba_flag &= ~HBA_ERATT_HANDLED;
566
dea31012005-04-17 16:05:31 -0500567 /* Enable appropriate host interrupts */
James Smart9940b972011-03-11 16:06:12 -0500568 if (lpfc_readl(phba->HCregaddr, &status)) {
569 spin_unlock_irq(&phba->hbalock);
570 return -EIO;
571 }
dea31012005-04-17 16:05:31 -0500572 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
573 if (psli->num_rings > 0)
574 status |= HC_R0INT_ENA;
575 if (psli->num_rings > 1)
576 status |= HC_R1INT_ENA;
577 if (psli->num_rings > 2)
578 status |= HC_R2INT_ENA;
579 if (psli->num_rings > 3)
580 status |= HC_R3INT_ENA;
581
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500582 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
583 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400584 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500585
dea31012005-04-17 16:05:31 -0500586 writel(status, phba->HCregaddr);
587 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500588 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500589
James Smart93996272008-08-24 21:50:30 -0400590 /* Set up ring-0 (ELS) timer */
591 timeout = phba->fc_ratov * 2;
James Smart256ec0d2013-04-17 20:14:58 -0400592 mod_timer(&vport->els_tmofunc,
593 jiffies + msecs_to_jiffies(1000 * timeout));
James Smart93996272008-08-24 21:50:30 -0400594 /* Set up heart beat (HB) timer */
James Smart256ec0d2013-04-17 20:14:58 -0400595 mod_timer(&phba->hb_tmofunc,
596 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -0500597 phba->hb_outstanding = 0;
598 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400599 /* Set up error attention (ERATT) polling timer */
James Smart256ec0d2013-04-17 20:14:58 -0400600 mod_timer(&phba->eratt_poll,
James Smart65791f12016-07-06 12:35:56 -0700601 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
dea31012005-04-17 16:05:31 -0500602
James Smarta0c87cb2009-07-19 10:01:10 -0400603 if (phba->hba_flag & LINK_DISABLED) {
604 lpfc_printf_log(phba,
605 KERN_ERR, LOG_INIT,
606 "2598 Adapter Link is disabled.\n");
607 lpfc_down_link(phba, pmb);
608 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
609 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
610 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
611 lpfc_printf_log(phba,
612 KERN_ERR, LOG_INIT,
613 "2599 Adapter failed to issue DOWN_LINK"
614 " mbox command rc 0x%x\n", rc);
615
616 mempool_free(pmb, phba->mbox_mem_pool);
617 return -EIO;
618 }
James Smarte40a02c2010-02-26 14:13:54 -0500619 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
James Smart026abb82011-12-13 13:20:45 -0500620 mempool_free(pmb, phba->mbox_mem_pool);
621 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
622 if (rc)
623 return rc;
dea31012005-04-17 16:05:31 -0500624 }
625 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400626 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500627 if (!pmb) {
628 phba->link_state = LPFC_HBA_ERROR;
629 return -ENOMEM;
630 }
631
James Smart57127f12007-10-27 13:37:05 -0400632 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
633 pmb->mbox_cmpl = lpfc_config_async_cmpl;
634 pmb->vport = phba->pport;
635 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500636
James Smart57127f12007-10-27 13:37:05 -0400637 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
638 lpfc_printf_log(phba,
639 KERN_ERR,
640 LOG_INIT,
641 "0456 Adapter failed to issue "
James Smarte4e74272009-07-19 10:01:38 -0400642 "ASYNCEVT_ENABLE mbox status x%x\n",
James Smart57127f12007-10-27 13:37:05 -0400643 rc);
644 mempool_free(pmb, phba->mbox_mem_pool);
645 }
James Smart97207482008-12-04 22:39:19 -0500646
647 /* Get Option rom version */
648 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500649 if (!pmb) {
650 phba->link_state = LPFC_HBA_ERROR;
651 return -ENOMEM;
652 }
653
James Smart97207482008-12-04 22:39:19 -0500654 lpfc_dump_wakeup_param(phba, pmb);
655 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
656 pmb->vport = phba->pport;
657 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
658
659 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
660 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
James Smarte4e74272009-07-19 10:01:38 -0400661 "to get Option ROM version status x%x\n", rc);
James Smart97207482008-12-04 22:39:19 -0500662 mempool_free(pmb, phba->mbox_mem_pool);
663 }
664
James Smartd7c255b2008-08-24 21:50:00 -0400665 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400666}
667
James Smarte59058c2008-08-24 21:49:00 -0400668/**
James Smart84d1b002010-02-12 14:42:33 -0500669 * lpfc_hba_init_link - Initialize the FC link
670 * @phba: pointer to lpfc hba data structure.
James Smart6e7288d2010-06-07 15:23:35 -0400671 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500672 *
673 * This routine will issue the INIT_LINK mailbox command call.
674 * It is available to other drivers through the lpfc_hba data
675 * structure for use as a delayed link up mechanism with the
676 * module parameter lpfc_suppress_link_up.
677 *
678 * Return code
679 * 0 - success
680 * Any other value - error
681 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400682static int
James Smart6e7288d2010-06-07 15:23:35 -0400683lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500684{
James Smart1b511972011-12-13 13:23:09 -0500685 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
686}
687
688/**
689 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
690 * @phba: pointer to lpfc hba data structure.
691 * @fc_topology: desired fc topology.
692 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
693 *
694 * This routine will issue the INIT_LINK mailbox command call.
695 * It is available to other drivers through the lpfc_hba data
696 * structure for use as a delayed link up mechanism with the
697 * module parameter lpfc_suppress_link_up.
698 *
699 * Return code
700 * 0 - success
701 * Any other value - error
702 **/
703int
704lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
705 uint32_t flag)
706{
James Smart84d1b002010-02-12 14:42:33 -0500707 struct lpfc_vport *vport = phba->pport;
708 LPFC_MBOXQ_t *pmb;
709 MAILBOX_t *mb;
710 int rc;
711
712 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
713 if (!pmb) {
714 phba->link_state = LPFC_HBA_ERROR;
715 return -ENOMEM;
716 }
717 mb = &pmb->u.mb;
718 pmb->vport = vport;
719
James Smart026abb82011-12-13 13:20:45 -0500720 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
721 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
722 !(phba->lmt & LMT_1Gb)) ||
723 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
724 !(phba->lmt & LMT_2Gb)) ||
725 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
726 !(phba->lmt & LMT_4Gb)) ||
727 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
728 !(phba->lmt & LMT_8Gb)) ||
729 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
730 !(phba->lmt & LMT_10Gb)) ||
731 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
James Smartd38dd522015-08-31 16:48:17 -0400732 !(phba->lmt & LMT_16Gb)) ||
733 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
James Smartfbd8a6b2018-02-22 08:18:45 -0800734 !(phba->lmt & LMT_32Gb)) ||
735 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) &&
736 !(phba->lmt & LMT_64Gb))) {
James Smart026abb82011-12-13 13:20:45 -0500737 /* Reset link speed to auto */
738 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
739 "1302 Invalid speed for this board:%d "
740 "Reset link speed to auto.\n",
741 phba->cfg_link_speed);
742 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
743 }
James Smart1b511972011-12-13 13:23:09 -0500744 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
James Smart84d1b002010-02-12 14:42:33 -0500745 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart1b511972011-12-13 13:23:09 -0500746 if (phba->sli_rev < LPFC_SLI_REV4)
747 lpfc_set_loopback_flag(phba);
James Smart6e7288d2010-06-07 15:23:35 -0400748 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart76a95d72010-11-20 23:11:48 -0500749 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
James Smart84d1b002010-02-12 14:42:33 -0500750 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
751 "0498 Adapter failed to init, mbxCmd x%x "
752 "INIT_LINK, mbxStatus x%x\n",
753 mb->mbxCommand, mb->mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -0500754 if (phba->sli_rev <= LPFC_SLI_REV3) {
755 /* Clear all interrupt enable conditions */
756 writel(0, phba->HCregaddr);
757 readl(phba->HCregaddr); /* flush */
758 /* Clear all pending interrupts */
759 writel(0xffffffff, phba->HAregaddr);
760 readl(phba->HAregaddr); /* flush */
761 }
James Smart84d1b002010-02-12 14:42:33 -0500762 phba->link_state = LPFC_HBA_ERROR;
James Smart6e7288d2010-06-07 15:23:35 -0400763 if (rc != MBX_BUSY || flag == MBX_POLL)
James Smart84d1b002010-02-12 14:42:33 -0500764 mempool_free(pmb, phba->mbox_mem_pool);
765 return -EIO;
766 }
James Smarte40a02c2010-02-26 14:13:54 -0500767 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
James Smart6e7288d2010-06-07 15:23:35 -0400768 if (flag == MBX_POLL)
769 mempool_free(pmb, phba->mbox_mem_pool);
James Smart84d1b002010-02-12 14:42:33 -0500770
771 return 0;
772}
773
774/**
775 * lpfc_hba_down_link - this routine downs the FC link
James Smart6e7288d2010-06-07 15:23:35 -0400776 * @phba: pointer to lpfc hba data structure.
777 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500778 *
779 * This routine will issue the DOWN_LINK mailbox command call.
780 * It is available to other drivers through the lpfc_hba data
781 * structure for use to stop the link.
782 *
783 * Return code
784 * 0 - success
785 * Any other value - error
786 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400787static int
James Smart6e7288d2010-06-07 15:23:35 -0400788lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500789{
790 LPFC_MBOXQ_t *pmb;
791 int rc;
792
793 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
794 if (!pmb) {
795 phba->link_state = LPFC_HBA_ERROR;
796 return -ENOMEM;
797 }
798
799 lpfc_printf_log(phba,
800 KERN_ERR, LOG_INIT,
801 "0491 Adapter Link is disabled.\n");
802 lpfc_down_link(phba, pmb);
803 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart6e7288d2010-06-07 15:23:35 -0400804 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart84d1b002010-02-12 14:42:33 -0500805 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
806 lpfc_printf_log(phba,
807 KERN_ERR, LOG_INIT,
808 "2522 Adapter failed to issue DOWN_LINK"
809 " mbox command rc 0x%x\n", rc);
810
811 mempool_free(pmb, phba->mbox_mem_pool);
812 return -EIO;
813 }
James Smart6e7288d2010-06-07 15:23:35 -0400814 if (flag == MBX_POLL)
815 mempool_free(pmb, phba->mbox_mem_pool);
816
James Smart84d1b002010-02-12 14:42:33 -0500817 return 0;
818}
819
820/**
James Smart3621a712009-04-06 18:47:14 -0400821 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400822 * @phba: pointer to lpfc HBA data structure.
823 *
824 * This routine will do LPFC uninitialization before the HBA is reset when
825 * bringing down the SLI Layer.
826 *
827 * Return codes
828 * 0 - success.
829 * Any other value - error.
830 **/
dea31012005-04-17 16:05:31 -0500831int
James Smart2e0fef82007-06-17 19:56:36 -0500832lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500833{
James Smart1b32f6a2008-02-08 18:49:39 -0500834 struct lpfc_vport **vports;
835 int i;
James Smart3772a992009-05-22 14:50:54 -0400836
837 if (phba->sli_rev <= LPFC_SLI_REV3) {
838 /* Disable interrupts */
839 writel(0, phba->HCregaddr);
840 readl(phba->HCregaddr); /* flush */
841 }
dea31012005-04-17 16:05:31 -0500842
James Smart1b32f6a2008-02-08 18:49:39 -0500843 if (phba->pport->load_flag & FC_UNLOADING)
844 lpfc_cleanup_discovery_resources(phba->pport);
845 else {
846 vports = lpfc_create_vport_work_array(phba);
847 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -0400848 for (i = 0; i <= phba->max_vports &&
849 vports[i] != NULL; i++)
James Smart1b32f6a2008-02-08 18:49:39 -0500850 lpfc_cleanup_discovery_resources(vports[i]);
851 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500852 }
853 return 0;
dea31012005-04-17 16:05:31 -0500854}
855
James Smarte59058c2008-08-24 21:49:00 -0400856/**
James Smart68e814f2014-05-21 08:04:59 -0400857 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
858 * rspiocb which got deferred
859 *
860 * @phba: pointer to lpfc HBA data structure.
861 *
862 * This routine will cleanup completed slow path events after HBA is reset
863 * when bringing down the SLI Layer.
864 *
865 *
866 * Return codes
867 * void.
868 **/
869static void
870lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
871{
872 struct lpfc_iocbq *rspiocbq;
873 struct hbq_dmabuf *dmabuf;
874 struct lpfc_cq_event *cq_event;
875
876 spin_lock_irq(&phba->hbalock);
877 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
878 spin_unlock_irq(&phba->hbalock);
879
880 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
881 /* Get the response iocb from the head of work queue */
882 spin_lock_irq(&phba->hbalock);
883 list_remove_head(&phba->sli4_hba.sp_queue_event,
884 cq_event, struct lpfc_cq_event, list);
885 spin_unlock_irq(&phba->hbalock);
886
887 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
888 case CQE_CODE_COMPL_WQE:
889 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
890 cq_event);
891 lpfc_sli_release_iocbq(phba, rspiocbq);
892 break;
893 case CQE_CODE_RECEIVE:
894 case CQE_CODE_RECEIVE_V1:
895 dmabuf = container_of(cq_event, struct hbq_dmabuf,
896 cq_event);
897 lpfc_in_buf_free(phba, &dmabuf->dbuf);
898 }
899 }
900}
901
902/**
James Smartbcece5f2014-04-04 13:51:34 -0400903 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
904 * @phba: pointer to lpfc HBA data structure.
905 *
906 * This routine will cleanup posted ELS buffers after the HBA is reset
907 * when bringing down the SLI Layer.
908 *
909 *
910 * Return codes
911 * void.
912 **/
913static void
914lpfc_hba_free_post_buf(struct lpfc_hba *phba)
915{
916 struct lpfc_sli *psli = &phba->sli;
917 struct lpfc_sli_ring *pring;
918 struct lpfc_dmabuf *mp, *next_mp;
James Smart07eab622014-04-04 13:51:44 -0400919 LIST_HEAD(buflist);
920 int count;
James Smartbcece5f2014-04-04 13:51:34 -0400921
922 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
923 lpfc_sli_hbqbuf_free_all(phba);
924 else {
925 /* Cleanup preposted buffers on the ELS ring */
James Smart895427b2017-02-12 13:52:30 -0800926 pring = &psli->sli3_ring[LPFC_ELS_RING];
James Smart07eab622014-04-04 13:51:44 -0400927 spin_lock_irq(&phba->hbalock);
928 list_splice_init(&pring->postbufq, &buflist);
929 spin_unlock_irq(&phba->hbalock);
930
931 count = 0;
932 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
James Smartbcece5f2014-04-04 13:51:34 -0400933 list_del(&mp->list);
James Smart07eab622014-04-04 13:51:44 -0400934 count++;
James Smartbcece5f2014-04-04 13:51:34 -0400935 lpfc_mbuf_free(phba, mp->virt, mp->phys);
936 kfree(mp);
937 }
James Smart07eab622014-04-04 13:51:44 -0400938
939 spin_lock_irq(&phba->hbalock);
940 pring->postbufq_cnt -= count;
James Smartbcece5f2014-04-04 13:51:34 -0400941 spin_unlock_irq(&phba->hbalock);
942 }
943}
944
945/**
946 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
947 * @phba: pointer to lpfc HBA data structure.
948 *
949 * This routine will cleanup the txcmplq after the HBA is reset when bringing
950 * down the SLI Layer.
951 *
952 * Return codes
953 * void
954 **/
955static void
956lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
957{
958 struct lpfc_sli *psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -0800959 struct lpfc_queue *qp = NULL;
James Smartbcece5f2014-04-04 13:51:34 -0400960 struct lpfc_sli_ring *pring;
961 LIST_HEAD(completions);
962 int i;
James Smartc1dd9112018-01-30 15:58:57 -0800963 struct lpfc_iocbq *piocb, *next_iocb;
James Smartbcece5f2014-04-04 13:51:34 -0400964
James Smart895427b2017-02-12 13:52:30 -0800965 if (phba->sli_rev != LPFC_SLI_REV4) {
966 for (i = 0; i < psli->num_rings; i++) {
967 pring = &psli->sli3_ring[i];
James Smartbcece5f2014-04-04 13:51:34 -0400968 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -0800969 /* At this point in time the HBA is either reset or DOA
970 * Nothing should be on txcmplq as it will
971 * NEVER complete.
972 */
973 list_splice_init(&pring->txcmplq, &completions);
974 pring->txcmplq_cnt = 0;
James Smartbcece5f2014-04-04 13:51:34 -0400975 spin_unlock_irq(&phba->hbalock);
976
James Smart895427b2017-02-12 13:52:30 -0800977 lpfc_sli_abort_iocb_ring(phba, pring);
978 }
James Smartbcece5f2014-04-04 13:51:34 -0400979 /* Cancel all the IOCBs from the completions list */
James Smart895427b2017-02-12 13:52:30 -0800980 lpfc_sli_cancel_iocbs(phba, &completions,
981 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
982 return;
983 }
984 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
985 pring = qp->pring;
986 if (!pring)
987 continue;
988 spin_lock_irq(&pring->ring_lock);
James Smartc1dd9112018-01-30 15:58:57 -0800989 list_for_each_entry_safe(piocb, next_iocb,
990 &pring->txcmplq, list)
991 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
James Smart895427b2017-02-12 13:52:30 -0800992 list_splice_init(&pring->txcmplq, &completions);
993 pring->txcmplq_cnt = 0;
994 spin_unlock_irq(&pring->ring_lock);
James Smartbcece5f2014-04-04 13:51:34 -0400995 lpfc_sli_abort_iocb_ring(phba, pring);
996 }
James Smart895427b2017-02-12 13:52:30 -0800997 /* Cancel all the IOCBs from the completions list */
998 lpfc_sli_cancel_iocbs(phba, &completions,
999 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smartbcece5f2014-04-04 13:51:34 -04001000}
1001
1002/**
James Smart3772a992009-05-22 14:50:54 -04001003 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smartbcece5f2014-04-04 13:51:34 -04001004 int i;
James Smarte59058c2008-08-24 21:49:00 -04001005 * @phba: pointer to lpfc HBA data structure.
1006 *
1007 * This routine will do uninitialization after the HBA is reset when bring
1008 * down the SLI Layer.
1009 *
1010 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001011 * 0 - success.
James Smarte59058c2008-08-24 21:49:00 -04001012 * Any other value - error.
1013 **/
James Smart3772a992009-05-22 14:50:54 -04001014static int
1015lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001016{
James Smartbcece5f2014-04-04 13:51:34 -04001017 lpfc_hba_free_post_buf(phba);
1018 lpfc_hba_clean_txcmplq(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001019 return 0;
1020}
James Smart5af5eee2010-10-22 11:06:38 -04001021
James Smartda0436e2009-05-22 14:51:39 -04001022/**
1023 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
1024 * @phba: pointer to lpfc HBA data structure.
1025 *
1026 * This routine will do uninitialization after the HBA is reset when bring
1027 * down the SLI Layer.
1028 *
1029 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001030 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001031 * Any other value - error.
1032 **/
1033static int
1034lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1035{
1036 struct lpfc_scsi_buf *psb, *psb_next;
James Smart86c67372017-04-21 16:05:04 -07001037 struct lpfc_nvmet_rcv_ctx *ctxp, *ctxp_next;
James Smartda0436e2009-05-22 14:51:39 -04001038 LIST_HEAD(aborts);
James Smart895427b2017-02-12 13:52:30 -08001039 LIST_HEAD(nvme_aborts);
James Smart86c67372017-04-21 16:05:04 -07001040 LIST_HEAD(nvmet_aborts);
James Smartda0436e2009-05-22 14:51:39 -04001041 unsigned long iflag = 0;
James Smart0f65ff62010-02-26 14:14:23 -05001042 struct lpfc_sglq *sglq_entry = NULL;
James Smartcf1a1d32017-12-08 17:18:03 -08001043 int cnt;
James Smart0f65ff62010-02-26 14:14:23 -05001044
James Smart895427b2017-02-12 13:52:30 -08001045
1046 lpfc_sli_hbqbuf_free_all(phba);
James Smartbcece5f2014-04-04 13:51:34 -04001047 lpfc_hba_clean_txcmplq(phba);
1048
James Smartda0436e2009-05-22 14:51:39 -04001049 /* At this point in time the HBA is either reset or DOA. Either
1050 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
James Smart895427b2017-02-12 13:52:30 -08001051 * on the lpfc_els_sgl_list so that it can either be freed if the
James Smartda0436e2009-05-22 14:51:39 -04001052 * driver is unloading or reposted if the driver is restarting
1053 * the port.
1054 */
James Smart895427b2017-02-12 13:52:30 -08001055 spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */
James Smartda0436e2009-05-22 14:51:39 -04001056 /* scsl_buf_list */
James Smart895427b2017-02-12 13:52:30 -08001057 /* sgl_list_lock required because worker thread uses this
James Smartda0436e2009-05-22 14:51:39 -04001058 * list.
1059 */
James Smart895427b2017-02-12 13:52:30 -08001060 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05001061 list_for_each_entry(sglq_entry,
1062 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1063 sglq_entry->state = SGL_FREED;
1064
James Smartda0436e2009-05-22 14:51:39 -04001065 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
James Smart895427b2017-02-12 13:52:30 -08001066 &phba->sli4_hba.lpfc_els_sgl_list);
1067
James Smartf358dd02017-02-12 13:52:34 -08001068
James Smart895427b2017-02-12 13:52:30 -08001069 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04001070 /* abts_scsi_buf_list_lock required because worker thread uses this
1071 * list.
1072 */
James Smart895427b2017-02-12 13:52:30 -08001073 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
1074 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1075 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
1076 &aborts);
1077 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1078 }
1079
1080 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1081 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1082 list_splice_init(&phba->sli4_hba.lpfc_abts_nvme_buf_list,
1083 &nvme_aborts);
James Smart86c67372017-04-21 16:05:04 -07001084 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1085 &nvmet_aborts);
James Smart895427b2017-02-12 13:52:30 -08001086 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1087 }
1088
James Smartda0436e2009-05-22 14:51:39 -04001089 spin_unlock_irq(&phba->hbalock);
1090
1091 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1092 psb->pCmd = NULL;
1093 psb->status = IOSTAT_SUCCESS;
1094 }
James Smarta40fc5f2013-04-17 20:17:40 -04001095 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1096 list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
1097 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
James Smart68e814f2014-05-21 08:04:59 -04001098
James Smart86c67372017-04-21 16:05:04 -07001099 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smartcf1a1d32017-12-08 17:18:03 -08001100 cnt = 0;
James Smart86c67372017-04-21 16:05:04 -07001101 list_for_each_entry_safe(psb, psb_next, &nvme_aborts, list) {
1102 psb->pCmd = NULL;
1103 psb->status = IOSTAT_SUCCESS;
James Smartcf1a1d32017-12-08 17:18:03 -08001104 cnt++;
James Smart86c67372017-04-21 16:05:04 -07001105 }
1106 spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag);
James Smartcf1a1d32017-12-08 17:18:03 -08001107 phba->put_nvme_bufs += cnt;
James Smart86c67372017-04-21 16:05:04 -07001108 list_splice(&nvme_aborts, &phba->lpfc_nvme_buf_list_put);
1109 spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag);
1110
1111 list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) {
1112 ctxp->flag &= ~(LPFC_NVMET_XBUSY | LPFC_NVMET_ABORT_OP);
James Smart6c621a22017-05-15 15:20:45 -07001113 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
James Smart86c67372017-04-21 16:05:04 -07001114 }
James Smart895427b2017-02-12 13:52:30 -08001115 }
James Smart895427b2017-02-12 13:52:30 -08001116
James Smart68e814f2014-05-21 08:04:59 -04001117 lpfc_sli4_free_sp_events(phba);
James Smartda0436e2009-05-22 14:51:39 -04001118 return 0;
1119}
1120
1121/**
1122 * lpfc_hba_down_post - Wrapper func for hba down post routine
1123 * @phba: pointer to lpfc HBA data structure.
1124 *
1125 * This routine wraps the actual SLI3 or SLI4 routine for performing
1126 * uninitialization after the HBA is reset when bring down the SLI Layer.
1127 *
1128 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001129 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001130 * Any other value - error.
1131 **/
1132int
1133lpfc_hba_down_post(struct lpfc_hba *phba)
1134{
1135 return (*phba->lpfc_hba_down_post)(phba);
1136}
Jamie Wellnitz41415862006-02-28 19:25:27 -05001137
James Smarte59058c2008-08-24 21:49:00 -04001138/**
James Smart3621a712009-04-06 18:47:14 -04001139 * lpfc_hb_timeout - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001140 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1141 *
1142 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1143 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1144 * work-port-events bitmap and the worker thread is notified. This timeout
1145 * event will be used by the worker thread to invoke the actual timeout
1146 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1147 * be performed in the timeout handler and the HBA timeout event bit shall
1148 * be cleared by the worker thread after it has taken the event bitmap out.
1149 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001150static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07001151lpfc_hb_timeout(struct timer_list *t)
James Smart858c9f62007-06-17 19:56:39 -05001152{
1153 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001154 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -05001155 unsigned long iflag;
1156
Kees Cookf22eb4d2017-09-06 20:24:26 -07001157 phba = from_timer(phba, t, hb_tmofunc);
James Smart93996272008-08-24 21:50:30 -04001158
1159 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -05001160 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001161 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1162 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -05001163 phba->pport->work_port_events |= WORKER_HB_TMO;
1164 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1165
James Smart93996272008-08-24 21:50:30 -04001166 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -04001167 if (!tmo_posted)
1168 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -05001169 return;
1170}
1171
James Smarte59058c2008-08-24 21:49:00 -04001172/**
James Smart19ca7602010-11-20 23:11:55 -05001173 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1174 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1175 *
1176 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1177 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1178 * work-port-events bitmap and the worker thread is notified. This timeout
1179 * event will be used by the worker thread to invoke the actual timeout
1180 * handler routine, lpfc_rrq_handler. Any periodical operations will
1181 * be performed in the timeout handler and the RRQ timeout event bit shall
1182 * be cleared by the worker thread after it has taken the event bitmap out.
1183 **/
1184static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07001185lpfc_rrq_timeout(struct timer_list *t)
James Smart19ca7602010-11-20 23:11:55 -05001186{
1187 struct lpfc_hba *phba;
James Smart19ca7602010-11-20 23:11:55 -05001188 unsigned long iflag;
1189
Kees Cookf22eb4d2017-09-06 20:24:26 -07001190 phba = from_timer(phba, t, rrq_tmr);
James Smart19ca7602010-11-20 23:11:55 -05001191 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001192 if (!(phba->pport->load_flag & FC_UNLOADING))
1193 phba->hba_flag |= HBA_RRQ_ACTIVE;
1194 else
1195 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
James Smart19ca7602010-11-20 23:11:55 -05001196 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001197
1198 if (!(phba->pport->load_flag & FC_UNLOADING))
1199 lpfc_worker_wake_up(phba);
James Smart19ca7602010-11-20 23:11:55 -05001200}
1201
1202/**
James Smart3621a712009-04-06 18:47:14 -04001203 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -04001204 * @phba: pointer to lpfc hba data structure.
1205 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1206 *
1207 * This is the callback function to the lpfc heart-beat mailbox command.
1208 * If configured, the lpfc driver issues the heart-beat mailbox command to
1209 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1210 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1211 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1212 * heart-beat outstanding state. Once the mailbox command comes back and
1213 * no error conditions detected, the heart-beat mailbox command timer is
1214 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1215 * state is cleared for the next heart-beat. If the timer expired with the
1216 * heart-beat outstanding state set, the driver will put the HBA offline.
1217 **/
James Smart858c9f62007-06-17 19:56:39 -05001218static void
1219lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1220{
1221 unsigned long drvr_flag;
1222
1223 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1224 phba->hb_outstanding = 0;
1225 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1226
James Smart93996272008-08-24 21:50:30 -04001227 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -05001228 mempool_free(pmboxq, phba->mbox_mem_pool);
1229 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1230 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -04001231 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -05001232 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001233 jiffies +
1234 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001235 return;
1236}
1237
James Smarte59058c2008-08-24 21:49:00 -04001238/**
James Smart3621a712009-04-06 18:47:14 -04001239 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001240 * @phba: pointer to lpfc hba data structure.
1241 *
1242 * This is the actual HBA-timer timeout handler to be invoked by the worker
1243 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1244 * handler performs any periodic operations needed for the device. If such
1245 * periodic event has already been attended to either in the interrupt handler
1246 * or by processing slow-ring or fast-ring events within the HBA-timer
1247 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1248 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1249 * is configured and there is no heart-beat mailbox command outstanding, a
1250 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1251 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1252 * to offline.
1253 **/
James Smart858c9f62007-06-17 19:56:39 -05001254void
1255lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1256{
James Smart45ed1192009-10-02 15:17:02 -04001257 struct lpfc_vport **vports;
James Smart858c9f62007-06-17 19:56:39 -05001258 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -05001259 struct lpfc_dmabuf *buf_ptr;
James Smart45ed1192009-10-02 15:17:02 -04001260 int retval, i;
James Smart858c9f62007-06-17 19:56:39 -05001261 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -05001262 LIST_HEAD(completions);
James Smart0cf07f842017-06-01 21:07:10 -07001263 struct lpfc_queue *qp;
1264 unsigned long time_elapsed;
1265 uint32_t tick_cqe, max_cqe, val;
1266 uint64_t tot, data1, data2, data3;
Dick Kennedy66d7ce92017-08-23 16:55:42 -07001267 struct lpfc_nvmet_tgtport *tgtp;
James Smart0cf07f842017-06-01 21:07:10 -07001268 struct lpfc_register reg_data;
James Smart66a210f2018-04-09 14:24:23 -07001269 struct nvme_fc_local_port *localport;
1270 struct lpfc_nvme_lport *lport;
1271 struct lpfc_nvme_ctrl_stat *cstat;
James Smart0cf07f842017-06-01 21:07:10 -07001272 void __iomem *eqdreg = phba->sli4_hba.u.if_type2.EQDregaddr;
James Smart858c9f62007-06-17 19:56:39 -05001273
James Smart45ed1192009-10-02 15:17:02 -04001274 vports = lpfc_create_vport_work_array(phba);
1275 if (vports != NULL)
James Smart4258e982015-12-16 18:11:58 -05001276 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart45ed1192009-10-02 15:17:02 -04001277 lpfc_rcv_seq_check_edtov(vports[i]);
James Smart4258e982015-12-16 18:11:58 -05001278 lpfc_fdmi_num_disc_check(vports[i]);
1279 }
James Smart45ed1192009-10-02 15:17:02 -04001280 lpfc_destroy_vport_work_array(phba, vports);
1281
James Smart858c9f62007-06-17 19:56:39 -05001282 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -04001283 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -05001284 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1285 return;
1286
James Smart0cf07f842017-06-01 21:07:10 -07001287 if (phba->cfg_auto_imax) {
1288 if (!phba->last_eqdelay_time) {
1289 phba->last_eqdelay_time = jiffies;
1290 goto skip_eqdelay;
1291 }
1292 time_elapsed = jiffies - phba->last_eqdelay_time;
1293 phba->last_eqdelay_time = jiffies;
1294
1295 tot = 0xffff;
1296 /* Check outstanding IO count */
1297 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1298 if (phba->nvmet_support) {
Dick Kennedy66d7ce92017-08-23 16:55:42 -07001299 tgtp = phba->targetport->private;
1300 /* Calculate outstanding IOs */
1301 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
1302 tot += atomic_read(&tgtp->xmt_fcp_release);
1303 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
James Smart0cf07f842017-06-01 21:07:10 -07001304 } else {
James Smart66a210f2018-04-09 14:24:23 -07001305 localport = phba->pport->localport;
1306 if (!localport || !localport->private)
1307 goto skip_eqdelay;
1308 lport = (struct lpfc_nvme_lport *)
1309 localport->private;
1310 tot = 0;
1311 for (i = 0;
1312 i < phba->cfg_nvme_io_channel; i++) {
1313 cstat = &lport->cstat[i];
1314 data1 = atomic_read(
1315 &cstat->fc4NvmeInputRequests);
1316 data2 = atomic_read(
1317 &cstat->fc4NvmeOutputRequests);
1318 data3 = atomic_read(
1319 &cstat->fc4NvmeControlRequests);
1320 tot += (data1 + data2 + data3);
1321 tot -= atomic_read(
1322 &cstat->fc4NvmeIoCmpls);
1323 }
James Smart0cf07f842017-06-01 21:07:10 -07001324 }
1325 }
1326
1327 /* Interrupts per sec per EQ */
1328 val = phba->cfg_fcp_imax / phba->io_channel_irqs;
1329 tick_cqe = val / CONFIG_HZ; /* Per tick per EQ */
1330
1331 /* Assume 1 CQE/ISR, calc max CQEs allowed for time duration */
1332 max_cqe = time_elapsed * tick_cqe;
1333
1334 for (i = 0; i < phba->io_channel_irqs; i++) {
1335 /* Fast-path EQ */
1336 qp = phba->sli4_hba.hba_eq[i];
1337 if (!qp)
1338 continue;
1339
1340 /* Use no EQ delay if we don't have many outstanding
1341 * IOs, or if we are only processing 1 CQE/ISR or less.
1342 * Otherwise, assume we can process up to lpfc_fcp_imax
1343 * interrupts per HBA.
1344 */
1345 if (tot < LPFC_NODELAY_MAX_IO ||
1346 qp->EQ_cqe_cnt <= max_cqe)
1347 val = 0;
1348 else
1349 val = phba->cfg_fcp_imax;
1350
1351 if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) {
1352 /* Use EQ Delay Register method */
1353
1354 /* Convert for EQ Delay register */
1355 if (val) {
1356 /* First, interrupts per sec per EQ */
1357 val = phba->cfg_fcp_imax /
1358 phba->io_channel_irqs;
1359
1360 /* us delay between each interrupt */
1361 val = LPFC_SEC_TO_USEC / val;
1362 }
1363 if (val != qp->q_mode) {
1364 reg_data.word0 = 0;
1365 bf_set(lpfc_sliport_eqdelay_id,
1366 &reg_data, qp->queue_id);
1367 bf_set(lpfc_sliport_eqdelay_delay,
1368 &reg_data, val);
1369 writel(reg_data.word0, eqdreg);
1370 }
1371 } else {
1372 /* Use mbox command method */
1373 if (val != qp->q_mode)
1374 lpfc_modify_hba_eq_delay(phba, i,
1375 1, val);
1376 }
1377
1378 /*
1379 * val is cfg_fcp_imax or 0 for mbox delay or us delay
1380 * between interrupts for EQDR.
1381 */
1382 qp->q_mode = val;
1383 qp->EQ_cqe_cnt = 0;
1384 }
1385 }
1386
1387skip_eqdelay:
James Smart858c9f62007-06-17 19:56:39 -05001388 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -05001389
James Smart256ec0d2013-04-17 20:14:58 -04001390 if (time_after(phba->last_completion_time +
1391 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1392 jiffies)) {
James Smart858c9f62007-06-17 19:56:39 -05001393 spin_unlock_irq(&phba->pport->work_port_lock);
1394 if (!phba->hb_outstanding)
1395 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001396 jiffies +
1397 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001398 else
1399 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001400 jiffies +
1401 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001402 return;
1403 }
1404 spin_unlock_irq(&phba->pport->work_port_lock);
1405
James Smart0ff10d42008-01-11 01:52:36 -05001406 if (phba->elsbuf_cnt &&
1407 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1408 spin_lock_irq(&phba->hbalock);
1409 list_splice_init(&phba->elsbuf, &completions);
1410 phba->elsbuf_cnt = 0;
1411 phba->elsbuf_prev_cnt = 0;
1412 spin_unlock_irq(&phba->hbalock);
1413
1414 while (!list_empty(&completions)) {
1415 list_remove_head(&completions, buf_ptr,
1416 struct lpfc_dmabuf, list);
1417 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1418 kfree(buf_ptr);
1419 }
1420 }
1421 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1422
James Smart858c9f62007-06-17 19:56:39 -05001423 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -05001424 if (phba->cfg_enable_hba_heartbeat) {
1425 if (!phba->hb_outstanding) {
James Smartbc739052010-08-04 16:11:18 -04001426 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1427 (list_empty(&psli->mboxq))) {
1428 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1429 GFP_KERNEL);
1430 if (!pmboxq) {
1431 mod_timer(&phba->hb_tmofunc,
1432 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001433 msecs_to_jiffies(1000 *
1434 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001435 return;
1436 }
James Smart13815c82008-01-11 01:52:48 -05001437
James Smartbc739052010-08-04 16:11:18 -04001438 lpfc_heart_beat(phba, pmboxq);
1439 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1440 pmboxq->vport = phba->pport;
1441 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1442 MBX_NOWAIT);
James Smart13815c82008-01-11 01:52:48 -05001443
James Smartbc739052010-08-04 16:11:18 -04001444 if (retval != MBX_BUSY &&
1445 retval != MBX_SUCCESS) {
1446 mempool_free(pmboxq,
1447 phba->mbox_mem_pool);
1448 mod_timer(&phba->hb_tmofunc,
1449 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001450 msecs_to_jiffies(1000 *
1451 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001452 return;
1453 }
1454 phba->skipped_hb = 0;
1455 phba->hb_outstanding = 1;
1456 } else if (time_before_eq(phba->last_completion_time,
1457 phba->skipped_hb)) {
1458 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1459 "2857 Last completion time not "
1460 " updated in %d ms\n",
1461 jiffies_to_msecs(jiffies
1462 - phba->last_completion_time));
1463 } else
1464 phba->skipped_hb = jiffies;
1465
James Smart858c9f62007-06-17 19:56:39 -05001466 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001467 jiffies +
1468 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001469 return;
James Smart13815c82008-01-11 01:52:48 -05001470 } else {
1471 /*
1472 * If heart beat timeout called with hb_outstanding set
James Smartdcf2a4e2010-09-29 11:18:53 -04001473 * we need to give the hb mailbox cmd a chance to
1474 * complete or TMO.
James Smart13815c82008-01-11 01:52:48 -05001475 */
James Smartdcf2a4e2010-09-29 11:18:53 -04001476 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1477 "0459 Adapter heartbeat still out"
1478 "standing:last compl time was %d ms.\n",
1479 jiffies_to_msecs(jiffies
1480 - phba->last_completion_time));
1481 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001482 jiffies +
1483 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001484 }
James Smart4258e982015-12-16 18:11:58 -05001485 } else {
1486 mod_timer(&phba->hb_tmofunc,
1487 jiffies +
1488 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001489 }
1490}
1491
James Smarte59058c2008-08-24 21:49:00 -04001492/**
James Smart3621a712009-04-06 18:47:14 -04001493 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -04001494 * @phba: pointer to lpfc hba data structure.
1495 *
1496 * This routine is called to bring the HBA offline when HBA hardware error
1497 * other than Port Error 6 has been detected.
1498 **/
James Smart09372822008-01-11 01:52:54 -05001499static void
1500lpfc_offline_eratt(struct lpfc_hba *phba)
1501{
1502 struct lpfc_sli *psli = &phba->sli;
1503
1504 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001505 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -05001506 spin_unlock_irq(&phba->hbalock);
James Smart618a5232012-06-12 13:54:36 -04001507 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart09372822008-01-11 01:52:54 -05001508
1509 lpfc_offline(phba);
1510 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001511 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001512 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001513 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001514 lpfc_hba_down_post(phba);
1515 lpfc_sli_brdready(phba, HS_MBRDY);
1516 lpfc_unblock_mgmt_io(phba);
1517 phba->link_state = LPFC_HBA_ERROR;
1518 return;
1519}
1520
James Smarte59058c2008-08-24 21:49:00 -04001521/**
James Smartda0436e2009-05-22 14:51:39 -04001522 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1523 * @phba: pointer to lpfc hba data structure.
1524 *
1525 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1526 * other than Port Error 6 has been detected.
1527 **/
James Smarta88dbb62013-04-17 20:18:39 -04001528void
James Smartda0436e2009-05-22 14:51:39 -04001529lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1530{
James Smart946727d2015-04-07 15:07:09 -04001531 spin_lock_irq(&phba->hbalock);
1532 phba->link_state = LPFC_HBA_ERROR;
1533 spin_unlock_irq(&phba->hbalock);
1534
James Smart618a5232012-06-12 13:54:36 -04001535 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smartda0436e2009-05-22 14:51:39 -04001536 lpfc_offline(phba);
James Smartda0436e2009-05-22 14:51:39 -04001537 lpfc_hba_down_post(phba);
James Smartda0436e2009-05-22 14:51:39 -04001538 lpfc_unblock_mgmt_io(phba);
James Smartda0436e2009-05-22 14:51:39 -04001539}
1540
1541/**
James Smarta257bf92009-04-06 18:48:10 -04001542 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1543 * @phba: pointer to lpfc hba data structure.
1544 *
1545 * This routine is invoked to handle the deferred HBA hardware error
1546 * conditions. This type of error is indicated by HBA by setting ER1
1547 * and another ER bit in the host status register. The driver will
1548 * wait until the ER1 bit clears before handling the error condition.
1549 **/
1550static void
1551lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1552{
1553 uint32_t old_host_status = phba->work_hs;
James Smarta257bf92009-04-06 18:48:10 -04001554 struct lpfc_sli *psli = &phba->sli;
1555
James Smartf4b4c682009-05-22 14:53:12 -04001556 /* If the pci channel is offline, ignore possible errors,
1557 * since we cannot communicate with the pci card anyway.
1558 */
1559 if (pci_channel_offline(phba->pcidev)) {
1560 spin_lock_irq(&phba->hbalock);
1561 phba->hba_flag &= ~DEFER_ERATT;
1562 spin_unlock_irq(&phba->hbalock);
1563 return;
1564 }
1565
James Smarta257bf92009-04-06 18:48:10 -04001566 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1567 "0479 Deferred Adapter Hardware Error "
1568 "Data: x%x x%x x%x\n",
1569 phba->work_hs,
1570 phba->work_status[0], phba->work_status[1]);
1571
1572 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001573 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001574 spin_unlock_irq(&phba->hbalock);
1575
1576
1577 /*
1578 * Firmware stops when it triggred erratt. That could cause the I/Os
1579 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1580 * SCSI layer retry it after re-establishing link.
1581 */
James Smartdb55fba2014-04-04 13:52:02 -04001582 lpfc_sli_abort_fcp_rings(phba);
James Smarta257bf92009-04-06 18:48:10 -04001583
1584 /*
1585 * There was a firmware error. Take the hba offline and then
1586 * attempt to restart it.
1587 */
James Smart618a5232012-06-12 13:54:36 -04001588 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smarta257bf92009-04-06 18:48:10 -04001589 lpfc_offline(phba);
1590
1591 /* Wait for the ER1 bit to clear.*/
1592 while (phba->work_hs & HS_FFER1) {
1593 msleep(100);
James Smart9940b972011-03-11 16:06:12 -05001594 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1595 phba->work_hs = UNPLUG_ERR ;
1596 break;
1597 }
James Smarta257bf92009-04-06 18:48:10 -04001598 /* If driver is unloading let the worker thread continue */
1599 if (phba->pport->load_flag & FC_UNLOADING) {
1600 phba->work_hs = 0;
1601 break;
1602 }
1603 }
1604
1605 /*
1606 * This is to ptrotect against a race condition in which
1607 * first write to the host attention register clear the
1608 * host status register.
1609 */
1610 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1611 phba->work_hs = old_host_status & ~HS_FFER1;
1612
James Smart3772a992009-05-22 14:50:54 -04001613 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001614 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001615 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001616 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1617 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1618}
1619
James Smart3772a992009-05-22 14:50:54 -04001620static void
1621lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1622{
1623 struct lpfc_board_event_header board_event;
1624 struct Scsi_Host *shost;
1625
1626 board_event.event_type = FC_REG_BOARD_EVENT;
1627 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1628 shost = lpfc_shost_from_vport(phba->pport);
1629 fc_host_post_vendor_event(shost, fc_get_event_number(),
1630 sizeof(board_event),
1631 (char *) &board_event,
1632 LPFC_NL_VENDOR_ID);
1633}
1634
James Smarta257bf92009-04-06 18:48:10 -04001635/**
James Smart3772a992009-05-22 14:50:54 -04001636 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001637 * @phba: pointer to lpfc hba data structure.
1638 *
1639 * This routine is invoked to handle the following HBA hardware error
1640 * conditions:
1641 * 1 - HBA error attention interrupt
1642 * 2 - DMA ring index out of range
1643 * 3 - Mailbox command came back as unknown
1644 **/
James Smart3772a992009-05-22 14:50:54 -04001645static void
1646lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001647{
James Smart2e0fef82007-06-17 19:56:36 -05001648 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001649 struct lpfc_sli *psli = &phba->sli;
James Smartd2873e42006-08-18 17:46:43 -04001650 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001651 unsigned long temperature;
1652 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001653 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001654
Linas Vepstas8d63f372007-02-14 14:28:36 -06001655 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001656 * since we cannot communicate with the pci card anyway.
1657 */
1658 if (pci_channel_offline(phba->pcidev)) {
1659 spin_lock_irq(&phba->hbalock);
1660 phba->hba_flag &= ~DEFER_ERATT;
1661 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001662 return;
James Smart3772a992009-05-22 14:50:54 -04001663 }
1664
James Smart13815c82008-01-11 01:52:48 -05001665 /* If resets are disabled then leave the HBA alone and return */
1666 if (!phba->cfg_enable_hba_reset)
1667 return;
dea31012005-04-17 16:05:31 -05001668
James Smartea2151b2008-09-07 11:52:10 -04001669 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001670 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001671
James Smarta257bf92009-04-06 18:48:10 -04001672 if (phba->hba_flag & DEFER_ERATT)
1673 lpfc_handle_deferred_eratt(phba);
1674
James Smartdcf2a4e2010-09-29 11:18:53 -04001675 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1676 if (phba->work_hs & HS_FFER6)
1677 /* Re-establishing Link */
1678 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1679 "1301 Re-establishing Link "
1680 "Data: x%x x%x x%x\n",
1681 phba->work_hs, phba->work_status[0],
1682 phba->work_status[1]);
1683 if (phba->work_hs & HS_FFER8)
1684 /* Device Zeroization */
1685 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1686 "2861 Host Authentication device "
1687 "zeroization Data:x%x x%x x%x\n",
1688 phba->work_hs, phba->work_status[0],
1689 phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001690
James Smart92d7f7b2007-06-17 19:56:38 -05001691 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001692 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001693 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001694
1695 /*
1696 * Firmware stops when it triggled erratt with HS_FFER6.
1697 * That could cause the I/Os dropped by the firmware.
1698 * Error iocb (I/O) on txcmplq and let the SCSI layer
1699 * retry it after re-establishing link.
1700 */
James Smartdb55fba2014-04-04 13:52:02 -04001701 lpfc_sli_abort_fcp_rings(phba);
dea31012005-04-17 16:05:31 -05001702
dea31012005-04-17 16:05:31 -05001703 /*
1704 * There was a firmware error. Take the hba offline and then
1705 * attempt to restart it.
1706 */
James Smart618a5232012-06-12 13:54:36 -04001707 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
dea31012005-04-17 16:05:31 -05001708 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001709 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001710 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001711 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001712 return;
1713 }
James Smart46fa3112007-04-25 09:51:45 -04001714 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001715 } else if (phba->work_hs & HS_CRIT_TEMP) {
1716 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1717 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1718 temp_event_data.event_code = LPFC_CRIT_TEMP;
1719 temp_event_data.data = (uint32_t)temperature;
1720
1721 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001722 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001723 "(%ld), taking this port offline "
1724 "Data: x%x x%x x%x\n",
1725 temperature, phba->work_hs,
1726 phba->work_status[0], phba->work_status[1]);
1727
1728 shost = lpfc_shost_from_vport(phba->pport);
1729 fc_host_post_vendor_event(shost, fc_get_event_number(),
1730 sizeof(temp_event_data),
1731 (char *) &temp_event_data,
1732 SCSI_NL_VID_TYPE_PCI
1733 | PCI_VENDOR_ID_EMULEX);
1734
James Smart7af67052007-10-27 13:38:11 -04001735 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001736 phba->over_temp_state = HBA_OVER_TEMP;
1737 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001738 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001739
dea31012005-04-17 16:05:31 -05001740 } else {
1741 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001742 * failure is a value other than FFER6. Do not call the offline
1743 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001744 */
1745 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001746 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001747 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001748 phba->work_hs,
dea31012005-04-17 16:05:31 -05001749 phba->work_status[0], phba->work_status[1]);
1750
James Smartd2873e42006-08-18 17:46:43 -04001751 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001752 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001753 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001754 sizeof(event_data), (char *) &event_data,
1755 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1756
James Smart09372822008-01-11 01:52:54 -05001757 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001758 }
James Smart93996272008-08-24 21:50:30 -04001759 return;
dea31012005-04-17 16:05:31 -05001760}
1761
James Smarte59058c2008-08-24 21:49:00 -04001762/**
James Smart618a5232012-06-12 13:54:36 -04001763 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1764 * @phba: pointer to lpfc hba data structure.
1765 * @mbx_action: flag for mailbox shutdown action.
1766 *
1767 * This routine is invoked to perform an SLI4 port PCI function reset in
1768 * response to port status register polling attention. It waits for port
1769 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1770 * During this process, interrupt vectors are freed and later requested
1771 * for handling possible port resource change.
1772 **/
1773static int
James Smarte10b2022014-02-20 09:57:43 -05001774lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1775 bool en_rn_msg)
James Smart618a5232012-06-12 13:54:36 -04001776{
1777 int rc;
1778 uint32_t intr_mode;
1779
James Smart27d6ac02018-02-22 08:18:42 -08001780 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
James Smart65791f12016-07-06 12:35:56 -07001781 LPFC_SLI_INTF_IF_TYPE_2) {
1782 /*
1783 * On error status condition, driver need to wait for port
1784 * ready before performing reset.
1785 */
1786 rc = lpfc_sli4_pdev_status_reg_wait(phba);
James Smart0e916ee2016-07-06 12:36:06 -07001787 if (rc)
James Smart65791f12016-07-06 12:35:56 -07001788 return rc;
James Smart618a5232012-06-12 13:54:36 -04001789 }
James Smart0e916ee2016-07-06 12:36:06 -07001790
James Smart65791f12016-07-06 12:35:56 -07001791 /* need reset: attempt for port recovery */
1792 if (en_rn_msg)
1793 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1794 "2887 Reset Needed: Attempting Port "
1795 "Recovery...\n");
1796 lpfc_offline_prep(phba, mbx_action);
1797 lpfc_offline(phba);
1798 /* release interrupt for possible resource change */
1799 lpfc_sli4_disable_intr(phba);
1800 lpfc_sli_brdrestart(phba);
1801 /* request and enable interrupt */
1802 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1803 if (intr_mode == LPFC_INTR_ERROR) {
1804 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1805 "3175 Failed to enable interrupt\n");
1806 return -EIO;
1807 }
1808 phba->intr_mode = intr_mode;
1809 rc = lpfc_online(phba);
1810 if (rc == 0)
1811 lpfc_unblock_mgmt_io(phba);
1812
James Smart618a5232012-06-12 13:54:36 -04001813 return rc;
1814}
1815
1816/**
James Smartda0436e2009-05-22 14:51:39 -04001817 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1818 * @phba: pointer to lpfc hba data structure.
1819 *
1820 * This routine is invoked to handle the SLI4 HBA hardware error attention
1821 * conditions.
1822 **/
1823static void
1824lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1825{
1826 struct lpfc_vport *vport = phba->pport;
1827 uint32_t event_data;
1828 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001829 uint32_t if_type;
James Smart2e90f4b2011-12-13 13:22:37 -05001830 struct lpfc_register portstat_reg = {0};
1831 uint32_t reg_err1, reg_err2;
1832 uint32_t uerrlo_reg, uemasklo_reg;
James Smart65791f12016-07-06 12:35:56 -07001833 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
James Smarte10b2022014-02-20 09:57:43 -05001834 bool en_rn_msg = true;
James Smart946727d2015-04-07 15:07:09 -04001835 struct temp_event temp_event_data;
James Smart65791f12016-07-06 12:35:56 -07001836 struct lpfc_register portsmphr_reg;
1837 int rc, i;
James Smartda0436e2009-05-22 14:51:39 -04001838
1839 /* If the pci channel is offline, ignore possible errors, since
1840 * we cannot communicate with the pci card anyway.
1841 */
1842 if (pci_channel_offline(phba->pcidev))
1843 return;
James Smartda0436e2009-05-22 14:51:39 -04001844
James Smart65791f12016-07-06 12:35:56 -07001845 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
James Smart2fcee4b2010-12-15 17:57:46 -05001846 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1847 switch (if_type) {
1848 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart2e90f4b2011-12-13 13:22:37 -05001849 pci_rd_rc1 = lpfc_readl(
1850 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1851 &uerrlo_reg);
1852 pci_rd_rc2 = lpfc_readl(
1853 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1854 &uemasklo_reg);
1855 /* consider PCI bus read error as pci_channel_offline */
1856 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1857 return;
James Smart65791f12016-07-06 12:35:56 -07001858 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
1859 lpfc_sli4_offline_eratt(phba);
1860 return;
1861 }
1862 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1863 "7623 Checking UE recoverable");
1864
1865 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
1866 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1867 &portsmphr_reg.word0))
1868 continue;
1869
1870 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
1871 &portsmphr_reg);
1872 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1873 LPFC_PORT_SEM_UE_RECOVERABLE)
1874 break;
1875 /*Sleep for 1Sec, before checking SEMAPHORE */
1876 msleep(1000);
1877 }
1878
1879 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1880 "4827 smphr_port_status x%x : Waited %dSec",
1881 smphr_port_status, i);
1882
1883 /* Recoverable UE, reset the HBA device */
1884 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1885 LPFC_PORT_SEM_UE_RECOVERABLE) {
1886 for (i = 0; i < 20; i++) {
1887 msleep(1000);
1888 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1889 &portsmphr_reg.word0) &&
1890 (LPFC_POST_STAGE_PORT_READY ==
1891 bf_get(lpfc_port_smphr_port_status,
1892 &portsmphr_reg))) {
1893 rc = lpfc_sli4_port_sta_fn_reset(phba,
1894 LPFC_MBX_NO_WAIT, en_rn_msg);
1895 if (rc == 0)
1896 return;
1897 lpfc_printf_log(phba,
1898 KERN_ERR, LOG_INIT,
1899 "4215 Failed to recover UE");
1900 break;
1901 }
1902 }
1903 }
1904 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1905 "7624 Firmware not ready: Failing UE recovery,"
1906 " waited %dSec", i);
James Smart2fcee4b2010-12-15 17:57:46 -05001907 lpfc_sli4_offline_eratt(phba);
1908 break;
James Smart946727d2015-04-07 15:07:09 -04001909
James Smart2fcee4b2010-12-15 17:57:46 -05001910 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08001911 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2e90f4b2011-12-13 13:22:37 -05001912 pci_rd_rc1 = lpfc_readl(
1913 phba->sli4_hba.u.if_type2.STATUSregaddr,
1914 &portstat_reg.word0);
1915 /* consider PCI bus read error as pci_channel_offline */
James Smart6b5151f2012-01-18 16:24:06 -05001916 if (pci_rd_rc1 == -EIO) {
1917 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1918 "3151 PCI bus read access failure: x%x\n",
1919 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
James Smart2e90f4b2011-12-13 13:22:37 -05001920 return;
James Smart6b5151f2012-01-18 16:24:06 -05001921 }
James Smart2e90f4b2011-12-13 13:22:37 -05001922 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1923 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
James Smart2fcee4b2010-12-15 17:57:46 -05001924 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
James Smart2fcee4b2010-12-15 17:57:46 -05001925 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1926 "2889 Port Overtemperature event, "
James Smart946727d2015-04-07 15:07:09 -04001927 "taking port offline Data: x%x x%x\n",
1928 reg_err1, reg_err2);
1929
James Smart310429e2016-07-06 12:35:54 -07001930 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04001931 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1932 temp_event_data.event_code = LPFC_CRIT_TEMP;
1933 temp_event_data.data = 0xFFFFFFFF;
1934
1935 shost = lpfc_shost_from_vport(phba->pport);
1936 fc_host_post_vendor_event(shost, fc_get_event_number(),
1937 sizeof(temp_event_data),
1938 (char *)&temp_event_data,
1939 SCSI_NL_VID_TYPE_PCI
1940 | PCI_VENDOR_ID_EMULEX);
1941
James Smart2fcee4b2010-12-15 17:57:46 -05001942 spin_lock_irq(&phba->hbalock);
1943 phba->over_temp_state = HBA_OVER_TEMP;
1944 spin_unlock_irq(&phba->hbalock);
1945 lpfc_sli4_offline_eratt(phba);
James Smart946727d2015-04-07 15:07:09 -04001946 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001947 }
James Smart2e90f4b2011-12-13 13:22:37 -05001948 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smarte10b2022014-02-20 09:57:43 -05001949 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
James Smart2e90f4b2011-12-13 13:22:37 -05001950 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte10b2022014-02-20 09:57:43 -05001951 "3143 Port Down: Firmware Update "
1952 "Detected\n");
1953 en_rn_msg = false;
1954 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smart2e90f4b2011-12-13 13:22:37 -05001955 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1956 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1957 "3144 Port Down: Debug Dump\n");
1958 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1959 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1960 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1961 "3145 Port Down: Provisioning\n");
James Smart618a5232012-06-12 13:54:36 -04001962
James Smart946727d2015-04-07 15:07:09 -04001963 /* If resets are disabled then leave the HBA alone and return */
1964 if (!phba->cfg_enable_hba_reset)
1965 return;
1966
James Smart618a5232012-06-12 13:54:36 -04001967 /* Check port status register for function reset */
James Smarte10b2022014-02-20 09:57:43 -05001968 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1969 en_rn_msg);
James Smart618a5232012-06-12 13:54:36 -04001970 if (rc == 0) {
1971 /* don't report event on forced debug dump */
1972 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1973 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1974 return;
1975 else
1976 break;
James Smart2fcee4b2010-12-15 17:57:46 -05001977 }
James Smart618a5232012-06-12 13:54:36 -04001978 /* fall through for not able to recover */
James Smart6b5151f2012-01-18 16:24:06 -05001979 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1980 "3152 Unrecoverable error, bring the port "
1981 "offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05001982 lpfc_sli4_offline_eratt(phba);
1983 break;
1984 case LPFC_SLI_INTF_IF_TYPE_1:
1985 default:
1986 break;
1987 }
James Smart2e90f4b2011-12-13 13:22:37 -05001988 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1989 "3123 Report dump event to upper layer\n");
1990 /* Send an internal error event to mgmt application */
1991 lpfc_board_errevt_to_mgmt(phba);
1992
1993 event_data = FC_REG_DUMP_EVENT;
1994 shost = lpfc_shost_from_vport(vport);
1995 fc_host_post_vendor_event(shost, fc_get_event_number(),
1996 sizeof(event_data), (char *) &event_data,
1997 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
James Smartda0436e2009-05-22 14:51:39 -04001998}
1999
2000/**
2001 * lpfc_handle_eratt - Wrapper func for handling hba error attention
2002 * @phba: pointer to lpfc HBA data structure.
2003 *
2004 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
2005 * routine from the API jump table function pointer from the lpfc_hba struct.
2006 *
2007 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02002008 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04002009 * Any other value - error.
2010 **/
2011void
2012lpfc_handle_eratt(struct lpfc_hba *phba)
2013{
2014 (*phba->lpfc_handle_eratt)(phba);
2015}
2016
2017/**
James Smart3621a712009-04-06 18:47:14 -04002018 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04002019 * @phba: pointer to lpfc hba data structure.
2020 *
2021 * This routine is invoked from the worker thread to handle a HBA host
James Smart895427b2017-02-12 13:52:30 -08002022 * attention link event. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002023 **/
dea31012005-04-17 16:05:31 -05002024void
James Smart2e0fef82007-06-17 19:56:36 -05002025lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002026{
James Smart2e0fef82007-06-17 19:56:36 -05002027 struct lpfc_vport *vport = phba->pport;
2028 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05002029 LPFC_MBOXQ_t *pmb;
2030 volatile uint32_t control;
2031 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05002032 int rc = 0;
dea31012005-04-17 16:05:31 -05002033
2034 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05002035 if (!pmb) {
2036 rc = 1;
dea31012005-04-17 16:05:31 -05002037 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05002038 }
dea31012005-04-17 16:05:31 -05002039
2040 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05002041 if (!mp) {
2042 rc = 2;
dea31012005-04-17 16:05:31 -05002043 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05002044 }
dea31012005-04-17 16:05:31 -05002045
2046 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05002047 if (!mp->virt) {
2048 rc = 3;
dea31012005-04-17 16:05:31 -05002049 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05002050 }
dea31012005-04-17 16:05:31 -05002051
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05002052 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04002053 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05002054
2055 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05002056 lpfc_read_topology(phba, pmb, mp);
2057 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05002058 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04002059 /* Block ELS IOCBs until we have processed this mbox command */
James Smart895427b2017-02-12 13:52:30 -08002060 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04002061 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05002062 if (rc == MBX_NOT_FINISHED) {
2063 rc = 4;
James Smart14691152006-12-02 13:34:28 -05002064 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05002065 }
dea31012005-04-17 16:05:31 -05002066
2067 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05002068 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002069 writel(HA_LATT, phba->HAregaddr);
2070 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05002071 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002072
2073 return;
2074
James Smart14691152006-12-02 13:34:28 -05002075lpfc_handle_latt_free_mbuf:
James Smart895427b2017-02-12 13:52:30 -08002076 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05002077 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05002078lpfc_handle_latt_free_mp:
2079 kfree(mp);
2080lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04002081 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002082lpfc_handle_latt_err_exit:
2083 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05002084 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002085 psli->sli_flag |= LPFC_PROCESS_LA;
2086 control = readl(phba->HCregaddr);
2087 control |= HC_LAINT_ENA;
2088 writel(control, phba->HCregaddr);
2089 readl(phba->HCregaddr); /* flush */
2090
2091 /* Clear Link Attention in HA REG */
2092 writel(HA_LATT, phba->HAregaddr);
2093 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05002094 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002095 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002096 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002097
James Smart09372822008-01-11 01:52:54 -05002098 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
2099 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05002100
2101 return;
2102}
2103
James Smarte59058c2008-08-24 21:49:00 -04002104/**
James Smart3621a712009-04-06 18:47:14 -04002105 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04002106 * @phba: pointer to lpfc hba data structure.
2107 * @vpd: pointer to the vital product data.
2108 * @len: length of the vital product data in bytes.
2109 *
2110 * This routine parses the Vital Product Data (VPD). The VPD is treated as
2111 * an array of characters. In this routine, the ModelName, ProgramType, and
2112 * ModelDesc, etc. fields of the phba data structure will be populated.
2113 *
2114 * Return codes
2115 * 0 - pointer to the VPD passed in is NULL
2116 * 1 - success
2117 **/
James Smart3772a992009-05-22 14:50:54 -04002118int
James Smart2e0fef82007-06-17 19:56:36 -05002119lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05002120{
2121 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05002122 int Length;
dea31012005-04-17 16:05:31 -05002123 int i, j;
2124 int finished = 0;
2125 int index = 0;
2126
2127 if (!vpd)
2128 return 0;
2129
2130 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05002131 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002132 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05002133 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
2134 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002135 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05002136 switch (vpd[index]) {
2137 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002138 case 0x91:
dea31012005-04-17 16:05:31 -05002139 index += 1;
2140 lenlo = vpd[index];
2141 index += 1;
2142 lenhi = vpd[index];
2143 index += 1;
2144 i = ((((unsigned short)lenhi) << 8) + lenlo);
2145 index += i;
2146 break;
2147 case 0x90:
2148 index += 1;
2149 lenlo = vpd[index];
2150 index += 1;
2151 lenhi = vpd[index];
2152 index += 1;
2153 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002154 if (Length > len - index)
2155 Length = len - index;
dea31012005-04-17 16:05:31 -05002156 while (Length > 0) {
2157 /* Look for Serial Number */
2158 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
2159 index += 2;
2160 i = vpd[index];
2161 index += 1;
2162 j = 0;
2163 Length -= (3+i);
2164 while(i--) {
2165 phba->SerialNumber[j++] = vpd[index++];
2166 if (j == 31)
2167 break;
2168 }
2169 phba->SerialNumber[j] = 0;
2170 continue;
2171 }
2172 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
2173 phba->vpd_flag |= VPD_MODEL_DESC;
2174 index += 2;
2175 i = vpd[index];
2176 index += 1;
2177 j = 0;
2178 Length -= (3+i);
2179 while(i--) {
2180 phba->ModelDesc[j++] = vpd[index++];
2181 if (j == 255)
2182 break;
2183 }
2184 phba->ModelDesc[j] = 0;
2185 continue;
2186 }
2187 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
2188 phba->vpd_flag |= VPD_MODEL_NAME;
2189 index += 2;
2190 i = vpd[index];
2191 index += 1;
2192 j = 0;
2193 Length -= (3+i);
2194 while(i--) {
2195 phba->ModelName[j++] = vpd[index++];
2196 if (j == 79)
2197 break;
2198 }
2199 phba->ModelName[j] = 0;
2200 continue;
2201 }
2202 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2203 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2204 index += 2;
2205 i = vpd[index];
2206 index += 1;
2207 j = 0;
2208 Length -= (3+i);
2209 while(i--) {
2210 phba->ProgramType[j++] = vpd[index++];
2211 if (j == 255)
2212 break;
2213 }
2214 phba->ProgramType[j] = 0;
2215 continue;
2216 }
2217 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2218 phba->vpd_flag |= VPD_PORT;
2219 index += 2;
2220 i = vpd[index];
2221 index += 1;
2222 j = 0;
2223 Length -= (3+i);
2224 while(i--) {
James Smartcd1c8302011-10-10 21:33:25 -04002225 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2226 (phba->sli4_hba.pport_name_sta ==
2227 LPFC_SLI4_PPNAME_GET)) {
2228 j++;
2229 index++;
2230 } else
2231 phba->Port[j++] = vpd[index++];
2232 if (j == 19)
2233 break;
dea31012005-04-17 16:05:31 -05002234 }
James Smartcd1c8302011-10-10 21:33:25 -04002235 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2236 (phba->sli4_hba.pport_name_sta ==
2237 LPFC_SLI4_PPNAME_NON))
2238 phba->Port[j] = 0;
dea31012005-04-17 16:05:31 -05002239 continue;
2240 }
2241 else {
2242 index += 2;
2243 i = vpd[index];
2244 index += 1;
2245 index += i;
2246 Length -= (3 + i);
2247 }
2248 }
2249 finished = 0;
2250 break;
2251 case 0x78:
2252 finished = 1;
2253 break;
2254 default:
2255 index ++;
2256 break;
2257 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002258 }
dea31012005-04-17 16:05:31 -05002259
2260 return(1);
2261}
2262
James Smarte59058c2008-08-24 21:49:00 -04002263/**
James Smart3621a712009-04-06 18:47:14 -04002264 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04002265 * @phba: pointer to lpfc hba data structure.
2266 * @mdp: pointer to the data structure to hold the derived model name.
2267 * @descp: pointer to the data structure to hold the derived description.
2268 *
2269 * This routine retrieves HBA's description based on its registered PCI device
2270 * ID. The @descp passed into this function points to an array of 256 chars. It
2271 * shall be returned with the model name, maximum speed, and the host bus type.
2272 * The @mdp passed into this function points to an array of 80 chars. When the
2273 * function returns, the @mdp will be filled with the model name.
2274 **/
dea31012005-04-17 16:05:31 -05002275static void
James Smart2e0fef82007-06-17 19:56:36 -05002276lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05002277{
2278 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05002279 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002280 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04002281 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04002282 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002283 struct {
James Smarta747c9c2009-11-18 15:41:10 -05002284 char *name;
2285 char *bus;
2286 char *function;
2287 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002288
2289 if (mdp && mdp[0] != '\0'
2290 && descp && descp[0] != '\0')
2291 return;
2292
James Smartfbd8a6b2018-02-22 08:18:45 -08002293 if (phba->lmt & LMT_64Gb)
2294 max_speed = 64;
2295 else if (phba->lmt & LMT_32Gb)
James Smartd38dd522015-08-31 16:48:17 -04002296 max_speed = 32;
2297 else if (phba->lmt & LMT_16Gb)
James Smartc0c11512011-05-24 11:41:34 -04002298 max_speed = 16;
2299 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002300 max_speed = 10;
2301 else if (phba->lmt & LMT_8Gb)
2302 max_speed = 8;
2303 else if (phba->lmt & LMT_4Gb)
2304 max_speed = 4;
2305 else if (phba->lmt & LMT_2Gb)
2306 max_speed = 2;
James Smart4169d862012-09-29 11:32:09 -04002307 else if (phba->lmt & LMT_1Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002308 max_speed = 1;
James Smart4169d862012-09-29 11:32:09 -04002309 else
2310 max_speed = 0;
dea31012005-04-17 16:05:31 -05002311
2312 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05002313
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002314 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002315 case PCI_DEVICE_ID_FIREFLY:
James Smart12222f42014-05-21 08:05:19 -04002316 m = (typeof(m)){"LP6000", "PCI",
2317 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002318 break;
dea31012005-04-17 16:05:31 -05002319 case PCI_DEVICE_ID_SUPERFLY:
2320 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart12222f42014-05-21 08:05:19 -04002321 m = (typeof(m)){"LP7000", "PCI", ""};
dea31012005-04-17 16:05:31 -05002322 else
James Smart12222f42014-05-21 08:05:19 -04002323 m = (typeof(m)){"LP7000E", "PCI", ""};
2324 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002325 break;
2326 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002327 m = (typeof(m)){"LP8000", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002328 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002329 break;
2330 case PCI_DEVICE_ID_CENTAUR:
2331 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart12222f42014-05-21 08:05:19 -04002332 m = (typeof(m)){"LP9002", "PCI", ""};
dea31012005-04-17 16:05:31 -05002333 else
James Smart12222f42014-05-21 08:05:19 -04002334 m = (typeof(m)){"LP9000", "PCI", ""};
2335 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002336 break;
2337 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002338 m = (typeof(m)){"LP952", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002339 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002340 break;
2341 case PCI_DEVICE_ID_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05002342 m = (typeof(m)){"LP9802", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002343 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002344 break;
2345 case PCI_DEVICE_ID_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05002346 m = (typeof(m)){"LP10000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002347 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002348 break;
2349 case PCI_DEVICE_ID_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05002350 m = (typeof(m)){"LPX1000", "PCI-X",
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_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002354 m = (typeof(m)){"LP982", "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_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002358 m = (typeof(m)){"LP1050", "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_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05002362 m = (typeof(m)){"LP11000", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002363 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002364 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002365 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002366 m = (typeof(m)){"LP11000-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002367 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002368 break;
2369 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002370 m = (typeof(m)){"LP11002-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002371 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002372 break;
2373 case PCI_DEVICE_ID_NEPTUNE:
James Smart12222f42014-05-21 08:05:19 -04002374 m = (typeof(m)){"LPe1000", "PCIe",
2375 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002376 break;
2377 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart12222f42014-05-21 08:05:19 -04002378 m = (typeof(m)){"LPe1000-SP", "PCIe",
2379 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002380 break;
2381 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart12222f42014-05-21 08:05:19 -04002382 m = (typeof(m)){"LPe1002-SP", "PCIe",
2383 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002384 break;
dea31012005-04-17 16:05:31 -05002385 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05002386 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002387 break;
2388 case PCI_DEVICE_ID_BSMB:
James Smart12222f42014-05-21 08:05:19 -04002389 m = (typeof(m)){"LP111", "PCI-X2",
2390 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002391 break;
2392 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05002393 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002394 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002395 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002396 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002397 break;
2398 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002399 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04002400 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002401 break;
dea31012005-04-17 16:05:31 -05002402 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05002403 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002404 break;
2405 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05002406 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002407 break;
2408 case PCI_DEVICE_ID_LP101:
James Smart12222f42014-05-21 08:05:19 -04002409 m = (typeof(m)){"LP101", "PCI-X",
2410 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002411 break;
2412 case PCI_DEVICE_ID_LP10000S:
James Smart12222f42014-05-21 08:05:19 -04002413 m = (typeof(m)){"LP10000-S", "PCI",
2414 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002415 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002416 case PCI_DEVICE_ID_LP11000S:
James Smart12222f42014-05-21 08:05:19 -04002417 m = (typeof(m)){"LP11000-S", "PCI-X2",
2418 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05002419 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002420 case PCI_DEVICE_ID_LPE11000S:
James Smart12222f42014-05-21 08:05:19 -04002421 m = (typeof(m)){"LPe11000-S", "PCIe",
2422 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002423 break;
James Smartb87eab32007-04-25 09:53:28 -04002424 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05002425 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002426 break;
2427 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05002428 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002429 break;
2430 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05002431 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002432 break;
2433 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002434 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002435 break;
2436 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002437 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002438 break;
2439 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05002440 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002441 break;
James Smart84774a42008-08-24 21:50:06 -04002442 case PCI_DEVICE_ID_HORNET:
James Smart12222f42014-05-21 08:05:19 -04002443 m = (typeof(m)){"LP21000", "PCIe",
2444 "Obsolete, Unsupported FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002445 GE = 1;
2446 break;
2447 case PCI_DEVICE_ID_PROTEUS_VF:
James Smarta747c9c2009-11-18 15:41:10 -05002448 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002449 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002450 break;
2451 case PCI_DEVICE_ID_PROTEUS_PF:
James Smarta747c9c2009-11-18 15:41:10 -05002452 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002453 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002454 break;
2455 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05002456 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002457 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002458 break;
James Smartda0436e2009-05-22 14:51:39 -04002459 case PCI_DEVICE_ID_TIGERSHARK:
2460 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002461 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04002462 break;
James Smarta747c9c2009-11-18 15:41:10 -05002463 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04002464 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002465 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2466 break;
2467 case PCI_DEVICE_ID_FALCON:
2468 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2469 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04002470 break;
James Smart98fc5dd2010-06-07 15:24:29 -04002471 case PCI_DEVICE_ID_BALIUS:
2472 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
James Smart12222f42014-05-21 08:05:19 -04002473 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart98fc5dd2010-06-07 15:24:29 -04002474 break;
James Smart085c6472010-11-20 23:11:37 -05002475 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04002476 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05002477 break;
James Smart12222f42014-05-21 08:05:19 -04002478 case PCI_DEVICE_ID_LANCER_FC_VF:
2479 m = (typeof(m)){"LPe16000", "PCIe",
2480 "Obsolete, Unsupported Fibre Channel Adapter"};
2481 break;
James Smart085c6472010-11-20 23:11:37 -05002482 case PCI_DEVICE_ID_LANCER_FCOE:
2483 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04002484 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05002485 break;
James Smart12222f42014-05-21 08:05:19 -04002486 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2487 oneConnect = 1;
2488 m = (typeof(m)){"OCe15100", "PCIe",
2489 "Obsolete, Unsupported FCoE"};
2490 break;
James Smartd38dd522015-08-31 16:48:17 -04002491 case PCI_DEVICE_ID_LANCER_G6_FC:
2492 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2493 break;
James Smartc238b9b2018-02-22 08:18:44 -08002494 case PCI_DEVICE_ID_LANCER_G7_FC:
2495 m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"};
2496 break;
James Smartf8cafd32012-08-03 12:42:51 -04002497 case PCI_DEVICE_ID_SKYHAWK:
2498 case PCI_DEVICE_ID_SKYHAWK_VF:
2499 oneConnect = 1;
2500 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2501 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002502 default:
James Smarta747c9c2009-11-18 15:41:10 -05002503 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002504 break;
dea31012005-04-17 16:05:31 -05002505 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002506
2507 if (mdp && mdp[0] == '\0')
2508 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04002509 /*
2510 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04002511 * and we put the port number on the end
2512 */
2513 if (descp && descp[0] == '\0') {
2514 if (oneConnect)
2515 snprintf(descp, 255,
James Smart4169d862012-09-29 11:32:09 -04002516 "Emulex OneConnect %s, %s Initiator %s",
James Smarta747c9c2009-11-18 15:41:10 -05002517 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04002518 phba->Port);
James Smart4169d862012-09-29 11:32:09 -04002519 else if (max_speed == 0)
2520 snprintf(descp, 255,
Sebastian Herbszt290237d2015-08-31 16:48:08 -04002521 "Emulex %s %s %s",
James Smart4169d862012-09-29 11:32:09 -04002522 m.name, m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002523 else
2524 snprintf(descp, 255,
2525 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05002526 m.name, max_speed, (GE) ? "GE" : "Gb",
2527 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002528 }
dea31012005-04-17 16:05:31 -05002529}
2530
James Smarte59058c2008-08-24 21:49:00 -04002531/**
James Smart3621a712009-04-06 18:47:14 -04002532 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04002533 * @phba: pointer to lpfc hba data structure.
2534 * @pring: pointer to a IOCB ring.
2535 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2536 *
2537 * This routine posts a given number of IOCBs with the associated DMA buffer
2538 * descriptors specified by the cnt argument to the given IOCB ring.
2539 *
2540 * Return codes
2541 * The number of IOCBs NOT able to be posted to the IOCB ring.
2542 **/
dea31012005-04-17 16:05:31 -05002543int
James Smart495a7142008-06-14 22:52:59 -04002544lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002545{
2546 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002547 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002548 struct lpfc_dmabuf *mp1, *mp2;
2549
2550 cnt += pring->missbufcnt;
2551
2552 /* While there are buffers to post */
2553 while (cnt > 0) {
2554 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002555 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002556 if (iocb == NULL) {
2557 pring->missbufcnt = cnt;
2558 return cnt;
2559 }
dea31012005-04-17 16:05:31 -05002560 icmd = &iocb->iocb;
2561
2562 /* 2 buffers can be posted per command */
2563 /* Allocate buffer to post */
2564 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2565 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002566 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2567 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002568 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002569 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002570 pring->missbufcnt = cnt;
2571 return cnt;
2572 }
2573
2574 INIT_LIST_HEAD(&mp1->list);
2575 /* Allocate buffer to post */
2576 if (cnt > 1) {
2577 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2578 if (mp2)
2579 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2580 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002581 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002582 kfree(mp2);
dea31012005-04-17 16:05:31 -05002583 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2584 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002585 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002586 pring->missbufcnt = cnt;
2587 return cnt;
2588 }
2589
2590 INIT_LIST_HEAD(&mp2->list);
2591 } else {
2592 mp2 = NULL;
2593 }
2594
2595 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2596 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2597 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2598 icmd->ulpBdeCount = 1;
2599 cnt--;
2600 if (mp2) {
2601 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2602 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2603 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2604 cnt--;
2605 icmd->ulpBdeCount = 2;
2606 }
2607
2608 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2609 icmd->ulpLe = 1;
2610
James Smart3772a992009-05-22 14:50:54 -04002611 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2612 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002613 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2614 kfree(mp1);
2615 cnt++;
2616 if (mp2) {
2617 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2618 kfree(mp2);
2619 cnt++;
2620 }
James Bottomley604a3e32005-10-29 10:28:33 -05002621 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002622 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002623 return cnt;
2624 }
dea31012005-04-17 16:05:31 -05002625 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002626 if (mp2)
dea31012005-04-17 16:05:31 -05002627 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002628 }
2629 pring->missbufcnt = 0;
2630 return 0;
2631}
2632
James Smarte59058c2008-08-24 21:49:00 -04002633/**
James Smart3621a712009-04-06 18:47:14 -04002634 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002635 * @phba: pointer to lpfc hba data structure.
2636 *
2637 * This routine posts initial receive IOCB buffers to the ELS ring. The
2638 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
James Smart895427b2017-02-12 13:52:30 -08002639 * set to 64 IOCBs. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002640 *
2641 * Return codes
2642 * 0 - success (currently always success)
2643 **/
dea31012005-04-17 16:05:31 -05002644static int
James Smart2e0fef82007-06-17 19:56:36 -05002645lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002646{
2647 struct lpfc_sli *psli = &phba->sli;
2648
2649 /* Ring 0, ELS / CT buffers */
James Smart895427b2017-02-12 13:52:30 -08002650 lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002651 /* Ring 2 - FCP no buffers needed */
2652
2653 return 0;
2654}
2655
2656#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2657
James Smarte59058c2008-08-24 21:49:00 -04002658/**
James Smart3621a712009-04-06 18:47:14 -04002659 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002660 * @HashResultPointer: pointer to an array as hash table.
2661 *
2662 * This routine sets up the initial values to the array of hash table entries
2663 * for the LC HBAs.
2664 **/
dea31012005-04-17 16:05:31 -05002665static void
2666lpfc_sha_init(uint32_t * HashResultPointer)
2667{
2668 HashResultPointer[0] = 0x67452301;
2669 HashResultPointer[1] = 0xEFCDAB89;
2670 HashResultPointer[2] = 0x98BADCFE;
2671 HashResultPointer[3] = 0x10325476;
2672 HashResultPointer[4] = 0xC3D2E1F0;
2673}
2674
James Smarte59058c2008-08-24 21:49:00 -04002675/**
James Smart3621a712009-04-06 18:47:14 -04002676 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002677 * @HashResultPointer: pointer to an initial/result hash table.
2678 * @HashWorkingPointer: pointer to an working hash table.
2679 *
2680 * This routine iterates an initial hash table pointed by @HashResultPointer
2681 * with the values from the working hash table pointeed by @HashWorkingPointer.
2682 * The results are putting back to the initial hash table, returned through
2683 * the @HashResultPointer as the result hash table.
2684 **/
dea31012005-04-17 16:05:31 -05002685static void
2686lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2687{
2688 int t;
2689 uint32_t TEMP;
2690 uint32_t A, B, C, D, E;
2691 t = 16;
2692 do {
2693 HashWorkingPointer[t] =
2694 S(1,
2695 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2696 8] ^
2697 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2698 } while (++t <= 79);
2699 t = 0;
2700 A = HashResultPointer[0];
2701 B = HashResultPointer[1];
2702 C = HashResultPointer[2];
2703 D = HashResultPointer[3];
2704 E = HashResultPointer[4];
2705
2706 do {
2707 if (t < 20) {
2708 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2709 } else if (t < 40) {
2710 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2711 } else if (t < 60) {
2712 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2713 } else {
2714 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2715 }
2716 TEMP += S(5, A) + E + HashWorkingPointer[t];
2717 E = D;
2718 D = C;
2719 C = S(30, B);
2720 B = A;
2721 A = TEMP;
2722 } while (++t <= 79);
2723
2724 HashResultPointer[0] += A;
2725 HashResultPointer[1] += B;
2726 HashResultPointer[2] += C;
2727 HashResultPointer[3] += D;
2728 HashResultPointer[4] += E;
2729
2730}
2731
James Smarte59058c2008-08-24 21:49:00 -04002732/**
James Smart3621a712009-04-06 18:47:14 -04002733 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002734 * @RandomChallenge: pointer to the entry of host challenge random number array.
2735 * @HashWorking: pointer to the entry of the working hash array.
2736 *
2737 * This routine calculates the working hash array referred by @HashWorking
2738 * from the challenge random numbers associated with the host, referred by
2739 * @RandomChallenge. The result is put into the entry of the working hash
2740 * array and returned by reference through @HashWorking.
2741 **/
dea31012005-04-17 16:05:31 -05002742static void
2743lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2744{
2745 *HashWorking = (*RandomChallenge ^ *HashWorking);
2746}
2747
James Smarte59058c2008-08-24 21:49:00 -04002748/**
James Smart3621a712009-04-06 18:47:14 -04002749 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002750 * @phba: pointer to lpfc hba data structure.
2751 * @hbainit: pointer to an array of unsigned 32-bit integers.
2752 *
2753 * This routine performs the special handling for LC HBA initialization.
2754 **/
dea31012005-04-17 16:05:31 -05002755void
2756lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2757{
2758 int t;
2759 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002760 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002761
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002762 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002763 if (!HashWorking)
2764 return;
2765
dea31012005-04-17 16:05:31 -05002766 HashWorking[0] = HashWorking[78] = *pwwnn++;
2767 HashWorking[1] = HashWorking[79] = *pwwnn;
2768
2769 for (t = 0; t < 7; t++)
2770 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2771
2772 lpfc_sha_init(hbainit);
2773 lpfc_sha_iterate(hbainit, HashWorking);
2774 kfree(HashWorking);
2775}
2776
James Smarte59058c2008-08-24 21:49:00 -04002777/**
James Smart3621a712009-04-06 18:47:14 -04002778 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002779 * @vport: pointer to a virtual N_Port data structure.
2780 *
2781 * This routine performs the necessary cleanups before deleting the @vport.
2782 * It invokes the discovery state machine to perform necessary state
2783 * transitions and to release the ndlps associated with the @vport. Note,
2784 * the physical port is treated as @vport 0.
2785 **/
James Smart87af33f2007-10-27 13:37:43 -04002786void
James Smart2e0fef82007-06-17 19:56:36 -05002787lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002788{
James Smart87af33f2007-10-27 13:37:43 -04002789 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002790 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002791 int i = 0;
dea31012005-04-17 16:05:31 -05002792
James Smart87af33f2007-10-27 13:37:43 -04002793 if (phba->link_state > LPFC_LINK_DOWN)
2794 lpfc_port_link_failure(vport);
2795
2796 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002797 if (!NLP_CHK_NODE_ACT(ndlp)) {
2798 ndlp = lpfc_enable_node(vport, ndlp,
2799 NLP_STE_UNUSED_NODE);
2800 if (!ndlp)
2801 continue;
2802 spin_lock_irq(&phba->ndlp_lock);
2803 NLP_SET_FREE_REQ(ndlp);
2804 spin_unlock_irq(&phba->ndlp_lock);
2805 /* Trigger the release of the ndlp memory */
2806 lpfc_nlp_put(ndlp);
2807 continue;
2808 }
2809 spin_lock_irq(&phba->ndlp_lock);
2810 if (NLP_CHK_FREE_REQ(ndlp)) {
2811 /* The ndlp should not be in memory free mode already */
2812 spin_unlock_irq(&phba->ndlp_lock);
2813 continue;
2814 } else
2815 /* Indicate request for freeing ndlp memory */
2816 NLP_SET_FREE_REQ(ndlp);
2817 spin_unlock_irq(&phba->ndlp_lock);
2818
James Smart58da1ff2008-04-07 10:15:56 -04002819 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2820 ndlp->nlp_DID == Fabric_DID) {
2821 /* Just free up ndlp with Fabric_DID for vports */
2822 lpfc_nlp_put(ndlp);
2823 continue;
2824 }
2825
James Smarteff4a012012-01-18 16:25:25 -05002826 /* take care of nodes in unused state before the state
2827 * machine taking action.
2828 */
2829 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2830 lpfc_nlp_put(ndlp);
2831 continue;
2832 }
2833
James Smart87af33f2007-10-27 13:37:43 -04002834 if (ndlp->nlp_type & NLP_FABRIC)
2835 lpfc_disc_state_machine(vport, ndlp, NULL,
2836 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002837
James Smart87af33f2007-10-27 13:37:43 -04002838 lpfc_disc_state_machine(vport, ndlp, NULL,
2839 NLP_EVT_DEVICE_RM);
2840 }
2841
James Smarta8adb832007-10-27 13:37:53 -04002842 /* At this point, ALL ndlp's should be gone
2843 * because of the previous NLP_EVT_DEVICE_RM.
2844 * Lets wait for this to happen, if needed.
2845 */
James Smart87af33f2007-10-27 13:37:43 -04002846 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002847 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04002848 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04002849 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002850 list_for_each_entry_safe(ndlp, next_ndlp,
2851 &vport->fc_nodes, nlp_listp) {
2852 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2853 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04002854 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05002855 "usgmap:x%x refcnt:%d\n",
2856 ndlp->nlp_DID, (void *)ndlp,
2857 ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01002858 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05002859 }
James Smarta8adb832007-10-27 13:37:53 -04002860 break;
James Smart87af33f2007-10-27 13:37:43 -04002861 }
James Smarta8adb832007-10-27 13:37:53 -04002862
2863 /* Wait for any activity on ndlps to settle */
2864 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002865 }
James Smart1151e3e2011-02-16 12:39:35 -05002866 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002867}
2868
James Smarte59058c2008-08-24 21:49:00 -04002869/**
James Smart3621a712009-04-06 18:47:14 -04002870 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002871 * @vport: pointer to a virtual N_Port data structure.
2872 *
2873 * This routine stops all the timers associated with a @vport. This function
2874 * is invoked before disabling or deleting a @vport. Note that the physical
2875 * port is treated as @vport 0.
2876 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002877void
2878lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002879{
James Smart92d7f7b2007-06-17 19:56:38 -05002880 del_timer_sync(&vport->els_tmofunc);
James Smart92494142011-02-16 12:39:44 -05002881 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002882 lpfc_can_disctmo(vport);
2883 return;
dea31012005-04-17 16:05:31 -05002884}
2885
James Smarte59058c2008-08-24 21:49:00 -04002886/**
James Smartecfd03c2010-02-12 14:41:27 -05002887 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2888 * @phba: pointer to lpfc hba data structure.
2889 *
2890 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2891 * caller of this routine should already hold the host lock.
2892 **/
2893void
2894__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2895{
James Smart5ac6b302010-10-22 11:05:36 -04002896 /* Clear pending FCF rediscovery wait flag */
2897 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2898
James Smartecfd03c2010-02-12 14:41:27 -05002899 /* Now, try to stop the timer */
2900 del_timer(&phba->fcf.redisc_wait);
2901}
2902
2903/**
2904 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2905 * @phba: pointer to lpfc hba data structure.
2906 *
2907 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2908 * checks whether the FCF rediscovery wait timer is pending with the host
2909 * lock held before proceeding with disabling the timer and clearing the
2910 * wait timer pendig flag.
2911 **/
2912void
2913lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2914{
2915 spin_lock_irq(&phba->hbalock);
2916 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2917 /* FCF rediscovery timer already fired or stopped */
2918 spin_unlock_irq(&phba->hbalock);
2919 return;
2920 }
2921 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002922 /* Clear failover in progress flags */
2923 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002924 spin_unlock_irq(&phba->hbalock);
2925}
2926
2927/**
James Smart3772a992009-05-22 14:50:54 -04002928 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002929 * @phba: pointer to lpfc hba data structure.
2930 *
2931 * This routine stops all the timers associated with a HBA. This function is
2932 * invoked before either putting a HBA offline or unloading the driver.
2933 **/
James Smart3772a992009-05-22 14:50:54 -04002934void
2935lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002936{
James Smart51ef4c22007-08-02 11:10:31 -04002937 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05002938 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002939 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002940 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002941 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002942 if (phba->sli_rev == LPFC_SLI_REV4) {
2943 del_timer_sync(&phba->rrq_tmr);
2944 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2945 }
James Smart3772a992009-05-22 14:50:54 -04002946 phba->hb_outstanding = 0;
2947
2948 switch (phba->pci_dev_grp) {
2949 case LPFC_PCI_DEV_LP:
2950 /* Stop any LightPulse device specific driver timers */
2951 del_timer_sync(&phba->fcp_poll_timer);
2952 break;
2953 case LPFC_PCI_DEV_OC:
2954 /* Stop any OneConnect device sepcific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002955 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002956 break;
2957 default:
2958 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2959 "0297 Invalid device group (x%x)\n",
2960 phba->pci_dev_grp);
2961 break;
2962 }
James Smart2e0fef82007-06-17 19:56:36 -05002963 return;
dea31012005-04-17 16:05:31 -05002964}
2965
James Smarte59058c2008-08-24 21:49:00 -04002966/**
James Smart3621a712009-04-06 18:47:14 -04002967 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002968 * @phba: pointer to lpfc hba data structure.
2969 *
2970 * This routine marks a HBA's management interface as blocked. Once the HBA's
2971 * management interface is marked as blocked, all the user space access to
2972 * the HBA, whether they are from sysfs interface or libdfc interface will
2973 * all be blocked. The HBA is set to block the management interface when the
2974 * driver prepares the HBA interface for online or offline.
2975 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01002976static void
James Smart618a5232012-06-12 13:54:36 -04002977lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
Adrian Bunka6ababd2007-11-05 18:07:33 +01002978{
2979 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04002980 uint8_t actcmd = MBX_HEARTBEAT;
2981 unsigned long timeout;
2982
Adrian Bunka6ababd2007-11-05 18:07:33 +01002983 spin_lock_irqsave(&phba->hbalock, iflag);
2984 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart618a5232012-06-12 13:54:36 -04002985 spin_unlock_irqrestore(&phba->hbalock, iflag);
2986 if (mbx_action == LPFC_MBX_NO_WAIT)
2987 return;
2988 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2989 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002990 if (phba->sli.mbox_active) {
James Smart6e7288d2010-06-07 15:23:35 -04002991 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
James Smarta183a152011-10-10 21:32:43 -04002992 /* Determine how long we might wait for the active mailbox
2993 * command to be gracefully completed by firmware.
2994 */
2995 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
2996 phba->sli.mbox_active) * 1000) + jiffies;
2997 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002998 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002999
James Smart6e7288d2010-06-07 15:23:35 -04003000 /* Wait for the outstnading mailbox command to complete */
3001 while (phba->sli.mbox_active) {
3002 /* Check active mailbox complete status every 2ms */
3003 msleep(2);
3004 if (time_after(jiffies, timeout)) {
3005 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3006 "2813 Mgmt IO is Blocked %x "
3007 "- mbox cmd %x still active\n",
3008 phba->sli.sli_flag, actcmd);
3009 break;
3010 }
3011 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01003012}
3013
James Smarte59058c2008-08-24 21:49:00 -04003014/**
James Smart6b5151f2012-01-18 16:24:06 -05003015 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
3016 * @phba: pointer to lpfc hba data structure.
3017 *
3018 * Allocate RPIs for all active remote nodes. This is needed whenever
3019 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
3020 * is to fixup the temporary rpi assignments.
3021 **/
3022void
3023lpfc_sli4_node_prep(struct lpfc_hba *phba)
3024{
3025 struct lpfc_nodelist *ndlp, *next_ndlp;
3026 struct lpfc_vport **vports;
James Smart9d3d3402017-04-21 16:05:00 -07003027 int i, rpi;
3028 unsigned long flags;
James Smart6b5151f2012-01-18 16:24:06 -05003029
3030 if (phba->sli_rev != LPFC_SLI_REV4)
3031 return;
3032
3033 vports = lpfc_create_vport_work_array(phba);
James Smart9d3d3402017-04-21 16:05:00 -07003034 if (vports == NULL)
3035 return;
James Smart6b5151f2012-01-18 16:24:06 -05003036
James Smart9d3d3402017-04-21 16:05:00 -07003037 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3038 if (vports[i]->load_flag & FC_UNLOADING)
3039 continue;
3040
3041 list_for_each_entry_safe(ndlp, next_ndlp,
3042 &vports[i]->fc_nodes,
3043 nlp_listp) {
3044 if (!NLP_CHK_NODE_ACT(ndlp))
3045 continue;
3046 rpi = lpfc_sli4_alloc_rpi(phba);
3047 if (rpi == LPFC_RPI_ALLOC_ERROR) {
3048 spin_lock_irqsave(&phba->ndlp_lock, flags);
3049 NLP_CLR_NODE_ACT(ndlp);
3050 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3051 continue;
James Smart6b5151f2012-01-18 16:24:06 -05003052 }
James Smart9d3d3402017-04-21 16:05:00 -07003053 ndlp->nlp_rpi = rpi;
3054 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3055 "0009 rpi:%x DID:%x "
3056 "flg:%x map:%x %p\n", ndlp->nlp_rpi,
3057 ndlp->nlp_DID, ndlp->nlp_flag,
3058 ndlp->nlp_usg_map, ndlp);
James Smart6b5151f2012-01-18 16:24:06 -05003059 }
3060 }
3061 lpfc_destroy_vport_work_array(phba, vports);
3062}
3063
3064/**
James Smart3621a712009-04-06 18:47:14 -04003065 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04003066 * @phba: pointer to lpfc hba data structure.
3067 *
3068 * This routine initializes the HBA and brings a HBA online. During this
3069 * process, the management interface is blocked to prevent user space access
3070 * to the HBA interfering with the driver initialization.
3071 *
3072 * Return codes
3073 * 0 - successful
3074 * 1 - failed
3075 **/
dea31012005-04-17 16:05:31 -05003076int
James Smart2e0fef82007-06-17 19:56:36 -05003077lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003078{
Julia Lawall372bd282008-12-16 16:15:08 +01003079 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04003080 struct lpfc_vport **vports;
Dick Kennedya145fda2017-08-23 16:55:44 -07003081 int i, error = 0;
James Smart16a3a202013-04-17 20:14:38 -04003082 bool vpis_cleared = false;
James Smart2e0fef82007-06-17 19:56:36 -05003083
dea31012005-04-17 16:05:31 -05003084 if (!phba)
3085 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01003086 vport = phba->pport;
dea31012005-04-17 16:05:31 -05003087
James Smart2e0fef82007-06-17 19:56:36 -05003088 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05003089 return 0;
3090
James Smarted957682007-06-17 19:56:37 -05003091 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003092 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05003093
James Smart618a5232012-06-12 13:54:36 -04003094 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05003095
James Smartda0436e2009-05-22 14:51:39 -04003096 if (phba->sli_rev == LPFC_SLI_REV4) {
3097 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
3098 lpfc_unblock_mgmt_io(phba);
3099 return 1;
3100 }
James Smart16a3a202013-04-17 20:14:38 -04003101 spin_lock_irq(&phba->hbalock);
3102 if (!phba->sli4_hba.max_cfg_param.vpi_used)
3103 vpis_cleared = true;
3104 spin_unlock_irq(&phba->hbalock);
Dick Kennedya145fda2017-08-23 16:55:44 -07003105
3106 /* Reestablish the local initiator port.
3107 * The offline process destroyed the previous lport.
3108 */
3109 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
3110 !phba->nvmet_support) {
3111 error = lpfc_nvme_create_localport(phba->pport);
3112 if (error)
3113 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3114 "6132 NVME restore reg failed "
3115 "on nvmei error x%x\n", error);
3116 }
James Smartda0436e2009-05-22 14:51:39 -04003117 } else {
James Smart895427b2017-02-12 13:52:30 -08003118 lpfc_sli_queue_init(phba);
James Smartda0436e2009-05-22 14:51:39 -04003119 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
3120 lpfc_unblock_mgmt_io(phba);
3121 return 1;
3122 }
James Smart46fa3112007-04-25 09:51:45 -04003123 }
dea31012005-04-17 16:05:31 -05003124
James Smart549e55c2007-08-02 11:09:51 -04003125 vports = lpfc_create_vport_work_array(phba);
Arnd Bergmannaeb66412016-03-14 15:29:44 +01003126 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003127 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003128 struct Scsi_Host *shost;
3129 shost = lpfc_shost_from_vport(vports[i]);
3130 spin_lock_irq(shost->host_lock);
3131 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
3132 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
3133 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart16a3a202013-04-17 20:14:38 -04003134 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart1c6834a2009-07-19 10:01:26 -04003135 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart16a3a202013-04-17 20:14:38 -04003136 if ((vpis_cleared) &&
3137 (vports[i]->port_type !=
3138 LPFC_PHYSICAL_PORT))
3139 vports[i]->vpi = 0;
3140 }
James Smart549e55c2007-08-02 11:09:51 -04003141 spin_unlock_irq(shost->host_lock);
3142 }
Arnd Bergmannaeb66412016-03-14 15:29:44 +01003143 }
3144 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003145
James Smart46fa3112007-04-25 09:51:45 -04003146 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05003147 return 0;
3148}
3149
James Smarte59058c2008-08-24 21:49:00 -04003150/**
James Smart3621a712009-04-06 18:47:14 -04003151 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04003152 * @phba: pointer to lpfc hba data structure.
3153 *
3154 * This routine marks a HBA's management interface as not blocked. Once the
3155 * HBA's management interface is marked as not blocked, all the user space
3156 * access to the HBA, whether they are from sysfs interface or libdfc
3157 * interface will be allowed. The HBA is set to block the management interface
3158 * when the driver prepares the HBA interface for online or offline and then
3159 * set to unblock the management interface afterwards.
3160 **/
James Smart46fa3112007-04-25 09:51:45 -04003161void
James Smart46fa3112007-04-25 09:51:45 -04003162lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
3163{
3164 unsigned long iflag;
3165
James Smart2e0fef82007-06-17 19:56:36 -05003166 spin_lock_irqsave(&phba->hbalock, iflag);
3167 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3168 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04003169}
3170
James Smarte59058c2008-08-24 21:49:00 -04003171/**
James Smart3621a712009-04-06 18:47:14 -04003172 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04003173 * @phba: pointer to lpfc hba data structure.
3174 *
3175 * This routine is invoked to prepare a HBA to be brought offline. It performs
3176 * unregistration login to all the nodes on all vports and flushes the mailbox
3177 * queue to make it ready to be brought offline.
3178 **/
James Smart46fa3112007-04-25 09:51:45 -04003179void
James Smart618a5232012-06-12 13:54:36 -04003180lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04003181{
James Smart2e0fef82007-06-17 19:56:36 -05003182 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04003183 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04003184 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05003185 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04003186 int i;
dea31012005-04-17 16:05:31 -05003187
James Smart2e0fef82007-06-17 19:56:36 -05003188 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003189 return;
dea31012005-04-17 16:05:31 -05003190
James Smart618a5232012-06-12 13:54:36 -04003191 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05003192
3193 lpfc_linkdown(phba);
3194
James Smart87af33f2007-10-27 13:37:43 -04003195 /* Issue an unreg_login to all nodes on all vports */
3196 vports = lpfc_create_vport_work_array(phba);
3197 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003198 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04003199 if (vports[i]->load_flag & FC_UNLOADING)
3200 continue;
James Smart72100cc2010-02-12 14:43:01 -05003201 shost = lpfc_shost_from_vport(vports[i]);
3202 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003203 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003204 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3205 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05003206 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05003207
James Smart87af33f2007-10-27 13:37:43 -04003208 shost = lpfc_shost_from_vport(vports[i]);
3209 list_for_each_entry_safe(ndlp, next_ndlp,
3210 &vports[i]->fc_nodes,
3211 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003212 if (!NLP_CHK_NODE_ACT(ndlp))
3213 continue;
James Smart87af33f2007-10-27 13:37:43 -04003214 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3215 continue;
3216 if (ndlp->nlp_type & NLP_FABRIC) {
3217 lpfc_disc_state_machine(vports[i], ndlp,
3218 NULL, NLP_EVT_DEVICE_RECOVERY);
3219 lpfc_disc_state_machine(vports[i], ndlp,
3220 NULL, NLP_EVT_DEVICE_RM);
3221 }
3222 spin_lock_irq(shost->host_lock);
3223 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart401ee0c2012-03-01 22:35:34 -05003224 spin_unlock_irq(shost->host_lock);
James Smart6b5151f2012-01-18 16:24:06 -05003225 /*
3226 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05003227 * RPI. Get a new RPI when the adapter port
3228 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05003229 */
James Smartbe6bb942015-04-07 15:07:22 -04003230 if (phba->sli_rev == LPFC_SLI_REV4) {
3231 lpfc_printf_vlog(ndlp->vport,
3232 KERN_INFO, LOG_NODE,
3233 "0011 lpfc_offline: "
3234 "ndlp:x%p did %x "
3235 "usgmap:x%x rpi:%x\n",
3236 ndlp, ndlp->nlp_DID,
3237 ndlp->nlp_usg_map,
3238 ndlp->nlp_rpi);
3239
James Smart6b5151f2012-01-18 16:24:06 -05003240 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smartbe6bb942015-04-07 15:07:22 -04003241 }
James Smart87af33f2007-10-27 13:37:43 -04003242 lpfc_unreg_rpi(vports[i], ndlp);
3243 }
3244 }
3245 }
James Smart09372822008-01-11 01:52:54 -05003246 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003247
James Smart618a5232012-06-12 13:54:36 -04003248 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
Dick Kennedyf485c182017-09-29 17:34:34 -07003249
3250 if (phba->wq)
3251 flush_workqueue(phba->wq);
James Smart46fa3112007-04-25 09:51:45 -04003252}
3253
James Smarte59058c2008-08-24 21:49:00 -04003254/**
James Smart3621a712009-04-06 18:47:14 -04003255 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04003256 * @phba: pointer to lpfc hba data structure.
3257 *
3258 * This routine actually brings a HBA offline. It stops all the timers
3259 * associated with the HBA, brings down the SLI layer, and eventually
3260 * marks the HBA as in offline state for the upper layer protocol.
3261 **/
James Smart46fa3112007-04-25 09:51:45 -04003262void
James Smart2e0fef82007-06-17 19:56:36 -05003263lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04003264{
James Smart549e55c2007-08-02 11:09:51 -04003265 struct Scsi_Host *shost;
3266 struct lpfc_vport **vports;
3267 int i;
James Smart46fa3112007-04-25 09:51:45 -04003268
James Smart549e55c2007-08-02 11:09:51 -04003269 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003270 return;
James Smart688a8862006-07-06 15:49:56 -04003271
James Smartda0436e2009-05-22 14:51:39 -04003272 /* stop port and all timers associated with this hba */
3273 lpfc_stop_port(phba);
Dick Kennedy4b40d022017-08-23 16:55:38 -07003274
3275 /* Tear down the local and target port registrations. The
3276 * nvme transports need to cleanup.
3277 */
3278 lpfc_nvmet_destroy_targetport(phba);
3279 lpfc_nvme_destroy_localport(phba->pport);
3280
James Smart51ef4c22007-08-02 11:10:31 -04003281 vports = lpfc_create_vport_work_array(phba);
3282 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003283 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04003284 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05003285 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05003286 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003287 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05003288 /* Bring down the SLI Layer and cleanup. The HBA is offline
3289 now. */
3290 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003291 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04003292 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003293 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04003294 vports = lpfc_create_vport_work_array(phba);
3295 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003296 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003297 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04003298 spin_lock_irq(shost->host_lock);
3299 vports[i]->work_port_events = 0;
3300 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3301 spin_unlock_irq(shost->host_lock);
3302 }
James Smart09372822008-01-11 01:52:54 -05003303 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003304}
3305
James Smarte59058c2008-08-24 21:49:00 -04003306/**
James Smart3621a712009-04-06 18:47:14 -04003307 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04003308 * @phba: pointer to lpfc hba data structure.
3309 *
3310 * This routine is to free all the SCSI buffers and IOCBs from the driver
3311 * list back to kernel. It is called from lpfc_pci_remove_one to free
3312 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04003313 **/
James Smart8a9d2e82012-05-09 21:16:12 -04003314static void
James Smart2e0fef82007-06-17 19:56:36 -05003315lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003316{
3317 struct lpfc_scsi_buf *sb, *sb_next;
dea31012005-04-17 16:05:31 -05003318
James Smart895427b2017-02-12 13:52:30 -08003319 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3320 return;
3321
James Smart2e0fef82007-06-17 19:56:36 -05003322 spin_lock_irq(&phba->hbalock);
James Smarta40fc5f2013-04-17 20:17:40 -04003323
dea31012005-04-17 16:05:31 -05003324 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smarta40fc5f2013-04-17 20:17:40 -04003325
3326 spin_lock(&phba->scsi_buf_list_put_lock);
3327 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3328 list) {
dea31012005-04-17 16:05:31 -05003329 list_del(&sb->list);
Romain Perier771db5c2017-07-06 10:13:05 +02003330 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05003331 sb->dma_handle);
dea31012005-04-17 16:05:31 -05003332 kfree(sb);
3333 phba->total_scsi_bufs--;
3334 }
James Smarta40fc5f2013-04-17 20:17:40 -04003335 spin_unlock(&phba->scsi_buf_list_put_lock);
3336
3337 spin_lock(&phba->scsi_buf_list_get_lock);
3338 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3339 list) {
3340 list_del(&sb->list);
Romain Perier771db5c2017-07-06 10:13:05 +02003341 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smarta40fc5f2013-04-17 20:17:40 -04003342 sb->dma_handle);
3343 kfree(sb);
3344 phba->total_scsi_bufs--;
3345 }
3346 spin_unlock(&phba->scsi_buf_list_get_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003347 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003348}
James Smart8a9d2e82012-05-09 21:16:12 -04003349/**
James Smart895427b2017-02-12 13:52:30 -08003350 * lpfc_nvme_free - Free all the NVME buffers and IOCBs from driver lists
3351 * @phba: pointer to lpfc hba data structure.
3352 *
3353 * This routine is to free all the NVME buffers and IOCBs from the driver
3354 * list back to kernel. It is called from lpfc_pci_remove_one to free
3355 * the internal resources before the device is removed from the system.
3356 **/
3357static void
3358lpfc_nvme_free(struct lpfc_hba *phba)
3359{
3360 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
James Smart895427b2017-02-12 13:52:30 -08003361
3362 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3363 return;
3364
3365 spin_lock_irq(&phba->hbalock);
3366
3367 /* Release all the lpfc_nvme_bufs maintained by this host. */
3368 spin_lock(&phba->nvme_buf_list_put_lock);
3369 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3370 &phba->lpfc_nvme_buf_list_put, list) {
3371 list_del(&lpfc_ncmd->list);
James Smartcf1a1d32017-12-08 17:18:03 -08003372 phba->put_nvme_bufs--;
Romain Perier771db5c2017-07-06 10:13:05 +02003373 dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
James Smart895427b2017-02-12 13:52:30 -08003374 lpfc_ncmd->dma_handle);
3375 kfree(lpfc_ncmd);
3376 phba->total_nvme_bufs--;
3377 }
3378 spin_unlock(&phba->nvme_buf_list_put_lock);
3379
3380 spin_lock(&phba->nvme_buf_list_get_lock);
3381 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3382 &phba->lpfc_nvme_buf_list_get, list) {
3383 list_del(&lpfc_ncmd->list);
James Smartcf1a1d32017-12-08 17:18:03 -08003384 phba->get_nvme_bufs--;
Romain Perier771db5c2017-07-06 10:13:05 +02003385 dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
James Smart895427b2017-02-12 13:52:30 -08003386 lpfc_ncmd->dma_handle);
3387 kfree(lpfc_ncmd);
3388 phba->total_nvme_bufs--;
3389 }
3390 spin_unlock(&phba->nvme_buf_list_get_lock);
James Smart895427b2017-02-12 13:52:30 -08003391 spin_unlock_irq(&phba->hbalock);
3392}
3393/**
3394 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
James Smart8a9d2e82012-05-09 21:16:12 -04003395 * @phba: pointer to lpfc hba data structure.
3396 *
3397 * This routine first calculates the sizes of the current els and allocated
3398 * scsi sgl lists, and then goes through all sgls to updates the physical
3399 * XRIs assigned due to port function reset. During port initialization, the
3400 * current els and allocated scsi sgl lists are 0s.
3401 *
3402 * Return codes
3403 * 0 - successful (for now, it always returns 0)
3404 **/
3405int
James Smart895427b2017-02-12 13:52:30 -08003406lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
James Smart8a9d2e82012-05-09 21:16:12 -04003407{
3408 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
James Smart895427b2017-02-12 13:52:30 -08003409 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart8a9d2e82012-05-09 21:16:12 -04003410 LIST_HEAD(els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003411 int rc;
3412
3413 /*
3414 * update on pci function's els xri-sgl list
3415 */
3416 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart895427b2017-02-12 13:52:30 -08003417
James Smart8a9d2e82012-05-09 21:16:12 -04003418 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3419 /* els xri-sgl expanded */
3420 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3421 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3422 "3157 ELS xri-sgl count increased from "
3423 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3424 els_xri_cnt);
3425 /* allocate the additional els sgls */
3426 for (i = 0; i < xri_cnt; i++) {
3427 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3428 GFP_KERNEL);
3429 if (sglq_entry == NULL) {
3430 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3431 "2562 Failure to allocate an "
3432 "ELS sgl entry:%d\n", i);
3433 rc = -ENOMEM;
3434 goto out_free_mem;
3435 }
3436 sglq_entry->buff_type = GEN_BUFF_TYPE;
3437 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3438 &sglq_entry->phys);
3439 if (sglq_entry->virt == NULL) {
3440 kfree(sglq_entry);
3441 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3442 "2563 Failure to allocate an "
3443 "ELS mbuf:%d\n", i);
3444 rc = -ENOMEM;
3445 goto out_free_mem;
3446 }
3447 sglq_entry->sgl = sglq_entry->virt;
3448 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3449 sglq_entry->state = SGL_FREED;
3450 list_add_tail(&sglq_entry->list, &els_sgl_list);
3451 }
James Smart38c20672013-03-01 16:37:44 -05003452 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003453 spin_lock(&phba->sli4_hba.sgl_list_lock);
3454 list_splice_init(&els_sgl_list,
3455 &phba->sli4_hba.lpfc_els_sgl_list);
3456 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart38c20672013-03-01 16:37:44 -05003457 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003458 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3459 /* els xri-sgl shrinked */
3460 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3461 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3462 "3158 ELS xri-sgl count decreased from "
3463 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3464 els_xri_cnt);
3465 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003466 spin_lock(&phba->sli4_hba.sgl_list_lock);
3467 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
3468 &els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003469 /* release extra els sgls from list */
3470 for (i = 0; i < xri_cnt; i++) {
3471 list_remove_head(&els_sgl_list,
3472 sglq_entry, struct lpfc_sglq, list);
3473 if (sglq_entry) {
James Smart895427b2017-02-12 13:52:30 -08003474 __lpfc_mbuf_free(phba, sglq_entry->virt,
3475 sglq_entry->phys);
James Smart8a9d2e82012-05-09 21:16:12 -04003476 kfree(sglq_entry);
3477 }
3478 }
James Smart895427b2017-02-12 13:52:30 -08003479 list_splice_init(&els_sgl_list,
3480 &phba->sli4_hba.lpfc_els_sgl_list);
3481 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003482 spin_unlock_irq(&phba->hbalock);
3483 } else
3484 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3485 "3163 ELS xri-sgl count unchanged: %d\n",
3486 els_xri_cnt);
3487 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3488
3489 /* update xris to els sgls on the list */
3490 sglq_entry = NULL;
3491 sglq_entry_next = NULL;
3492 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
James Smart895427b2017-02-12 13:52:30 -08003493 &phba->sli4_hba.lpfc_els_sgl_list, list) {
James Smart8a9d2e82012-05-09 21:16:12 -04003494 lxri = lpfc_sli4_next_xritag(phba);
3495 if (lxri == NO_XRI) {
3496 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3497 "2400 Failed to allocate xri for "
3498 "ELS sgl\n");
3499 rc = -ENOMEM;
3500 goto out_free_mem;
3501 }
3502 sglq_entry->sli4_lxritag = lxri;
3503 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3504 }
James Smart895427b2017-02-12 13:52:30 -08003505 return 0;
3506
3507out_free_mem:
3508 lpfc_free_els_sgl_list(phba);
3509 return rc;
3510}
3511
3512/**
James Smartf358dd02017-02-12 13:52:34 -08003513 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
3514 * @phba: pointer to lpfc hba data structure.
3515 *
3516 * This routine first calculates the sizes of the current els and allocated
3517 * scsi sgl lists, and then goes through all sgls to updates the physical
3518 * XRIs assigned due to port function reset. During port initialization, the
3519 * current els and allocated scsi sgl lists are 0s.
3520 *
3521 * Return codes
3522 * 0 - successful (for now, it always returns 0)
3523 **/
3524int
3525lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
3526{
3527 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3528 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart6c621a22017-05-15 15:20:45 -07003529 uint16_t nvmet_xri_cnt;
James Smartf358dd02017-02-12 13:52:34 -08003530 LIST_HEAD(nvmet_sgl_list);
3531 int rc;
3532
3533 /*
3534 * update on pci function's nvmet xri-sgl list
3535 */
3536 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart61f3d4b2017-05-15 15:20:41 -07003537
James Smart6c621a22017-05-15 15:20:45 -07003538 /* For NVMET, ALL remaining XRIs are dedicated for IO processing */
3539 nvmet_xri_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
James Smartf358dd02017-02-12 13:52:34 -08003540 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
3541 /* els xri-sgl expanded */
3542 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
3543 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3544 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
3545 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
3546 /* allocate the additional nvmet sgls */
3547 for (i = 0; i < xri_cnt; i++) {
3548 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3549 GFP_KERNEL);
3550 if (sglq_entry == NULL) {
3551 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3552 "6303 Failure to allocate an "
3553 "NVMET sgl entry:%d\n", i);
3554 rc = -ENOMEM;
3555 goto out_free_mem;
3556 }
3557 sglq_entry->buff_type = NVMET_BUFF_TYPE;
3558 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
3559 &sglq_entry->phys);
3560 if (sglq_entry->virt == NULL) {
3561 kfree(sglq_entry);
3562 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3563 "6304 Failure to allocate an "
3564 "NVMET buf:%d\n", i);
3565 rc = -ENOMEM;
3566 goto out_free_mem;
3567 }
3568 sglq_entry->sgl = sglq_entry->virt;
3569 memset(sglq_entry->sgl, 0,
3570 phba->cfg_sg_dma_buf_size);
3571 sglq_entry->state = SGL_FREED;
3572 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
3573 }
3574 spin_lock_irq(&phba->hbalock);
3575 spin_lock(&phba->sli4_hba.sgl_list_lock);
3576 list_splice_init(&nvmet_sgl_list,
3577 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3578 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3579 spin_unlock_irq(&phba->hbalock);
3580 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
3581 /* nvmet xri-sgl shrunk */
3582 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
3583 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3584 "6305 NVMET xri-sgl count decreased from "
3585 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
3586 nvmet_xri_cnt);
3587 spin_lock_irq(&phba->hbalock);
3588 spin_lock(&phba->sli4_hba.sgl_list_lock);
3589 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
3590 &nvmet_sgl_list);
3591 /* release extra nvmet sgls from list */
3592 for (i = 0; i < xri_cnt; i++) {
3593 list_remove_head(&nvmet_sgl_list,
3594 sglq_entry, struct lpfc_sglq, list);
3595 if (sglq_entry) {
3596 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
3597 sglq_entry->phys);
3598 kfree(sglq_entry);
3599 }
3600 }
3601 list_splice_init(&nvmet_sgl_list,
3602 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3603 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3604 spin_unlock_irq(&phba->hbalock);
3605 } else
3606 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3607 "6306 NVMET xri-sgl count unchanged: %d\n",
3608 nvmet_xri_cnt);
3609 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
3610
3611 /* update xris to nvmet sgls on the list */
3612 sglq_entry = NULL;
3613 sglq_entry_next = NULL;
3614 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3615 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
3616 lxri = lpfc_sli4_next_xritag(phba);
3617 if (lxri == NO_XRI) {
3618 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3619 "6307 Failed to allocate xri for "
3620 "NVMET sgl\n");
3621 rc = -ENOMEM;
3622 goto out_free_mem;
3623 }
3624 sglq_entry->sli4_lxritag = lxri;
3625 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3626 }
3627 return 0;
3628
3629out_free_mem:
3630 lpfc_free_nvmet_sgl_list(phba);
3631 return rc;
3632}
3633
3634/**
James Smart895427b2017-02-12 13:52:30 -08003635 * lpfc_sli4_scsi_sgl_update - update xri-sgl sizing and mapping
3636 * @phba: pointer to lpfc hba data structure.
3637 *
3638 * This routine first calculates the sizes of the current els and allocated
3639 * scsi sgl lists, and then goes through all sgls to updates the physical
3640 * XRIs assigned due to port function reset. During port initialization, the
3641 * current els and allocated scsi sgl lists are 0s.
3642 *
3643 * Return codes
3644 * 0 - successful (for now, it always returns 0)
3645 **/
3646int
3647lpfc_sli4_scsi_sgl_update(struct lpfc_hba *phba)
3648{
3649 struct lpfc_scsi_buf *psb, *psb_next;
3650 uint16_t i, lxri, els_xri_cnt, scsi_xri_cnt;
3651 LIST_HEAD(scsi_sgl_list);
3652 int rc;
3653
3654 /*
3655 * update on pci function's els xri-sgl list
3656 */
3657 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3658 phba->total_scsi_bufs = 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003659
3660 /*
3661 * update on pci function's allocated scsi xri-sgl list
3662 */
James Smart8a9d2e82012-05-09 21:16:12 -04003663 /* maximum number of xris available for scsi buffers */
3664 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3665 els_xri_cnt;
3666
James Smart895427b2017-02-12 13:52:30 -08003667 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3668 return 0;
3669
3670 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3671 phba->sli4_hba.scsi_xri_max = /* Split them up */
3672 (phba->sli4_hba.scsi_xri_max *
3673 phba->cfg_xri_split) / 100;
James Smart8a9d2e82012-05-09 21:16:12 -04003674
James Smarta40fc5f2013-04-17 20:17:40 -04003675 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003676 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003677 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3678 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
James Smart164cecd2013-09-06 12:22:38 -04003679 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003680 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003681
James Smarte8c0a772017-04-21 16:04:49 -07003682 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3683 "6060 Current allocated SCSI xri-sgl count:%d, "
3684 "maximum SCSI xri count:%d (split:%d)\n",
3685 phba->sli4_hba.scsi_xri_cnt,
3686 phba->sli4_hba.scsi_xri_max, phba->cfg_xri_split);
3687
James Smart8a9d2e82012-05-09 21:16:12 -04003688 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3689 /* max scsi xri shrinked below the allocated scsi buffers */
3690 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3691 phba->sli4_hba.scsi_xri_max;
3692 /* release the extra allocated scsi buffers */
3693 for (i = 0; i < scsi_xri_cnt; i++) {
3694 list_remove_head(&scsi_sgl_list, psb,
3695 struct lpfc_scsi_buf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04003696 if (psb) {
Romain Perier771db5c2017-07-06 10:13:05 +02003697 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
James Smarta2fc4aef2014-09-03 12:57:55 -04003698 psb->data, psb->dma_handle);
3699 kfree(psb);
3700 }
James Smart8a9d2e82012-05-09 21:16:12 -04003701 }
James Smarta40fc5f2013-04-17 20:17:40 -04003702 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003703 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
James Smarta40fc5f2013-04-17 20:17:40 -04003704 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003705 }
3706
3707 /* update xris associated to remaining allocated scsi buffers */
3708 psb = NULL;
3709 psb_next = NULL;
3710 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3711 lxri = lpfc_sli4_next_xritag(phba);
3712 if (lxri == NO_XRI) {
3713 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3714 "2560 Failed to allocate xri for "
3715 "scsi buffer\n");
3716 rc = -ENOMEM;
3717 goto out_free_mem;
3718 }
3719 psb->cur_iocbq.sli4_lxritag = lxri;
3720 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3721 }
James Smarta40fc5f2013-04-17 20:17:40 -04003722 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003723 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003724 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3725 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
James Smart164cecd2013-09-06 12:22:38 -04003726 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003727 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
dea31012005-04-17 16:05:31 -05003728 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003729
3730out_free_mem:
James Smart8a9d2e82012-05-09 21:16:12 -04003731 lpfc_scsi_free(phba);
3732 return rc;
dea31012005-04-17 16:05:31 -05003733}
3734
James Smart96418b52017-03-04 09:30:31 -08003735static uint64_t
3736lpfc_get_wwpn(struct lpfc_hba *phba)
3737{
3738 uint64_t wwn;
3739 int rc;
3740 LPFC_MBOXQ_t *mboxq;
3741 MAILBOX_t *mb;
3742
James Smart96418b52017-03-04 09:30:31 -08003743 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
3744 GFP_KERNEL);
3745 if (!mboxq)
3746 return (uint64_t)-1;
3747
3748 /* First get WWN of HBA instance */
3749 lpfc_read_nv(phba, mboxq);
3750 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
3751 if (rc != MBX_SUCCESS) {
3752 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3753 "6019 Mailbox failed , mbxCmd x%x "
3754 "READ_NV, mbxStatus x%x\n",
3755 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
3756 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
3757 mempool_free(mboxq, phba->mbox_mem_pool);
3758 return (uint64_t) -1;
3759 }
3760 mb = &mboxq->u.mb;
3761 memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
3762 /* wwn is WWPN of HBA instance */
3763 mempool_free(mboxq, phba->mbox_mem_pool);
3764 if (phba->sli_rev == LPFC_SLI_REV4)
3765 return be64_to_cpu(wwn);
3766 else
Maurizio Lombardi286871a2017-08-23 16:55:48 -07003767 return rol64(wwn, 32);
James Smart96418b52017-03-04 09:30:31 -08003768}
3769
James Smarte59058c2008-08-24 21:49:00 -04003770/**
James Smart895427b2017-02-12 13:52:30 -08003771 * lpfc_sli4_nvme_sgl_update - update xri-sgl sizing and mapping
3772 * @phba: pointer to lpfc hba data structure.
3773 *
3774 * This routine first calculates the sizes of the current els and allocated
3775 * scsi sgl lists, and then goes through all sgls to updates the physical
3776 * XRIs assigned due to port function reset. During port initialization, the
3777 * current els and allocated scsi sgl lists are 0s.
3778 *
3779 * Return codes
3780 * 0 - successful (for now, it always returns 0)
3781 **/
3782int
3783lpfc_sli4_nvme_sgl_update(struct lpfc_hba *phba)
3784{
3785 struct lpfc_nvme_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
3786 uint16_t i, lxri, els_xri_cnt;
3787 uint16_t nvme_xri_cnt, nvme_xri_max;
3788 LIST_HEAD(nvme_sgl_list);
James Smartcf1a1d32017-12-08 17:18:03 -08003789 int rc, cnt;
James Smart895427b2017-02-12 13:52:30 -08003790
3791 phba->total_nvme_bufs = 0;
James Smartcf1a1d32017-12-08 17:18:03 -08003792 phba->get_nvme_bufs = 0;
3793 phba->put_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08003794
3795 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3796 return 0;
3797 /*
3798 * update on pci function's allocated nvme xri-sgl list
3799 */
3800
3801 /* maximum number of xris available for nvme buffers */
3802 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3803 nvme_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3804 phba->sli4_hba.nvme_xri_max = nvme_xri_max;
3805 phba->sli4_hba.nvme_xri_max -= phba->sli4_hba.scsi_xri_max;
3806
3807 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3808 "6074 Current allocated NVME xri-sgl count:%d, "
3809 "maximum NVME xri count:%d\n",
3810 phba->sli4_hba.nvme_xri_cnt,
3811 phba->sli4_hba.nvme_xri_max);
3812
3813 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3814 spin_lock(&phba->nvme_buf_list_put_lock);
3815 list_splice_init(&phba->lpfc_nvme_buf_list_get, &nvme_sgl_list);
3816 list_splice(&phba->lpfc_nvme_buf_list_put, &nvme_sgl_list);
James Smartcf1a1d32017-12-08 17:18:03 -08003817 cnt = phba->get_nvme_bufs + phba->put_nvme_bufs;
3818 phba->get_nvme_bufs = 0;
3819 phba->put_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08003820 spin_unlock(&phba->nvme_buf_list_put_lock);
3821 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3822
3823 if (phba->sli4_hba.nvme_xri_cnt > phba->sli4_hba.nvme_xri_max) {
3824 /* max nvme xri shrunk below the allocated nvme buffers */
3825 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3826 nvme_xri_cnt = phba->sli4_hba.nvme_xri_cnt -
3827 phba->sli4_hba.nvme_xri_max;
3828 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3829 /* release the extra allocated nvme buffers */
3830 for (i = 0; i < nvme_xri_cnt; i++) {
3831 list_remove_head(&nvme_sgl_list, lpfc_ncmd,
3832 struct lpfc_nvme_buf, list);
3833 if (lpfc_ncmd) {
Romain Perier771db5c2017-07-06 10:13:05 +02003834 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
James Smart895427b2017-02-12 13:52:30 -08003835 lpfc_ncmd->data,
3836 lpfc_ncmd->dma_handle);
3837 kfree(lpfc_ncmd);
3838 }
3839 }
3840 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3841 phba->sli4_hba.nvme_xri_cnt -= nvme_xri_cnt;
3842 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3843 }
3844
3845 /* update xris associated to remaining allocated nvme buffers */
3846 lpfc_ncmd = NULL;
3847 lpfc_ncmd_next = NULL;
3848 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3849 &nvme_sgl_list, list) {
3850 lxri = lpfc_sli4_next_xritag(phba);
3851 if (lxri == NO_XRI) {
3852 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3853 "6075 Failed to allocate xri for "
3854 "nvme buffer\n");
3855 rc = -ENOMEM;
3856 goto out_free_mem;
3857 }
3858 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
3859 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3860 }
3861 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3862 spin_lock(&phba->nvme_buf_list_put_lock);
3863 list_splice_init(&nvme_sgl_list, &phba->lpfc_nvme_buf_list_get);
James Smartcf1a1d32017-12-08 17:18:03 -08003864 phba->get_nvme_bufs = cnt;
James Smart895427b2017-02-12 13:52:30 -08003865 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
3866 spin_unlock(&phba->nvme_buf_list_put_lock);
3867 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3868 return 0;
3869
3870out_free_mem:
3871 lpfc_nvme_free(phba);
3872 return rc;
3873}
3874
3875/**
James Smart3621a712009-04-06 18:47:14 -04003876 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04003877 * @phba: pointer to lpfc hba data structure.
3878 * @instance: a unique integer ID to this FC port.
3879 * @dev: pointer to the device data structure.
3880 *
3881 * This routine creates a FC port for the upper layer protocol. The FC port
3882 * can be created on top of either a physical port or a virtual port provided
3883 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3884 * and associates the FC port created before adding the shost into the SCSI
3885 * layer.
3886 *
3887 * Return codes
3888 * @vport - pointer to the virtual N_Port data structure.
3889 * NULL - port create failed.
3890 **/
James Smart2e0fef82007-06-17 19:56:36 -05003891struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04003892lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04003893{
James Smart2e0fef82007-06-17 19:56:36 -05003894 struct lpfc_vport *vport;
James Smart895427b2017-02-12 13:52:30 -08003895 struct Scsi_Host *shost = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003896 int error = 0;
James Smart96418b52017-03-04 09:30:31 -08003897 int i;
3898 uint64_t wwn;
3899 bool use_no_reset_hba = false;
James Smart56bc8022017-06-15 22:56:43 -07003900 int rc;
James Smart96418b52017-03-04 09:30:31 -08003901
James Smart56bc8022017-06-15 22:56:43 -07003902 if (lpfc_no_hba_reset_cnt) {
3903 if (phba->sli_rev < LPFC_SLI_REV4 &&
3904 dev == &phba->pcidev->dev) {
3905 /* Reset the port first */
3906 lpfc_sli_brdrestart(phba);
3907 rc = lpfc_sli_chipset_init(phba);
3908 if (rc)
3909 return NULL;
3910 }
3911 wwn = lpfc_get_wwpn(phba);
3912 }
James Smart96418b52017-03-04 09:30:31 -08003913
3914 for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
3915 if (wwn == lpfc_no_hba_reset[i]) {
3916 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3917 "6020 Setting use_no_reset port=%llx\n",
3918 wwn);
3919 use_no_reset_hba = true;
3920 break;
3921 }
3922 }
James Smart47a86172007-04-25 09:53:22 -04003923
James Smart895427b2017-02-12 13:52:30 -08003924 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
3925 if (dev != &phba->pcidev->dev) {
3926 shost = scsi_host_alloc(&lpfc_vport_template,
3927 sizeof(struct lpfc_vport));
3928 } else {
James Smart96418b52017-03-04 09:30:31 -08003929 if (!use_no_reset_hba)
James Smart895427b2017-02-12 13:52:30 -08003930 shost = scsi_host_alloc(&lpfc_template,
3931 sizeof(struct lpfc_vport));
3932 else
James Smart96418b52017-03-04 09:30:31 -08003933 shost = scsi_host_alloc(&lpfc_template_no_hr,
James Smart895427b2017-02-12 13:52:30 -08003934 sizeof(struct lpfc_vport));
3935 }
3936 } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
3937 shost = scsi_host_alloc(&lpfc_template_nvme,
James Smartea4142f2015-04-07 15:07:13 -04003938 sizeof(struct lpfc_vport));
3939 }
James Smart2e0fef82007-06-17 19:56:36 -05003940 if (!shost)
3941 goto out;
James Smart47a86172007-04-25 09:53:22 -04003942
James Smart2e0fef82007-06-17 19:56:36 -05003943 vport = (struct lpfc_vport *) shost->hostdata;
3944 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05003945 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05003946 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05003947 vport->fc_rscn_flush = 0;
James Smart3de2a652007-08-02 11:09:59 -04003948 lpfc_get_vport_cfgparam(vport);
James Smart895427b2017-02-12 13:52:30 -08003949
James Smart2e0fef82007-06-17 19:56:36 -05003950 shost->unique_id = instance;
3951 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04003952 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05003953 shost->this_id = -1;
3954 shost->max_cmd_len = 16;
James Smart8b0dff12015-05-22 10:42:38 -04003955 shost->nr_hw_queues = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04003956 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05003957 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04003958 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smart5b9e70b2018-09-10 10:30:42 -07003959 shost->sg_tablesize = phba->cfg_scsi_seg_cnt;
James Smartda0436e2009-05-22 14:51:39 -04003960 }
James Smart81301a92008-12-04 22:39:46 -05003961
James Smart47a86172007-04-25 09:53:22 -04003962 /*
James Smart2e0fef82007-06-17 19:56:36 -05003963 * Set initial can_queue value since 0 is no longer supported and
3964 * scsi_add_host will fail. This will be adjusted later based on the
3965 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04003966 */
James Smart2e0fef82007-06-17 19:56:36 -05003967 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04003968 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05003969 shost->transportt = lpfc_vport_transport_template;
3970 vport->port_type = LPFC_NPIV_PORT;
3971 } else {
3972 shost->transportt = lpfc_transport_template;
3973 vport->port_type = LPFC_PHYSICAL_PORT;
3974 }
James Smart47a86172007-04-25 09:53:22 -04003975
James Smart2e0fef82007-06-17 19:56:36 -05003976 /* Initialize all internally managed lists. */
3977 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04003978 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05003979 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04003980
Kees Cookf22eb4d2017-09-06 20:24:26 -07003981 timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0);
James Smart47a86172007-04-25 09:53:22 -04003982
Kees Cookf22eb4d2017-09-06 20:24:26 -07003983 timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0);
James Smart92494142011-02-16 12:39:44 -05003984
Kees Cookf22eb4d2017-09-06 20:24:26 -07003985 timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0);
James Smart92494142011-02-16 12:39:44 -05003986
James Bottomleyd139b9b2009-11-05 13:33:12 -06003987 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05003988 if (error)
3989 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04003990
James Smart523128e2018-09-10 10:30:46 -07003991 spin_lock_irq(&phba->port_list_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003992 list_add_tail(&vport->listentry, &phba->port_list);
James Smart523128e2018-09-10 10:30:46 -07003993 spin_unlock_irq(&phba->port_list_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003994 return vport;
James Smart47a86172007-04-25 09:53:22 -04003995
James Smart2e0fef82007-06-17 19:56:36 -05003996out_put_shost:
3997 scsi_host_put(shost);
3998out:
3999 return NULL;
James Smart47a86172007-04-25 09:53:22 -04004000}
4001
James Smarte59058c2008-08-24 21:49:00 -04004002/**
James Smart3621a712009-04-06 18:47:14 -04004003 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04004004 * @vport: pointer to an lpfc virtual N_Port data structure.
4005 *
4006 * This routine destroys a FC port from the upper layer protocol. All the
4007 * resources associated with the port are released.
4008 **/
James Smart2e0fef82007-06-17 19:56:36 -05004009void
4010destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04004011{
James Smart92d7f7b2007-06-17 19:56:38 -05004012 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4013 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04004014
James Smart858c9f62007-06-17 19:56:39 -05004015 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05004016 fc_remove_host(shost);
4017 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04004018
James Smart523128e2018-09-10 10:30:46 -07004019 spin_lock_irq(&phba->port_list_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004020 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -07004021 spin_unlock_irq(&phba->port_list_lock);
James Smart47a86172007-04-25 09:53:22 -04004022
James Smart92d7f7b2007-06-17 19:56:38 -05004023 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04004024 return;
James Smart47a86172007-04-25 09:53:22 -04004025}
4026
James Smarte59058c2008-08-24 21:49:00 -04004027/**
James Smart3621a712009-04-06 18:47:14 -04004028 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04004029 *
4030 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
4031 * uses the kernel idr facility to perform the task.
4032 *
4033 * Return codes:
4034 * instance - a unique integer ID allocated as the new instance.
4035 * -1 - lpfc get instance failed.
4036 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004037int
4038lpfc_get_instance(void)
4039{
Tejun Heoab516032013-02-27 17:04:44 -08004040 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05004041
Tejun Heoab516032013-02-27 17:04:44 -08004042 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
4043 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05004044}
4045
James Smarte59058c2008-08-24 21:49:00 -04004046/**
James Smart3621a712009-04-06 18:47:14 -04004047 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04004048 * @shost: pointer to SCSI host data structure.
4049 * @time: elapsed time of the scan in jiffies.
4050 *
4051 * This routine is called by the SCSI layer with a SCSI host to determine
4052 * whether the scan host is finished.
4053 *
4054 * Note: there is no scan_start function as adapter initialization will have
4055 * asynchronously kicked off the link initialization.
4056 *
4057 * Return codes
4058 * 0 - SCSI host scan is not over yet.
4059 * 1 - SCSI host scan is over.
4060 **/
James Smart47a86172007-04-25 09:53:22 -04004061int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
4062{
James Smart2e0fef82007-06-17 19:56:36 -05004063 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4064 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05004065 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04004066
James Smart858c9f62007-06-17 19:56:39 -05004067 spin_lock_irq(shost->host_lock);
4068
James Smart51ef4c22007-08-02 11:10:31 -04004069 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05004070 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004071 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05004072 }
James Smart256ec0d2013-04-17 20:14:58 -04004073 if (time >= msecs_to_jiffies(30 * 1000)) {
James Smart2e0fef82007-06-17 19:56:36 -05004074 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004075 "0461 Scanning longer than 30 "
4076 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05004077 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004078 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004079 }
James Smart256ec0d2013-04-17 20:14:58 -04004080 if (time >= msecs_to_jiffies(15 * 1000) &&
4081 phba->link_state <= LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05004082 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004083 "0465 Link down longer than 15 "
4084 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05004085 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05004086 goto finished;
James Smart47a86172007-04-25 09:53:22 -04004087 }
4088
James Smart2e0fef82007-06-17 19:56:36 -05004089 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05004090 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004091 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05004092 goto finished;
James Smart256ec0d2013-04-17 20:14:58 -04004093 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
James Smart858c9f62007-06-17 19:56:39 -05004094 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004095 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05004096 goto finished;
4097
4098 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004099
4100finished:
James Smart858c9f62007-06-17 19:56:39 -05004101 spin_unlock_irq(shost->host_lock);
4102 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05004103}
4104
James Smarte59058c2008-08-24 21:49:00 -04004105/**
James Smart3621a712009-04-06 18:47:14 -04004106 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04004107 * @shost: pointer to SCSI host data structure.
4108 *
4109 * This routine initializes a given SCSI host attributes on a FC port. The
4110 * SCSI host can be either on top of a physical port or a virtual port.
4111 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004112void lpfc_host_attrib_init(struct Scsi_Host *shost)
4113{
4114 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4115 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04004116 /*
James Smart2e0fef82007-06-17 19:56:36 -05004117 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04004118 */
4119
James Smart2e0fef82007-06-17 19:56:36 -05004120 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
4121 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04004122 fc_host_supported_classes(shost) = FC_COS_CLASS3;
4123
4124 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05004125 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04004126 fc_host_supported_fc4s(shost)[2] = 1;
4127 fc_host_supported_fc4s(shost)[7] = 1;
4128
James Smart92d7f7b2007-06-17 19:56:38 -05004129 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
4130 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04004131
4132 fc_host_supported_speeds(shost) = 0;
James Smartfbd8a6b2018-02-22 08:18:45 -08004133 if (phba->lmt & LMT_64Gb)
4134 fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT;
James Smartd38dd522015-08-31 16:48:17 -04004135 if (phba->lmt & LMT_32Gb)
4136 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
James Smart88a2cfb2011-07-22 18:36:33 -04004137 if (phba->lmt & LMT_16Gb)
4138 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
James Smart47a86172007-04-25 09:53:22 -04004139 if (phba->lmt & LMT_10Gb)
4140 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04004141 if (phba->lmt & LMT_8Gb)
4142 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04004143 if (phba->lmt & LMT_4Gb)
4144 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
4145 if (phba->lmt & LMT_2Gb)
4146 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
4147 if (phba->lmt & LMT_1Gb)
4148 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
4149
4150 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05004151 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
4152 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04004153
Mike Christie0af5d702010-09-15 16:52:31 -05004154 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
4155
James Smart47a86172007-04-25 09:53:22 -04004156 /* This value is also unchanging */
4157 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05004158 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04004159 fc_host_active_fc4s(shost)[2] = 1;
4160 fc_host_active_fc4s(shost)[7] = 1;
4161
James Smart92d7f7b2007-06-17 19:56:38 -05004162 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04004163 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04004164 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04004165 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04004166}
dea31012005-04-17 16:05:31 -05004167
James Smarte59058c2008-08-24 21:49:00 -04004168/**
James Smartda0436e2009-05-22 14:51:39 -04004169 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04004170 * @phba: pointer to lpfc hba data structure.
4171 *
James Smartda0436e2009-05-22 14:51:39 -04004172 * This routine is invoked to stop an SLI3 device port, it stops the device
4173 * from generating interrupts and stops the device driver's timers for the
4174 * device.
James Smarte59058c2008-08-24 21:49:00 -04004175 **/
James Smartdb2378e2008-02-08 18:49:51 -05004176static void
James Smartda0436e2009-05-22 14:51:39 -04004177lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05004178{
James Smartda0436e2009-05-22 14:51:39 -04004179 /* Clear all interrupt enable conditions */
4180 writel(0, phba->HCregaddr);
4181 readl(phba->HCregaddr); /* flush */
4182 /* Clear all pending interrupts */
4183 writel(0xffffffff, phba->HAregaddr);
4184 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04004185
James Smartda0436e2009-05-22 14:51:39 -04004186 /* Reset some HBA SLI setup states */
4187 lpfc_stop_hba_timers(phba);
4188 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05004189}
4190
James Smarte59058c2008-08-24 21:49:00 -04004191/**
James Smartda0436e2009-05-22 14:51:39 -04004192 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05004193 * @phba: pointer to lpfc hba data structure.
4194 *
James Smartda0436e2009-05-22 14:51:39 -04004195 * This routine is invoked to stop an SLI4 device port, it stops the device
4196 * from generating interrupts and stops the device driver's timers for the
4197 * device.
4198 **/
4199static void
4200lpfc_stop_port_s4(struct lpfc_hba *phba)
4201{
4202 /* Reset some HBA SLI4 setup states */
4203 lpfc_stop_hba_timers(phba);
4204 phba->pport->work_port_events = 0;
4205 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04004206}
4207
4208/**
4209 * lpfc_stop_port - Wrapper function for stopping hba port
4210 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05004211 *
James Smartda0436e2009-05-22 14:51:39 -04004212 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
4213 * the API jump table function pointer from the lpfc_hba struct.
4214 **/
4215void
4216lpfc_stop_port(struct lpfc_hba *phba)
4217{
4218 phba->lpfc_stop_port(phba);
Dick Kennedyf485c182017-09-29 17:34:34 -07004219
4220 if (phba->wq)
4221 flush_workqueue(phba->wq);
James Smartda0436e2009-05-22 14:51:39 -04004222}
4223
4224/**
James Smartecfd03c2010-02-12 14:41:27 -05004225 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
4226 * @phba: Pointer to hba for which this call is being executed.
4227 *
4228 * This routine starts the timer waiting for the FCF rediscovery to complete.
4229 **/
4230void
4231lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
4232{
4233 unsigned long fcf_redisc_wait_tmo =
4234 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
4235 /* Start fcf rediscovery wait period timer */
4236 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
4237 spin_lock_irq(&phba->hbalock);
4238 /* Allow action to new fcf asynchronous event */
4239 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
4240 /* Mark the FCF rediscovery pending state */
4241 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
4242 spin_unlock_irq(&phba->hbalock);
4243}
4244
4245/**
4246 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
4247 * @ptr: Map to lpfc_hba data structure pointer.
4248 *
4249 * This routine is invoked when waiting for FCF table rediscover has been
4250 * timed out. If new FCF record(s) has (have) been discovered during the
4251 * wait period, a new FCF event shall be added to the FCOE async event
4252 * list, and then worker thread shall be waked up for processing from the
4253 * worker thread context.
4254 **/
Rashika Kheriae399b222014-09-03 12:55:28 -04004255static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07004256lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t)
James Smartecfd03c2010-02-12 14:41:27 -05004257{
Kees Cookf22eb4d2017-09-06 20:24:26 -07004258 struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait);
James Smartecfd03c2010-02-12 14:41:27 -05004259
4260 /* Don't send FCF rediscovery event if timer cancelled */
4261 spin_lock_irq(&phba->hbalock);
4262 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
4263 spin_unlock_irq(&phba->hbalock);
4264 return;
4265 }
4266 /* Clear FCF rediscovery timer pending flag */
4267 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
4268 /* FCF rediscovery event to worker thread */
4269 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
4270 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004271 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04004272 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05004273 /* wake up worker thread */
4274 lpfc_worker_wake_up(phba);
4275}
4276
4277/**
James Smartda0436e2009-05-22 14:51:39 -04004278 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
4279 * @phba: pointer to lpfc hba data structure.
4280 * @acqe_link: pointer to the async link completion queue entry.
4281 *
James Smart23288b72018-05-04 20:37:53 -07004282 * This routine is to parse the SLI4 link-attention link fault code.
James Smartda0436e2009-05-22 14:51:39 -04004283 **/
James Smart23288b72018-05-04 20:37:53 -07004284static void
James Smartda0436e2009-05-22 14:51:39 -04004285lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
4286 struct lpfc_acqe_link *acqe_link)
4287{
James Smartda0436e2009-05-22 14:51:39 -04004288 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
4289 case LPFC_ASYNC_LINK_FAULT_NONE:
4290 case LPFC_ASYNC_LINK_FAULT_LOCAL:
4291 case LPFC_ASYNC_LINK_FAULT_REMOTE:
James Smart23288b72018-05-04 20:37:53 -07004292 case LPFC_ASYNC_LINK_FAULT_LR_LRR:
James Smartda0436e2009-05-22 14:51:39 -04004293 break;
4294 default:
4295 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart23288b72018-05-04 20:37:53 -07004296 "0398 Unknown link fault code: x%x\n",
James Smartda0436e2009-05-22 14:51:39 -04004297 bf_get(lpfc_acqe_link_fault, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04004298 break;
4299 }
James Smartda0436e2009-05-22 14:51:39 -04004300}
4301
4302/**
4303 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
4304 * @phba: pointer to lpfc hba data structure.
4305 * @acqe_link: pointer to the async link completion queue entry.
4306 *
4307 * This routine is to parse the SLI4 link attention type and translate it
4308 * into the base driver's link attention type coding.
4309 *
4310 * Return: Link attention type in terms of base driver's coding.
4311 **/
4312static uint8_t
4313lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
4314 struct lpfc_acqe_link *acqe_link)
4315{
4316 uint8_t att_type;
4317
4318 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
4319 case LPFC_ASYNC_LINK_STATUS_DOWN:
4320 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05004321 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04004322 break;
4323 case LPFC_ASYNC_LINK_STATUS_UP:
4324 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05004325 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004326 break;
4327 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05004328 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04004329 break;
4330 default:
4331 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4332 "0399 Invalid link attention type: x%x\n",
4333 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05004334 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004335 break;
4336 }
4337 return att_type;
4338}
4339
4340/**
James Smart8b68cd52012-09-29 11:32:37 -04004341 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
4342 * @phba: pointer to lpfc hba data structure.
4343 *
4344 * This routine is to get an SLI3 FC port's link speed in Mbps.
4345 *
4346 * Return: link speed in terms of Mbps.
4347 **/
4348uint32_t
4349lpfc_sli_port_speed_get(struct lpfc_hba *phba)
4350{
4351 uint32_t link_speed;
4352
4353 if (!lpfc_is_link_up(phba))
4354 return 0;
4355
James Smarta085e872015-12-16 18:12:02 -05004356 if (phba->sli_rev <= LPFC_SLI_REV3) {
4357 switch (phba->fc_linkspeed) {
4358 case LPFC_LINK_SPEED_1GHZ:
4359 link_speed = 1000;
4360 break;
4361 case LPFC_LINK_SPEED_2GHZ:
4362 link_speed = 2000;
4363 break;
4364 case LPFC_LINK_SPEED_4GHZ:
4365 link_speed = 4000;
4366 break;
4367 case LPFC_LINK_SPEED_8GHZ:
4368 link_speed = 8000;
4369 break;
4370 case LPFC_LINK_SPEED_10GHZ:
4371 link_speed = 10000;
4372 break;
4373 case LPFC_LINK_SPEED_16GHZ:
4374 link_speed = 16000;
4375 break;
4376 default:
4377 link_speed = 0;
4378 }
4379 } else {
4380 if (phba->sli4_hba.link_state.logical_speed)
4381 link_speed =
4382 phba->sli4_hba.link_state.logical_speed;
4383 else
4384 link_speed = phba->sli4_hba.link_state.speed;
James Smart8b68cd52012-09-29 11:32:37 -04004385 }
4386 return link_speed;
4387}
4388
4389/**
4390 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
4391 * @phba: pointer to lpfc hba data structure.
4392 * @evt_code: asynchronous event code.
4393 * @speed_code: asynchronous event link speed code.
4394 *
4395 * This routine is to parse the giving SLI4 async event link speed code into
4396 * value of Mbps for the link speed.
4397 *
4398 * Return: link speed in terms of Mbps.
4399 **/
4400static uint32_t
4401lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
4402 uint8_t speed_code)
4403{
4404 uint32_t port_speed;
4405
4406 switch (evt_code) {
4407 case LPFC_TRAILER_CODE_LINK:
4408 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004409 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smart8b68cd52012-09-29 11:32:37 -04004410 port_speed = 0;
4411 break;
James Smart26d830e2015-04-07 15:07:17 -04004412 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004413 port_speed = 10;
4414 break;
James Smart26d830e2015-04-07 15:07:17 -04004415 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004416 port_speed = 100;
4417 break;
James Smart26d830e2015-04-07 15:07:17 -04004418 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004419 port_speed = 1000;
4420 break;
James Smart26d830e2015-04-07 15:07:17 -04004421 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004422 port_speed = 10000;
4423 break;
James Smart26d830e2015-04-07 15:07:17 -04004424 case LPFC_ASYNC_LINK_SPEED_20GBPS:
4425 port_speed = 20000;
4426 break;
4427 case LPFC_ASYNC_LINK_SPEED_25GBPS:
4428 port_speed = 25000;
4429 break;
4430 case LPFC_ASYNC_LINK_SPEED_40GBPS:
4431 port_speed = 40000;
4432 break;
James Smart8b68cd52012-09-29 11:32:37 -04004433 default:
4434 port_speed = 0;
4435 }
4436 break;
4437 case LPFC_TRAILER_CODE_FC:
4438 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004439 case LPFC_FC_LA_SPEED_UNKNOWN:
James Smart8b68cd52012-09-29 11:32:37 -04004440 port_speed = 0;
4441 break;
James Smart26d830e2015-04-07 15:07:17 -04004442 case LPFC_FC_LA_SPEED_1G:
James Smart8b68cd52012-09-29 11:32:37 -04004443 port_speed = 1000;
4444 break;
James Smart26d830e2015-04-07 15:07:17 -04004445 case LPFC_FC_LA_SPEED_2G:
James Smart8b68cd52012-09-29 11:32:37 -04004446 port_speed = 2000;
4447 break;
James Smart26d830e2015-04-07 15:07:17 -04004448 case LPFC_FC_LA_SPEED_4G:
James Smart8b68cd52012-09-29 11:32:37 -04004449 port_speed = 4000;
4450 break;
James Smart26d830e2015-04-07 15:07:17 -04004451 case LPFC_FC_LA_SPEED_8G:
James Smart8b68cd52012-09-29 11:32:37 -04004452 port_speed = 8000;
4453 break;
James Smart26d830e2015-04-07 15:07:17 -04004454 case LPFC_FC_LA_SPEED_10G:
James Smart8b68cd52012-09-29 11:32:37 -04004455 port_speed = 10000;
4456 break;
James Smart26d830e2015-04-07 15:07:17 -04004457 case LPFC_FC_LA_SPEED_16G:
James Smart8b68cd52012-09-29 11:32:37 -04004458 port_speed = 16000;
4459 break;
James Smartd38dd522015-08-31 16:48:17 -04004460 case LPFC_FC_LA_SPEED_32G:
4461 port_speed = 32000;
4462 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08004463 case LPFC_FC_LA_SPEED_64G:
4464 port_speed = 64000;
4465 break;
James Smart8b68cd52012-09-29 11:32:37 -04004466 default:
4467 port_speed = 0;
4468 }
4469 break;
4470 default:
4471 port_speed = 0;
4472 }
4473 return port_speed;
4474}
4475
4476/**
James Smart70f3c072010-12-15 17:57:33 -05004477 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04004478 * @phba: pointer to lpfc hba data structure.
4479 * @acqe_link: pointer to the async link completion queue entry.
4480 *
James Smart70f3c072010-12-15 17:57:33 -05004481 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04004482 **/
4483static void
4484lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
4485 struct lpfc_acqe_link *acqe_link)
4486{
4487 struct lpfc_dmabuf *mp;
4488 LPFC_MBOXQ_t *pmb;
4489 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05004490 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04004491 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05004492 int rc;
James Smartda0436e2009-05-22 14:51:39 -04004493
4494 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05004495 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04004496 return;
James Smart32b97932009-07-19 10:01:21 -04004497 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004498 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4499 if (!pmb) {
4500 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4501 "0395 The mboxq allocation failed\n");
4502 return;
4503 }
4504 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4505 if (!mp) {
4506 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4507 "0396 The lpfc_dmabuf allocation failed\n");
4508 goto out_free_pmb;
4509 }
4510 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4511 if (!mp->virt) {
4512 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4513 "0397 The mbuf allocation failed\n");
4514 goto out_free_dmabuf;
4515 }
4516
4517 /* Cleanup any outstanding ELS commands */
4518 lpfc_els_flush_all_cmd(phba);
4519
4520 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004521 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smartda0436e2009-05-22 14:51:39 -04004522
4523 /* Update link event statistics */
4524 phba->sli.slistat.link_event++;
4525
James Smart76a95d72010-11-20 23:11:48 -05004526 /* Create lpfc_handle_latt mailbox command from link ACQE */
4527 lpfc_read_topology(phba, pmb, mp);
4528 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04004529 pmb->vport = phba->pport;
4530
James Smartda0436e2009-05-22 14:51:39 -04004531 /* Keep the link status for extra SLI4 state machine reference */
4532 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004533 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
4534 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04004535 phba->sli4_hba.link_state.duplex =
4536 bf_get(lpfc_acqe_link_duplex, acqe_link);
4537 phba->sli4_hba.link_state.status =
4538 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05004539 phba->sli4_hba.link_state.type =
4540 bf_get(lpfc_acqe_link_type, acqe_link);
4541 phba->sli4_hba.link_state.number =
4542 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04004543 phba->sli4_hba.link_state.fault =
4544 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05004545 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004546 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
4547
James Smart70f3c072010-12-15 17:57:33 -05004548 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04004549 "2900 Async FC/FCoE Link event - Speed:%dGBit "
4550 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
4551 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05004552 phba->sli4_hba.link_state.speed,
4553 phba->sli4_hba.link_state.topology,
4554 phba->sli4_hba.link_state.status,
4555 phba->sli4_hba.link_state.type,
4556 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004557 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004558 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05004559 /*
4560 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
4561 * topology info. Note: Optional for non FC-AL ports.
4562 */
4563 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
4564 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4565 if (rc == MBX_NOT_FINISHED)
4566 goto out_free_dmabuf;
4567 return;
4568 }
4569 /*
4570 * For FCoE Mode: fill in all the topology information we need and call
4571 * the READ_TOPOLOGY completion routine to continue without actually
4572 * sending the READ_TOPOLOGY mailbox command to the port.
4573 */
James Smart23288b72018-05-04 20:37:53 -07004574 /* Initialize completion status */
James Smart76a95d72010-11-20 23:11:48 -05004575 mb = &pmb->u.mb;
James Smart23288b72018-05-04 20:37:53 -07004576 mb->mbxStatus = MBX_SUCCESS;
4577
4578 /* Parse port fault information field */
4579 lpfc_sli4_parse_latt_fault(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05004580
4581 /* Parse and translate link attention fields */
4582 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
4583 la->eventTag = acqe_link->event_tag;
4584 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
4585 bf_set(lpfc_mbx_read_top_link_spd, la,
James Smarta085e872015-12-16 18:12:02 -05004586 (bf_get(lpfc_acqe_link_speed, acqe_link)));
James Smart76a95d72010-11-20 23:11:48 -05004587
4588 /* Fake the the following irrelvant fields */
4589 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
4590 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
4591 bf_set(lpfc_mbx_read_top_il, la, 0);
4592 bf_set(lpfc_mbx_read_top_pb, la, 0);
4593 bf_set(lpfc_mbx_read_top_fa, la, 0);
4594 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04004595
4596 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05004597 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04004598
4599 return;
4600
4601out_free_dmabuf:
4602 kfree(mp);
4603out_free_pmb:
4604 mempool_free(pmb, phba->mbox_mem_pool);
4605}
4606
4607/**
James Smart70f3c072010-12-15 17:57:33 -05004608 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
4609 * @phba: pointer to lpfc hba data structure.
4610 * @acqe_fc: pointer to the async fc completion queue entry.
4611 *
4612 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
4613 * that the event was received and then issue a read_topology mailbox command so
4614 * that the rest of the driver will treat it the same as SLI3.
4615 **/
4616static void
4617lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
4618{
4619 struct lpfc_dmabuf *mp;
4620 LPFC_MBOXQ_t *pmb;
James Smart7bdedb32016-07-06 12:36:00 -07004621 MAILBOX_t *mb;
4622 struct lpfc_mbx_read_top *la;
James Smart70f3c072010-12-15 17:57:33 -05004623 int rc;
4624
4625 if (bf_get(lpfc_trailer_type, acqe_fc) !=
4626 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
4627 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4628 "2895 Non FC link Event detected.(%d)\n",
4629 bf_get(lpfc_trailer_type, acqe_fc));
4630 return;
4631 }
4632 /* Keep the link status for extra SLI4 state machine reference */
4633 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004634 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
4635 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05004636 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
4637 phba->sli4_hba.link_state.topology =
4638 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
4639 phba->sli4_hba.link_state.status =
4640 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
4641 phba->sli4_hba.link_state.type =
4642 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
4643 phba->sli4_hba.link_state.number =
4644 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
4645 phba->sli4_hba.link_state.fault =
4646 bf_get(lpfc_acqe_link_fault, acqe_fc);
4647 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004648 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart70f3c072010-12-15 17:57:33 -05004649 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4650 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4651 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4652 "%dMbps Fault:%d\n",
4653 phba->sli4_hba.link_state.speed,
4654 phba->sli4_hba.link_state.topology,
4655 phba->sli4_hba.link_state.status,
4656 phba->sli4_hba.link_state.type,
4657 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004658 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004659 phba->sli4_hba.link_state.fault);
4660 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4661 if (!pmb) {
4662 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4663 "2897 The mboxq allocation failed\n");
4664 return;
4665 }
4666 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4667 if (!mp) {
4668 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4669 "2898 The lpfc_dmabuf allocation failed\n");
4670 goto out_free_pmb;
4671 }
4672 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4673 if (!mp->virt) {
4674 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4675 "2899 The mbuf allocation failed\n");
4676 goto out_free_dmabuf;
4677 }
4678
4679 /* Cleanup any outstanding ELS commands */
4680 lpfc_els_flush_all_cmd(phba);
4681
4682 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004683 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smart70f3c072010-12-15 17:57:33 -05004684
4685 /* Update link event statistics */
4686 phba->sli.slistat.link_event++;
4687
4688 /* Create lpfc_handle_latt mailbox command from link ACQE */
4689 lpfc_read_topology(phba, pmb, mp);
4690 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4691 pmb->vport = phba->pport;
4692
James Smart7bdedb32016-07-06 12:36:00 -07004693 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
James Smartae9e28f2017-05-15 15:20:51 -07004694 phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK);
4695
4696 switch (phba->sli4_hba.link_state.status) {
4697 case LPFC_FC_LA_TYPE_MDS_LINK_DOWN:
4698 phba->link_flag |= LS_MDS_LINK_DOWN;
4699 break;
4700 case LPFC_FC_LA_TYPE_MDS_LOOPBACK:
4701 phba->link_flag |= LS_MDS_LOOPBACK;
4702 break;
4703 default:
4704 break;
4705 }
4706
James Smart23288b72018-05-04 20:37:53 -07004707 /* Initialize completion status */
James Smart7bdedb32016-07-06 12:36:00 -07004708 mb = &pmb->u.mb;
James Smart23288b72018-05-04 20:37:53 -07004709 mb->mbxStatus = MBX_SUCCESS;
4710
4711 /* Parse port fault information field */
4712 lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc);
James Smart7bdedb32016-07-06 12:36:00 -07004713
4714 /* Parse and translate link attention fields */
4715 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
4716 la->eventTag = acqe_fc->event_tag;
James Smart7bdedb32016-07-06 12:36:00 -07004717
James Smartaeb3c812017-04-21 16:05:02 -07004718 if (phba->sli4_hba.link_state.status ==
4719 LPFC_FC_LA_TYPE_UNEXP_WWPN) {
4720 bf_set(lpfc_mbx_read_top_att_type, la,
4721 LPFC_FC_LA_TYPE_UNEXP_WWPN);
4722 } else {
4723 bf_set(lpfc_mbx_read_top_att_type, la,
4724 LPFC_FC_LA_TYPE_LINK_DOWN);
4725 }
James Smart7bdedb32016-07-06 12:36:00 -07004726 /* Invoke the mailbox command callback function */
4727 lpfc_mbx_cmpl_read_topology(phba, pmb);
4728
4729 return;
4730 }
4731
James Smart70f3c072010-12-15 17:57:33 -05004732 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4733 if (rc == MBX_NOT_FINISHED)
4734 goto out_free_dmabuf;
4735 return;
4736
4737out_free_dmabuf:
4738 kfree(mp);
4739out_free_pmb:
4740 mempool_free(pmb, phba->mbox_mem_pool);
4741}
4742
4743/**
4744 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4745 * @phba: pointer to lpfc hba data structure.
4746 * @acqe_fc: pointer to the async SLI completion queue entry.
4747 *
4748 * This routine is to handle the SLI4 asynchronous SLI events.
4749 **/
4750static void
4751lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
4752{
James Smart4b8bae02012-06-12 13:55:07 -04004753 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04004754 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04004755 uint8_t status;
James Smart946727d2015-04-07 15:07:09 -04004756 uint8_t evt_type;
James Smart448193b2015-12-16 18:12:05 -05004757 uint8_t operational = 0;
James Smart946727d2015-04-07 15:07:09 -04004758 struct temp_event temp_event_data;
James Smart4b8bae02012-06-12 13:55:07 -04004759 struct lpfc_acqe_misconfigured_event *misconfigured;
James Smart946727d2015-04-07 15:07:09 -04004760 struct Scsi_Host *shost;
James Smart4b8bae02012-06-12 13:55:07 -04004761
James Smart946727d2015-04-07 15:07:09 -04004762 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
4763
James Smart448193b2015-12-16 18:12:05 -05004764 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4765 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4766 "x%08x SLI Event Type:%d\n",
4767 acqe_sli->event_data1, acqe_sli->event_data2,
4768 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004769
4770 port_name = phba->Port[0];
4771 if (port_name == 0x00)
4772 port_name = '?'; /* get port name is empty */
4773
James Smart946727d2015-04-07 15:07:09 -04004774 switch (evt_type) {
4775 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
4776 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4777 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
4778 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4779
4780 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4781 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4782 acqe_sli->event_data1, port_name);
4783
James Smart310429e2016-07-06 12:35:54 -07004784 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04004785 shost = lpfc_shost_from_vport(phba->pport);
4786 fc_host_post_vendor_event(shost, fc_get_event_number(),
4787 sizeof(temp_event_data),
4788 (char *)&temp_event_data,
4789 SCSI_NL_VID_TYPE_PCI
4790 | PCI_VENDOR_ID_EMULEX);
4791 break;
4792 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
4793 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4794 temp_event_data.event_code = LPFC_NORMAL_TEMP;
4795 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4796
4797 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4798 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4799 acqe_sli->event_data1, port_name);
4800
4801 shost = lpfc_shost_from_vport(phba->pport);
4802 fc_host_post_vendor_event(shost, fc_get_event_number(),
4803 sizeof(temp_event_data),
4804 (char *)&temp_event_data,
4805 SCSI_NL_VID_TYPE_PCI
4806 | PCI_VENDOR_ID_EMULEX);
4807 break;
4808 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
4809 misconfigured = (struct lpfc_acqe_misconfigured_event *)
James Smart4b8bae02012-06-12 13:55:07 -04004810 &acqe_sli->event_data1;
4811
James Smart946727d2015-04-07 15:07:09 -04004812 /* fetch the status for this port */
4813 switch (phba->sli4_hba.lnk_info.lnk_no) {
4814 case LPFC_LINK_NUMBER_0:
James Smart448193b2015-12-16 18:12:05 -05004815 status = bf_get(lpfc_sli_misconfigured_port0_state,
4816 &misconfigured->theEvent);
4817 operational = bf_get(lpfc_sli_misconfigured_port0_op,
James Smart4b8bae02012-06-12 13:55:07 -04004818 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004819 break;
4820 case LPFC_LINK_NUMBER_1:
James Smart448193b2015-12-16 18:12:05 -05004821 status = bf_get(lpfc_sli_misconfigured_port1_state,
4822 &misconfigured->theEvent);
4823 operational = bf_get(lpfc_sli_misconfigured_port1_op,
James Smart4b8bae02012-06-12 13:55:07 -04004824 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004825 break;
4826 case LPFC_LINK_NUMBER_2:
James Smart448193b2015-12-16 18:12:05 -05004827 status = bf_get(lpfc_sli_misconfigured_port2_state,
4828 &misconfigured->theEvent);
4829 operational = bf_get(lpfc_sli_misconfigured_port2_op,
James Smart4b8bae02012-06-12 13:55:07 -04004830 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004831 break;
4832 case LPFC_LINK_NUMBER_3:
James Smart448193b2015-12-16 18:12:05 -05004833 status = bf_get(lpfc_sli_misconfigured_port3_state,
4834 &misconfigured->theEvent);
4835 operational = bf_get(lpfc_sli_misconfigured_port3_op,
James Smart4b8bae02012-06-12 13:55:07 -04004836 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004837 break;
4838 default:
James Smart448193b2015-12-16 18:12:05 -05004839 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4840 "3296 "
4841 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
4842 "event: Invalid link %d",
4843 phba->sli4_hba.lnk_info.lnk_no);
4844 return;
James Smart946727d2015-04-07 15:07:09 -04004845 }
James Smart4b8bae02012-06-12 13:55:07 -04004846
James Smart448193b2015-12-16 18:12:05 -05004847 /* Skip if optic state unchanged */
4848 if (phba->sli4_hba.lnk_info.optic_state == status)
4849 return;
4850
James Smart946727d2015-04-07 15:07:09 -04004851 switch (status) {
4852 case LPFC_SLI_EVENT_STATUS_VALID:
James Smart448193b2015-12-16 18:12:05 -05004853 sprintf(message, "Physical Link is functional");
4854 break;
James Smart946727d2015-04-07 15:07:09 -04004855 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
4856 sprintf(message, "Optics faulted/incorrectly "
4857 "installed/not installed - Reseat optics, "
4858 "if issue not resolved, replace.");
4859 break;
4860 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
4861 sprintf(message,
4862 "Optics of two types installed - Remove one "
4863 "optic or install matching pair of optics.");
4864 break;
4865 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
4866 sprintf(message, "Incompatible optics - Replace with "
James Smart292098b2012-09-29 11:31:41 -04004867 "compatible optics for card to function.");
James Smart946727d2015-04-07 15:07:09 -04004868 break;
James Smart448193b2015-12-16 18:12:05 -05004869 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
4870 sprintf(message, "Unqualified optics - Replace with "
4871 "Avago optics for Warranty and Technical "
4872 "Support - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08004873 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05004874 break;
4875 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
4876 sprintf(message, "Uncertified optics - Replace with "
4877 "Avago-certified optics to enable link "
4878 "operation - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08004879 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05004880 break;
James Smart946727d2015-04-07 15:07:09 -04004881 default:
4882 /* firmware is reporting a status we don't know about */
4883 sprintf(message, "Unknown event status x%02x", status);
4884 break;
4885 }
James Smart448193b2015-12-16 18:12:05 -05004886 phba->sli4_hba.lnk_info.optic_state = status;
James Smart946727d2015-04-07 15:07:09 -04004887 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart448193b2015-12-16 18:12:05 -05004888 "3176 Port Name %c %s\n", port_name, message);
James Smart946727d2015-04-07 15:07:09 -04004889 break;
4890 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
4891 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4892 "3192 Remote DPort Test Initiated - "
4893 "Event Data1:x%08x Event Data2: x%08x\n",
4894 acqe_sli->event_data1, acqe_sli->event_data2);
James Smart4b8bae02012-06-12 13:55:07 -04004895 break;
4896 default:
James Smart946727d2015-04-07 15:07:09 -04004897 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4898 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
4899 "x%08x SLI Event Type:%d\n",
4900 acqe_sli->event_data1, acqe_sli->event_data2,
4901 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004902 break;
4903 }
James Smart70f3c072010-12-15 17:57:33 -05004904}
4905
4906/**
James Smartfc2b9892010-02-26 14:15:29 -05004907 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
4908 * @vport: pointer to vport data structure.
4909 *
4910 * This routine is to perform Clear Virtual Link (CVL) on a vport in
4911 * response to a CVL event.
4912 *
4913 * Return the pointer to the ndlp with the vport if successful, otherwise
4914 * return NULL.
4915 **/
4916static struct lpfc_nodelist *
4917lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
4918{
4919 struct lpfc_nodelist *ndlp;
4920 struct Scsi_Host *shost;
4921 struct lpfc_hba *phba;
4922
4923 if (!vport)
4924 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05004925 phba = vport->phba;
4926 if (!phba)
4927 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04004928 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4929 if (!ndlp) {
4930 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07004931 ndlp = lpfc_nlp_init(vport, Fabric_DID);
James Smart78730cf2010-04-06 15:06:30 -04004932 if (!ndlp)
4933 return 0;
James Smart78730cf2010-04-06 15:06:30 -04004934 /* Set the node type */
4935 ndlp->nlp_type |= NLP_FABRIC;
4936 /* Put ndlp onto node list */
4937 lpfc_enqueue_node(vport, ndlp);
4938 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4939 /* re-setup ndlp without removing from node list */
4940 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4941 if (!ndlp)
4942 return 0;
4943 }
James Smart63e801c2010-11-20 23:14:19 -05004944 if ((phba->pport->port_state < LPFC_FLOGI) &&
4945 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004946 return NULL;
4947 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05004948 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
4949 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004950 return NULL;
4951 shost = lpfc_shost_from_vport(vport);
4952 if (!shost)
4953 return NULL;
4954 lpfc_linkdown_port(vport);
4955 lpfc_cleanup_pending_mbox(vport);
4956 spin_lock_irq(shost->host_lock);
4957 vport->fc_flag |= FC_VPORT_CVL_RCVD;
4958 spin_unlock_irq(shost->host_lock);
4959
4960 return ndlp;
4961}
4962
4963/**
4964 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4965 * @vport: pointer to lpfc hba data structure.
4966 *
4967 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4968 * response to a FCF dead event.
4969 **/
4970static void
4971lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
4972{
4973 struct lpfc_vport **vports;
4974 int i;
4975
4976 vports = lpfc_create_vport_work_array(phba);
4977 if (vports)
4978 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4979 lpfc_sli4_perform_vport_cvl(vports[i]);
4980 lpfc_destroy_vport_work_array(phba, vports);
4981}
4982
4983/**
James Smart76a95d72010-11-20 23:11:48 -05004984 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04004985 * @phba: pointer to lpfc hba data structure.
4986 * @acqe_link: pointer to the async fcoe completion queue entry.
4987 *
4988 * This routine is to handle the SLI4 asynchronous fcoe event.
4989 **/
4990static void
James Smart76a95d72010-11-20 23:11:48 -05004991lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05004992 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04004993{
James Smart70f3c072010-12-15 17:57:33 -05004994 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004995 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04004996 struct lpfc_vport *vport;
4997 struct lpfc_nodelist *ndlp;
4998 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05004999 int active_vlink_present;
5000 struct lpfc_vport **vports;
5001 int i;
James Smartda0436e2009-05-22 14:51:39 -04005002
James Smart70f3c072010-12-15 17:57:33 -05005003 phba->fc_eventTag = acqe_fip->event_tag;
5004 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04005005 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05005006 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
5007 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
5008 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04005009 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5010 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005011 "2546 New FCF event, evt_tag:x%x, "
5012 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005013 acqe_fip->event_tag,
5014 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04005015 else
5016 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
5017 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005018 "2788 FCF param modified event, "
5019 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005020 acqe_fip->event_tag,
5021 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04005022 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05005023 /*
5024 * During period of FCF discovery, read the FCF
5025 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04005026 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05005027 */
5028 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5029 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005030 "2779 Read FCF (x%x) for updating "
5031 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05005032 acqe_fip->index);
5033 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05005034 }
James Smart38b92ef2010-08-04 16:11:39 -04005035
5036 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04005037 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04005038 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04005039 spin_unlock_irq(&phba->hbalock);
5040 break;
5041 }
5042 /* If fast FCF failover rescan event is pending, do nothing */
5043 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
5044 spin_unlock_irq(&phba->hbalock);
5045 break;
5046 }
5047
James Smartc2b97122013-05-31 17:05:36 -04005048 /* If the FCF has been in discovered state, do nothing. */
5049 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
James Smart3804dc82010-07-14 15:31:37 -04005050 spin_unlock_irq(&phba->hbalock);
5051 break;
5052 }
5053 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04005054
James Smart0c9ab6f2010-02-26 14:15:57 -05005055 /* Otherwise, scan the entire FCF table and re-discover SAN */
5056 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005057 "2770 Start FCF table scan per async FCF "
5058 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005059 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05005060 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
5061 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04005062 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05005063 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5064 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04005065 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04005066 break;
5067
James Smart70f3c072010-12-15 17:57:33 -05005068 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04005069 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04005070 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005071 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
5072 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04005073 break;
5074
James Smart70f3c072010-12-15 17:57:33 -05005075 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05005076 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05005077 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005078 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05005079 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04005080 /*
5081 * If we are in the middle of FCF failover process, clear
5082 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04005083 */
James Smartfc2b9892010-02-26 14:15:29 -05005084 spin_lock_irq(&phba->hbalock);
James Smarta1cadfe2016-07-06 12:36:02 -07005085 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
5086 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
James Smartfc2b9892010-02-26 14:15:29 -05005087 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005088 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05005089 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05005090 break;
5091 }
James Smart38b92ef2010-08-04 16:11:39 -04005092 spin_unlock_irq(&phba->hbalock);
5093
5094 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05005095 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04005096 break;
5097
5098 /*
5099 * Otherwise, request the port to rediscover the entire FCF
5100 * table for a fast recovery from case that the current FCF
5101 * is no longer valid as we are not in the middle of FCF
5102 * failover process already.
5103 */
James Smartc2b97122013-05-31 17:05:36 -04005104 spin_lock_irq(&phba->hbalock);
5105 /* Mark the fast failover process in progress */
5106 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
5107 spin_unlock_irq(&phba->hbalock);
5108
5109 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
5110 "2771 Start FCF fast failover process due to "
5111 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
5112 "\n", acqe_fip->event_tag, acqe_fip->index);
5113 rc = lpfc_sli4_redisc_fcf_table(phba);
5114 if (rc) {
5115 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5116 LOG_DISCOVERY,
Colin Ian King7afc0ce2018-05-03 10:26:12 +01005117 "2772 Issue FCF rediscover mailbox "
James Smartc2b97122013-05-31 17:05:36 -04005118 "command failed, fail through to FCF "
5119 "dead event\n");
5120 spin_lock_irq(&phba->hbalock);
5121 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
5122 spin_unlock_irq(&phba->hbalock);
5123 /*
5124 * Last resort will fail over by treating this
5125 * as a link down to FCF registration.
5126 */
5127 lpfc_sli4_fcf_dead_failthrough(phba);
5128 } else {
5129 /* Reset FCF roundrobin bmask for new discovery */
5130 lpfc_sli4_clear_fcf_rr_bmask(phba);
5131 /*
5132 * Handling fast FCF failover to a DEAD FCF event is
5133 * considered equalivant to receiving CVL to all vports.
5134 */
5135 lpfc_sli4_perform_all_vport_cvl(phba);
5136 }
James Smartda0436e2009-05-22 14:51:39 -04005137 break;
James Smart70f3c072010-12-15 17:57:33 -05005138 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05005139 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05005140 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04005141 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05005142 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04005143
James Smart6669f9b2009-10-02 15:16:45 -04005144 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04005145 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05005146 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04005147 if (!ndlp)
5148 break;
James Smart695a8142010-01-26 23:08:03 -05005149 active_vlink_present = 0;
5150
5151 vports = lpfc_create_vport_work_array(phba);
5152 if (vports) {
5153 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
5154 i++) {
5155 if ((!(vports[i]->fc_flag &
5156 FC_VPORT_CVL_RCVD)) &&
5157 (vports[i]->port_state > LPFC_FDISC)) {
5158 active_vlink_present = 1;
5159 break;
5160 }
5161 }
5162 lpfc_destroy_vport_work_array(phba, vports);
5163 }
5164
James Smartcc823552015-05-21 13:55:26 -04005165 /*
5166 * Don't re-instantiate if vport is marked for deletion.
5167 * If we are here first then vport_delete is going to wait
5168 * for discovery to complete.
5169 */
5170 if (!(vport->load_flag & FC_UNLOADING) &&
5171 active_vlink_present) {
James Smart695a8142010-01-26 23:08:03 -05005172 /*
5173 * If there are other active VLinks present,
5174 * re-instantiate the Vlink using FDISC.
5175 */
James Smart256ec0d2013-04-17 20:14:58 -04005176 mod_timer(&ndlp->nlp_delayfunc,
5177 jiffies + msecs_to_jiffies(1000));
James Smartfc2b9892010-02-26 14:15:29 -05005178 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04005179 spin_lock_irq(shost->host_lock);
5180 ndlp->nlp_flag |= NLP_DELAY_TMO;
5181 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05005182 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
5183 vport->port_state = LPFC_FDISC;
5184 } else {
James Smartecfd03c2010-02-12 14:41:27 -05005185 /*
5186 * Otherwise, we request port to rediscover
5187 * the entire FCF table for a fast recovery
5188 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05005189 * is no longer valid if we are not already
5190 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05005191 */
James Smartfc2b9892010-02-26 14:15:29 -05005192 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005193 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05005194 spin_unlock_irq(&phba->hbalock);
5195 break;
5196 }
5197 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05005198 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05005199 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005200 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5201 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005202 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05005203 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05005204 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05005205 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05005206 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5207 LOG_DISCOVERY,
5208 "2774 Issue FCF rediscover "
Colin Ian King7afc0ce2018-05-03 10:26:12 +01005209 "mailbox command failed, "
James Smart0c9ab6f2010-02-26 14:15:57 -05005210 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05005211 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005212 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05005213 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05005214 /*
5215 * Last resort will be re-try on the
5216 * the current registered FCF entry.
5217 */
5218 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04005219 } else
5220 /*
5221 * Reset FCF roundrobin bmask for new
5222 * discovery.
5223 */
James Smart7d791df2011-07-22 18:37:52 -04005224 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04005225 }
5226 break;
James Smartda0436e2009-05-22 14:51:39 -04005227 default:
5228 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5229 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05005230 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04005231 break;
5232 }
5233}
5234
5235/**
5236 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
5237 * @phba: pointer to lpfc hba data structure.
5238 * @acqe_link: pointer to the async dcbx completion queue entry.
5239 *
5240 * This routine is to handle the SLI4 asynchronous dcbx event.
5241 **/
5242static void
5243lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
5244 struct lpfc_acqe_dcbx *acqe_dcbx)
5245{
James Smart4d9ab992009-10-02 15:16:39 -04005246 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04005247 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5248 "0290 The SLI4 DCBX asynchronous event is not "
5249 "handled yet\n");
5250}
5251
5252/**
James Smartb19a0612010-04-06 14:48:51 -04005253 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
5254 * @phba: pointer to lpfc hba data structure.
5255 * @acqe_link: pointer to the async grp5 completion queue entry.
5256 *
5257 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
5258 * is an asynchronous notified of a logical link speed change. The Port
5259 * reports the logical link speed in units of 10Mbps.
5260 **/
5261static void
5262lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
5263 struct lpfc_acqe_grp5 *acqe_grp5)
5264{
5265 uint16_t prev_ll_spd;
5266
5267 phba->fc_eventTag = acqe_grp5->event_tag;
5268 phba->fcoe_eventtag = acqe_grp5->event_tag;
5269 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
5270 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04005271 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04005272 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5273 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04005274 "from %dMbps to %dMbps\n", prev_ll_spd,
5275 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04005276}
5277
5278/**
James Smartda0436e2009-05-22 14:51:39 -04005279 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
5280 * @phba: pointer to lpfc hba data structure.
5281 *
5282 * This routine is invoked by the worker thread to process all the pending
5283 * SLI4 asynchronous events.
5284 **/
5285void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
5286{
5287 struct lpfc_cq_event *cq_event;
5288
5289 /* First, declare the async event has been handled */
5290 spin_lock_irq(&phba->hbalock);
5291 phba->hba_flag &= ~ASYNC_EVENT;
5292 spin_unlock_irq(&phba->hbalock);
5293 /* Now, handle all the async events */
5294 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
5295 /* Get the first event from the head of the event queue */
5296 spin_lock_irq(&phba->hbalock);
5297 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
5298 cq_event, struct lpfc_cq_event, list);
5299 spin_unlock_irq(&phba->hbalock);
5300 /* Process the asynchronous event */
5301 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
5302 case LPFC_TRAILER_CODE_LINK:
5303 lpfc_sli4_async_link_evt(phba,
5304 &cq_event->cqe.acqe_link);
5305 break;
5306 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05005307 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04005308 break;
5309 case LPFC_TRAILER_CODE_DCBX:
5310 lpfc_sli4_async_dcbx_evt(phba,
5311 &cq_event->cqe.acqe_dcbx);
5312 break;
James Smartb19a0612010-04-06 14:48:51 -04005313 case LPFC_TRAILER_CODE_GRP5:
5314 lpfc_sli4_async_grp5_evt(phba,
5315 &cq_event->cqe.acqe_grp5);
5316 break;
James Smart70f3c072010-12-15 17:57:33 -05005317 case LPFC_TRAILER_CODE_FC:
5318 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
5319 break;
5320 case LPFC_TRAILER_CODE_SLI:
5321 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
5322 break;
James Smartda0436e2009-05-22 14:51:39 -04005323 default:
5324 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5325 "1804 Invalid asynchrous event code: "
5326 "x%x\n", bf_get(lpfc_trailer_code,
5327 &cq_event->cqe.mcqe_cmpl));
5328 break;
5329 }
5330 /* Free the completion event processed to the free pool */
5331 lpfc_sli4_cq_event_release(phba, cq_event);
5332 }
5333}
5334
5335/**
James Smartecfd03c2010-02-12 14:41:27 -05005336 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
5337 * @phba: pointer to lpfc hba data structure.
5338 *
5339 * This routine is invoked by the worker thread to process FCF table
5340 * rediscovery pending completion event.
5341 **/
5342void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
5343{
5344 int rc;
5345
5346 spin_lock_irq(&phba->hbalock);
5347 /* Clear FCF rediscovery timeout event */
5348 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
5349 /* Clear driver fast failover FCF record flag */
5350 phba->fcf.failover_rec.flag = 0;
5351 /* Set state for FCF fast failover */
5352 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
5353 spin_unlock_irq(&phba->hbalock);
5354
5355 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05005356 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005357 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05005358 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05005359 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05005360 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5361 "2747 Issue FCF scan read FCF mailbox "
5362 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05005363}
5364
5365/**
James Smartda0436e2009-05-22 14:51:39 -04005366 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
5367 * @phba: pointer to lpfc hba data structure.
5368 * @dev_grp: The HBA PCI-Device group number.
5369 *
5370 * This routine is invoked to set up the per HBA PCI-Device group function
5371 * API jump table entries.
5372 *
5373 * Return: 0 if success, otherwise -ENODEV
5374 **/
5375int
5376lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05005377{
5378 int rc;
5379
James Smartda0436e2009-05-22 14:51:39 -04005380 /* Set up lpfc PCI-device group */
5381 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05005382
James Smartda0436e2009-05-22 14:51:39 -04005383 /* The LPFC_PCI_DEV_OC uses SLI4 */
5384 if (dev_grp == LPFC_PCI_DEV_OC)
5385 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05005386
James Smartda0436e2009-05-22 14:51:39 -04005387 /* Set up device INIT API function jump table */
5388 rc = lpfc_init_api_table_setup(phba, dev_grp);
5389 if (rc)
5390 return -ENODEV;
5391 /* Set up SCSI API function jump table */
5392 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
5393 if (rc)
5394 return -ENODEV;
5395 /* Set up SLI API function jump table */
5396 rc = lpfc_sli_api_table_setup(phba, dev_grp);
5397 if (rc)
5398 return -ENODEV;
5399 /* Set up MBOX API function jump table */
5400 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
5401 if (rc)
5402 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05005403
James Smartda0436e2009-05-22 14:51:39 -04005404 return 0;
James Smart5b75da22008-12-04 22:39:35 -05005405}
5406
5407/**
James Smart3621a712009-04-06 18:47:14 -04005408 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05005409 * @phba: pointer to lpfc hba data structure.
5410 * @intr_mode: active interrupt mode adopted.
5411 *
5412 * This routine it invoked to log the currently used active interrupt mode
5413 * to the device.
James Smart3772a992009-05-22 14:50:54 -04005414 **/
5415static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05005416{
5417 switch (intr_mode) {
5418 case 0:
5419 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5420 "0470 Enable INTx interrupt mode.\n");
5421 break;
5422 case 1:
5423 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5424 "0481 Enabled MSI interrupt mode.\n");
5425 break;
5426 case 2:
5427 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5428 "0480 Enabled MSI-X interrupt mode.\n");
5429 break;
5430 default:
5431 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5432 "0482 Illegal interrupt mode.\n");
5433 break;
5434 }
5435 return;
5436}
5437
James Smart5b75da22008-12-04 22:39:35 -05005438/**
James Smart3772a992009-05-22 14:50:54 -04005439 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05005440 * @phba: pointer to lpfc hba data structure.
5441 *
James Smart3772a992009-05-22 14:50:54 -04005442 * This routine is invoked to enable the PCI device that is common to all
5443 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05005444 *
5445 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005446 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005447 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05005448 **/
James Smart3772a992009-05-22 14:50:54 -04005449static int
5450lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05005451{
James Smart3772a992009-05-22 14:50:54 -04005452 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05005453
James Smart3772a992009-05-22 14:50:54 -04005454 /* Obtain PCI device reference */
5455 if (!phba->pcidev)
5456 goto out_error;
5457 else
5458 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04005459 /* Enable PCI device */
5460 if (pci_enable_device_mem(pdev))
5461 goto out_error;
5462 /* Request PCI resource for the device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005463 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
James Smart3772a992009-05-22 14:50:54 -04005464 goto out_disable_device;
5465 /* Set up device as PCI master and save state for EEH */
5466 pci_set_master(pdev);
5467 pci_try_set_mwi(pdev);
5468 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05005469
James Smart05580562011-05-24 11:40:48 -04005470 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
Jon Mason453193e2013-09-11 15:38:13 -07005471 if (pci_is_pcie(pdev))
James Smart05580562011-05-24 11:40:48 -04005472 pdev->needs_freset = 1;
5473
James Smart3772a992009-05-22 14:50:54 -04005474 return 0;
James Smart5b75da22008-12-04 22:39:35 -05005475
James Smart3772a992009-05-22 14:50:54 -04005476out_disable_device:
5477 pci_disable_device(pdev);
5478out_error:
James Smart079b5c92011-08-21 21:48:49 -04005479 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005480 "1401 Failed to enable pci device\n");
James Smart3772a992009-05-22 14:50:54 -04005481 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05005482}
5483
5484/**
James Smart3772a992009-05-22 14:50:54 -04005485 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05005486 * @phba: pointer to lpfc hba data structure.
5487 *
James Smart3772a992009-05-22 14:50:54 -04005488 * This routine is invoked to disable the PCI device that is common to all
5489 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05005490 **/
5491static void
James Smart3772a992009-05-22 14:50:54 -04005492lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05005493{
James Smart3772a992009-05-22 14:50:54 -04005494 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05005495
James Smart3772a992009-05-22 14:50:54 -04005496 /* Obtain PCI device reference */
5497 if (!phba->pcidev)
5498 return;
5499 else
5500 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04005501 /* Release PCI resource and disable PCI device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005502 pci_release_mem_regions(pdev);
James Smart3772a992009-05-22 14:50:54 -04005503 pci_disable_device(pdev);
James Smart5b75da22008-12-04 22:39:35 -05005504
5505 return;
5506}
5507
5508/**
James Smart3772a992009-05-22 14:50:54 -04005509 * lpfc_reset_hba - Reset a hba
5510 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04005511 *
James Smart3772a992009-05-22 14:50:54 -04005512 * This routine is invoked to reset a hba device. It brings the HBA
5513 * offline, performs a board restart, and then brings the board back
5514 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
5515 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04005516 **/
James Smart3772a992009-05-22 14:50:54 -04005517void
5518lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05005519{
James Smart3772a992009-05-22 14:50:54 -04005520 /* If resets are disabled then set error state and return. */
5521 if (!phba->cfg_enable_hba_reset) {
5522 phba->link_state = LPFC_HBA_ERROR;
5523 return;
5524 }
James Smartee620212014-04-04 13:51:53 -04005525 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
5526 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
5527 else
5528 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart3772a992009-05-22 14:50:54 -04005529 lpfc_offline(phba);
5530 lpfc_sli_brdrestart(phba);
5531 lpfc_online(phba);
5532 lpfc_unblock_mgmt_io(phba);
5533}
dea31012005-04-17 16:05:31 -05005534
James Smart3772a992009-05-22 14:50:54 -04005535/**
James Smart0a96e972011-07-22 18:37:28 -04005536 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
5537 * @phba: pointer to lpfc hba data structure.
5538 *
5539 * This function enables the PCI SR-IOV virtual functions to a physical
5540 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5541 * enable the number of virtual functions to the physical function. As
5542 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5543 * API call does not considered as an error condition for most of the device.
5544 **/
5545uint16_t
5546lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
5547{
5548 struct pci_dev *pdev = phba->pcidev;
5549 uint16_t nr_virtfn;
5550 int pos;
5551
James Smart0a96e972011-07-22 18:37:28 -04005552 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
5553 if (pos == 0)
5554 return 0;
5555
5556 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
5557 return nr_virtfn;
5558}
5559
5560/**
James Smart912e3ac2011-05-24 11:42:11 -04005561 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
5562 * @phba: pointer to lpfc hba data structure.
5563 * @nr_vfn: number of virtual functions to be enabled.
5564 *
5565 * This function enables the PCI SR-IOV virtual functions to a physical
5566 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5567 * enable the number of virtual functions to the physical function. As
5568 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5569 * API call does not considered as an error condition for most of the device.
5570 **/
5571int
5572lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
5573{
5574 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04005575 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04005576 int rc;
5577
James Smart0a96e972011-07-22 18:37:28 -04005578 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
5579 if (nr_vfn > max_nr_vfn) {
5580 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5581 "3057 Requested vfs (%d) greater than "
5582 "supported vfs (%d)", nr_vfn, max_nr_vfn);
5583 return -EINVAL;
5584 }
5585
James Smart912e3ac2011-05-24 11:42:11 -04005586 rc = pci_enable_sriov(pdev, nr_vfn);
5587 if (rc) {
5588 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5589 "2806 Failed to enable sriov on this device "
5590 "with vfn number nr_vf:%d, rc:%d\n",
5591 nr_vfn, rc);
5592 } else
5593 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5594 "2807 Successful enable sriov on this device "
5595 "with vfn number nr_vf:%d\n", nr_vfn);
5596 return rc;
5597}
5598
5599/**
James Smart895427b2017-02-12 13:52:30 -08005600 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
James Smart3772a992009-05-22 14:50:54 -04005601 * @phba: pointer to lpfc hba data structure.
5602 *
James Smart895427b2017-02-12 13:52:30 -08005603 * This routine is invoked to set up the driver internal resources before the
5604 * device specific resource setup to support the HBA device it attached to.
James Smart3772a992009-05-22 14:50:54 -04005605 *
5606 * Return codes
James Smart895427b2017-02-12 13:52:30 -08005607 * 0 - successful
5608 * other values - error
James Smart3772a992009-05-22 14:50:54 -04005609 **/
5610static int
James Smart895427b2017-02-12 13:52:30 -08005611lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
James Smart3772a992009-05-22 14:50:54 -04005612{
James Smart895427b2017-02-12 13:52:30 -08005613 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05005614
James Smart3772a992009-05-22 14:50:54 -04005615 /*
James Smart895427b2017-02-12 13:52:30 -08005616 * Driver resources common to all SLI revisions
James Smart3772a992009-05-22 14:50:54 -04005617 */
James Smart895427b2017-02-12 13:52:30 -08005618 atomic_set(&phba->fast_event_count, 0);
5619 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005620
James Smart895427b2017-02-12 13:52:30 -08005621 /* Initialize ndlp management spinlock */
5622 spin_lock_init(&phba->ndlp_lock);
James Smart3772a992009-05-22 14:50:54 -04005623
James Smart523128e2018-09-10 10:30:46 -07005624 /* Initialize port_list spinlock */
5625 spin_lock_init(&phba->port_list_lock);
James Smart895427b2017-02-12 13:52:30 -08005626 INIT_LIST_HEAD(&phba->port_list);
James Smart523128e2018-09-10 10:30:46 -07005627
James Smart895427b2017-02-12 13:52:30 -08005628 INIT_LIST_HEAD(&phba->work_list);
5629 init_waitqueue_head(&phba->wait_4_mlo_m_q);
5630
5631 /* Initialize the wait queue head for the kernel thread */
5632 init_waitqueue_head(&phba->work_waitq);
5633
5634 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartf358dd02017-02-12 13:52:34 -08005635 "1403 Protocols supported %s %s %s\n",
James Smart895427b2017-02-12 13:52:30 -08005636 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
5637 "SCSI" : " "),
5638 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
James Smartf358dd02017-02-12 13:52:34 -08005639 "NVME" : " "),
5640 (phba->nvmet_support ? "NVMET" : " "));
James Smart895427b2017-02-12 13:52:30 -08005641
5642 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5643 /* Initialize the scsi buffer list used by driver for scsi IO */
5644 spin_lock_init(&phba->scsi_buf_list_get_lock);
5645 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5646 spin_lock_init(&phba->scsi_buf_list_put_lock);
5647 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
5648 }
5649
5650 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
5651 (phba->nvmet_support == 0)) {
5652 /* Initialize the NVME buffer list used by driver for NVME IO */
5653 spin_lock_init(&phba->nvme_buf_list_get_lock);
5654 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_get);
James Smartcf1a1d32017-12-08 17:18:03 -08005655 phba->get_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08005656 spin_lock_init(&phba->nvme_buf_list_put_lock);
5657 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
James Smartcf1a1d32017-12-08 17:18:03 -08005658 phba->put_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08005659 }
5660
5661 /* Initialize the fabric iocb list */
5662 INIT_LIST_HEAD(&phba->fabric_iocb_list);
5663
5664 /* Initialize list to save ELS buffers */
5665 INIT_LIST_HEAD(&phba->elsbuf);
5666
5667 /* Initialize FCF connection rec list */
5668 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
5669
5670 /* Initialize OAS configuration list */
5671 spin_lock_init(&phba->devicelock);
5672 INIT_LIST_HEAD(&phba->luns);
5673
James Smart3772a992009-05-22 14:50:54 -04005674 /* MBOX heartbeat timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005675 timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04005676 /* Fabric block timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005677 timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04005678 /* EA polling mode timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005679 timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0);
James Smart895427b2017-02-12 13:52:30 -08005680 /* Heartbeat timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005681 timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0);
James Smart895427b2017-02-12 13:52:30 -08005682
5683 return 0;
5684}
5685
5686/**
5687 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
5688 * @phba: pointer to lpfc hba data structure.
5689 *
5690 * This routine is invoked to set up the driver internal resources specific to
5691 * support the SLI-3 HBA device it attached to.
5692 *
5693 * Return codes
5694 * 0 - successful
5695 * other values - error
5696 **/
5697static int
5698lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
5699{
5700 int rc;
5701
5702 /*
5703 * Initialize timers used by driver
5704 */
5705
5706 /* FCP polling mode timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005707 timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04005708
5709 /* Host attention work mask setup */
5710 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
5711 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
5712
5713 /* Get all the module params for configuring this host */
5714 lpfc_get_cfgparam(phba);
James Smart895427b2017-02-12 13:52:30 -08005715 /* Set up phase-1 common device driver resources */
5716
5717 rc = lpfc_setup_driver_resource_phase1(phba);
5718 if (rc)
5719 return -ENODEV;
5720
James Smart49198b32010-04-06 15:04:33 -04005721 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
5722 phba->menlo_flag |= HBA_MENLO_SUPPORT;
5723 /* check for menlo minimum sg count */
5724 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
5725 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
5726 }
5727
James Smart895427b2017-02-12 13:52:30 -08005728 if (!phba->sli.sli3_ring)
Kees Cook6396bb22018-06-12 14:03:40 -07005729 phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING,
5730 sizeof(struct lpfc_sli_ring),
5731 GFP_KERNEL);
James Smart895427b2017-02-12 13:52:30 -08005732 if (!phba->sli.sli3_ring)
James Smart2a76a282012-08-03 12:35:54 -04005733 return -ENOMEM;
5734
James Smart3772a992009-05-22 14:50:54 -04005735 /*
James Smart96f70772013-04-17 20:16:15 -04005736 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smart3772a992009-05-22 14:50:54 -04005737 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart3772a992009-05-22 14:50:54 -04005738 */
James Smart3772a992009-05-22 14:50:54 -04005739
James Smart96f70772013-04-17 20:16:15 -04005740 /* Initialize the host templates the configured values. */
James Smart3772a992009-05-22 14:50:54 -04005741 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart96418b52017-03-04 09:30:31 -08005742 lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt;
5743 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart3772a992009-05-22 14:50:54 -04005744
James Smart96f70772013-04-17 20:16:15 -04005745 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
5746 if (phba->cfg_enable_bg) {
5747 /*
5748 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5749 * the FCP rsp, and a BDE for each. Sice we have no control
5750 * over how many protection data segments the SCSI Layer
5751 * will hand us (ie: there could be one for every block
5752 * in the IO), we just allocate enough BDEs to accomidate
5753 * our max amount and we need to limit lpfc_sg_seg_cnt to
5754 * minimize the risk of running out.
5755 */
5756 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5757 sizeof(struct fcp_rsp) +
5758 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
5759
5760 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
5761 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
5762
5763 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
5764 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
5765 } else {
5766 /*
5767 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5768 * the FCP rsp, a BDE for each, and a BDE for up to
5769 * cfg_sg_seg_cnt data segments.
5770 */
5771 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5772 sizeof(struct fcp_rsp) +
5773 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
5774
5775 /* Total BDEs in BPL for scsi_sg_list */
5776 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5777 }
5778
5779 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5780 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
5781 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5782 phba->cfg_total_seg_cnt);
5783
James Smart3772a992009-05-22 14:50:54 -04005784 phba->max_vpi = LPFC_MAX_VPI;
5785 /* This will be set to correct value after config_port mbox */
5786 phba->max_vports = 0;
5787
5788 /*
5789 * Initialize the SLI Layer to run with lpfc HBAs.
5790 */
5791 lpfc_sli_setup(phba);
James Smart895427b2017-02-12 13:52:30 -08005792 lpfc_sli_queue_init(phba);
James Smart3772a992009-05-22 14:50:54 -04005793
5794 /* Allocate device driver memory */
5795 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
5796 return -ENOMEM;
5797
James Smart912e3ac2011-05-24 11:42:11 -04005798 /*
5799 * Enable sr-iov virtual functions if supported and configured
5800 * through the module parameter.
5801 */
5802 if (phba->cfg_sriov_nr_virtfn > 0) {
5803 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5804 phba->cfg_sriov_nr_virtfn);
5805 if (rc) {
5806 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5807 "2808 Requested number of SR-IOV "
5808 "virtual functions (%d) is not "
5809 "supported\n",
5810 phba->cfg_sriov_nr_virtfn);
5811 phba->cfg_sriov_nr_virtfn = 0;
5812 }
5813 }
5814
James Smart3772a992009-05-22 14:50:54 -04005815 return 0;
5816}
5817
5818/**
5819 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
5820 * @phba: pointer to lpfc hba data structure.
5821 *
5822 * This routine is invoked to unset the driver internal resources set up
5823 * specific for supporting the SLI-3 HBA device it attached to.
5824 **/
5825static void
5826lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
5827{
5828 /* Free device driver memory allocated */
5829 lpfc_mem_free_all(phba);
5830
5831 return;
5832}
5833
5834/**
James Smartda0436e2009-05-22 14:51:39 -04005835 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
5836 * @phba: pointer to lpfc hba data structure.
5837 *
5838 * This routine is invoked to set up the driver internal resources specific to
5839 * support the SLI-4 HBA device it attached to.
5840 *
5841 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005842 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04005843 * other values - error
5844 **/
5845static int
5846lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5847{
James Smart28baac72010-02-12 14:42:03 -05005848 LPFC_MBOXQ_t *mboxq;
James Smartf358dd02017-02-12 13:52:34 -08005849 MAILBOX_t *mb;
James Smart895427b2017-02-12 13:52:30 -08005850 int rc, i, max_buf_size;
James Smart28baac72010-02-12 14:42:03 -05005851 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
5852 struct lpfc_mqe *mqe;
James Smart09294d42013-04-17 20:16:05 -04005853 int longs;
James Smart1ba981f2014-02-20 09:56:45 -05005854 int fof_vectors = 0;
James Smart81e6a632017-11-20 16:00:43 -08005855 int extra;
James Smartf358dd02017-02-12 13:52:34 -08005856 uint64_t wwn;
James Smartb92dc722018-05-24 21:09:01 -07005857 u32 if_type;
5858 u32 if_fam;
James Smartda0436e2009-05-22 14:51:39 -04005859
James Smart895427b2017-02-12 13:52:30 -08005860 phba->sli4_hba.num_online_cpu = num_online_cpus();
5861 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
5862 phba->sli4_hba.curr_disp_cpu = 0;
5863
James Smart716d3bc2013-09-06 12:18:28 -04005864 /* Get all the module params for configuring this host */
5865 lpfc_get_cfgparam(phba);
5866
James Smart895427b2017-02-12 13:52:30 -08005867 /* Set up phase-1 common device driver resources */
5868 rc = lpfc_setup_driver_resource_phase1(phba);
5869 if (rc)
5870 return -ENODEV;
5871
James Smartda0436e2009-05-22 14:51:39 -04005872 /* Before proceed, wait for POST done and device ready */
5873 rc = lpfc_sli4_post_status_check(phba);
5874 if (rc)
5875 return -ENODEV;
5876
5877 /*
5878 * Initialize timers used by driver
5879 */
5880
Kees Cookf22eb4d2017-09-06 20:24:26 -07005881 timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0);
James Smartda0436e2009-05-22 14:51:39 -04005882
James Smartecfd03c2010-02-12 14:41:27 -05005883 /* FCF rediscover timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005884 timer_setup(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo, 0);
James Smartecfd03c2010-02-12 14:41:27 -05005885
James Smartda0436e2009-05-22 14:51:39 -04005886 /*
James Smart7ad20aa2011-05-24 11:44:28 -04005887 * Control structure for handling external multi-buffer mailbox
5888 * command pass-through.
5889 */
5890 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
5891 sizeof(struct lpfc_mbox_ext_buf_ctx));
5892 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
5893
James Smartda0436e2009-05-22 14:51:39 -04005894 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04005895
James Smartda0436e2009-05-22 14:51:39 -04005896 /* This will be set to correct value after the read_config mbox */
5897 phba->max_vports = 0;
5898
5899 /* Program the default value of vlan_id and fc_map */
5900 phba->valid_vlan = 0;
5901 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5902 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5903 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5904
5905 /*
James Smart2a76a282012-08-03 12:35:54 -04005906 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
James Smart895427b2017-02-12 13:52:30 -08005907 * we will associate a new ring, for each EQ/CQ/WQ tuple.
5908 * The WQ create will allocate the ring.
James Smart2a76a282012-08-03 12:35:54 -04005909 */
James Smart085c6472010-11-20 23:11:37 -05005910
James Smart09294d42013-04-17 20:16:05 -04005911 /*
James Smart81e6a632017-11-20 16:00:43 -08005912 * 1 for cmd, 1 for rsp, NVME adds an extra one
5913 * for boundary conditions in its max_sgl_segment template.
5914 */
5915 extra = 2;
5916 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
5917 extra++;
5918
5919 /*
James Smart09294d42013-04-17 20:16:05 -04005920 * It doesn't matter what family our adapter is in, we are
5921 * limited to 2 Pages, 512 SGEs, for our SGL.
5922 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
5923 */
5924 max_buf_size = (2 * SLI4_PAGE_SIZE);
James Smart09294d42013-04-17 20:16:05 -04005925
James Smartda0436e2009-05-22 14:51:39 -04005926 /*
James Smart895427b2017-02-12 13:52:30 -08005927 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
5928 * used to create the sg_dma_buf_pool must be calculated.
James Smart28baac72010-02-12 14:42:03 -05005929 */
James Smartf44ac122018-03-05 12:04:08 -08005930 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
James Smart96f70772013-04-17 20:16:15 -04005931 /*
James Smart895427b2017-02-12 13:52:30 -08005932 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
5933 * the FCP rsp, and a SGE. Sice we have no control
5934 * over how many protection segments the SCSI Layer
James Smart96f70772013-04-17 20:16:15 -04005935 * will hand us (ie: there could be one for every block
James Smart895427b2017-02-12 13:52:30 -08005936 * in the IO), just allocate enough SGEs to accomidate
5937 * our max amount and we need to limit lpfc_sg_seg_cnt
5938 * to minimize the risk of running out.
James Smart96f70772013-04-17 20:16:15 -04005939 */
5940 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08005941 sizeof(struct fcp_rsp) + max_buf_size;
James Smart96f70772013-04-17 20:16:15 -04005942
5943 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
5944 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
5945
James Smart5b9e70b2018-09-10 10:30:42 -07005946 /*
5947 * If supporting DIF, reduce the seg count for scsi to
5948 * allow room for the DIF sges.
5949 */
5950 if (phba->cfg_enable_bg &&
5951 phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF)
5952 phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF;
5953 else
5954 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
5955
James Smart96f70772013-04-17 20:16:15 -04005956 } else {
5957 /*
James Smart895427b2017-02-12 13:52:30 -08005958 * The scsi_buf for a regular I/O holds the FCP cmnd,
James Smart96f70772013-04-17 20:16:15 -04005959 * the FCP rsp, a SGE for each, and a SGE for up to
5960 * cfg_sg_seg_cnt data segments.
5961 */
5962 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08005963 sizeof(struct fcp_rsp) +
James Smart81e6a632017-11-20 16:00:43 -08005964 ((phba->cfg_sg_seg_cnt + extra) *
James Smart895427b2017-02-12 13:52:30 -08005965 sizeof(struct sli4_sge));
James Smart96f70772013-04-17 20:16:15 -04005966
5967 /* Total SGEs for scsi_sg_list */
James Smart81e6a632017-11-20 16:00:43 -08005968 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra;
James Smart5b9e70b2018-09-10 10:30:42 -07005969 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
James Smart895427b2017-02-12 13:52:30 -08005970
James Smart96f70772013-04-17 20:16:15 -04005971 /*
James Smart81e6a632017-11-20 16:00:43 -08005972 * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only
James Smart895427b2017-02-12 13:52:30 -08005973 * need to post 1 page for the SGL.
James Smart96f70772013-04-17 20:16:15 -04005974 */
James Smart085c6472010-11-20 23:11:37 -05005975 }
James Smartacd68592012-01-18 16:25:09 -05005976
James Smart5b9e70b2018-09-10 10:30:42 -07005977 /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */
5978 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
5979 if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) {
5980 lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT,
5981 "6300 Reducing NVME sg segment "
5982 "cnt to %d\n",
5983 LPFC_MAX_NVME_SEG_CNT);
5984 phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
5985 } else
5986 phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt;
5987 }
5988
James Smart96f70772013-04-17 20:16:15 -04005989 /* Initialize the host templates with the updated values. */
James Smart5b9e70b2018-09-10 10:30:42 -07005990 lpfc_vport_template.sg_tablesize = phba->cfg_scsi_seg_cnt;
5991 lpfc_template.sg_tablesize = phba->cfg_scsi_seg_cnt;
5992 lpfc_template_no_hr.sg_tablesize = phba->cfg_scsi_seg_cnt;
James Smart96f70772013-04-17 20:16:15 -04005993
5994 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
5995 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
5996 else
5997 phba->cfg_sg_dma_buf_size =
5998 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
5999
6000 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
James Smart5b9e70b2018-09-10 10:30:42 -07006001 "9087 sg_seg_cnt:%d dmabuf_size:%d "
6002 "total:%d scsi:%d nvme:%d\n",
James Smart96f70772013-04-17 20:16:15 -04006003 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
James Smart5b9e70b2018-09-10 10:30:42 -07006004 phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt,
6005 phba->cfg_nvme_seg_cnt);
James Smartda0436e2009-05-22 14:51:39 -04006006
6007 /* Initialize buffer queue management fields */
James Smart895427b2017-02-12 13:52:30 -08006008 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
James Smartda0436e2009-05-22 14:51:39 -04006009 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
6010 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
6011
6012 /*
6013 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
6014 */
James Smart895427b2017-02-12 13:52:30 -08006015 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
6016 /* Initialize the Abort scsi buffer list used by driver */
6017 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
6018 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
6019 }
6020
6021 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
6022 /* Initialize the Abort nvme buffer list used by driver */
6023 spin_lock_init(&phba->sli4_hba.abts_nvme_buf_list_lock);
6024 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
James Smart86c67372017-04-21 16:05:04 -07006025 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
James Smarta8cf5df2017-05-15 15:20:46 -07006026 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list);
James Smart895427b2017-02-12 13:52:30 -08006027 }
6028
James Smartda0436e2009-05-22 14:51:39 -04006029 /* This abort list used by worker thread */
James Smart895427b2017-02-12 13:52:30 -08006030 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
James Smarta8cf5df2017-05-15 15:20:46 -07006031 spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock);
James Smartda0436e2009-05-22 14:51:39 -04006032
6033 /*
James Smart6d368e52011-05-24 11:44:12 -04006034 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04006035 */
6036
6037 /* Driver internel slow-path CQ Event pool */
6038 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
6039 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04006040 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04006041 /* Asynchronous event CQ Event work queue list */
6042 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
6043 /* Fast-path XRI aborted CQ Event work queue list */
6044 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
6045 /* Slow-path XRI aborted CQ Event work queue list */
6046 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
6047 /* Receive queue CQ Event work queue list */
6048 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
6049
James Smart6d368e52011-05-24 11:44:12 -04006050 /* Initialize extent block lists. */
6051 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
6052 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
6053 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
6054 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
6055
James Smartd1f525a2017-04-21 16:04:55 -07006056 /* Initialize mboxq lists. If the early init routines fail
6057 * these lists need to be correctly initialized.
6058 */
6059 INIT_LIST_HEAD(&phba->sli.mboxq);
6060 INIT_LIST_HEAD(&phba->sli.mboxq_cmpl);
6061
James Smart448193b2015-12-16 18:12:05 -05006062 /* initialize optic_state to 0xFF */
6063 phba->sli4_hba.lnk_info.optic_state = 0xff;
6064
James Smartda0436e2009-05-22 14:51:39 -04006065 /* Allocate device driver memory */
6066 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
6067 if (rc)
6068 return -ENOMEM;
6069
James Smart2fcee4b2010-12-15 17:57:46 -05006070 /* IF Type 2 ports get initialized now. */
James Smart27d6ac02018-02-22 08:18:42 -08006071 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
James Smart2fcee4b2010-12-15 17:57:46 -05006072 LPFC_SLI_INTF_IF_TYPE_2) {
6073 rc = lpfc_pci_function_reset(phba);
James Smart895427b2017-02-12 13:52:30 -08006074 if (unlikely(rc)) {
6075 rc = -ENODEV;
6076 goto out_free_mem;
6077 }
James Smart946727d2015-04-07 15:07:09 -04006078 phba->temp_sensor_support = 1;
James Smart2fcee4b2010-12-15 17:57:46 -05006079 }
6080
James Smartda0436e2009-05-22 14:51:39 -04006081 /* Create the bootstrap mailbox command */
6082 rc = lpfc_create_bootstrap_mbox(phba);
6083 if (unlikely(rc))
6084 goto out_free_mem;
6085
6086 /* Set up the host's endian order with the device. */
6087 rc = lpfc_setup_endian_order(phba);
6088 if (unlikely(rc))
6089 goto out_free_bsmbx;
6090
6091 /* Set up the hba's configuration parameters. */
6092 rc = lpfc_sli4_read_config(phba);
6093 if (unlikely(rc))
6094 goto out_free_bsmbx;
James Smartcff261f2013-12-17 20:29:47 -05006095 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
6096 if (unlikely(rc))
6097 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04006098
James Smart2fcee4b2010-12-15 17:57:46 -05006099 /* IF Type 0 ports get initialized now. */
6100 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
6101 LPFC_SLI_INTF_IF_TYPE_0) {
6102 rc = lpfc_pci_function_reset(phba);
6103 if (unlikely(rc))
6104 goto out_free_bsmbx;
6105 }
James Smartda0436e2009-05-22 14:51:39 -04006106
James Smartcb5172e2010-03-15 11:25:07 -04006107 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
6108 GFP_KERNEL);
6109 if (!mboxq) {
6110 rc = -ENOMEM;
6111 goto out_free_bsmbx;
6112 }
6113
James Smartf358dd02017-02-12 13:52:34 -08006114 /* Check for NVMET being configured */
James Smart895427b2017-02-12 13:52:30 -08006115 phba->nvmet_support = 0;
James Smartf358dd02017-02-12 13:52:34 -08006116 if (lpfc_enable_nvmet_cnt) {
6117
6118 /* First get WWN of HBA instance */
6119 lpfc_read_nv(phba, mboxq);
6120 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6121 if (rc != MBX_SUCCESS) {
6122 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6123 "6016 Mailbox failed , mbxCmd x%x "
6124 "READ_NV, mbxStatus x%x\n",
6125 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
6126 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
James Smartd1f525a2017-04-21 16:04:55 -07006127 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartf358dd02017-02-12 13:52:34 -08006128 rc = -EIO;
6129 goto out_free_bsmbx;
6130 }
6131 mb = &mboxq->u.mb;
6132 memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
6133 sizeof(uint64_t));
6134 wwn = cpu_to_be64(wwn);
6135 phba->sli4_hba.wwnn.u.name = wwn;
6136 memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
6137 sizeof(uint64_t));
6138 /* wwn is WWPN of HBA instance */
6139 wwn = cpu_to_be64(wwn);
6140 phba->sli4_hba.wwpn.u.name = wwn;
6141
6142 /* Check to see if it matches any module parameter */
6143 for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
6144 if (wwn == lpfc_enable_nvmet[i]) {
James Smart7d708032017-03-08 14:36:01 -08006145#if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
James Smart3c603be2017-05-15 15:20:44 -07006146 if (lpfc_nvmet_mem_alloc(phba))
6147 break;
6148
6149 phba->nvmet_support = 1; /* a match */
6150
James Smartf358dd02017-02-12 13:52:34 -08006151 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6152 "6017 NVME Target %016llx\n",
6153 wwn);
James Smart7d708032017-03-08 14:36:01 -08006154#else
6155 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6156 "6021 Can't enable NVME Target."
6157 " NVME_TARGET_FC infrastructure"
6158 " is not in kernel\n");
6159#endif
James Smart3c603be2017-05-15 15:20:44 -07006160 break;
James Smartf358dd02017-02-12 13:52:34 -08006161 }
6162 }
6163 }
James Smart895427b2017-02-12 13:52:30 -08006164
6165 lpfc_nvme_mod_param_dep(phba);
6166
James Smartfedd3b72011-02-16 12:39:24 -05006167 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04006168 lpfc_supported_pages(mboxq);
6169 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05006170 if (!rc) {
6171 mqe = &mboxq->u.mqe;
6172 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
6173 LPFC_MAX_SUPPORTED_PAGES);
6174 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
6175 switch (pn_page[i]) {
6176 case LPFC_SLI4_PARAMETERS:
6177 phba->sli4_hba.pc_sli4_params.supported = 1;
6178 break;
6179 default:
6180 break;
6181 }
6182 }
6183 /* Read the port's SLI4 Parameters capabilities if supported. */
6184 if (phba->sli4_hba.pc_sli4_params.supported)
6185 rc = lpfc_pc_sli4_params_get(phba, mboxq);
6186 if (rc) {
6187 mempool_free(mboxq, phba->mbox_mem_pool);
6188 rc = -EIO;
6189 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04006190 }
6191 }
James Smart65791f12016-07-06 12:35:56 -07006192
James Smartfedd3b72011-02-16 12:39:24 -05006193 /*
6194 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04006195 * If this call fails, it isn't critical unless the SLI4 parameters come
6196 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05006197 */
James Smart6d368e52011-05-24 11:44:12 -04006198 rc = lpfc_get_sli4_parameters(phba, mboxq);
6199 if (rc) {
James Smartb92dc722018-05-24 21:09:01 -07006200 if_type = bf_get(lpfc_sli_intf_if_type,
6201 &phba->sli4_hba.sli_intf);
6202 if_fam = bf_get(lpfc_sli_intf_sli_family,
6203 &phba->sli4_hba.sli_intf);
James Smart6d368e52011-05-24 11:44:12 -04006204 if (phba->sli4_hba.extents_in_use &&
6205 phba->sli4_hba.rpi_hdrs_in_use) {
6206 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6207 "2999 Unsupported SLI4 Parameters "
6208 "Extents and RPI headers enabled.\n");
James Smartb92dc722018-05-24 21:09:01 -07006209 if (if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
6210 if_fam == LPFC_SLI_INTF_FAMILY_BE2) {
6211 mempool_free(mboxq, phba->mbox_mem_pool);
6212 rc = -EIO;
6213 goto out_free_bsmbx;
6214 }
James Smart6d368e52011-05-24 11:44:12 -04006215 }
James Smartb92dc722018-05-24 21:09:01 -07006216 if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
6217 if_fam == LPFC_SLI_INTF_FAMILY_BE2)) {
6218 mempool_free(mboxq, phba->mbox_mem_pool);
6219 rc = -EIO;
6220 goto out_free_bsmbx;
6221 }
James Smart6d368e52011-05-24 11:44:12 -04006222 }
James Smart895427b2017-02-12 13:52:30 -08006223
James Smartcb5172e2010-03-15 11:25:07 -04006224 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -05006225
6226 /* Verify OAS is supported */
6227 lpfc_sli4_oas_verify(phba);
6228 if (phba->cfg_fof)
6229 fof_vectors = 1;
6230
James Smart5350d872011-10-10 21:33:49 -04006231 /* Verify all the SLI4 queues */
6232 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04006233 if (rc)
6234 goto out_free_bsmbx;
6235
6236 /* Create driver internal CQE event pool */
6237 rc = lpfc_sli4_cq_event_pool_create(phba);
6238 if (rc)
James Smart5350d872011-10-10 21:33:49 -04006239 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04006240
James Smart8a9d2e82012-05-09 21:16:12 -04006241 /* Initialize sgl lists per host */
6242 lpfc_init_sgl_list(phba);
6243
6244 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04006245 rc = lpfc_init_active_sgl_array(phba);
6246 if (rc) {
6247 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6248 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04006249 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04006250 }
James Smartda0436e2009-05-22 14:51:39 -04006251 rc = lpfc_sli4_init_rpi_hdrs(phba);
6252 if (rc) {
6253 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6254 "1432 Failed to initialize rpi headers.\n");
6255 goto out_free_active_sgl;
6256 }
6257
James Smarta93ff372010-10-22 11:06:08 -04006258 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05006259 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
Kees Cook6396bb22018-06-12 14:03:40 -07006260 phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long),
James Smart0c9ab6f2010-02-26 14:15:57 -05006261 GFP_KERNEL);
6262 if (!phba->fcf.fcf_rr_bmask) {
6263 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6264 "2759 Failed allocate memory for FCF round "
6265 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04006266 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05006267 goto out_remove_rpi_hdrs;
6268 }
6269
James Smart895427b2017-02-12 13:52:30 -08006270 phba->sli4_hba.hba_eq_hdl = kcalloc(fof_vectors + phba->io_channel_irqs,
6271 sizeof(struct lpfc_hba_eq_hdl),
6272 GFP_KERNEL);
6273 if (!phba->sli4_hba.hba_eq_hdl) {
James Smart67d12732012-08-03 12:36:13 -04006274 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6275 "2572 Failed allocate memory for "
6276 "fast-path per-EQ handle array\n");
6277 rc = -ENOMEM;
6278 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04006279 }
6280
James Smart895427b2017-02-12 13:52:30 -08006281 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_present_cpu,
6282 sizeof(struct lpfc_vector_map_info),
6283 GFP_KERNEL);
James Smart7bb03bb2013-04-17 20:19:16 -04006284 if (!phba->sli4_hba.cpu_map) {
6285 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6286 "3327 Failed allocate memory for msi-x "
6287 "interrupt vector mapping\n");
6288 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08006289 goto out_free_hba_eq_hdl;
James Smart7bb03bb2013-04-17 20:19:16 -04006290 }
James Smartb246de12013-05-31 17:03:07 -04006291 if (lpfc_used_cpu == NULL) {
James Smart895427b2017-02-12 13:52:30 -08006292 lpfc_used_cpu = kcalloc(lpfc_present_cpu, sizeof(uint16_t),
6293 GFP_KERNEL);
James Smartb246de12013-05-31 17:03:07 -04006294 if (!lpfc_used_cpu) {
6295 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6296 "3335 Failed allocate memory for msi-x "
6297 "interrupt vector mapping\n");
6298 kfree(phba->sli4_hba.cpu_map);
6299 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08006300 goto out_free_hba_eq_hdl;
James Smartb246de12013-05-31 17:03:07 -04006301 }
6302 for (i = 0; i < lpfc_present_cpu; i++)
6303 lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
6304 }
6305
James Smart912e3ac2011-05-24 11:42:11 -04006306 /*
6307 * Enable sr-iov virtual functions if supported and configured
6308 * through the module parameter.
6309 */
6310 if (phba->cfg_sriov_nr_virtfn > 0) {
6311 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
6312 phba->cfg_sriov_nr_virtfn);
6313 if (rc) {
6314 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6315 "3020 Requested number of SR-IOV "
6316 "virtual functions (%d) is not "
6317 "supported\n",
6318 phba->cfg_sriov_nr_virtfn);
6319 phba->cfg_sriov_nr_virtfn = 0;
6320 }
6321 }
6322
James Smart5248a742011-07-22 18:37:06 -04006323 return 0;
James Smartda0436e2009-05-22 14:51:39 -04006324
James Smart895427b2017-02-12 13:52:30 -08006325out_free_hba_eq_hdl:
6326 kfree(phba->sli4_hba.hba_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05006327out_free_fcf_rr_bmask:
6328 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04006329out_remove_rpi_hdrs:
6330 lpfc_sli4_remove_rpi_hdrs(phba);
6331out_free_active_sgl:
6332 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04006333out_destroy_cq_event_pool:
6334 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04006335out_free_bsmbx:
6336 lpfc_destroy_bootstrap_mbox(phba);
6337out_free_mem:
6338 lpfc_mem_free(phba);
6339 return rc;
6340}
6341
6342/**
6343 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
6344 * @phba: pointer to lpfc hba data structure.
6345 *
6346 * This routine is invoked to unset the driver internal resources set up
6347 * specific for supporting the SLI-4 HBA device it attached to.
6348 **/
6349static void
6350lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
6351{
6352 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6353
James Smart7bb03bb2013-04-17 20:19:16 -04006354 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
6355 kfree(phba->sli4_hba.cpu_map);
6356 phba->sli4_hba.num_present_cpu = 0;
6357 phba->sli4_hba.num_online_cpu = 0;
James Smart76fd07a2014-02-20 09:57:18 -05006358 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04006359
James Smartda0436e2009-05-22 14:51:39 -04006360 /* Free memory allocated for fast-path work queue handles */
James Smart895427b2017-02-12 13:52:30 -08006361 kfree(phba->sli4_hba.hba_eq_hdl);
James Smartda0436e2009-05-22 14:51:39 -04006362
6363 /* Free the allocated rpi headers. */
6364 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04006365 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04006366
James Smart0c9ab6f2010-02-26 14:15:57 -05006367 /* Free eligible FCF index bmask */
6368 kfree(phba->fcf.fcf_rr_bmask);
6369
James Smartda0436e2009-05-22 14:51:39 -04006370 /* Free the ELS sgl list */
6371 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04006372 lpfc_free_els_sgl_list(phba);
James Smartf358dd02017-02-12 13:52:34 -08006373 lpfc_free_nvmet_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04006374
James Smartda0436e2009-05-22 14:51:39 -04006375 /* Free the completion queue EQ event pool */
6376 lpfc_sli4_cq_event_release_all(phba);
6377 lpfc_sli4_cq_event_pool_destroy(phba);
6378
James Smart6d368e52011-05-24 11:44:12 -04006379 /* Release resource identifiers. */
6380 lpfc_sli4_dealloc_resource_identifiers(phba);
6381
James Smartda0436e2009-05-22 14:51:39 -04006382 /* Free the bsmbx region. */
6383 lpfc_destroy_bootstrap_mbox(phba);
6384
6385 /* Free the SLI Layer memory with SLI4 HBAs */
6386 lpfc_mem_free_all(phba);
6387
6388 /* Free the current connect table */
6389 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04006390 &phba->fcf_conn_rec_list, list) {
6391 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04006392 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04006393 }
James Smartda0436e2009-05-22 14:51:39 -04006394
6395 return;
6396}
6397
6398/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006399 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04006400 * @phba: The hba struct for which this call is being executed.
6401 * @dev_grp: The HBA PCI-Device group number.
6402 *
6403 * This routine sets up the device INIT interface API function jump table
6404 * in @phba struct.
6405 *
6406 * Returns: 0 - success, -ENODEV - failure.
6407 **/
6408int
6409lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
6410{
James Smart84d1b002010-02-12 14:42:33 -05006411 phba->lpfc_hba_init_link = lpfc_hba_init_link;
6412 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05006413 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04006414 switch (dev_grp) {
6415 case LPFC_PCI_DEV_LP:
6416 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
6417 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
6418 phba->lpfc_stop_port = lpfc_stop_port_s3;
6419 break;
James Smartda0436e2009-05-22 14:51:39 -04006420 case LPFC_PCI_DEV_OC:
6421 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
6422 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
6423 phba->lpfc_stop_port = lpfc_stop_port_s4;
6424 break;
James Smart3772a992009-05-22 14:50:54 -04006425 default:
6426 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6427 "1431 Invalid HBA PCI-device group: 0x%x\n",
6428 dev_grp);
6429 return -ENODEV;
6430 break;
6431 }
6432 return 0;
6433}
6434
6435/**
James Smart3772a992009-05-22 14:50:54 -04006436 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
6437 * @phba: pointer to lpfc hba data structure.
6438 *
6439 * This routine is invoked to set up the driver internal resources after the
6440 * device specific resource setup to support the HBA device it attached to.
6441 *
6442 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006443 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006444 * other values - error
6445 **/
6446static int
6447lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
6448{
6449 int error;
6450
6451 /* Startup the kernel thread for this host adapter. */
6452 phba->worker_thread = kthread_run(lpfc_do_work, phba,
6453 "lpfc_worker_%d", phba->brd_no);
6454 if (IS_ERR(phba->worker_thread)) {
6455 error = PTR_ERR(phba->worker_thread);
6456 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006457 }
6458
James Smart0cdb84e2018-04-09 14:24:26 -07006459 /* The lpfc_wq workqueue for deferred irq use, is only used for SLI4 */
6460 if (phba->sli_rev == LPFC_SLI_REV4)
6461 phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0);
6462 else
6463 phba->wq = NULL;
Dick Kennedyf485c182017-09-29 17:34:34 -07006464
James Smart3772a992009-05-22 14:50:54 -04006465 return 0;
6466}
6467
6468/**
6469 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
6470 * @phba: pointer to lpfc hba data structure.
6471 *
6472 * This routine is invoked to unset the driver internal resources set up after
6473 * the device specific resource setup for supporting the HBA device it
6474 * attached to.
6475 **/
6476static void
6477lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
6478{
Dick Kennedyf485c182017-09-29 17:34:34 -07006479 if (phba->wq) {
6480 flush_workqueue(phba->wq);
6481 destroy_workqueue(phba->wq);
6482 phba->wq = NULL;
6483 }
6484
James Smart3772a992009-05-22 14:50:54 -04006485 /* Stop kernel worker thread */
James Smart0cdb84e2018-04-09 14:24:26 -07006486 if (phba->worker_thread)
6487 kthread_stop(phba->worker_thread);
James Smart3772a992009-05-22 14:50:54 -04006488}
6489
6490/**
6491 * lpfc_free_iocb_list - Free iocb list.
6492 * @phba: pointer to lpfc hba data structure.
6493 *
6494 * This routine is invoked to free the driver's IOCB list and memory.
6495 **/
James Smart6c621a22017-05-15 15:20:45 -07006496void
James Smart3772a992009-05-22 14:50:54 -04006497lpfc_free_iocb_list(struct lpfc_hba *phba)
6498{
6499 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
6500
6501 spin_lock_irq(&phba->hbalock);
6502 list_for_each_entry_safe(iocbq_entry, iocbq_next,
6503 &phba->lpfc_iocb_list, list) {
6504 list_del(&iocbq_entry->list);
6505 kfree(iocbq_entry);
6506 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006507 }
James Smart3772a992009-05-22 14:50:54 -04006508 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006509
James Smart3772a992009-05-22 14:50:54 -04006510 return;
6511}
dea31012005-04-17 16:05:31 -05006512
James Smart3772a992009-05-22 14:50:54 -04006513/**
6514 * lpfc_init_iocb_list - Allocate and initialize iocb list.
6515 * @phba: pointer to lpfc hba data structure.
6516 *
6517 * This routine is invoked to allocate and initizlize the driver's IOCB
6518 * list and set up the IOCB tag array accordingly.
6519 *
6520 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006521 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006522 * other values - error
6523 **/
James Smart6c621a22017-05-15 15:20:45 -07006524int
James Smart3772a992009-05-22 14:50:54 -04006525lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
6526{
6527 struct lpfc_iocbq *iocbq_entry = NULL;
6528 uint16_t iotag;
6529 int i;
dea31012005-04-17 16:05:31 -05006530
6531 /* Initialize and populate the iocb list per host. */
6532 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04006533 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07006534 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05006535 if (iocbq_entry == NULL) {
6536 printk(KERN_ERR "%s: only allocated %d iocbs of "
6537 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07006538 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05006539 goto out_free_iocbq;
6540 }
6541
James Bottomley604a3e32005-10-29 10:28:33 -05006542 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
6543 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04006544 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05006545 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04006546 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05006547 goto out_free_iocbq;
6548 }
James Smart6d368e52011-05-24 11:44:12 -04006549 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04006550 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05006551
6552 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006553 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
6554 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05006555 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006556 }
6557
James Smart3772a992009-05-22 14:50:54 -04006558 return 0;
6559
6560out_free_iocbq:
6561 lpfc_free_iocb_list(phba);
6562
6563 return -ENOMEM;
6564}
6565
6566/**
James Smart8a9d2e82012-05-09 21:16:12 -04006567 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04006568 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04006569 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04006570 *
James Smart8a9d2e82012-05-09 21:16:12 -04006571 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04006572 **/
James Smart8a9d2e82012-05-09 21:16:12 -04006573void
6574lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04006575{
6576 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04006577
6578 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
6579 list_del(&sglq_entry->list);
6580 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
6581 kfree(sglq_entry);
6582 }
6583}
6584
6585/**
6586 * lpfc_free_els_sgl_list - Free els sgl list.
6587 * @phba: pointer to lpfc hba data structure.
6588 *
6589 * This routine is invoked to free the driver's els sgl list and memory.
6590 **/
6591static void
6592lpfc_free_els_sgl_list(struct lpfc_hba *phba)
6593{
James Smartda0436e2009-05-22 14:51:39 -04006594 LIST_HEAD(sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04006595
James Smart8a9d2e82012-05-09 21:16:12 -04006596 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04006597 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08006598 spin_lock(&phba->sli4_hba.sgl_list_lock);
6599 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
6600 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04006601 spin_unlock_irq(&phba->hbalock);
6602
James Smart8a9d2e82012-05-09 21:16:12 -04006603 /* Now free the sgl list */
6604 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04006605}
6606
6607/**
James Smartf358dd02017-02-12 13:52:34 -08006608 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
6609 * @phba: pointer to lpfc hba data structure.
6610 *
6611 * This routine is invoked to free the driver's nvmet sgl list and memory.
6612 **/
6613static void
6614lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
6615{
6616 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6617 LIST_HEAD(sglq_list);
6618
6619 /* Retrieve all nvmet sgls from driver list */
6620 spin_lock_irq(&phba->hbalock);
6621 spin_lock(&phba->sli4_hba.sgl_list_lock);
6622 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
6623 spin_unlock(&phba->sli4_hba.sgl_list_lock);
6624 spin_unlock_irq(&phba->hbalock);
6625
6626 /* Now free the sgl list */
6627 list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
6628 list_del(&sglq_entry->list);
6629 lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
6630 kfree(sglq_entry);
6631 }
Dick Kennedy4b40d022017-08-23 16:55:38 -07006632
6633 /* Update the nvmet_xri_cnt to reflect no current sgls.
6634 * The next initialization cycle sets the count and allocates
6635 * the sgls over again.
6636 */
6637 phba->sli4_hba.nvmet_xri_cnt = 0;
James Smartf358dd02017-02-12 13:52:34 -08006638}
6639
6640/**
James Smartda0436e2009-05-22 14:51:39 -04006641 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
6642 * @phba: pointer to lpfc hba data structure.
6643 *
6644 * This routine is invoked to allocate the driver's active sgl memory.
6645 * This array will hold the sglq_entry's for active IOs.
6646 **/
6647static int
6648lpfc_init_active_sgl_array(struct lpfc_hba *phba)
6649{
6650 int size;
6651 size = sizeof(struct lpfc_sglq *);
6652 size *= phba->sli4_hba.max_cfg_param.max_xri;
6653
6654 phba->sli4_hba.lpfc_sglq_active_list =
6655 kzalloc(size, GFP_KERNEL);
6656 if (!phba->sli4_hba.lpfc_sglq_active_list)
6657 return -ENOMEM;
6658 return 0;
6659}
6660
6661/**
6662 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
6663 * @phba: pointer to lpfc hba data structure.
6664 *
6665 * This routine is invoked to walk through the array of active sglq entries
6666 * and free all of the resources.
6667 * This is just a place holder for now.
6668 **/
6669static void
6670lpfc_free_active_sgl(struct lpfc_hba *phba)
6671{
6672 kfree(phba->sli4_hba.lpfc_sglq_active_list);
6673}
6674
6675/**
6676 * lpfc_init_sgl_list - Allocate and initialize sgl list.
6677 * @phba: pointer to lpfc hba data structure.
6678 *
6679 * This routine is invoked to allocate and initizlize the driver's sgl
6680 * list and set up the sgl xritag tag array accordingly.
6681 *
James Smartda0436e2009-05-22 14:51:39 -04006682 **/
James Smart8a9d2e82012-05-09 21:16:12 -04006683static void
James Smartda0436e2009-05-22 14:51:39 -04006684lpfc_init_sgl_list(struct lpfc_hba *phba)
6685{
James Smartda0436e2009-05-22 14:51:39 -04006686 /* Initialize and populate the sglq list per host/VF. */
James Smart895427b2017-02-12 13:52:30 -08006687 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
James Smartda0436e2009-05-22 14:51:39 -04006688 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -08006689 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
James Smart86c67372017-04-21 16:05:04 -07006690 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
James Smartda0436e2009-05-22 14:51:39 -04006691
James Smart8a9d2e82012-05-09 21:16:12 -04006692 /* els xri-sgl book keeping */
6693 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04006694
James Smart8a9d2e82012-05-09 21:16:12 -04006695 /* scsi xri-buffer book keeping */
James Smartda0436e2009-05-22 14:51:39 -04006696 phba->sli4_hba.scsi_xri_cnt = 0;
James Smart895427b2017-02-12 13:52:30 -08006697
6698 /* nvme xri-buffer book keeping */
6699 phba->sli4_hba.nvme_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04006700}
6701
6702/**
6703 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
6704 * @phba: pointer to lpfc hba data structure.
6705 *
6706 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04006707 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04006708 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04006709 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
6710 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04006711 *
6712 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006713 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04006714 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04006715 **/
6716int
6717lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
6718{
6719 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04006720 struct lpfc_rpi_hdr *rpi_hdr;
6721
6722 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05006723 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04006724 return rc;
James Smart6d368e52011-05-24 11:44:12 -04006725 if (phba->sli4_hba.extents_in_use)
6726 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04006727
6728 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
6729 if (!rpi_hdr) {
6730 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6731 "0391 Error during rpi post operation\n");
6732 lpfc_sli4_remove_rpis(phba);
6733 rc = -ENODEV;
6734 }
6735
6736 return rc;
6737}
6738
6739/**
6740 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
6741 * @phba: pointer to lpfc hba data structure.
6742 *
6743 * This routine is invoked to allocate a single 4KB memory region to
6744 * support rpis and stores them in the phba. This single region
6745 * provides support for up to 64 rpis. The region is used globally
6746 * by the device.
6747 *
6748 * Returns:
6749 * A valid rpi hdr on success.
6750 * A NULL pointer on any failure.
6751 **/
6752struct lpfc_rpi_hdr *
6753lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
6754{
6755 uint16_t rpi_limit, curr_rpi_range;
6756 struct lpfc_dmabuf *dmabuf;
6757 struct lpfc_rpi_hdr *rpi_hdr;
6758
James Smart6d368e52011-05-24 11:44:12 -04006759 /*
6760 * If the SLI4 port supports extents, posting the rpi header isn't
6761 * required. Set the expected maximum count and let the actual value
6762 * get set when extents are fully allocated.
6763 */
6764 if (!phba->sli4_hba.rpi_hdrs_in_use)
6765 return NULL;
6766 if (phba->sli4_hba.extents_in_use)
6767 return NULL;
6768
6769 /* The limit on the logical index is just the max_rpi count. */
James Smart845d9e82017-05-15 15:20:38 -07006770 rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi;
James Smartda0436e2009-05-22 14:51:39 -04006771
6772 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006773 /*
6774 * Establish the starting RPI in this header block. The starting
6775 * rpi is normalized to a zero base because the physical rpi is
6776 * port based.
6777 */
James Smart97f2ecf2012-03-01 22:35:23 -05006778 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04006779 spin_unlock_irq(&phba->hbalock);
6780
James Smart845d9e82017-05-15 15:20:38 -07006781 /* Reached full RPI range */
6782 if (curr_rpi_range == rpi_limit)
James Smart6d368e52011-05-24 11:44:12 -04006783 return NULL;
James Smart845d9e82017-05-15 15:20:38 -07006784
James Smartda0436e2009-05-22 14:51:39 -04006785 /*
6786 * First allocate the protocol header region for the port. The
6787 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
6788 */
6789 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6790 if (!dmabuf)
6791 return NULL;
6792
Joe Perches1aee3832014-09-03 12:56:12 -04006793 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
6794 LPFC_HDR_TEMPLATE_SIZE,
6795 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04006796 if (!dmabuf->virt) {
6797 rpi_hdr = NULL;
6798 goto err_free_dmabuf;
6799 }
6800
James Smartda0436e2009-05-22 14:51:39 -04006801 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
6802 rpi_hdr = NULL;
6803 goto err_free_coherent;
6804 }
6805
6806 /* Save the rpi header data for cleanup later. */
6807 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
6808 if (!rpi_hdr)
6809 goto err_free_coherent;
6810
6811 rpi_hdr->dmabuf = dmabuf;
6812 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
6813 rpi_hdr->page_count = 1;
6814 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006815
6816 /* The rpi_hdr stores the logical index only. */
6817 rpi_hdr->start_rpi = curr_rpi_range;
James Smart845d9e82017-05-15 15:20:38 -07006818 rpi_hdr->next_rpi = phba->sli4_hba.next_rpi + LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04006819 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
6820
James Smartda0436e2009-05-22 14:51:39 -04006821 spin_unlock_irq(&phba->hbalock);
6822 return rpi_hdr;
6823
6824 err_free_coherent:
6825 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
6826 dmabuf->virt, dmabuf->phys);
6827 err_free_dmabuf:
6828 kfree(dmabuf);
6829 return NULL;
6830}
6831
6832/**
6833 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
6834 * @phba: pointer to lpfc hba data structure.
6835 *
6836 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04006837 * to support rpis for SLI4 ports not supporting extents. This routine
6838 * presumes the caller has released all rpis consumed by fabric or port
6839 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04006840 **/
6841void
6842lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
6843{
6844 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
6845
James Smart6d368e52011-05-24 11:44:12 -04006846 if (!phba->sli4_hba.rpi_hdrs_in_use)
6847 goto exit;
6848
James Smartda0436e2009-05-22 14:51:39 -04006849 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
6850 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
6851 list_del(&rpi_hdr->list);
6852 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
6853 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
6854 kfree(rpi_hdr->dmabuf);
6855 kfree(rpi_hdr);
6856 }
James Smart6d368e52011-05-24 11:44:12 -04006857 exit:
6858 /* There are no rpis available to the port now. */
6859 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04006860}
6861
6862/**
James Smart3772a992009-05-22 14:50:54 -04006863 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
6864 * @pdev: pointer to pci device data structure.
6865 *
6866 * This routine is invoked to allocate the driver hba data structure for an
6867 * HBA device. If the allocation is successful, the phba reference to the
6868 * PCI device data structure is set.
6869 *
6870 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006871 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04006872 * NULL - error
6873 **/
6874static struct lpfc_hba *
6875lpfc_hba_alloc(struct pci_dev *pdev)
6876{
6877 struct lpfc_hba *phba;
6878
6879 /* Allocate memory for HBA structure */
6880 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
6881 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02006882 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04006883 return NULL;
6884 }
6885
6886 /* Set reference to PCI device in HBA structure */
6887 phba->pcidev = pdev;
6888
6889 /* Assign an unused board number */
6890 phba->brd_no = lpfc_get_instance();
6891 if (phba->brd_no < 0) {
6892 kfree(phba);
6893 return NULL;
6894 }
James Smart65791f12016-07-06 12:35:56 -07006895 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
James Smart3772a992009-05-22 14:50:54 -04006896
James Smart4fede782010-01-26 23:08:55 -05006897 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04006898 INIT_LIST_HEAD(&phba->ct_ev_waiters);
6899
James Smart3772a992009-05-22 14:50:54 -04006900 return phba;
6901}
6902
6903/**
6904 * lpfc_hba_free - Free driver hba data structure with a device.
6905 * @phba: pointer to lpfc hba data structure.
6906 *
6907 * This routine is invoked to free the driver hba data structure with an
6908 * HBA device.
6909 **/
6910static void
6911lpfc_hba_free(struct lpfc_hba *phba)
6912{
6913 /* Release the driver assigned board number */
6914 idr_remove(&lpfc_hba_index, phba->brd_no);
6915
James Smart895427b2017-02-12 13:52:30 -08006916 /* Free memory allocated with sli3 rings */
6917 kfree(phba->sli.sli3_ring);
6918 phba->sli.sli3_ring = NULL;
James Smart2a76a282012-08-03 12:35:54 -04006919
James Smart3772a992009-05-22 14:50:54 -04006920 kfree(phba);
6921 return;
6922}
6923
6924/**
6925 * lpfc_create_shost - Create hba physical port with associated scsi host.
6926 * @phba: pointer to lpfc hba data structure.
6927 *
6928 * This routine is invoked to create HBA physical port and associate a SCSI
6929 * host with it.
6930 *
6931 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006932 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006933 * other values - error
6934 **/
6935static int
6936lpfc_create_shost(struct lpfc_hba *phba)
6937{
6938 struct lpfc_vport *vport;
6939 struct Scsi_Host *shost;
6940
6941 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05006942 phba->fc_edtov = FF_DEF_EDTOV;
6943 phba->fc_ratov = FF_DEF_RATOV;
6944 phba->fc_altov = FF_DEF_ALTOV;
6945 phba->fc_arbtov = FF_DEF_ARBTOV;
6946
James Smartd7c47992010-06-08 18:31:54 -04006947 atomic_set(&phba->sdev_cnt, 0);
James Smart2cee7802017-06-01 21:07:02 -07006948 atomic_set(&phba->fc4ScsiInputRequests, 0);
6949 atomic_set(&phba->fc4ScsiOutputRequests, 0);
6950 atomic_set(&phba->fc4ScsiControlRequests, 0);
6951 atomic_set(&phba->fc4ScsiIoCmpls, 0);
James Smart3de2a652007-08-02 11:09:59 -04006952 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05006953 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04006954 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05006955
6956 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05006957 phba->pport = vport;
James Smart2ea259e2017-02-12 13:52:27 -08006958
James Smartf358dd02017-02-12 13:52:34 -08006959 if (phba->nvmet_support) {
6960 /* Only 1 vport (pport) will support NVME target */
6961 if (phba->txrdy_payload_pool == NULL) {
Romain Perier771db5c2017-07-06 10:13:05 +02006962 phba->txrdy_payload_pool = dma_pool_create(
6963 "txrdy_pool", &phba->pcidev->dev,
James Smartf358dd02017-02-12 13:52:34 -08006964 TXRDY_PAYLOAD_LEN, 16, 0);
6965 if (phba->txrdy_payload_pool) {
6966 phba->targetport = NULL;
6967 phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
6968 lpfc_printf_log(phba, KERN_INFO,
6969 LOG_INIT | LOG_NVME_DISC,
6970 "6076 NVME Target Found\n");
6971 }
6972 }
6973 }
6974
James Smart858c9f62007-06-17 19:56:39 -05006975 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04006976 /* Put reference to SCSI host to driver's device private data */
6977 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05006978
James Smart4258e982015-12-16 18:11:58 -05006979 /*
6980 * At this point we are fully registered with PSA. In addition,
6981 * any initial discovery should be completed.
6982 */
6983 vport->load_flag |= FC_ALLOW_FDMI;
James Smart8663cbb2016-03-31 14:12:33 -07006984 if (phba->cfg_enable_SmartSAN ||
6985 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -05006986
6987 /* Setup appropriate attribute masks */
6988 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -07006989 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -05006990 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
6991 else
6992 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
6993 }
James Smart3772a992009-05-22 14:50:54 -04006994 return 0;
6995}
dea31012005-04-17 16:05:31 -05006996
James Smart3772a992009-05-22 14:50:54 -04006997/**
6998 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
6999 * @phba: pointer to lpfc hba data structure.
7000 *
7001 * This routine is invoked to destroy HBA physical port and the associated
7002 * SCSI host.
7003 **/
7004static void
7005lpfc_destroy_shost(struct lpfc_hba *phba)
7006{
7007 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04007008
James Smart3772a992009-05-22 14:50:54 -04007009 /* Destroy physical port that associated with the SCSI host */
7010 destroy_port(vport);
7011
7012 return;
7013}
7014
7015/**
7016 * lpfc_setup_bg - Setup Block guard structures and debug areas.
7017 * @phba: pointer to lpfc hba data structure.
7018 * @shost: the shost to be used to detect Block guard settings.
7019 *
7020 * This routine sets up the local Block guard protocol settings for @shost.
7021 * This routine also allocates memory for debugging bg buffers.
7022 **/
7023static void
7024lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
7025{
James Smartbbeb79b2012-06-12 13:54:27 -04007026 uint32_t old_mask;
7027 uint32_t old_guard;
7028
James Smart3772a992009-05-22 14:50:54 -04007029 int pagecnt = 10;
James Smartb3b98b72016-10-13 15:06:06 -07007030 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
James Smart3772a992009-05-22 14:50:54 -04007031 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7032 "1478 Registering BlockGuard with the "
7033 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04007034
James Smartb3b98b72016-10-13 15:06:06 -07007035 old_mask = phba->cfg_prot_mask;
7036 old_guard = phba->cfg_prot_guard;
James Smartbbeb79b2012-06-12 13:54:27 -04007037
7038 /* Only allow supported values */
James Smartb3b98b72016-10-13 15:06:06 -07007039 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
James Smartbbeb79b2012-06-12 13:54:27 -04007040 SHOST_DIX_TYPE0_PROTECTION |
7041 SHOST_DIX_TYPE1_PROTECTION);
James Smartb3b98b72016-10-13 15:06:06 -07007042 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
7043 SHOST_DIX_GUARD_CRC);
James Smartbbeb79b2012-06-12 13:54:27 -04007044
7045 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
James Smartb3b98b72016-10-13 15:06:06 -07007046 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
7047 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
James Smartbbeb79b2012-06-12 13:54:27 -04007048
James Smartb3b98b72016-10-13 15:06:06 -07007049 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
7050 if ((old_mask != phba->cfg_prot_mask) ||
7051 (old_guard != phba->cfg_prot_guard))
James Smartbbeb79b2012-06-12 13:54:27 -04007052 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7053 "1475 Registering BlockGuard with the "
7054 "SCSI layer: mask %d guard %d\n",
James Smartb3b98b72016-10-13 15:06:06 -07007055 phba->cfg_prot_mask,
7056 phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04007057
James Smartb3b98b72016-10-13 15:06:06 -07007058 scsi_host_set_prot(shost, phba->cfg_prot_mask);
7059 scsi_host_set_guard(shost, phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04007060 } else
7061 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7062 "1479 Not Registering BlockGuard with the SCSI "
7063 "layer, Bad protection parameters: %d %d\n",
7064 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04007065 }
James Smartbbeb79b2012-06-12 13:54:27 -04007066
James Smart81301a92008-12-04 22:39:46 -05007067 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05007068 while (pagecnt) {
7069 spin_lock_init(&_dump_buf_lock);
7070 _dump_buf_data =
7071 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
7072 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04007073 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7074 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04007075 "_dump_buf_data at 0x%p\n",
7076 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05007077 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04007078 memset(_dump_buf_data, 0,
7079 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05007080 break;
James Smart3772a992009-05-22 14:50:54 -04007081 } else
James Smart81301a92008-12-04 22:39:46 -05007082 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05007083 }
James Smart81301a92008-12-04 22:39:46 -05007084 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04007085 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7086 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04007087 "memory for hexdump\n");
7088 } else
James Smart6a9c52c2009-10-02 15:16:51 -04007089 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7090 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05007091 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05007092 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05007093 while (pagecnt) {
7094 _dump_buf_dif =
7095 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
7096 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04007097 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7098 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04007099 "_dump_buf_dif at 0x%p\n",
7100 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05007101 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04007102 memset(_dump_buf_dif, 0,
7103 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05007104 break;
James Smart3772a992009-05-22 14:50:54 -04007105 } else
James Smart81301a92008-12-04 22:39:46 -05007106 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05007107 }
James Smart81301a92008-12-04 22:39:46 -05007108 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04007109 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7110 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04007111 "memory for hexdump\n");
7112 } else
James Smart6a9c52c2009-10-02 15:16:51 -04007113 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7114 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04007115 _dump_buf_dif);
7116}
7117
7118/**
7119 * lpfc_post_init_setup - Perform necessary device post initialization setup.
7120 * @phba: pointer to lpfc hba data structure.
7121 *
7122 * This routine is invoked to perform all the necessary post initialization
7123 * setup for the device.
7124 **/
7125static void
7126lpfc_post_init_setup(struct lpfc_hba *phba)
7127{
7128 struct Scsi_Host *shost;
7129 struct lpfc_adapter_event_header adapter_event;
7130
7131 /* Get the default values for Model Name and Description */
7132 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
7133
7134 /*
7135 * hba setup may have changed the hba_queue_depth so we need to
7136 * adjust the value of can_queue.
7137 */
7138 shost = pci_get_drvdata(phba->pcidev);
7139 shost->can_queue = phba->cfg_hba_queue_depth - 10;
7140 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
7141 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05007142
7143 lpfc_host_attrib_init(shost);
7144
James Smart2e0fef82007-06-17 19:56:36 -05007145 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
7146 spin_lock_irq(shost->host_lock);
7147 lpfc_poll_start_timer(phba);
7148 spin_unlock_irq(shost->host_lock);
7149 }
James Smart8f6d98d2006-08-01 07:34:00 -04007150
James Smart93996272008-08-24 21:50:30 -04007151 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7152 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04007153 /* Send board arrival event to upper layer */
7154 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
7155 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
7156 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04007157 sizeof(adapter_event),
7158 (char *) &adapter_event,
7159 LPFC_NL_VENDOR_ID);
7160 return;
7161}
7162
7163/**
7164 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
7165 * @phba: pointer to lpfc hba data structure.
7166 *
7167 * This routine is invoked to set up the PCI device memory space for device
7168 * with SLI-3 interface spec.
7169 *
7170 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007171 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007172 * other values - error
7173 **/
7174static int
7175lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
7176{
7177 struct pci_dev *pdev;
7178 unsigned long bar0map_len, bar2map_len;
7179 int i, hbq_count;
7180 void *ptr;
7181 int error = -ENODEV;
7182
7183 /* Obtain PCI device reference */
7184 if (!phba->pcidev)
7185 return error;
7186 else
7187 pdev = phba->pcidev;
7188
7189 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05007190 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
7191 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
7192 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
7193 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smart3772a992009-05-22 14:50:54 -04007194 return error;
Michael Reed8e685972009-09-18 12:02:05 -05007195 }
7196 }
James Smart3772a992009-05-22 14:50:54 -04007197
7198 /* Get the bus address of Bar0 and Bar2 and the number of bytes
7199 * required by each mapping.
7200 */
7201 phba->pci_bar0_map = pci_resource_start(pdev, 0);
7202 bar0map_len = pci_resource_len(pdev, 0);
7203
7204 phba->pci_bar2_map = pci_resource_start(pdev, 2);
7205 bar2map_len = pci_resource_len(pdev, 2);
7206
7207 /* Map HBA SLIM to a kernel virtual address. */
7208 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
7209 if (!phba->slim_memmap_p) {
7210 dev_printk(KERN_ERR, &pdev->dev,
7211 "ioremap failed for SLIM memory.\n");
7212 goto out;
7213 }
7214
7215 /* Map HBA Control Registers to a kernel virtual address. */
7216 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
7217 if (!phba->ctrl_regs_memmap_p) {
7218 dev_printk(KERN_ERR, &pdev->dev,
7219 "ioremap failed for HBA control registers.\n");
7220 goto out_iounmap_slim;
7221 }
7222
7223 /* Allocate memory for SLI-2 structures */
Joe Perches1aee3832014-09-03 12:56:12 -04007224 phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7225 &phba->slim2p.phys, GFP_KERNEL);
James Smart3772a992009-05-22 14:50:54 -04007226 if (!phba->slim2p.virt)
7227 goto out_iounmap;
7228
James Smart3772a992009-05-22 14:50:54 -04007229 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04007230 phba->mbox_ext = (phba->slim2p.virt +
7231 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04007232 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
7233 phba->IOCBs = (phba->slim2p.virt +
7234 offsetof(struct lpfc_sli2_slim, IOCBs));
7235
7236 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
7237 lpfc_sli_hbq_size(),
7238 &phba->hbqslimp.phys,
7239 GFP_KERNEL);
7240 if (!phba->hbqslimp.virt)
7241 goto out_free_slim;
7242
7243 hbq_count = lpfc_sli_hbq_count();
7244 ptr = phba->hbqslimp.virt;
7245 for (i = 0; i < hbq_count; ++i) {
7246 phba->hbqs[i].hbq_virt = ptr;
7247 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
7248 ptr += (lpfc_hbq_defs[i]->entry_count *
7249 sizeof(struct lpfc_hbq_entry));
7250 }
7251 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
7252 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
7253
7254 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
7255
James Smart3772a992009-05-22 14:50:54 -04007256 phba->MBslimaddr = phba->slim_memmap_p;
7257 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
7258 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
7259 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
7260 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04007261
dea31012005-04-17 16:05:31 -05007262 return 0;
7263
dea31012005-04-17 16:05:31 -05007264out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04007265 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7266 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05007267out_iounmap:
7268 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05007269out_iounmap_slim:
dea31012005-04-17 16:05:31 -05007270 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05007271out:
7272 return error;
7273}
7274
James Smarte59058c2008-08-24 21:49:00 -04007275/**
James Smart3772a992009-05-22 14:50:54 -04007276 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
7277 * @phba: pointer to lpfc hba data structure.
7278 *
7279 * This routine is invoked to unset the PCI device memory space for device
7280 * with SLI-3 interface spec.
7281 **/
7282static void
7283lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
7284{
7285 struct pci_dev *pdev;
7286
7287 /* Obtain PCI device reference */
7288 if (!phba->pcidev)
7289 return;
7290 else
7291 pdev = phba->pcidev;
7292
7293 /* Free coherent DMA memory allocated */
7294 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
7295 phba->hbqslimp.virt, phba->hbqslimp.phys);
7296 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7297 phba->slim2p.virt, phba->slim2p.phys);
7298
7299 /* I/O memory unmap */
7300 iounmap(phba->ctrl_regs_memmap_p);
7301 iounmap(phba->slim_memmap_p);
7302
7303 return;
7304}
7305
7306/**
James Smartda0436e2009-05-22 14:51:39 -04007307 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
7308 * @phba: pointer to lpfc hba data structure.
7309 *
7310 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
7311 * done and check status.
7312 *
7313 * Return 0 if successful, otherwise -ENODEV.
7314 **/
7315int
7316lpfc_sli4_post_status_check(struct lpfc_hba *phba)
7317{
James Smart2fcee4b2010-12-15 17:57:46 -05007318 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
7319 struct lpfc_register reg_data;
7320 int i, port_error = 0;
7321 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04007322
James Smart9940b972011-03-11 16:06:12 -05007323 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
7324 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05007325 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04007326 return -ENODEV;
7327
James Smartda0436e2009-05-22 14:51:39 -04007328 /* Wait up to 30 seconds for the SLI Port POST done and ready */
7329 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05007330 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
7331 &portsmphr_reg.word0) ||
7332 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007333 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04007334 port_error = -ENODEV;
7335 break;
7336 }
James Smart2fcee4b2010-12-15 17:57:46 -05007337 if (LPFC_POST_STAGE_PORT_READY ==
7338 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04007339 break;
James Smartda0436e2009-05-22 14:51:39 -04007340 msleep(10);
7341 }
7342
James Smart2fcee4b2010-12-15 17:57:46 -05007343 /*
7344 * If there was a port error during POST, then don't proceed with
7345 * other register reads as the data may not be valid. Just exit.
7346 */
7347 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04007348 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05007349 "1408 Port Failed POST - portsmphr=0x%x, "
7350 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
7351 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
7352 portsmphr_reg.word0,
7353 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
7354 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
7355 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
7356 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
7357 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
7358 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
7359 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
7360 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
7361 } else {
James Smart28baac72010-02-12 14:42:03 -05007362 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05007363 "2534 Device Info: SLIFamily=0x%x, "
7364 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
7365 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05007366 bf_get(lpfc_sli_intf_sli_family,
7367 &phba->sli4_hba.sli_intf),
7368 bf_get(lpfc_sli_intf_slirev,
7369 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05007370 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05007371 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05007372 bf_get(lpfc_sli_intf_sli_hint1,
7373 &phba->sli4_hba.sli_intf),
7374 bf_get(lpfc_sli_intf_sli_hint2,
7375 &phba->sli4_hba.sli_intf),
7376 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05007377 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05007378 /*
7379 * Check for other Port errors during the initialization
7380 * process. Fail the load if the port did not come up
7381 * correctly.
7382 */
7383 if_type = bf_get(lpfc_sli_intf_if_type,
7384 &phba->sli4_hba.sli_intf);
7385 switch (if_type) {
7386 case LPFC_SLI_INTF_IF_TYPE_0:
7387 phba->sli4_hba.ue_mask_lo =
7388 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
7389 phba->sli4_hba.ue_mask_hi =
7390 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
7391 uerrlo_reg.word0 =
7392 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
7393 uerrhi_reg.word0 =
7394 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
7395 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
7396 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
7397 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7398 "1422 Unrecoverable Error "
7399 "Detected during POST "
7400 "uerr_lo_reg=0x%x, "
7401 "uerr_hi_reg=0x%x, "
7402 "ue_mask_lo_reg=0x%x, "
7403 "ue_mask_hi_reg=0x%x\n",
7404 uerrlo_reg.word0,
7405 uerrhi_reg.word0,
7406 phba->sli4_hba.ue_mask_lo,
7407 phba->sli4_hba.ue_mask_hi);
7408 port_error = -ENODEV;
7409 }
7410 break;
7411 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08007412 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2fcee4b2010-12-15 17:57:46 -05007413 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05007414 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
7415 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04007416 (bf_get(lpfc_sliport_status_err, &reg_data) &&
7417 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007418 phba->work_status[0] =
7419 readl(phba->sli4_hba.u.if_type2.
7420 ERR1regaddr);
7421 phba->work_status[1] =
7422 readl(phba->sli4_hba.u.if_type2.
7423 ERR2regaddr);
7424 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05007425 "2888 Unrecoverable port error "
7426 "following POST: port status reg "
7427 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05007428 "error 1=0x%x, error 2=0x%x\n",
7429 reg_data.word0,
7430 portsmphr_reg.word0,
7431 phba->work_status[0],
7432 phba->work_status[1]);
7433 port_error = -ENODEV;
7434 }
7435 break;
7436 case LPFC_SLI_INTF_IF_TYPE_1:
7437 default:
7438 break;
7439 }
James Smart28baac72010-02-12 14:42:03 -05007440 }
James Smartda0436e2009-05-22 14:51:39 -04007441 return port_error;
7442}
7443
7444/**
7445 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
7446 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05007447 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04007448 *
7449 * This routine is invoked to set up SLI4 BAR0 PCI config space register
7450 * memory map.
7451 **/
7452static void
James Smart2fcee4b2010-12-15 17:57:46 -05007453lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04007454{
James Smart2fcee4b2010-12-15 17:57:46 -05007455 switch (if_type) {
7456 case LPFC_SLI_INTF_IF_TYPE_0:
7457 phba->sli4_hba.u.if_type0.UERRLOregaddr =
7458 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
7459 phba->sli4_hba.u.if_type0.UERRHIregaddr =
7460 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
7461 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
7462 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
7463 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
7464 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
7465 phba->sli4_hba.SLIINTFregaddr =
7466 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7467 break;
7468 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart0cf07f842017-06-01 21:07:10 -07007469 phba->sli4_hba.u.if_type2.EQDregaddr =
7470 phba->sli4_hba.conf_regs_memmap_p +
7471 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007472 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007473 phba->sli4_hba.conf_regs_memmap_p +
7474 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007475 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007476 phba->sli4_hba.conf_regs_memmap_p +
7477 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007478 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007479 phba->sli4_hba.conf_regs_memmap_p +
7480 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007481 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007482 phba->sli4_hba.conf_regs_memmap_p +
7483 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007484 phba->sli4_hba.SLIINTFregaddr =
7485 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7486 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007487 phba->sli4_hba.conf_regs_memmap_p +
7488 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007489 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05007490 phba->sli4_hba.conf_regs_memmap_p +
7491 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05007492 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05007493 phba->sli4_hba.conf_regs_memmap_p +
7494 LPFC_ULP0_WQ_DOORBELL;
James Smart9dd35422018-02-22 08:18:41 -08007495 phba->sli4_hba.CQDBregaddr =
James Smart2fcee4b2010-12-15 17:57:46 -05007496 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
James Smart9dd35422018-02-22 08:18:41 -08007497 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
James Smart2fcee4b2010-12-15 17:57:46 -05007498 phba->sli4_hba.MQDBregaddr =
7499 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
7500 phba->sli4_hba.BMBXregaddr =
7501 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
7502 break;
James Smart27d6ac02018-02-22 08:18:42 -08007503 case LPFC_SLI_INTF_IF_TYPE_6:
7504 phba->sli4_hba.u.if_type2.EQDregaddr =
7505 phba->sli4_hba.conf_regs_memmap_p +
7506 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
7507 phba->sli4_hba.u.if_type2.ERR1regaddr =
7508 phba->sli4_hba.conf_regs_memmap_p +
7509 LPFC_CTL_PORT_ER1_OFFSET;
7510 phba->sli4_hba.u.if_type2.ERR2regaddr =
7511 phba->sli4_hba.conf_regs_memmap_p +
7512 LPFC_CTL_PORT_ER2_OFFSET;
7513 phba->sli4_hba.u.if_type2.CTRLregaddr =
7514 phba->sli4_hba.conf_regs_memmap_p +
7515 LPFC_CTL_PORT_CTL_OFFSET;
7516 phba->sli4_hba.u.if_type2.STATUSregaddr =
7517 phba->sli4_hba.conf_regs_memmap_p +
7518 LPFC_CTL_PORT_STA_OFFSET;
7519 phba->sli4_hba.PSMPHRregaddr =
7520 phba->sli4_hba.conf_regs_memmap_p +
7521 LPFC_CTL_PORT_SEM_OFFSET;
7522 phba->sli4_hba.BMBXregaddr =
7523 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
7524 break;
James Smart2fcee4b2010-12-15 17:57:46 -05007525 case LPFC_SLI_INTF_IF_TYPE_1:
7526 default:
7527 dev_printk(KERN_ERR, &phba->pcidev->dev,
7528 "FATAL - unsupported SLI4 interface type - %d\n",
7529 if_type);
7530 break;
7531 }
James Smartda0436e2009-05-22 14:51:39 -04007532}
7533
7534/**
7535 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
7536 * @phba: pointer to lpfc hba data structure.
7537 *
James Smart27d6ac02018-02-22 08:18:42 -08007538 * This routine is invoked to set up SLI4 BAR1 register memory map.
James Smartda0436e2009-05-22 14:51:39 -04007539 **/
7540static void
James Smart27d6ac02018-02-22 08:18:42 -08007541lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04007542{
James Smart27d6ac02018-02-22 08:18:42 -08007543 switch (if_type) {
7544 case LPFC_SLI_INTF_IF_TYPE_0:
7545 phba->sli4_hba.PSMPHRregaddr =
7546 phba->sli4_hba.ctrl_regs_memmap_p +
7547 LPFC_SLIPORT_IF0_SMPHR;
7548 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7549 LPFC_HST_ISR0;
7550 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7551 LPFC_HST_IMR0;
7552 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7553 LPFC_HST_ISCR0;
7554 break;
7555 case LPFC_SLI_INTF_IF_TYPE_6:
7556 phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7557 LPFC_IF6_RQ_DOORBELL;
7558 phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7559 LPFC_IF6_WQ_DOORBELL;
7560 phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7561 LPFC_IF6_CQ_DOORBELL;
7562 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7563 LPFC_IF6_EQ_DOORBELL;
7564 phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7565 LPFC_IF6_MQ_DOORBELL;
7566 break;
7567 case LPFC_SLI_INTF_IF_TYPE_2:
7568 case LPFC_SLI_INTF_IF_TYPE_1:
7569 default:
7570 dev_err(&phba->pcidev->dev,
7571 "FATAL - unsupported SLI4 interface type - %d\n",
7572 if_type);
7573 break;
7574 }
James Smartda0436e2009-05-22 14:51:39 -04007575}
7576
7577/**
7578 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
7579 * @phba: pointer to lpfc hba data structure.
7580 * @vf: virtual function number
7581 *
7582 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
7583 * based on the given viftual function number, @vf.
7584 *
7585 * Return 0 if successful, otherwise -ENODEV.
7586 **/
7587static int
7588lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
7589{
7590 if (vf > LPFC_VIR_FUNC_MAX)
7591 return -ENODEV;
7592
7593 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05007594 vf * LPFC_VFR_PAGE_SIZE +
7595 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04007596 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05007597 vf * LPFC_VFR_PAGE_SIZE +
7598 LPFC_ULP0_WQ_DOORBELL);
James Smart9dd35422018-02-22 08:18:41 -08007599 phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7600 vf * LPFC_VFR_PAGE_SIZE +
7601 LPFC_EQCQ_DOORBELL);
7602 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
James Smartda0436e2009-05-22 14:51:39 -04007603 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7604 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
7605 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7606 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
7607 return 0;
7608}
7609
7610/**
7611 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
7612 * @phba: pointer to lpfc hba data structure.
7613 *
7614 * This routine is invoked to create the bootstrap mailbox
7615 * region consistent with the SLI-4 interface spec. This
7616 * routine allocates all memory necessary to communicate
7617 * mailbox commands to the port and sets up all alignment
7618 * needs. No locks are expected to be held when calling
7619 * this routine.
7620 *
7621 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007622 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04007623 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04007624 **/
7625static int
7626lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
7627{
7628 uint32_t bmbx_size;
7629 struct lpfc_dmabuf *dmabuf;
7630 struct dma_address *dma_address;
7631 uint32_t pa_addr;
7632 uint64_t phys_addr;
7633
7634 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
7635 if (!dmabuf)
7636 return -ENOMEM;
7637
7638 /*
7639 * The bootstrap mailbox region is comprised of 2 parts
7640 * plus an alignment restriction of 16 bytes.
7641 */
7642 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
Joe Perches1aee3832014-09-03 12:56:12 -04007643 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
7644 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04007645 if (!dmabuf->virt) {
7646 kfree(dmabuf);
7647 return -ENOMEM;
7648 }
James Smartda0436e2009-05-22 14:51:39 -04007649
7650 /*
7651 * Initialize the bootstrap mailbox pointers now so that the register
7652 * operations are simple later. The mailbox dma address is required
7653 * to be 16-byte aligned. Also align the virtual memory as each
7654 * maibox is copied into the bmbx mailbox region before issuing the
7655 * command to the port.
7656 */
7657 phba->sli4_hba.bmbx.dmabuf = dmabuf;
7658 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
7659
7660 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
7661 LPFC_ALIGN_16_BYTE);
7662 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
7663 LPFC_ALIGN_16_BYTE);
7664
7665 /*
7666 * Set the high and low physical addresses now. The SLI4 alignment
7667 * requirement is 16 bytes and the mailbox is posted to the port
7668 * as two 30-bit addresses. The other data is a bit marking whether
7669 * the 30-bit address is the high or low address.
7670 * Upcast bmbx aphys to 64bits so shift instruction compiles
7671 * clean on 32 bit machines.
7672 */
7673 dma_address = &phba->sli4_hba.bmbx.dma_address;
7674 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
7675 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
7676 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
7677 LPFC_BMBX_BIT1_ADDR_HI);
7678
7679 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
7680 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
7681 LPFC_BMBX_BIT1_ADDR_LO);
7682 return 0;
7683}
7684
7685/**
7686 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
7687 * @phba: pointer to lpfc hba data structure.
7688 *
7689 * This routine is invoked to teardown the bootstrap mailbox
7690 * region and release all host resources. This routine requires
7691 * the caller to ensure all mailbox commands recovered, no
7692 * additional mailbox comands are sent, and interrupts are disabled
7693 * before calling this routine.
7694 *
7695 **/
7696static void
7697lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
7698{
7699 dma_free_coherent(&phba->pcidev->dev,
7700 phba->sli4_hba.bmbx.bmbx_size,
7701 phba->sli4_hba.bmbx.dmabuf->virt,
7702 phba->sli4_hba.bmbx.dmabuf->phys);
7703
7704 kfree(phba->sli4_hba.bmbx.dmabuf);
7705 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
7706}
7707
7708/**
7709 * lpfc_sli4_read_config - Get the config parameters.
7710 * @phba: pointer to lpfc hba data structure.
7711 *
7712 * This routine is invoked to read the configuration parameters from the HBA.
7713 * The configuration parameters are used to set the base and maximum values
7714 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
7715 * allocation for the port.
7716 *
7717 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007718 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007719 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007720 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007721 **/
James Smartff78d8f2011-12-13 13:21:35 -05007722int
James Smartda0436e2009-05-22 14:51:39 -04007723lpfc_sli4_read_config(struct lpfc_hba *phba)
7724{
7725 LPFC_MBOXQ_t *pmb;
7726 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04007727 union lpfc_sli4_cfg_shdr *shdr;
7728 uint32_t shdr_status, shdr_add_status;
7729 struct lpfc_mbx_get_func_cfg *get_func_cfg;
7730 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04007731 char *pdesc_0;
James Smartc6918162016-10-13 15:06:16 -07007732 uint16_t forced_link_speed;
7733 uint32_t if_type;
James Smart8aa134a2012-08-14 14:25:29 -04007734 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04007735
7736 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7737 if (!pmb) {
7738 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7739 "2011 Unable to allocate memory for issuing "
7740 "SLI_CONFIG_SPECIAL mailbox command\n");
7741 return -ENOMEM;
7742 }
7743
7744 lpfc_read_config(phba, pmb);
7745
7746 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
7747 if (rc != MBX_SUCCESS) {
7748 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7749 "2012 Mailbox failed , mbxCmd x%x "
7750 "READ_CONFIG, mbxStatus x%x\n",
7751 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7752 bf_get(lpfc_mqe_status, &pmb->u.mqe));
7753 rc = -EIO;
7754 } else {
7755 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05007756 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
7757 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
7758 phba->sli4_hba.lnk_info.lnk_tp =
7759 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
7760 phba->sli4_hba.lnk_info.lnk_no =
7761 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
7762 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7763 "3081 lnk_type:%d, lnk_numb:%d\n",
7764 phba->sli4_hba.lnk_info.lnk_tp,
7765 phba->sli4_hba.lnk_info.lnk_no);
7766 } else
7767 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
7768 "3082 Mailbox (x%x) returned ldv:x0\n",
7769 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart44fd7fe2017-08-23 16:55:47 -07007770 if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) {
7771 phba->bbcredit_support = 1;
7772 phba->sli4_hba.bbscn_params.word0 = rd_config->word8;
7773 }
7774
James Smart6d368e52011-05-24 11:44:12 -04007775 phba->sli4_hba.extents_in_use =
7776 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04007777 phba->sli4_hba.max_cfg_param.max_xri =
7778 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
7779 phba->sli4_hba.max_cfg_param.xri_base =
7780 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
7781 phba->sli4_hba.max_cfg_param.max_vpi =
7782 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
7783 phba->sli4_hba.max_cfg_param.vpi_base =
7784 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
7785 phba->sli4_hba.max_cfg_param.max_rpi =
7786 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
7787 phba->sli4_hba.max_cfg_param.rpi_base =
7788 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
7789 phba->sli4_hba.max_cfg_param.max_vfi =
7790 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
7791 phba->sli4_hba.max_cfg_param.vfi_base =
7792 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
7793 phba->sli4_hba.max_cfg_param.max_fcfi =
7794 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04007795 phba->sli4_hba.max_cfg_param.max_eq =
7796 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
7797 phba->sli4_hba.max_cfg_param.max_rq =
7798 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
7799 phba->sli4_hba.max_cfg_param.max_wq =
7800 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
7801 phba->sli4_hba.max_cfg_param.max_cq =
7802 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
7803 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
7804 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
7805 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
7806 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05007807 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
7808 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04007809 phba->max_vports = phba->max_vpi;
7810 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04007811 "2003 cfg params Extents? %d "
7812 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04007813 "VPI(B:%d M:%d) "
7814 "VFI(B:%d M:%d) "
7815 "RPI(B:%d M:%d) "
James Smart2ea259e2017-02-12 13:52:27 -08007816 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n",
James Smart6d368e52011-05-24 11:44:12 -04007817 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04007818 phba->sli4_hba.max_cfg_param.xri_base,
7819 phba->sli4_hba.max_cfg_param.max_xri,
7820 phba->sli4_hba.max_cfg_param.vpi_base,
7821 phba->sli4_hba.max_cfg_param.max_vpi,
7822 phba->sli4_hba.max_cfg_param.vfi_base,
7823 phba->sli4_hba.max_cfg_param.max_vfi,
7824 phba->sli4_hba.max_cfg_param.rpi_base,
7825 phba->sli4_hba.max_cfg_param.max_rpi,
James Smart2ea259e2017-02-12 13:52:27 -08007826 phba->sli4_hba.max_cfg_param.max_fcfi,
7827 phba->sli4_hba.max_cfg_param.max_eq,
7828 phba->sli4_hba.max_cfg_param.max_cq,
7829 phba->sli4_hba.max_cfg_param.max_wq,
7830 phba->sli4_hba.max_cfg_param.max_rq);
7831
James Smartd38f33b2018-05-04 20:37:54 -07007832 /*
7833 * Calculate NVME queue resources based on how
7834 * many WQ/CQs are available.
7835 */
7836 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
7837 length = phba->sli4_hba.max_cfg_param.max_wq;
7838 if (phba->sli4_hba.max_cfg_param.max_cq <
7839 phba->sli4_hba.max_cfg_param.max_wq)
7840 length = phba->sli4_hba.max_cfg_param.max_cq;
7841
7842 /*
7843 * Whats left after this can go toward NVME.
7844 * The minus 6 accounts for ELS, NVME LS, MBOX
7845 * fof plus a couple extra. When configured for
7846 * NVMET, FCP io channel WQs are not created.
7847 */
7848 length -= 6;
7849 if (!phba->nvmet_support)
7850 length -= phba->cfg_fcp_io_channel;
7851
7852 if (phba->cfg_nvme_io_channel > length) {
7853 lpfc_printf_log(
7854 phba, KERN_ERR, LOG_SLI,
7855 "2005 Reducing NVME IO channel to %d: "
7856 "WQ %d CQ %d NVMEIO %d FCPIO %d\n",
7857 length,
7858 phba->sli4_hba.max_cfg_param.max_wq,
7859 phba->sli4_hba.max_cfg_param.max_cq,
7860 phba->cfg_nvme_io_channel,
7861 phba->cfg_fcp_io_channel);
7862
7863 phba->cfg_nvme_io_channel = length;
7864 }
7865 }
James Smartda0436e2009-05-22 14:51:39 -04007866 }
James Smart912e3ac2011-05-24 11:42:11 -04007867
7868 if (rc)
7869 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04007870
James Smartc6918162016-10-13 15:06:16 -07007871 /* Update link speed if forced link speed is supported */
7872 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smart27d6ac02018-02-22 08:18:42 -08007873 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
James Smartc6918162016-10-13 15:06:16 -07007874 forced_link_speed =
7875 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
7876 if (forced_link_speed) {
7877 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
7878
7879 switch (forced_link_speed) {
7880 case LINK_SPEED_1G:
7881 phba->cfg_link_speed =
7882 LPFC_USER_LINK_SPEED_1G;
7883 break;
7884 case LINK_SPEED_2G:
7885 phba->cfg_link_speed =
7886 LPFC_USER_LINK_SPEED_2G;
7887 break;
7888 case LINK_SPEED_4G:
7889 phba->cfg_link_speed =
7890 LPFC_USER_LINK_SPEED_4G;
7891 break;
7892 case LINK_SPEED_8G:
7893 phba->cfg_link_speed =
7894 LPFC_USER_LINK_SPEED_8G;
7895 break;
7896 case LINK_SPEED_10G:
7897 phba->cfg_link_speed =
7898 LPFC_USER_LINK_SPEED_10G;
7899 break;
7900 case LINK_SPEED_16G:
7901 phba->cfg_link_speed =
7902 LPFC_USER_LINK_SPEED_16G;
7903 break;
7904 case LINK_SPEED_32G:
7905 phba->cfg_link_speed =
7906 LPFC_USER_LINK_SPEED_32G;
7907 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08007908 case LINK_SPEED_64G:
7909 phba->cfg_link_speed =
7910 LPFC_USER_LINK_SPEED_64G;
7911 break;
James Smartc6918162016-10-13 15:06:16 -07007912 case 0xffff:
7913 phba->cfg_link_speed =
7914 LPFC_USER_LINK_SPEED_AUTO;
7915 break;
7916 default:
7917 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7918 "0047 Unrecognized link "
7919 "speed : %d\n",
7920 forced_link_speed);
7921 phba->cfg_link_speed =
7922 LPFC_USER_LINK_SPEED_AUTO;
7923 }
7924 }
7925 }
7926
James Smartda0436e2009-05-22 14:51:39 -04007927 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -04007928 length = phba->sli4_hba.max_cfg_param.max_xri -
7929 lpfc_sli4_get_els_iocb_cnt(phba);
7930 if (phba->cfg_hba_queue_depth > length) {
7931 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7932 "3361 HBA queue depth changed from %d to %d\n",
7933 phba->cfg_hba_queue_depth, length);
7934 phba->cfg_hba_queue_depth = length;
7935 }
James Smart912e3ac2011-05-24 11:42:11 -04007936
James Smart27d6ac02018-02-22 08:18:42 -08007937 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smart912e3ac2011-05-24 11:42:11 -04007938 LPFC_SLI_INTF_IF_TYPE_2)
7939 goto read_cfg_out;
7940
7941 /* get the pf# and vf# for SLI4 if_type 2 port */
7942 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
7943 sizeof(struct lpfc_sli4_cfg_mhdr));
7944 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
7945 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
7946 length, LPFC_SLI4_MBX_EMBED);
7947
James Smart8aa134a2012-08-14 14:25:29 -04007948 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04007949 shdr = (union lpfc_sli4_cfg_shdr *)
7950 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
7951 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7952 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04007953 if (rc2 || shdr_status || shdr_add_status) {
James Smart912e3ac2011-05-24 11:42:11 -04007954 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7955 "3026 Mailbox failed , mbxCmd x%x "
7956 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
7957 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7958 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04007959 goto read_cfg_out;
7960 }
7961
7962 /* search for fc_fcoe resrouce descriptor */
7963 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
James Smart912e3ac2011-05-24 11:42:11 -04007964
James Smart8aa134a2012-08-14 14:25:29 -04007965 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
7966 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
7967 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
7968 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
7969 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
7970 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
7971 goto read_cfg_out;
7972
James Smart912e3ac2011-05-24 11:42:11 -04007973 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04007974 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04007975 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04007976 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04007977 phba->sli4_hba.iov.pf_number =
7978 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
7979 phba->sli4_hba.iov.vf_number =
7980 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
7981 break;
7982 }
7983 }
7984
7985 if (i < LPFC_RSRC_DESC_MAX_NUM)
7986 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7987 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
7988 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
7989 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04007990 else
James Smart912e3ac2011-05-24 11:42:11 -04007991 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7992 "3028 GET_FUNCTION_CONFIG: failed to find "
7993 "Resrouce Descriptor:x%x\n",
7994 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04007995
7996read_cfg_out:
7997 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04007998 return rc;
7999}
8000
8001/**
James Smart2fcee4b2010-12-15 17:57:46 -05008002 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04008003 * @phba: pointer to lpfc hba data structure.
8004 *
James Smart2fcee4b2010-12-15 17:57:46 -05008005 * This routine is invoked to setup the port-side endian order when
8006 * the port if_type is 0. This routine has no function for other
8007 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04008008 *
8009 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008010 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008011 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008012 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008013 **/
8014static int
8015lpfc_setup_endian_order(struct lpfc_hba *phba)
8016{
8017 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05008018 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04008019 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
8020 HOST_ENDIAN_HIGH_WORD1};
8021
James Smart2fcee4b2010-12-15 17:57:46 -05008022 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8023 switch (if_type) {
8024 case LPFC_SLI_INTF_IF_TYPE_0:
8025 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8026 GFP_KERNEL);
8027 if (!mboxq) {
8028 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8029 "0492 Unable to allocate memory for "
8030 "issuing SLI_CONFIG_SPECIAL mailbox "
8031 "command\n");
8032 return -ENOMEM;
8033 }
James Smartda0436e2009-05-22 14:51:39 -04008034
James Smart2fcee4b2010-12-15 17:57:46 -05008035 /*
8036 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
8037 * two words to contain special data values and no other data.
8038 */
8039 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
8040 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
8041 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8042 if (rc != MBX_SUCCESS) {
8043 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8044 "0493 SLI_CONFIG_SPECIAL mailbox "
8045 "failed with status x%x\n",
8046 rc);
8047 rc = -EIO;
8048 }
8049 mempool_free(mboxq, phba->mbox_mem_pool);
8050 break;
James Smart27d6ac02018-02-22 08:18:42 -08008051 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2fcee4b2010-12-15 17:57:46 -05008052 case LPFC_SLI_INTF_IF_TYPE_2:
8053 case LPFC_SLI_INTF_IF_TYPE_1:
8054 default:
8055 break;
James Smartda0436e2009-05-22 14:51:39 -04008056 }
James Smartda0436e2009-05-22 14:51:39 -04008057 return rc;
8058}
8059
8060/**
James Smart895427b2017-02-12 13:52:30 -08008061 * lpfc_sli4_queue_verify - Verify and update EQ counts
James Smartda0436e2009-05-22 14:51:39 -04008062 * @phba: pointer to lpfc hba data structure.
8063 *
James Smart895427b2017-02-12 13:52:30 -08008064 * This routine is invoked to check the user settable queue counts for EQs.
8065 * After this routine is called the counts will be set to valid values that
James Smart5350d872011-10-10 21:33:49 -04008066 * adhere to the constraints of the system's interrupt vectors and the port's
8067 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04008068 *
8069 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008070 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008071 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04008072 **/
8073static int
James Smart5350d872011-10-10 21:33:49 -04008074lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04008075{
James Smart895427b2017-02-12 13:52:30 -08008076 int io_channel;
James Smart1ba981f2014-02-20 09:56:45 -05008077 int fof_vectors = phba->cfg_fof ? 1 : 0;
James Smartda0436e2009-05-22 14:51:39 -04008078
8079 /*
James Smart67d12732012-08-03 12:36:13 -04008080 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04008081 * device parameters
8082 */
8083
James Smart67d12732012-08-03 12:36:13 -04008084 /* Sanity check on HBA EQ parameters */
James Smart895427b2017-02-12 13:52:30 -08008085 io_channel = phba->io_channel_irqs;
James Smartda0436e2009-05-22 14:51:39 -04008086
James Smart895427b2017-02-12 13:52:30 -08008087 if (phba->sli4_hba.num_online_cpu < io_channel) {
James Smart82c3e9b2012-09-29 11:29:50 -04008088 lpfc_printf_log(phba,
8089 KERN_ERR, LOG_INIT,
James Smart90695ee2012-08-14 14:25:36 -04008090 "3188 Reducing IO channels to match number of "
James Smart7bb03bb2013-04-17 20:19:16 -04008091 "online CPUs: from %d to %d\n",
James Smart895427b2017-02-12 13:52:30 -08008092 io_channel, phba->sli4_hba.num_online_cpu);
8093 io_channel = phba->sli4_hba.num_online_cpu;
James Smart90695ee2012-08-14 14:25:36 -04008094 }
8095
James Smart895427b2017-02-12 13:52:30 -08008096 if (io_channel + fof_vectors > phba->sli4_hba.max_cfg_param.max_eq) {
James Smart82c3e9b2012-09-29 11:29:50 -04008097 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8098 "2575 Reducing IO channels to match number of "
8099 "available EQs: from %d to %d\n",
James Smart895427b2017-02-12 13:52:30 -08008100 io_channel,
James Smart82c3e9b2012-09-29 11:29:50 -04008101 phba->sli4_hba.max_cfg_param.max_eq);
James Smart895427b2017-02-12 13:52:30 -08008102 io_channel = phba->sli4_hba.max_cfg_param.max_eq - fof_vectors;
James Smartda0436e2009-05-22 14:51:39 -04008103 }
James Smart67d12732012-08-03 12:36:13 -04008104
James Smart895427b2017-02-12 13:52:30 -08008105 /* The actual number of FCP / NVME event queues adopted */
8106 if (io_channel != phba->io_channel_irqs)
8107 phba->io_channel_irqs = io_channel;
8108 if (phba->cfg_fcp_io_channel > io_channel)
8109 phba->cfg_fcp_io_channel = io_channel;
8110 if (phba->cfg_nvme_io_channel > io_channel)
8111 phba->cfg_nvme_io_channel = io_channel;
James Smartbcb24f62017-11-20 16:00:36 -08008112 if (phba->nvmet_support) {
8113 if (phba->cfg_nvme_io_channel < phba->cfg_nvmet_mrq)
8114 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
8115 }
8116 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
8117 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
James Smart895427b2017-02-12 13:52:30 -08008118
8119 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2d7dbc42017-02-12 13:52:35 -08008120 "2574 IO channels: irqs %d fcp %d nvme %d MRQ: %d\n",
James Smart895427b2017-02-12 13:52:30 -08008121 phba->io_channel_irqs, phba->cfg_fcp_io_channel,
James Smart2d7dbc42017-02-12 13:52:35 -08008122 phba->cfg_nvme_io_channel, phba->cfg_nvmet_mrq);
James Smartda0436e2009-05-22 14:51:39 -04008123
James Smartda0436e2009-05-22 14:51:39 -04008124 /* Get EQ depth from module parameter, fake the default for now */
8125 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8126 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8127
James Smart5350d872011-10-10 21:33:49 -04008128 /* Get CQ depth from module parameter, fake the default for now */
8129 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8130 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart5350d872011-10-10 21:33:49 -04008131 return 0;
James Smart895427b2017-02-12 13:52:30 -08008132}
8133
8134static int
8135lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx)
8136{
8137 struct lpfc_queue *qdesc;
James Smart895427b2017-02-12 13:52:30 -08008138
James Smarta51e41b2017-12-08 17:18:06 -08008139 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
James Smart81b96ed2017-11-20 16:00:29 -08008140 phba->sli4_hba.cq_esize,
James Smarta51e41b2017-12-08 17:18:06 -08008141 LPFC_CQE_EXP_COUNT);
James Smart895427b2017-02-12 13:52:30 -08008142 if (!qdesc) {
8143 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8144 "0508 Failed allocate fast-path NVME CQ (%d)\n",
8145 wqidx);
8146 return 1;
8147 }
James Smart7365f6f2018-02-22 08:18:46 -08008148 qdesc->qe_valid = 1;
James Smart895427b2017-02-12 13:52:30 -08008149 phba->sli4_hba.nvme_cq[wqidx] = qdesc;
8150
James Smarta51e41b2017-12-08 17:18:06 -08008151 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8152 LPFC_WQE128_SIZE, LPFC_WQE_EXP_COUNT);
James Smart895427b2017-02-12 13:52:30 -08008153 if (!qdesc) {
8154 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8155 "0509 Failed allocate fast-path NVME WQ (%d)\n",
8156 wqidx);
8157 return 1;
8158 }
8159 phba->sli4_hba.nvme_wq[wqidx] = qdesc;
8160 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8161 return 0;
8162}
8163
8164static int
8165lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx)
8166{
8167 struct lpfc_queue *qdesc;
James Smartc176ffa2018-01-30 15:58:46 -08008168 uint32_t wqesize;
James Smart895427b2017-02-12 13:52:30 -08008169
8170 /* Create Fast Path FCP CQs */
James Smartc176ffa2018-01-30 15:58:46 -08008171 if (phba->enab_exp_wqcq_pages)
James Smarta51e41b2017-12-08 17:18:06 -08008172 /* Increase the CQ size when WQEs contain an embedded cdb */
8173 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8174 phba->sli4_hba.cq_esize,
8175 LPFC_CQE_EXP_COUNT);
8176
8177 else
8178 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8179 phba->sli4_hba.cq_esize,
8180 phba->sli4_hba.cq_ecount);
James Smart895427b2017-02-12 13:52:30 -08008181 if (!qdesc) {
8182 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8183 "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx);
8184 return 1;
8185 }
James Smart7365f6f2018-02-22 08:18:46 -08008186 qdesc->qe_valid = 1;
James Smart895427b2017-02-12 13:52:30 -08008187 phba->sli4_hba.fcp_cq[wqidx] = qdesc;
8188
8189 /* Create Fast Path FCP WQs */
James Smartc176ffa2018-01-30 15:58:46 -08008190 if (phba->enab_exp_wqcq_pages) {
James Smarta51e41b2017-12-08 17:18:06 -08008191 /* Increase the WQ size when WQEs contain an embedded cdb */
James Smartc176ffa2018-01-30 15:58:46 -08008192 wqesize = (phba->fcp_embed_io) ?
8193 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
James Smarta51e41b2017-12-08 17:18:06 -08008194 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
James Smartc176ffa2018-01-30 15:58:46 -08008195 wqesize,
James Smarta51e41b2017-12-08 17:18:06 -08008196 LPFC_WQE_EXP_COUNT);
James Smartc176ffa2018-01-30 15:58:46 -08008197 } else
James Smarta51e41b2017-12-08 17:18:06 -08008198 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8199 phba->sli4_hba.wq_esize,
8200 phba->sli4_hba.wq_ecount);
James Smartc176ffa2018-01-30 15:58:46 -08008201
James Smart895427b2017-02-12 13:52:30 -08008202 if (!qdesc) {
8203 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8204 "0503 Failed allocate fast-path FCP WQ (%d)\n",
8205 wqidx);
8206 return 1;
8207 }
8208 phba->sli4_hba.fcp_wq[wqidx] = qdesc;
8209 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8210 return 0;
James Smart5350d872011-10-10 21:33:49 -04008211}
8212
8213/**
8214 * lpfc_sli4_queue_create - Create all the SLI4 queues
8215 * @phba: pointer to lpfc hba data structure.
8216 *
8217 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
8218 * operation. For each SLI4 queue type, the parameters such as queue entry
8219 * count (queue depth) shall be taken from the module parameter. For now,
8220 * we just use some constant number as place holder.
8221 *
8222 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07008223 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04008224 * -ENOMEM - No availble memory
8225 * -EIO - The mailbox failed to complete successfully.
8226 **/
8227int
8228lpfc_sli4_queue_create(struct lpfc_hba *phba)
8229{
8230 struct lpfc_queue *qdesc;
James Smartd1f525a2017-04-21 16:04:55 -07008231 int idx, io_channel;
James Smart5350d872011-10-10 21:33:49 -04008232
8233 /*
James Smart67d12732012-08-03 12:36:13 -04008234 * Create HBA Record arrays.
James Smart895427b2017-02-12 13:52:30 -08008235 * Both NVME and FCP will share that same vectors / EQs
James Smart5350d872011-10-10 21:33:49 -04008236 */
James Smart895427b2017-02-12 13:52:30 -08008237 io_channel = phba->io_channel_irqs;
8238 if (!io_channel)
James Smart67d12732012-08-03 12:36:13 -04008239 return -ERANGE;
James Smart5350d872011-10-10 21:33:49 -04008240
James Smart67d12732012-08-03 12:36:13 -04008241 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
8242 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
8243 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
8244 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
8245 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
8246 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
James Smart895427b2017-02-12 13:52:30 -08008247 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8248 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8249 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8250 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart67d12732012-08-03 12:36:13 -04008251
James Smart895427b2017-02-12 13:52:30 -08008252 phba->sli4_hba.hba_eq = kcalloc(io_channel,
8253 sizeof(struct lpfc_queue *),
8254 GFP_KERNEL);
James Smart67d12732012-08-03 12:36:13 -04008255 if (!phba->sli4_hba.hba_eq) {
James Smartda0436e2009-05-22 14:51:39 -04008256 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04008257 "2576 Failed allocate memory for "
8258 "fast-path EQ record array\n");
James Smartda0436e2009-05-22 14:51:39 -04008259 goto out_error;
8260 }
James Smart67d12732012-08-03 12:36:13 -04008261
James Smart895427b2017-02-12 13:52:30 -08008262 if (phba->cfg_fcp_io_channel) {
8263 phba->sli4_hba.fcp_cq = kcalloc(phba->cfg_fcp_io_channel,
8264 sizeof(struct lpfc_queue *),
8265 GFP_KERNEL);
8266 if (!phba->sli4_hba.fcp_cq) {
8267 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8268 "2577 Failed allocate memory for "
8269 "fast-path CQ record array\n");
8270 goto out_error;
8271 }
8272 phba->sli4_hba.fcp_wq = kcalloc(phba->cfg_fcp_io_channel,
8273 sizeof(struct lpfc_queue *),
8274 GFP_KERNEL);
8275 if (!phba->sli4_hba.fcp_wq) {
8276 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8277 "2578 Failed allocate memory for "
8278 "fast-path FCP WQ record array\n");
8279 goto out_error;
8280 }
8281 /*
8282 * Since the first EQ can have multiple CQs associated with it,
8283 * this array is used to quickly see if we have a FCP fast-path
8284 * CQ match.
8285 */
8286 phba->sli4_hba.fcp_cq_map = kcalloc(phba->cfg_fcp_io_channel,
8287 sizeof(uint16_t),
8288 GFP_KERNEL);
8289 if (!phba->sli4_hba.fcp_cq_map) {
8290 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8291 "2545 Failed allocate memory for "
8292 "fast-path CQ map\n");
8293 goto out_error;
8294 }
James Smart67d12732012-08-03 12:36:13 -04008295 }
8296
James Smart895427b2017-02-12 13:52:30 -08008297 if (phba->cfg_nvme_io_channel) {
8298 phba->sli4_hba.nvme_cq = kcalloc(phba->cfg_nvme_io_channel,
8299 sizeof(struct lpfc_queue *),
8300 GFP_KERNEL);
8301 if (!phba->sli4_hba.nvme_cq) {
8302 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8303 "6077 Failed allocate memory for "
8304 "fast-path CQ record array\n");
8305 goto out_error;
8306 }
8307
James Smart895427b2017-02-12 13:52:30 -08008308 phba->sli4_hba.nvme_wq = kcalloc(phba->cfg_nvme_io_channel,
8309 sizeof(struct lpfc_queue *),
8310 GFP_KERNEL);
8311 if (!phba->sli4_hba.nvme_wq) {
8312 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8313 "2581 Failed allocate memory for "
8314 "fast-path NVME WQ record array\n");
8315 goto out_error;
8316 }
8317
8318 /*
8319 * Since the first EQ can have multiple CQs associated with it,
8320 * this array is used to quickly see if we have a NVME fast-path
8321 * CQ match.
8322 */
8323 phba->sli4_hba.nvme_cq_map = kcalloc(phba->cfg_nvme_io_channel,
8324 sizeof(uint16_t),
8325 GFP_KERNEL);
8326 if (!phba->sli4_hba.nvme_cq_map) {
8327 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8328 "6078 Failed allocate memory for "
8329 "fast-path CQ map\n");
8330 goto out_error;
8331 }
James Smart2d7dbc42017-02-12 13:52:35 -08008332
8333 if (phba->nvmet_support) {
8334 phba->sli4_hba.nvmet_cqset = kcalloc(
8335 phba->cfg_nvmet_mrq,
8336 sizeof(struct lpfc_queue *),
8337 GFP_KERNEL);
8338 if (!phba->sli4_hba.nvmet_cqset) {
8339 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8340 "3121 Fail allocate memory for "
8341 "fast-path CQ set array\n");
8342 goto out_error;
8343 }
8344 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
8345 phba->cfg_nvmet_mrq,
8346 sizeof(struct lpfc_queue *),
8347 GFP_KERNEL);
8348 if (!phba->sli4_hba.nvmet_mrq_hdr) {
8349 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8350 "3122 Fail allocate memory for "
8351 "fast-path RQ set hdr array\n");
8352 goto out_error;
8353 }
8354 phba->sli4_hba.nvmet_mrq_data = kcalloc(
8355 phba->cfg_nvmet_mrq,
8356 sizeof(struct lpfc_queue *),
8357 GFP_KERNEL);
8358 if (!phba->sli4_hba.nvmet_mrq_data) {
8359 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8360 "3124 Fail allocate memory for "
8361 "fast-path RQ set data array\n");
8362 goto out_error;
8363 }
8364 }
James Smart67d12732012-08-03 12:36:13 -04008365 }
James Smartda0436e2009-05-22 14:51:39 -04008366
James Smart895427b2017-02-12 13:52:30 -08008367 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
James Smart67d12732012-08-03 12:36:13 -04008368
James Smart895427b2017-02-12 13:52:30 -08008369 /* Create HBA Event Queues (EQs) */
8370 for (idx = 0; idx < io_channel; idx++) {
James Smart67d12732012-08-03 12:36:13 -04008371 /* Create EQs */
James Smart81b96ed2017-11-20 16:00:29 -08008372 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8373 phba->sli4_hba.eq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008374 phba->sli4_hba.eq_ecount);
8375 if (!qdesc) {
8376 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04008377 "0497 Failed allocate EQ (%d)\n", idx);
8378 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008379 }
James Smart7365f6f2018-02-22 08:18:46 -08008380 qdesc->qe_valid = 1;
James Smart67d12732012-08-03 12:36:13 -04008381 phba->sli4_hba.hba_eq[idx] = qdesc;
James Smartda0436e2009-05-22 14:51:39 -04008382 }
8383
James Smart895427b2017-02-12 13:52:30 -08008384 /* FCP and NVME io channels are not required to be balanced */
8385
8386 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
8387 if (lpfc_alloc_fcp_wq_cq(phba, idx))
8388 goto out_error;
8389
8390 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
8391 if (lpfc_alloc_nvme_wq_cq(phba, idx))
8392 goto out_error;
James Smart67d12732012-08-03 12:36:13 -04008393
James Smart2d7dbc42017-02-12 13:52:35 -08008394 if (phba->nvmet_support) {
8395 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8396 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08008397 LPFC_DEFAULT_PAGE_SIZE,
8398 phba->sli4_hba.cq_esize,
8399 phba->sli4_hba.cq_ecount);
James Smart2d7dbc42017-02-12 13:52:35 -08008400 if (!qdesc) {
8401 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8402 "3142 Failed allocate NVME "
8403 "CQ Set (%d)\n", idx);
8404 goto out_error;
8405 }
James Smart7365f6f2018-02-22 08:18:46 -08008406 qdesc->qe_valid = 1;
James Smart2d7dbc42017-02-12 13:52:35 -08008407 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
8408 }
8409 }
8410
James Smartda0436e2009-05-22 14:51:39 -04008411 /*
James Smart67d12732012-08-03 12:36:13 -04008412 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04008413 */
8414
James Smartda0436e2009-05-22 14:51:39 -04008415 /* Create slow-path Mailbox Command Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008416 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8417 phba->sli4_hba.cq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008418 phba->sli4_hba.cq_ecount);
8419 if (!qdesc) {
8420 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8421 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04008422 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008423 }
James Smart7365f6f2018-02-22 08:18:46 -08008424 qdesc->qe_valid = 1;
James Smartda0436e2009-05-22 14:51:39 -04008425 phba->sli4_hba.mbx_cq = qdesc;
8426
8427 /* Create slow-path ELS Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008428 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8429 phba->sli4_hba.cq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008430 phba->sli4_hba.cq_ecount);
8431 if (!qdesc) {
8432 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8433 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -04008434 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008435 }
James Smart7365f6f2018-02-22 08:18:46 -08008436 qdesc->qe_valid = 1;
James Smartda0436e2009-05-22 14:51:39 -04008437 phba->sli4_hba.els_cq = qdesc;
8438
James Smartda0436e2009-05-22 14:51:39 -04008439
James Smart5350d872011-10-10 21:33:49 -04008440 /*
James Smart67d12732012-08-03 12:36:13 -04008441 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04008442 */
James Smartda0436e2009-05-22 14:51:39 -04008443
8444 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04008445
James Smart81b96ed2017-11-20 16:00:29 -08008446 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8447 phba->sli4_hba.mq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008448 phba->sli4_hba.mq_ecount);
8449 if (!qdesc) {
8450 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8451 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04008452 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008453 }
8454 phba->sli4_hba.mbx_wq = qdesc;
8455
8456 /*
James Smart67d12732012-08-03 12:36:13 -04008457 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04008458 */
James Smartda0436e2009-05-22 14:51:39 -04008459
8460 /* Create slow-path ELS Work Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008461 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8462 phba->sli4_hba.wq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008463 phba->sli4_hba.wq_ecount);
8464 if (!qdesc) {
8465 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8466 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04008467 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008468 }
8469 phba->sli4_hba.els_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08008470 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8471
8472 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8473 /* Create NVME LS Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008474 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8475 phba->sli4_hba.cq_esize,
James Smart895427b2017-02-12 13:52:30 -08008476 phba->sli4_hba.cq_ecount);
8477 if (!qdesc) {
8478 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8479 "6079 Failed allocate NVME LS CQ\n");
8480 goto out_error;
8481 }
James Smart7365f6f2018-02-22 08:18:46 -08008482 qdesc->qe_valid = 1;
James Smart895427b2017-02-12 13:52:30 -08008483 phba->sli4_hba.nvmels_cq = qdesc;
8484
8485 /* Create NVME LS Work Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008486 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8487 phba->sli4_hba.wq_esize,
James Smart895427b2017-02-12 13:52:30 -08008488 phba->sli4_hba.wq_ecount);
8489 if (!qdesc) {
8490 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8491 "6080 Failed allocate NVME LS WQ\n");
8492 goto out_error;
8493 }
8494 phba->sli4_hba.nvmels_wq = qdesc;
8495 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8496 }
James Smartda0436e2009-05-22 14:51:39 -04008497
James Smartda0436e2009-05-22 14:51:39 -04008498 /*
8499 * Create Receive Queue (RQ)
8500 */
James Smartda0436e2009-05-22 14:51:39 -04008501
8502 /* Create Receive Queue for header */
James Smart81b96ed2017-11-20 16:00:29 -08008503 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8504 phba->sli4_hba.rq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008505 phba->sli4_hba.rq_ecount);
8506 if (!qdesc) {
8507 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8508 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04008509 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008510 }
8511 phba->sli4_hba.hdr_rq = qdesc;
8512
8513 /* Create Receive Queue for data */
James Smart81b96ed2017-11-20 16:00:29 -08008514 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8515 phba->sli4_hba.rq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008516 phba->sli4_hba.rq_ecount);
8517 if (!qdesc) {
8518 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8519 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04008520 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008521 }
8522 phba->sli4_hba.dat_rq = qdesc;
8523
James Smart2d7dbc42017-02-12 13:52:35 -08008524 if (phba->nvmet_support) {
8525 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8526 /* Create NVMET Receive Queue for header */
8527 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08008528 LPFC_DEFAULT_PAGE_SIZE,
James Smart2d7dbc42017-02-12 13:52:35 -08008529 phba->sli4_hba.rq_esize,
James Smart61f3d4b2017-05-15 15:20:41 -07008530 LPFC_NVMET_RQE_DEF_COUNT);
James Smart2d7dbc42017-02-12 13:52:35 -08008531 if (!qdesc) {
8532 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8533 "3146 Failed allocate "
8534 "receive HRQ\n");
8535 goto out_error;
8536 }
8537 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
8538
8539 /* Only needed for header of RQ pair */
8540 qdesc->rqbp = kzalloc(sizeof(struct lpfc_rqb),
8541 GFP_KERNEL);
8542 if (qdesc->rqbp == NULL) {
8543 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8544 "6131 Failed allocate "
8545 "Header RQBP\n");
8546 goto out_error;
8547 }
8548
Dick Kennedy4b40d022017-08-23 16:55:38 -07008549 /* Put list in known state in case driver load fails. */
8550 INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list);
8551
James Smart2d7dbc42017-02-12 13:52:35 -08008552 /* Create NVMET Receive Queue for data */
8553 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08008554 LPFC_DEFAULT_PAGE_SIZE,
James Smart2d7dbc42017-02-12 13:52:35 -08008555 phba->sli4_hba.rq_esize,
James Smart61f3d4b2017-05-15 15:20:41 -07008556 LPFC_NVMET_RQE_DEF_COUNT);
James Smart2d7dbc42017-02-12 13:52:35 -08008557 if (!qdesc) {
8558 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8559 "3156 Failed allocate "
8560 "receive DRQ\n");
8561 goto out_error;
8562 }
8563 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
8564 }
8565 }
8566
James Smart1ba981f2014-02-20 09:56:45 -05008567 /* Create the Queues needed for Flash Optimized Fabric operations */
8568 if (phba->cfg_fof)
8569 lpfc_fof_queue_create(phba);
James Smartda0436e2009-05-22 14:51:39 -04008570 return 0;
8571
James Smartda0436e2009-05-22 14:51:39 -04008572out_error:
James Smart67d12732012-08-03 12:36:13 -04008573 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04008574 return -ENOMEM;
8575}
8576
James Smart895427b2017-02-12 13:52:30 -08008577static inline void
8578__lpfc_sli4_release_queue(struct lpfc_queue **qp)
8579{
8580 if (*qp != NULL) {
8581 lpfc_sli4_queue_free(*qp);
8582 *qp = NULL;
8583 }
8584}
8585
8586static inline void
8587lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
8588{
8589 int idx;
8590
8591 if (*qs == NULL)
8592 return;
8593
8594 for (idx = 0; idx < max; idx++)
8595 __lpfc_sli4_release_queue(&(*qs)[idx]);
8596
8597 kfree(*qs);
8598 *qs = NULL;
8599}
8600
8601static inline void
8602lpfc_sli4_release_queue_map(uint16_t **qmap)
8603{
8604 if (*qmap != NULL) {
8605 kfree(*qmap);
8606 *qmap = NULL;
8607 }
8608}
8609
James Smartda0436e2009-05-22 14:51:39 -04008610/**
8611 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
8612 * @phba: pointer to lpfc hba data structure.
8613 *
8614 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
8615 * operation.
8616 *
8617 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008618 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008619 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008620 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008621 **/
James Smart5350d872011-10-10 21:33:49 -04008622void
James Smartda0436e2009-05-22 14:51:39 -04008623lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
8624{
James Smart1ba981f2014-02-20 09:56:45 -05008625 if (phba->cfg_fof)
8626 lpfc_fof_queue_destroy(phba);
8627
James Smart895427b2017-02-12 13:52:30 -08008628 /* Release HBA eqs */
8629 lpfc_sli4_release_queues(&phba->sli4_hba.hba_eq, phba->io_channel_irqs);
James Smart67d12732012-08-03 12:36:13 -04008630
James Smart895427b2017-02-12 13:52:30 -08008631 /* Release FCP cqs */
8632 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_cq,
James Smartd1f525a2017-04-21 16:04:55 -07008633 phba->cfg_fcp_io_channel);
James Smart67d12732012-08-03 12:36:13 -04008634
James Smart895427b2017-02-12 13:52:30 -08008635 /* Release FCP wqs */
8636 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_wq,
James Smartd1f525a2017-04-21 16:04:55 -07008637 phba->cfg_fcp_io_channel);
James Smart67d12732012-08-03 12:36:13 -04008638
8639 /* Release FCP CQ mapping array */
James Smart895427b2017-02-12 13:52:30 -08008640 lpfc_sli4_release_queue_map(&phba->sli4_hba.fcp_cq_map);
8641
8642 /* Release NVME cqs */
8643 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_cq,
8644 phba->cfg_nvme_io_channel);
8645
8646 /* Release NVME wqs */
8647 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_wq,
8648 phba->cfg_nvme_io_channel);
8649
8650 /* Release NVME CQ mapping array */
8651 lpfc_sli4_release_queue_map(&phba->sli4_hba.nvme_cq_map);
James Smartda0436e2009-05-22 14:51:39 -04008652
James Smartbcb24f62017-11-20 16:00:36 -08008653 if (phba->nvmet_support) {
8654 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
8655 phba->cfg_nvmet_mrq);
James Smart2d7dbc42017-02-12 13:52:35 -08008656
James Smartbcb24f62017-11-20 16:00:36 -08008657 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
8658 phba->cfg_nvmet_mrq);
8659 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
8660 phba->cfg_nvmet_mrq);
8661 }
James Smart2d7dbc42017-02-12 13:52:35 -08008662
James Smartda0436e2009-05-22 14:51:39 -04008663 /* Release mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08008664 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
James Smartda0436e2009-05-22 14:51:39 -04008665
8666 /* Release ELS work queue */
James Smart895427b2017-02-12 13:52:30 -08008667 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
8668
8669 /* Release ELS work queue */
8670 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
James Smartda0436e2009-05-22 14:51:39 -04008671
8672 /* Release unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08008673 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
8674 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
James Smartda0436e2009-05-22 14:51:39 -04008675
James Smartda0436e2009-05-22 14:51:39 -04008676 /* Release ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08008677 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
8678
8679 /* Release NVME LS complete queue */
8680 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
James Smartda0436e2009-05-22 14:51:39 -04008681
8682 /* Release mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08008683 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
8684
8685 /* Everything on this list has been freed */
8686 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
8687}
8688
8689int
James Smart895427b2017-02-12 13:52:30 -08008690lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
8691{
8692 struct lpfc_rqb *rqbp;
8693 struct lpfc_dmabuf *h_buf;
8694 struct rqb_dmabuf *rqb_buffer;
8695
8696 rqbp = rq->rqbp;
8697 while (!list_empty(&rqbp->rqb_buffer_list)) {
8698 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
8699 struct lpfc_dmabuf, list);
8700
8701 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
8702 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
8703 rqbp->buffer_count--;
8704 }
8705 return 1;
8706}
8707
8708static int
8709lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
8710 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
8711 int qidx, uint32_t qtype)
8712{
8713 struct lpfc_sli_ring *pring;
8714 int rc;
8715
8716 if (!eq || !cq || !wq) {
8717 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8718 "6085 Fast-path %s (%d) not allocated\n",
8719 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
8720 return -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04008721 }
James Smartda0436e2009-05-22 14:51:39 -04008722
James Smart895427b2017-02-12 13:52:30 -08008723 /* create the Cq first */
8724 rc = lpfc_cq_create(phba, cq, eq,
8725 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
8726 if (rc) {
8727 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8728 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
8729 qidx, (uint32_t)rc);
8730 return rc;
8731 }
James Smart81b96ed2017-11-20 16:00:29 -08008732 cq->chann = qidx;
James Smart895427b2017-02-12 13:52:30 -08008733
8734 if (qtype != LPFC_MBOX) {
8735 /* Setup nvme_cq_map for fast lookup */
8736 if (cq_map)
8737 *cq_map = cq->queue_id;
8738
8739 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8740 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
8741 qidx, cq->queue_id, qidx, eq->queue_id);
8742
8743 /* create the wq */
8744 rc = lpfc_wq_create(phba, wq, cq, qtype);
8745 if (rc) {
8746 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8747 "6123 Fail setup fastpath WQ (%d), rc = 0x%x\n",
8748 qidx, (uint32_t)rc);
8749 /* no need to tear down cq - caller will do so */
8750 return rc;
8751 }
James Smart81b96ed2017-11-20 16:00:29 -08008752 wq->chann = qidx;
James Smart895427b2017-02-12 13:52:30 -08008753
8754 /* Bind this CQ/WQ to the NVME ring */
8755 pring = wq->pring;
8756 pring->sli.sli4.wqp = (void *)wq;
8757 cq->pring = pring;
8758
8759 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8760 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
8761 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
8762 } else {
8763 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
8764 if (rc) {
8765 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8766 "0539 Failed setup of slow-path MQ: "
8767 "rc = 0x%x\n", rc);
8768 /* no need to tear down cq - caller will do so */
8769 return rc;
8770 }
8771
8772 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8773 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
8774 phba->sli4_hba.mbx_wq->queue_id,
8775 phba->sli4_hba.mbx_cq->queue_id);
8776 }
8777
8778 return 0;
James Smartda0436e2009-05-22 14:51:39 -04008779}
8780
8781/**
8782 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
8783 * @phba: pointer to lpfc hba data structure.
8784 *
8785 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
8786 * operation.
8787 *
8788 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008789 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008790 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008791 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008792 **/
8793int
8794lpfc_sli4_queue_setup(struct lpfc_hba *phba)
8795{
James Smart962bc512013-01-03 15:44:00 -05008796 uint32_t shdr_status, shdr_add_status;
8797 union lpfc_sli4_cfg_shdr *shdr;
8798 LPFC_MBOXQ_t *mboxq;
James Smart895427b2017-02-12 13:52:30 -08008799 int qidx;
8800 uint32_t length, io_channel;
8801 int rc = -ENOMEM;
James Smart962bc512013-01-03 15:44:00 -05008802
8803 /* Check for dual-ULP support */
8804 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8805 if (!mboxq) {
8806 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8807 "3249 Unable to allocate memory for "
8808 "QUERY_FW_CFG mailbox command\n");
8809 return -ENOMEM;
8810 }
8811 length = (sizeof(struct lpfc_mbx_query_fw_config) -
8812 sizeof(struct lpfc_sli4_cfg_mhdr));
8813 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8814 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
8815 length, LPFC_SLI4_MBX_EMBED);
8816
8817 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8818
8819 shdr = (union lpfc_sli4_cfg_shdr *)
8820 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
8821 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8822 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
8823 if (shdr_status || shdr_add_status || rc) {
8824 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8825 "3250 QUERY_FW_CFG mailbox failed with status "
8826 "x%x add_status x%x, mbx status x%x\n",
8827 shdr_status, shdr_add_status, rc);
8828 if (rc != MBX_TIMEOUT)
8829 mempool_free(mboxq, phba->mbox_mem_pool);
8830 rc = -ENXIO;
8831 goto out_error;
8832 }
8833
8834 phba->sli4_hba.fw_func_mode =
8835 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
8836 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
8837 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
James Smart8b017a32015-05-21 13:55:18 -04008838 phba->sli4_hba.physical_port =
8839 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
James Smart962bc512013-01-03 15:44:00 -05008840 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8841 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
8842 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
8843 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
8844
8845 if (rc != MBX_TIMEOUT)
8846 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04008847
8848 /*
James Smart67d12732012-08-03 12:36:13 -04008849 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04008850 */
James Smart895427b2017-02-12 13:52:30 -08008851 io_channel = phba->io_channel_irqs;
James Smartda0436e2009-05-22 14:51:39 -04008852
James Smart67d12732012-08-03 12:36:13 -04008853 /* Set up HBA event queue */
James Smart895427b2017-02-12 13:52:30 -08008854 if (io_channel && !phba->sli4_hba.hba_eq) {
James Smart2e90f4b2011-12-13 13:22:37 -05008855 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8856 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05008857 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04008858 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05008859 }
James Smart895427b2017-02-12 13:52:30 -08008860 for (qidx = 0; qidx < io_channel; qidx++) {
8861 if (!phba->sli4_hba.hba_eq[qidx]) {
James Smartda0436e2009-05-22 14:51:39 -04008862 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8863 "0522 Fast-path EQ (%d) not "
James Smart895427b2017-02-12 13:52:30 -08008864 "allocated\n", qidx);
James Smart1b511972011-12-13 13:23:09 -05008865 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008866 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008867 }
James Smart895427b2017-02-12 13:52:30 -08008868 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[qidx],
8869 phba->cfg_fcp_imax);
James Smartda0436e2009-05-22 14:51:39 -04008870 if (rc) {
8871 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8872 "0523 Failed setup of fast-path EQ "
James Smart895427b2017-02-12 13:52:30 -08008873 "(%d), rc = 0x%x\n", qidx,
James Smarta2fc4aef2014-09-03 12:57:55 -04008874 (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08008875 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008876 }
8877 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008878 "2584 HBA EQ setup: queue[%d]-id=%d\n",
8879 qidx, phba->sli4_hba.hba_eq[qidx]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04008880 }
8881
James Smart895427b2017-02-12 13:52:30 -08008882 if (phba->cfg_nvme_io_channel) {
8883 if (!phba->sli4_hba.nvme_cq || !phba->sli4_hba.nvme_wq) {
James Smart67d12732012-08-03 12:36:13 -04008884 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008885 "6084 Fast-path NVME %s array not allocated\n",
8886 (phba->sli4_hba.nvme_cq) ? "CQ" : "WQ");
James Smart67d12732012-08-03 12:36:13 -04008887 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008888 goto out_destroy;
James Smart67d12732012-08-03 12:36:13 -04008889 }
8890
James Smart895427b2017-02-12 13:52:30 -08008891 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
8892 rc = lpfc_create_wq_cq(phba,
8893 phba->sli4_hba.hba_eq[
8894 qidx % io_channel],
8895 phba->sli4_hba.nvme_cq[qidx],
8896 phba->sli4_hba.nvme_wq[qidx],
8897 &phba->sli4_hba.nvme_cq_map[qidx],
8898 qidx, LPFC_NVME);
8899 if (rc) {
8900 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8901 "6123 Failed to setup fastpath "
8902 "NVME WQ/CQ (%d), rc = 0x%x\n",
8903 qidx, (uint32_t)rc);
8904 goto out_destroy;
8905 }
8906 }
James Smart67d12732012-08-03 12:36:13 -04008907 }
8908
James Smart895427b2017-02-12 13:52:30 -08008909 if (phba->cfg_fcp_io_channel) {
8910 /* Set up fast-path FCP Response Complete Queue */
8911 if (!phba->sli4_hba.fcp_cq || !phba->sli4_hba.fcp_wq) {
James Smart67d12732012-08-03 12:36:13 -04008912 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008913 "3148 Fast-path FCP %s array not allocated\n",
8914 phba->sli4_hba.fcp_cq ? "WQ" : "CQ");
James Smart67d12732012-08-03 12:36:13 -04008915 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008916 goto out_destroy;
James Smart67d12732012-08-03 12:36:13 -04008917 }
8918
James Smart895427b2017-02-12 13:52:30 -08008919 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
8920 rc = lpfc_create_wq_cq(phba,
8921 phba->sli4_hba.hba_eq[
8922 qidx % io_channel],
8923 phba->sli4_hba.fcp_cq[qidx],
8924 phba->sli4_hba.fcp_wq[qidx],
8925 &phba->sli4_hba.fcp_cq_map[qidx],
8926 qidx, LPFC_FCP);
8927 if (rc) {
8928 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8929 "0535 Failed to setup fastpath "
8930 "FCP WQ/CQ (%d), rc = 0x%x\n",
8931 qidx, (uint32_t)rc);
8932 goto out_destroy;
8933 }
8934 }
James Smart67d12732012-08-03 12:36:13 -04008935 }
James Smartda0436e2009-05-22 14:51:39 -04008936
8937 /*
James Smart895427b2017-02-12 13:52:30 -08008938 * Set up Slow Path Complete Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04008939 */
8940
James Smart895427b2017-02-12 13:52:30 -08008941 /* Set up slow-path MBOX CQ/MQ */
8942
8943 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
James Smartda0436e2009-05-22 14:51:39 -04008944 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008945 "0528 %s not allocated\n",
8946 phba->sli4_hba.mbx_cq ?
James Smartd1f525a2017-04-21 16:04:55 -07008947 "Mailbox WQ" : "Mailbox CQ");
James Smart1b511972011-12-13 13:23:09 -05008948 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008949 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008950 }
James Smart895427b2017-02-12 13:52:30 -08008951
8952 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
James Smartd1f525a2017-04-21 16:04:55 -07008953 phba->sli4_hba.mbx_cq,
8954 phba->sli4_hba.mbx_wq,
8955 NULL, 0, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04008956 if (rc) {
8957 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008958 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
8959 (uint32_t)rc);
8960 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008961 }
James Smart2d7dbc42017-02-12 13:52:35 -08008962 if (phba->nvmet_support) {
8963 if (!phba->sli4_hba.nvmet_cqset) {
8964 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8965 "3165 Fast-path NVME CQ Set "
8966 "array not allocated\n");
8967 rc = -ENOMEM;
8968 goto out_destroy;
8969 }
8970 if (phba->cfg_nvmet_mrq > 1) {
8971 rc = lpfc_cq_create_set(phba,
8972 phba->sli4_hba.nvmet_cqset,
8973 phba->sli4_hba.hba_eq,
8974 LPFC_WCQ, LPFC_NVMET);
8975 if (rc) {
8976 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8977 "3164 Failed setup of NVME CQ "
8978 "Set, rc = 0x%x\n",
8979 (uint32_t)rc);
8980 goto out_destroy;
8981 }
8982 } else {
8983 /* Set up NVMET Receive Complete Queue */
8984 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
8985 phba->sli4_hba.hba_eq[0],
8986 LPFC_WCQ, LPFC_NVMET);
8987 if (rc) {
8988 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8989 "6089 Failed setup NVMET CQ: "
8990 "rc = 0x%x\n", (uint32_t)rc);
8991 goto out_destroy;
8992 }
James Smart81b96ed2017-11-20 16:00:29 -08008993 phba->sli4_hba.nvmet_cqset[0]->chann = 0;
8994
James Smart2d7dbc42017-02-12 13:52:35 -08008995 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8996 "6090 NVMET CQ setup: cq-id=%d, "
8997 "parent eq-id=%d\n",
8998 phba->sli4_hba.nvmet_cqset[0]->queue_id,
8999 phba->sli4_hba.hba_eq[0]->queue_id);
9000 }
9001 }
James Smartda0436e2009-05-22 14:51:39 -04009002
James Smart895427b2017-02-12 13:52:30 -08009003 /* Set up slow-path ELS WQ/CQ */
9004 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
James Smartda0436e2009-05-22 14:51:39 -04009005 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009006 "0530 ELS %s not allocated\n",
9007 phba->sli4_hba.els_cq ? "WQ" : "CQ");
James Smart1b511972011-12-13 13:23:09 -05009008 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009009 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009010 }
James Smart895427b2017-02-12 13:52:30 -08009011 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
9012 phba->sli4_hba.els_cq,
9013 phba->sli4_hba.els_wq,
9014 NULL, 0, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04009015 if (rc) {
9016 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009017 "0529 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
9018 (uint32_t)rc);
9019 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009020 }
9021 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9022 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
9023 phba->sli4_hba.els_wq->queue_id,
9024 phba->sli4_hba.els_cq->queue_id);
9025
James Smart895427b2017-02-12 13:52:30 -08009026 if (phba->cfg_nvme_io_channel) {
9027 /* Set up NVME LS Complete Queue */
9028 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
9029 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9030 "6091 LS %s not allocated\n",
9031 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
9032 rc = -ENOMEM;
9033 goto out_destroy;
9034 }
9035 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
9036 phba->sli4_hba.nvmels_cq,
9037 phba->sli4_hba.nvmels_wq,
9038 NULL, 0, LPFC_NVME_LS);
9039 if (rc) {
9040 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9041 "0529 Failed setup of NVVME LS WQ/CQ: "
9042 "rc = 0x%x\n", (uint32_t)rc);
9043 goto out_destroy;
9044 }
9045
9046 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9047 "6096 ELS WQ setup: wq-id=%d, "
9048 "parent cq-id=%d\n",
9049 phba->sli4_hba.nvmels_wq->queue_id,
9050 phba->sli4_hba.nvmels_cq->queue_id);
9051 }
9052
James Smart2d7dbc42017-02-12 13:52:35 -08009053 /*
9054 * Create NVMET Receive Queue (RQ)
9055 */
9056 if (phba->nvmet_support) {
9057 if ((!phba->sli4_hba.nvmet_cqset) ||
9058 (!phba->sli4_hba.nvmet_mrq_hdr) ||
9059 (!phba->sli4_hba.nvmet_mrq_data)) {
9060 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9061 "6130 MRQ CQ Queues not "
9062 "allocated\n");
9063 rc = -ENOMEM;
9064 goto out_destroy;
9065 }
9066 if (phba->cfg_nvmet_mrq > 1) {
9067 rc = lpfc_mrq_create(phba,
9068 phba->sli4_hba.nvmet_mrq_hdr,
9069 phba->sli4_hba.nvmet_mrq_data,
9070 phba->sli4_hba.nvmet_cqset,
9071 LPFC_NVMET);
9072 if (rc) {
9073 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9074 "6098 Failed setup of NVMET "
9075 "MRQ: rc = 0x%x\n",
9076 (uint32_t)rc);
9077 goto out_destroy;
9078 }
9079
9080 } else {
9081 rc = lpfc_rq_create(phba,
9082 phba->sli4_hba.nvmet_mrq_hdr[0],
9083 phba->sli4_hba.nvmet_mrq_data[0],
9084 phba->sli4_hba.nvmet_cqset[0],
9085 LPFC_NVMET);
9086 if (rc) {
9087 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9088 "6057 Failed setup of NVMET "
9089 "Receive Queue: rc = 0x%x\n",
9090 (uint32_t)rc);
9091 goto out_destroy;
9092 }
9093
9094 lpfc_printf_log(
9095 phba, KERN_INFO, LOG_INIT,
9096 "6099 NVMET RQ setup: hdr-rq-id=%d, "
9097 "dat-rq-id=%d parent cq-id=%d\n",
9098 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
9099 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
9100 phba->sli4_hba.nvmet_cqset[0]->queue_id);
9101
9102 }
9103 }
9104
James Smartda0436e2009-05-22 14:51:39 -04009105 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
9106 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9107 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05009108 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009109 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009110 }
James Smart73d91e52011-10-10 21:32:10 -04009111
James Smartda0436e2009-05-22 14:51:39 -04009112 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04009113 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04009114 if (rc) {
9115 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9116 "0541 Failed setup of Receive Queue: "
James Smarta2fc4aef2014-09-03 12:57:55 -04009117 "rc = 0x%x\n", (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08009118 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009119 }
James Smart73d91e52011-10-10 21:32:10 -04009120
James Smartda0436e2009-05-22 14:51:39 -04009121 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9122 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
9123 "parent cq-id=%d\n",
9124 phba->sli4_hba.hdr_rq->queue_id,
9125 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04009126 phba->sli4_hba.els_cq->queue_id);
James Smart1ba981f2014-02-20 09:56:45 -05009127
9128 if (phba->cfg_fof) {
9129 rc = lpfc_fof_queue_setup(phba);
9130 if (rc) {
9131 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9132 "0549 Failed setup of FOF Queues: "
9133 "rc = 0x%x\n", rc);
James Smart895427b2017-02-12 13:52:30 -08009134 goto out_destroy;
James Smart1ba981f2014-02-20 09:56:45 -05009135 }
9136 }
James Smart2c9c5a02015-04-07 15:07:15 -04009137
James Smart43140ca2017-03-04 09:30:34 -08009138 for (qidx = 0; qidx < io_channel; qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
James Smart0cf07f842017-06-01 21:07:10 -07009139 lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT,
9140 phba->cfg_fcp_imax);
James Smart43140ca2017-03-04 09:30:34 -08009141
James Smartda0436e2009-05-22 14:51:39 -04009142 return 0;
9143
James Smart895427b2017-02-12 13:52:30 -08009144out_destroy:
9145 lpfc_sli4_queue_unset(phba);
James Smartda0436e2009-05-22 14:51:39 -04009146out_error:
9147 return rc;
9148}
9149
9150/**
9151 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
9152 * @phba: pointer to lpfc hba data structure.
9153 *
9154 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
9155 * operation.
9156 *
9157 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009158 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009159 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009160 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009161 **/
9162void
9163lpfc_sli4_queue_unset(struct lpfc_hba *phba)
9164{
James Smart895427b2017-02-12 13:52:30 -08009165 int qidx;
James Smartda0436e2009-05-22 14:51:39 -04009166
James Smart1ba981f2014-02-20 09:56:45 -05009167 /* Unset the queues created for Flash Optimized Fabric operations */
9168 if (phba->cfg_fof)
9169 lpfc_fof_queue_destroy(phba);
James Smart895427b2017-02-12 13:52:30 -08009170
James Smartda0436e2009-05-22 14:51:39 -04009171 /* Unset mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08009172 if (phba->sli4_hba.mbx_wq)
9173 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
9174
9175 /* Unset NVME LS work queue */
9176 if (phba->sli4_hba.nvmels_wq)
9177 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
9178
James Smartda0436e2009-05-22 14:51:39 -04009179 /* Unset ELS work queue */
Colin Ian King019c0d62017-05-06 23:13:55 +01009180 if (phba->sli4_hba.els_wq)
James Smart895427b2017-02-12 13:52:30 -08009181 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
9182
James Smartda0436e2009-05-22 14:51:39 -04009183 /* Unset unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08009184 if (phba->sli4_hba.hdr_rq)
9185 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
9186 phba->sli4_hba.dat_rq);
9187
James Smartda0436e2009-05-22 14:51:39 -04009188 /* Unset FCP work queue */
James Smart895427b2017-02-12 13:52:30 -08009189 if (phba->sli4_hba.fcp_wq)
9190 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
9191 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[qidx]);
9192
9193 /* Unset NVME work queue */
9194 if (phba->sli4_hba.nvme_wq) {
9195 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
9196 lpfc_wq_destroy(phba, phba->sli4_hba.nvme_wq[qidx]);
James Smart67d12732012-08-03 12:36:13 -04009197 }
James Smart895427b2017-02-12 13:52:30 -08009198
James Smartda0436e2009-05-22 14:51:39 -04009199 /* Unset mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08009200 if (phba->sli4_hba.mbx_cq)
9201 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
9202
James Smartda0436e2009-05-22 14:51:39 -04009203 /* Unset ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08009204 if (phba->sli4_hba.els_cq)
9205 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
9206
9207 /* Unset NVME LS complete queue */
9208 if (phba->sli4_hba.nvmels_cq)
9209 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
9210
9211 /* Unset NVME response complete queue */
9212 if (phba->sli4_hba.nvme_cq)
9213 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
9214 lpfc_cq_destroy(phba, phba->sli4_hba.nvme_cq[qidx]);
9215
James Smartbcb24f62017-11-20 16:00:36 -08009216 if (phba->nvmet_support) {
9217 /* Unset NVMET MRQ queue */
9218 if (phba->sli4_hba.nvmet_mrq_hdr) {
9219 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9220 lpfc_rq_destroy(
9221 phba,
James Smart2d7dbc42017-02-12 13:52:35 -08009222 phba->sli4_hba.nvmet_mrq_hdr[qidx],
9223 phba->sli4_hba.nvmet_mrq_data[qidx]);
James Smartbcb24f62017-11-20 16:00:36 -08009224 }
James Smart2d7dbc42017-02-12 13:52:35 -08009225
James Smartbcb24f62017-11-20 16:00:36 -08009226 /* Unset NVMET CQ Set complete queue */
9227 if (phba->sli4_hba.nvmet_cqset) {
9228 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9229 lpfc_cq_destroy(
9230 phba, phba->sli4_hba.nvmet_cqset[qidx]);
9231 }
James Smart2d7dbc42017-02-12 13:52:35 -08009232 }
9233
James Smartda0436e2009-05-22 14:51:39 -04009234 /* Unset FCP response complete queue */
James Smart895427b2017-02-12 13:52:30 -08009235 if (phba->sli4_hba.fcp_cq)
9236 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
9237 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[qidx]);
9238
James Smartda0436e2009-05-22 14:51:39 -04009239 /* Unset fast-path event queue */
James Smart895427b2017-02-12 13:52:30 -08009240 if (phba->sli4_hba.hba_eq)
9241 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++)
9242 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[qidx]);
James Smartda0436e2009-05-22 14:51:39 -04009243}
9244
9245/**
9246 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
9247 * @phba: pointer to lpfc hba data structure.
9248 *
9249 * This routine is invoked to allocate and set up a pool of completion queue
9250 * events. The body of the completion queue event is a completion queue entry
9251 * CQE. For now, this pool is used for the interrupt service routine to queue
9252 * the following HBA completion queue events for the worker thread to process:
9253 * - Mailbox asynchronous events
9254 * - Receive queue completion unsolicited events
9255 * Later, this can be used for all the slow-path events.
9256 *
9257 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009258 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009259 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04009260 **/
9261static int
9262lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
9263{
9264 struct lpfc_cq_event *cq_event;
9265 int i;
9266
9267 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
9268 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
9269 if (!cq_event)
9270 goto out_pool_create_fail;
9271 list_add_tail(&cq_event->list,
9272 &phba->sli4_hba.sp_cqe_event_pool);
9273 }
9274 return 0;
9275
9276out_pool_create_fail:
9277 lpfc_sli4_cq_event_pool_destroy(phba);
9278 return -ENOMEM;
9279}
9280
9281/**
9282 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
9283 * @phba: pointer to lpfc hba data structure.
9284 *
9285 * This routine is invoked to free the pool of completion queue events at
9286 * driver unload time. Note that, it is the responsibility of the driver
9287 * cleanup routine to free all the outstanding completion-queue events
9288 * allocated from this pool back into the pool before invoking this routine
9289 * to destroy the pool.
9290 **/
9291static void
9292lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
9293{
9294 struct lpfc_cq_event *cq_event, *next_cq_event;
9295
9296 list_for_each_entry_safe(cq_event, next_cq_event,
9297 &phba->sli4_hba.sp_cqe_event_pool, list) {
9298 list_del(&cq_event->list);
9299 kfree(cq_event);
9300 }
9301}
9302
9303/**
9304 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9305 * @phba: pointer to lpfc hba data structure.
9306 *
9307 * This routine is the lock free version of the API invoked to allocate a
9308 * completion-queue event from the free pool.
9309 *
9310 * Return: Pointer to the newly allocated completion-queue event if successful
9311 * NULL otherwise.
9312 **/
9313struct lpfc_cq_event *
9314__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9315{
9316 struct lpfc_cq_event *cq_event = NULL;
9317
9318 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
9319 struct lpfc_cq_event, list);
9320 return cq_event;
9321}
9322
9323/**
9324 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9325 * @phba: pointer to lpfc hba data structure.
9326 *
9327 * This routine is the lock version of the API invoked to allocate a
9328 * completion-queue event from the free pool.
9329 *
9330 * Return: Pointer to the newly allocated completion-queue event if successful
9331 * NULL otherwise.
9332 **/
9333struct lpfc_cq_event *
9334lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9335{
9336 struct lpfc_cq_event *cq_event;
9337 unsigned long iflags;
9338
9339 spin_lock_irqsave(&phba->hbalock, iflags);
9340 cq_event = __lpfc_sli4_cq_event_alloc(phba);
9341 spin_unlock_irqrestore(&phba->hbalock, iflags);
9342 return cq_event;
9343}
9344
9345/**
9346 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9347 * @phba: pointer to lpfc hba data structure.
9348 * @cq_event: pointer to the completion queue event to be freed.
9349 *
9350 * This routine is the lock free version of the API invoked to release a
9351 * completion-queue event back into the free pool.
9352 **/
9353void
9354__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9355 struct lpfc_cq_event *cq_event)
9356{
9357 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
9358}
9359
9360/**
9361 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9362 * @phba: pointer to lpfc hba data structure.
9363 * @cq_event: pointer to the completion queue event to be freed.
9364 *
9365 * This routine is the lock version of the API invoked to release a
9366 * completion-queue event back into the free pool.
9367 **/
9368void
9369lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9370 struct lpfc_cq_event *cq_event)
9371{
9372 unsigned long iflags;
9373 spin_lock_irqsave(&phba->hbalock, iflags);
9374 __lpfc_sli4_cq_event_release(phba, cq_event);
9375 spin_unlock_irqrestore(&phba->hbalock, iflags);
9376}
9377
9378/**
9379 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
9380 * @phba: pointer to lpfc hba data structure.
9381 *
9382 * This routine is to free all the pending completion-queue events to the
9383 * back into the free pool for device reset.
9384 **/
9385static void
9386lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
9387{
9388 LIST_HEAD(cqelist);
9389 struct lpfc_cq_event *cqe;
9390 unsigned long iflags;
9391
9392 /* Retrieve all the pending WCQEs from pending WCQE lists */
9393 spin_lock_irqsave(&phba->hbalock, iflags);
9394 /* Pending FCP XRI abort events */
9395 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
9396 &cqelist);
9397 /* Pending ELS XRI abort events */
9398 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
9399 &cqelist);
9400 /* Pending asynnc events */
9401 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
9402 &cqelist);
9403 spin_unlock_irqrestore(&phba->hbalock, iflags);
9404
9405 while (!list_empty(&cqelist)) {
9406 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
9407 lpfc_sli4_cq_event_release(phba, cqe);
9408 }
9409}
9410
9411/**
9412 * lpfc_pci_function_reset - Reset pci function.
9413 * @phba: pointer to lpfc hba data structure.
9414 *
9415 * This routine is invoked to request a PCI function reset. It will destroys
9416 * all resources assigned to the PCI function which originates this request.
9417 *
9418 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009419 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009420 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009421 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009422 **/
9423int
9424lpfc_pci_function_reset(struct lpfc_hba *phba)
9425{
9426 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05009427 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04009428 uint32_t shdr_status, shdr_add_status;
James Smart2f6fa2c2014-09-03 12:57:08 -04009429 uint32_t rdy_chk;
9430 uint32_t port_reset = 0;
James Smartda0436e2009-05-22 14:51:39 -04009431 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05009432 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -05009433 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -04009434
James Smart2fcee4b2010-12-15 17:57:46 -05009435 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9436 switch (if_type) {
9437 case LPFC_SLI_INTF_IF_TYPE_0:
9438 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
9439 GFP_KERNEL);
9440 if (!mboxq) {
9441 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9442 "0494 Unable to allocate memory for "
9443 "issuing SLI_FUNCTION_RESET mailbox "
9444 "command\n");
9445 return -ENOMEM;
9446 }
9447
9448 /* Setup PCI function reset mailbox-ioctl command */
9449 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9450 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
9451 LPFC_SLI4_MBX_EMBED);
9452 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9453 shdr = (union lpfc_sli4_cfg_shdr *)
9454 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
9455 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9456 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
9457 &shdr->response);
9458 if (rc != MBX_TIMEOUT)
9459 mempool_free(mboxq, phba->mbox_mem_pool);
9460 if (shdr_status || shdr_add_status || rc) {
9461 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9462 "0495 SLI_FUNCTION_RESET mailbox "
9463 "failed with status x%x add_status x%x,"
9464 " mbx status x%x\n",
9465 shdr_status, shdr_add_status, rc);
9466 rc = -ENXIO;
9467 }
9468 break;
9469 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08009470 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2f6fa2c2014-09-03 12:57:08 -04009471wait:
9472 /*
9473 * Poll the Port Status Register and wait for RDY for
9474 * up to 30 seconds. If the port doesn't respond, treat
9475 * it as an error.
9476 */
James Smart77d093f2015-04-07 15:07:08 -04009477 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
James Smart2f6fa2c2014-09-03 12:57:08 -04009478 if (lpfc_readl(phba->sli4_hba.u.if_type2.
9479 STATUSregaddr, &reg_data.word0)) {
9480 rc = -ENODEV;
9481 goto out;
9482 }
9483 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
9484 break;
9485 msleep(20);
9486 }
9487
9488 if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
9489 phba->work_status[0] = readl(
9490 phba->sli4_hba.u.if_type2.ERR1regaddr);
9491 phba->work_status[1] = readl(
9492 phba->sli4_hba.u.if_type2.ERR2regaddr);
9493 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9494 "2890 Port not ready, port status reg "
9495 "0x%x error 1=0x%x, error 2=0x%x\n",
9496 reg_data.word0,
9497 phba->work_status[0],
9498 phba->work_status[1]);
9499 rc = -ENODEV;
9500 goto out;
9501 }
9502
9503 if (!port_reset) {
9504 /*
9505 * Reset the port now
9506 */
James Smart2fcee4b2010-12-15 17:57:46 -05009507 reg_data.word0 = 0;
9508 bf_set(lpfc_sliport_ctrl_end, &reg_data,
9509 LPFC_SLIPORT_LITTLE_ENDIAN);
9510 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
9511 LPFC_SLIPORT_INIT_PORT);
9512 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
9513 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -05009514 /* flush */
James Smart2b81f942012-03-01 22:37:18 -05009515 pci_read_config_word(phba->pcidev,
9516 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -05009517
James Smart2f6fa2c2014-09-03 12:57:08 -04009518 port_reset = 1;
9519 msleep(20);
9520 goto wait;
9521 } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
9522 rc = -ENODEV;
9523 goto out;
James Smart2fcee4b2010-12-15 17:57:46 -05009524 }
9525 break;
James Smart2f6fa2c2014-09-03 12:57:08 -04009526
James Smart2fcee4b2010-12-15 17:57:46 -05009527 case LPFC_SLI_INTF_IF_TYPE_1:
9528 default:
9529 break;
James Smartda0436e2009-05-22 14:51:39 -04009530 }
9531
James Smart73d91e52011-10-10 21:32:10 -04009532out:
James Smart2fcee4b2010-12-15 17:57:46 -05009533 /* Catch the not-ready port failure after a port reset. */
James Smart2f6fa2c2014-09-03 12:57:08 -04009534 if (rc) {
James Smart229adb02013-04-17 20:16:51 -04009535 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9536 "3317 HBA not functional: IP Reset Failed "
James Smart2f6fa2c2014-09-03 12:57:08 -04009537 "try: echo fw_reset > board_mode\n");
James Smart2fcee4b2010-12-15 17:57:46 -05009538 rc = -ENODEV;
James Smart229adb02013-04-17 20:16:51 -04009539 }
James Smart2fcee4b2010-12-15 17:57:46 -05009540
James Smartda0436e2009-05-22 14:51:39 -04009541 return rc;
9542}
9543
9544/**
James Smartda0436e2009-05-22 14:51:39 -04009545 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
9546 * @phba: pointer to lpfc hba data structure.
9547 *
9548 * This routine is invoked to set up the PCI device memory space for device
9549 * with SLI-4 interface spec.
9550 *
9551 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009552 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009553 * other values - error
9554 **/
9555static int
9556lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
9557{
9558 struct pci_dev *pdev;
9559 unsigned long bar0map_len, bar1map_len, bar2map_len;
9560 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05009561 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04009562
9563 /* Obtain PCI device reference */
9564 if (!phba->pcidev)
9565 return error;
9566 else
9567 pdev = phba->pcidev;
9568
9569 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05009570 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
9571 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
9572 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
9573 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smartda0436e2009-05-22 14:51:39 -04009574 return error;
Michael Reed8e685972009-09-18 12:02:05 -05009575 }
9576 }
James Smartda0436e2009-05-22 14:51:39 -04009577
James Smart2fcee4b2010-12-15 17:57:46 -05009578 /*
9579 * The BARs and register set definitions and offset locations are
9580 * dependent on the if_type.
9581 */
9582 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
9583 &phba->sli4_hba.sli_intf.word0)) {
9584 return error;
9585 }
9586
9587 /* There is no SLI3 failback for SLI4 devices. */
9588 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
9589 LPFC_SLI_INTF_VALID) {
9590 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9591 "2894 SLI_INTF reg contents invalid "
9592 "sli_intf reg 0x%x\n",
9593 phba->sli4_hba.sli_intf.word0);
9594 return error;
9595 }
9596
9597 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9598 /*
9599 * Get the bus address of SLI4 device Bar regions and the
9600 * number of bytes required by each mapping. The mapping of the
9601 * particular PCI BARs regions is dependent on the type of
9602 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04009603 */
James Smartf5ca6f22013-09-06 12:21:09 -04009604 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
9605 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
9606 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
James Smart2fcee4b2010-12-15 17:57:46 -05009607
9608 /*
9609 * Map SLI4 PCI Config Space Register base to a kernel virtual
9610 * addr
9611 */
9612 phba->sli4_hba.conf_regs_memmap_p =
9613 ioremap(phba->pci_bar0_map, bar0map_len);
9614 if (!phba->sli4_hba.conf_regs_memmap_p) {
9615 dev_printk(KERN_ERR, &pdev->dev,
9616 "ioremap failed for SLI4 PCI config "
9617 "registers.\n");
9618 goto out;
9619 }
James Smartf5ca6f22013-09-06 12:21:09 -04009620 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05009621 /* Set up BAR0 PCI config space register memory map */
9622 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05009623 } else {
9624 phba->pci_bar0_map = pci_resource_start(pdev, 1);
9625 bar0map_len = pci_resource_len(pdev, 1);
James Smart27d6ac02018-02-22 08:18:42 -08009626 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
James Smart2fcee4b2010-12-15 17:57:46 -05009627 dev_printk(KERN_ERR, &pdev->dev,
9628 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
9629 goto out;
9630 }
9631 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04009632 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05009633 if (!phba->sli4_hba.conf_regs_memmap_p) {
9634 dev_printk(KERN_ERR, &pdev->dev,
9635 "ioremap failed for SLI4 PCI config "
9636 "registers.\n");
9637 goto out;
9638 }
9639 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04009640 }
9641
James Smarte4b97942017-11-20 16:00:31 -08009642 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
9643 if (pci_resource_start(pdev, PCI_64BIT_BAR2)) {
9644 /*
9645 * Map SLI4 if type 0 HBA Control Register base to a
9646 * kernel virtual address and setup the registers.
9647 */
9648 phba->pci_bar1_map = pci_resource_start(pdev,
9649 PCI_64BIT_BAR2);
9650 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
9651 phba->sli4_hba.ctrl_regs_memmap_p =
9652 ioremap(phba->pci_bar1_map,
9653 bar1map_len);
9654 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
9655 dev_err(&pdev->dev,
9656 "ioremap failed for SLI4 HBA "
9657 "control registers.\n");
9658 error = -ENOMEM;
9659 goto out_iounmap_conf;
9660 }
9661 phba->pci_bar2_memmap_p =
9662 phba->sli4_hba.ctrl_regs_memmap_p;
James Smart27d6ac02018-02-22 08:18:42 -08009663 lpfc_sli4_bar1_register_memmap(phba, if_type);
James Smarte4b97942017-11-20 16:00:31 -08009664 } else {
9665 error = -ENOMEM;
James Smart2fcee4b2010-12-15 17:57:46 -05009666 goto out_iounmap_conf;
9667 }
James Smartda0436e2009-05-22 14:51:39 -04009668 }
9669
James Smart27d6ac02018-02-22 08:18:42 -08009670 if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) &&
9671 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
9672 /*
9673 * Map SLI4 if type 6 HBA Doorbell Register base to a kernel
9674 * virtual address and setup the registers.
9675 */
9676 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
9677 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
9678 phba->sli4_hba.drbl_regs_memmap_p =
9679 ioremap(phba->pci_bar1_map, bar1map_len);
9680 if (!phba->sli4_hba.drbl_regs_memmap_p) {
9681 dev_err(&pdev->dev,
9682 "ioremap failed for SLI4 HBA doorbell registers.\n");
9683 goto out_iounmap_conf;
9684 }
9685 phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
9686 lpfc_sli4_bar1_register_memmap(phba, if_type);
9687 }
9688
James Smarte4b97942017-11-20 16:00:31 -08009689 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
9690 if (pci_resource_start(pdev, PCI_64BIT_BAR4)) {
9691 /*
9692 * Map SLI4 if type 0 HBA Doorbell Register base to
9693 * a kernel virtual address and setup the registers.
9694 */
9695 phba->pci_bar2_map = pci_resource_start(pdev,
9696 PCI_64BIT_BAR4);
9697 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
9698 phba->sli4_hba.drbl_regs_memmap_p =
9699 ioremap(phba->pci_bar2_map,
9700 bar2map_len);
9701 if (!phba->sli4_hba.drbl_regs_memmap_p) {
9702 dev_err(&pdev->dev,
9703 "ioremap failed for SLI4 HBA"
9704 " doorbell registers.\n");
9705 error = -ENOMEM;
9706 goto out_iounmap_ctrl;
9707 }
9708 phba->pci_bar4_memmap_p =
9709 phba->sli4_hba.drbl_regs_memmap_p;
9710 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
9711 if (error)
9712 goto out_iounmap_all;
9713 } else {
9714 error = -ENOMEM;
James Smart2fcee4b2010-12-15 17:57:46 -05009715 goto out_iounmap_all;
James Smarte4b97942017-11-20 16:00:31 -08009716 }
James Smartda0436e2009-05-22 14:51:39 -04009717 }
9718
James Smart1351e692018-02-22 08:18:43 -08009719 if (if_type == LPFC_SLI_INTF_IF_TYPE_6 &&
9720 pci_resource_start(pdev, PCI_64BIT_BAR4)) {
9721 /*
9722 * Map SLI4 if type 6 HBA DPP Register base to a kernel
9723 * virtual address and setup the registers.
9724 */
9725 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
9726 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
9727 phba->sli4_hba.dpp_regs_memmap_p =
9728 ioremap(phba->pci_bar2_map, bar2map_len);
9729 if (!phba->sli4_hba.dpp_regs_memmap_p) {
9730 dev_err(&pdev->dev,
9731 "ioremap failed for SLI4 HBA dpp registers.\n");
9732 goto out_iounmap_ctrl;
9733 }
9734 phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
9735 }
9736
James Smartb71413d2018-02-22 08:18:40 -08009737 /* Set up the EQ/CQ register handeling functions now */
James Smart27d6ac02018-02-22 08:18:42 -08009738 switch (if_type) {
9739 case LPFC_SLI_INTF_IF_TYPE_0:
9740 case LPFC_SLI_INTF_IF_TYPE_2:
James Smartb71413d2018-02-22 08:18:40 -08009741 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr;
9742 phba->sli4_hba.sli4_eq_release = lpfc_sli4_eq_release;
9743 phba->sli4_hba.sli4_cq_release = lpfc_sli4_cq_release;
James Smart27d6ac02018-02-22 08:18:42 -08009744 break;
9745 case LPFC_SLI_INTF_IF_TYPE_6:
9746 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_if6_eq_clr_intr;
9747 phba->sli4_hba.sli4_eq_release = lpfc_sli4_if6_eq_release;
9748 phba->sli4_hba.sli4_cq_release = lpfc_sli4_if6_cq_release;
9749 break;
9750 default:
9751 break;
James Smartb71413d2018-02-22 08:18:40 -08009752 }
9753
James Smartda0436e2009-05-22 14:51:39 -04009754 return 0;
9755
9756out_iounmap_all:
9757 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9758out_iounmap_ctrl:
9759 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9760out_iounmap_conf:
9761 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9762out:
9763 return error;
9764}
9765
9766/**
9767 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
9768 * @phba: pointer to lpfc hba data structure.
9769 *
9770 * This routine is invoked to unset the PCI device memory space for device
9771 * with SLI-4 interface spec.
9772 **/
9773static void
9774lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
9775{
James Smart2e90f4b2011-12-13 13:22:37 -05009776 uint32_t if_type;
9777 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -04009778
James Smart2e90f4b2011-12-13 13:22:37 -05009779 switch (if_type) {
9780 case LPFC_SLI_INTF_IF_TYPE_0:
9781 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9782 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9783 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9784 break;
9785 case LPFC_SLI_INTF_IF_TYPE_2:
9786 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9787 break;
James Smart27d6ac02018-02-22 08:18:42 -08009788 case LPFC_SLI_INTF_IF_TYPE_6:
9789 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9790 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9791 break;
James Smart2e90f4b2011-12-13 13:22:37 -05009792 case LPFC_SLI_INTF_IF_TYPE_1:
9793 default:
9794 dev_printk(KERN_ERR, &phba->pcidev->dev,
9795 "FATAL - unsupported SLI4 interface type - %d\n",
9796 if_type);
9797 break;
9798 }
James Smartda0436e2009-05-22 14:51:39 -04009799}
9800
9801/**
James Smart3772a992009-05-22 14:50:54 -04009802 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
9803 * @phba: pointer to lpfc hba data structure.
9804 *
9805 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009806 * with SLI-3 interface specs.
James Smart3772a992009-05-22 14:50:54 -04009807 *
9808 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009809 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009810 * other values - error
9811 **/
9812static int
9813lpfc_sli_enable_msix(struct lpfc_hba *phba)
9814{
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009815 int rc;
James Smart3772a992009-05-22 14:50:54 -04009816 LPFC_MBOXQ_t *pmb;
9817
9818 /* Set up MSI-X multi-message vectors */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009819 rc = pci_alloc_irq_vectors(phba->pcidev,
9820 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
9821 if (rc < 0) {
James Smart3772a992009-05-22 14:50:54 -04009822 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9823 "0420 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009824 goto vec_fail_out;
James Smart3772a992009-05-22 14:50:54 -04009825 }
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009826
James Smart3772a992009-05-22 14:50:54 -04009827 /*
9828 * Assign MSI-X vectors to interrupt handlers
9829 */
9830
9831 /* vector-0 is associated to slow-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009832 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
James Smarted243d32015-05-21 13:55:25 -04009833 &lpfc_sli_sp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04009834 LPFC_SP_DRIVER_HANDLER_NAME, phba);
9835 if (rc) {
9836 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9837 "0421 MSI-X slow-path request_irq failed "
9838 "(%d)\n", rc);
9839 goto msi_fail_out;
9840 }
9841
9842 /* vector-1 is associated to fast-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009843 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
James Smarted243d32015-05-21 13:55:25 -04009844 &lpfc_sli_fp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04009845 LPFC_FP_DRIVER_HANDLER_NAME, phba);
9846
9847 if (rc) {
9848 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9849 "0429 MSI-X fast-path request_irq failed "
9850 "(%d)\n", rc);
9851 goto irq_fail_out;
9852 }
9853
9854 /*
9855 * Configure HBA MSI-X attention conditions to messages
9856 */
9857 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9858
9859 if (!pmb) {
9860 rc = -ENOMEM;
9861 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9862 "0474 Unable to allocate memory for issuing "
9863 "MBOX_CONFIG_MSI command\n");
9864 goto mem_fail_out;
9865 }
9866 rc = lpfc_config_msi(phba, pmb);
9867 if (rc)
9868 goto mbx_fail_out;
9869 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
9870 if (rc != MBX_SUCCESS) {
9871 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
9872 "0351 Config MSI mailbox command failed, "
9873 "mbxCmd x%x, mbxStatus x%x\n",
9874 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
9875 goto mbx_fail_out;
9876 }
9877
9878 /* Free memory allocated for mailbox command */
9879 mempool_free(pmb, phba->mbox_mem_pool);
9880 return rc;
9881
9882mbx_fail_out:
9883 /* Free memory allocated for mailbox command */
9884 mempool_free(pmb, phba->mbox_mem_pool);
9885
9886mem_fail_out:
9887 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009888 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
James Smart3772a992009-05-22 14:50:54 -04009889
9890irq_fail_out:
9891 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009892 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
James Smart3772a992009-05-22 14:50:54 -04009893
9894msi_fail_out:
9895 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009896 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009897
9898vec_fail_out:
James Smart3772a992009-05-22 14:50:54 -04009899 return rc;
9900}
9901
9902/**
James Smart3772a992009-05-22 14:50:54 -04009903 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
9904 * @phba: pointer to lpfc hba data structure.
9905 *
9906 * This routine is invoked to enable the MSI interrupt mode to device with
9907 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
9908 * enable the MSI vector. The device driver is responsible for calling the
9909 * request_irq() to register MSI vector with a interrupt the handler, which
9910 * is done in this function.
9911 *
9912 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009913 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009914 * other values - error
9915 */
9916static int
9917lpfc_sli_enable_msi(struct lpfc_hba *phba)
9918{
9919 int rc;
9920
9921 rc = pci_enable_msi(phba->pcidev);
9922 if (!rc)
9923 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9924 "0462 PCI enable MSI mode success.\n");
9925 else {
9926 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9927 "0471 PCI enable MSI mode failed (%d)\n", rc);
9928 return rc;
9929 }
9930
9931 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04009932 0, LPFC_DRIVER_NAME, phba);
James Smart3772a992009-05-22 14:50:54 -04009933 if (rc) {
9934 pci_disable_msi(phba->pcidev);
9935 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9936 "0478 MSI request_irq failed (%d)\n", rc);
9937 }
9938 return rc;
9939}
9940
9941/**
James Smart3772a992009-05-22 14:50:54 -04009942 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
9943 * @phba: pointer to lpfc hba data structure.
9944 *
9945 * This routine is invoked to enable device interrupt and associate driver's
9946 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
9947 * spec. Depends on the interrupt mode configured to the driver, the driver
9948 * will try to fallback from the configured interrupt mode to an interrupt
9949 * mode which is supported by the platform, kernel, and device in the order
9950 * of:
9951 * MSI-X -> MSI -> IRQ.
9952 *
9953 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009954 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009955 * other values - error
9956 **/
9957static uint32_t
9958lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9959{
9960 uint32_t intr_mode = LPFC_INTR_ERROR;
9961 int retval;
9962
9963 if (cfg_mode == 2) {
9964 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
9965 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
9966 if (!retval) {
9967 /* Now, try to enable MSI-X interrupt mode */
9968 retval = lpfc_sli_enable_msix(phba);
9969 if (!retval) {
9970 /* Indicate initialization to MSI-X mode */
9971 phba->intr_type = MSIX;
9972 intr_mode = 2;
9973 }
9974 }
9975 }
9976
9977 /* Fallback to MSI if MSI-X initialization failed */
9978 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9979 retval = lpfc_sli_enable_msi(phba);
9980 if (!retval) {
9981 /* Indicate initialization to MSI mode */
9982 phba->intr_type = MSI;
9983 intr_mode = 1;
9984 }
9985 }
9986
9987 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9988 if (phba->intr_type == NONE) {
9989 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
9990 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9991 if (!retval) {
9992 /* Indicate initialization to INTx mode */
9993 phba->intr_type = INTx;
9994 intr_mode = 0;
9995 }
9996 }
9997 return intr_mode;
9998}
9999
10000/**
10001 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
10002 * @phba: pointer to lpfc hba data structure.
10003 *
10004 * This routine is invoked to disable device interrupt and disassociate the
10005 * driver's interrupt handler(s) from interrupt vector(s) to device with
10006 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
10007 * release the interrupt vector(s) for the message signaled interrupt.
10008 **/
10009static void
10010lpfc_sli_disable_intr(struct lpfc_hba *phba)
10011{
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010012 int nr_irqs, i;
10013
James Smart3772a992009-05-22 14:50:54 -040010014 if (phba->intr_type == MSIX)
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010015 nr_irqs = LPFC_MSIX_VECTORS;
10016 else
10017 nr_irqs = 1;
10018
10019 for (i = 0; i < nr_irqs; i++)
10020 free_irq(pci_irq_vector(phba->pcidev, i), phba);
10021 pci_free_irq_vectors(phba->pcidev);
James Smart3772a992009-05-22 14:50:54 -040010022
10023 /* Reset interrupt management states */
10024 phba->intr_type = NONE;
10025 phba->sli.slistat.sli_intr = 0;
James Smart3772a992009-05-22 14:50:54 -040010026}
10027
10028/**
James Smart895427b2017-02-12 13:52:30 -080010029 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
James Smart7bb03bb2013-04-17 20:19:16 -040010030 * @phba: pointer to lpfc hba data structure.
James Smart895427b2017-02-12 13:52:30 -080010031 * @vectors: number of msix vectors allocated.
James Smart7bb03bb2013-04-17 20:19:16 -040010032 *
James Smart895427b2017-02-12 13:52:30 -080010033 * The routine will figure out the CPU affinity assignment for every
10034 * MSI-X vector allocated for the HBA. The hba_eq_hdl will be updated
10035 * with a pointer to the CPU mask that defines ALL the CPUs this vector
10036 * can be associated with. If the vector can be unquely associated with
10037 * a single CPU, that CPU will be recorded in hba_eq_hdl[index].cpu.
10038 * In addition, the CPU to IO channel mapping will be calculated
10039 * and the phba->sli4_hba.cpu_map array will reflect this.
James Smart7bb03bb2013-04-17 20:19:16 -040010040 */
James Smart895427b2017-02-12 13:52:30 -080010041static void
10042lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
James Smart7bb03bb2013-04-17 20:19:16 -040010043{
10044 struct lpfc_vector_map_info *cpup;
James Smart895427b2017-02-12 13:52:30 -080010045 int index = 0;
10046 int vec = 0;
James Smart7bb03bb2013-04-17 20:19:16 -040010047 int cpu;
James Smart7bb03bb2013-04-17 20:19:16 -040010048#ifdef CONFIG_X86
10049 struct cpuinfo_x86 *cpuinfo;
10050#endif
James Smart7bb03bb2013-04-17 20:19:16 -040010051
10052 /* Init cpu_map array */
10053 memset(phba->sli4_hba.cpu_map, 0xff,
10054 (sizeof(struct lpfc_vector_map_info) *
James Smart895427b2017-02-12 13:52:30 -080010055 phba->sli4_hba.num_present_cpu));
James Smart7bb03bb2013-04-17 20:19:16 -040010056
10057 /* Update CPU map with physical id and core id of each CPU */
10058 cpup = phba->sli4_hba.cpu_map;
10059 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
10060#ifdef CONFIG_X86
10061 cpuinfo = &cpu_data(cpu);
10062 cpup->phys_id = cpuinfo->phys_proc_id;
10063 cpup->core_id = cpuinfo->cpu_core_id;
10064#else
10065 /* No distinction between CPUs for other platforms */
10066 cpup->phys_id = 0;
10067 cpup->core_id = 0;
10068#endif
James Smart895427b2017-02-12 13:52:30 -080010069 cpup->channel_id = index; /* For now round robin */
10070 cpup->irq = pci_irq_vector(phba->pcidev, vec);
10071 vec++;
10072 if (vec >= vectors)
10073 vec = 0;
10074 index++;
10075 if (index >= phba->cfg_fcp_io_channel)
10076 index = 0;
James Smart7bb03bb2013-04-17 20:19:16 -040010077 cpup++;
10078 }
James Smart7bb03bb2013-04-17 20:19:16 -040010079}
10080
10081
10082/**
James Smartda0436e2009-05-22 14:51:39 -040010083 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
10084 * @phba: pointer to lpfc hba data structure.
10085 *
10086 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010087 * with SLI-4 interface spec.
James Smartda0436e2009-05-22 14:51:39 -040010088 *
10089 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010090 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040010091 * other values - error
10092 **/
10093static int
10094lpfc_sli4_enable_msix(struct lpfc_hba *phba)
10095{
James Smart75baf692010-06-08 18:31:21 -040010096 int vectors, rc, index;
James Smartb83d0052017-06-01 21:07:05 -070010097 char *name;
James Smartda0436e2009-05-22 14:51:39 -040010098
10099 /* Set up MSI-X multi-message vectors */
James Smart895427b2017-02-12 13:52:30 -080010100 vectors = phba->io_channel_irqs;
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010101 if (phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -050010102 vectors++;
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010103
James Smartf358dd02017-02-12 13:52:34 -080010104 rc = pci_alloc_irq_vectors(phba->pcidev,
10105 (phba->nvmet_support) ? 1 : 2,
10106 vectors, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY);
Alexander Gordeev4f871e12014-09-03 12:56:29 -040010107 if (rc < 0) {
James Smartda0436e2009-05-22 14:51:39 -040010108 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10109 "0484 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +020010110 goto vec_fail_out;
James Smartda0436e2009-05-22 14:51:39 -040010111 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -040010112 vectors = rc;
James Smart75baf692010-06-08 18:31:21 -040010113
James Smart7bb03bb2013-04-17 20:19:16 -040010114 /* Assign MSI-X vectors to interrupt handlers */
James Smart67d12732012-08-03 12:36:13 -040010115 for (index = 0; index < vectors; index++) {
James Smartb83d0052017-06-01 21:07:05 -070010116 name = phba->sli4_hba.hba_eq_hdl[index].handler_name;
10117 memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ);
10118 snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ,
James Smart4305f182012-08-03 12:36:33 -040010119 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -040010120
James Smart895427b2017-02-12 13:52:30 -080010121 phba->sli4_hba.hba_eq_hdl[index].idx = index;
10122 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
10123 atomic_set(&phba->sli4_hba.hba_eq_hdl[index].hba_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -050010124 if (phba->cfg_fof && (index == (vectors - 1)))
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010125 rc = request_irq(pci_irq_vector(phba->pcidev, index),
James Smarted243d32015-05-21 13:55:25 -040010126 &lpfc_sli4_fof_intr_handler, 0,
James Smartb83d0052017-06-01 21:07:05 -070010127 name,
James Smart895427b2017-02-12 13:52:30 -080010128 &phba->sli4_hba.hba_eq_hdl[index]);
James Smart1ba981f2014-02-20 09:56:45 -050010129 else
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010130 rc = request_irq(pci_irq_vector(phba->pcidev, index),
James Smarted243d32015-05-21 13:55:25 -040010131 &lpfc_sli4_hba_intr_handler, 0,
James Smartb83d0052017-06-01 21:07:05 -070010132 name,
James Smart895427b2017-02-12 13:52:30 -080010133 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -040010134 if (rc) {
10135 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10136 "0486 MSI-X fast-path (%d) "
10137 "request_irq failed (%d)\n", index, rc);
10138 goto cfg_fail_out;
10139 }
10140 }
10141
James Smart1ba981f2014-02-20 09:56:45 -050010142 if (phba->cfg_fof)
10143 vectors--;
10144
James Smart895427b2017-02-12 13:52:30 -080010145 if (vectors != phba->io_channel_irqs) {
James Smart82c3e9b2012-09-29 11:29:50 -040010146 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10147 "3238 Reducing IO channels to match number of "
10148 "MSI-X vectors, requested %d got %d\n",
James Smart895427b2017-02-12 13:52:30 -080010149 phba->io_channel_irqs, vectors);
10150 if (phba->cfg_fcp_io_channel > vectors)
10151 phba->cfg_fcp_io_channel = vectors;
10152 if (phba->cfg_nvme_io_channel > vectors)
10153 phba->cfg_nvme_io_channel = vectors;
10154 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
10155 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
10156 else
10157 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
James Smart82c3e9b2012-09-29 11:29:50 -040010158 }
James Smart895427b2017-02-12 13:52:30 -080010159 lpfc_cpu_affinity_check(phba, vectors);
James Smart7bb03bb2013-04-17 20:19:16 -040010160
James Smartda0436e2009-05-22 14:51:39 -040010161 return rc;
10162
10163cfg_fail_out:
10164 /* free the irq already requested */
James Smart895427b2017-02-12 13:52:30 -080010165 for (--index; index >= 0; index--)
10166 free_irq(pci_irq_vector(phba->pcidev, index),
10167 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -040010168
James Smartda0436e2009-05-22 14:51:39 -040010169 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010170 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +020010171
10172vec_fail_out:
James Smartda0436e2009-05-22 14:51:39 -040010173 return rc;
10174}
10175
10176/**
James Smartda0436e2009-05-22 14:51:39 -040010177 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
10178 * @phba: pointer to lpfc hba data structure.
10179 *
10180 * This routine is invoked to enable the MSI interrupt mode to device with
10181 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
10182 * to enable the MSI vector. The device driver is responsible for calling
10183 * the request_irq() to register MSI vector with a interrupt the handler,
10184 * which is done in this function.
10185 *
10186 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010187 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040010188 * other values - error
10189 **/
10190static int
10191lpfc_sli4_enable_msi(struct lpfc_hba *phba)
10192{
10193 int rc, index;
10194
10195 rc = pci_enable_msi(phba->pcidev);
10196 if (!rc)
10197 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10198 "0487 PCI enable MSI mode success.\n");
10199 else {
10200 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10201 "0488 PCI enable MSI mode failed (%d)\n", rc);
10202 return rc;
10203 }
10204
10205 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
James Smarted243d32015-05-21 13:55:25 -040010206 0, LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -040010207 if (rc) {
10208 pci_disable_msi(phba->pcidev);
10209 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10210 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -040010211 return rc;
James Smartda0436e2009-05-22 14:51:39 -040010212 }
10213
James Smart895427b2017-02-12 13:52:30 -080010214 for (index = 0; index < phba->io_channel_irqs; index++) {
10215 phba->sli4_hba.hba_eq_hdl[index].idx = index;
10216 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smartda0436e2009-05-22 14:51:39 -040010217 }
10218
James Smart1ba981f2014-02-20 09:56:45 -050010219 if (phba->cfg_fof) {
James Smart895427b2017-02-12 13:52:30 -080010220 phba->sli4_hba.hba_eq_hdl[index].idx = index;
10221 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smart1ba981f2014-02-20 09:56:45 -050010222 }
James Smart75baf692010-06-08 18:31:21 -040010223 return 0;
James Smartda0436e2009-05-22 14:51:39 -040010224}
10225
10226/**
James Smartda0436e2009-05-22 14:51:39 -040010227 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
10228 * @phba: pointer to lpfc hba data structure.
10229 *
10230 * This routine is invoked to enable device interrupt and associate driver's
10231 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
10232 * interface spec. Depends on the interrupt mode configured to the driver,
10233 * the driver will try to fallback from the configured interrupt mode to an
10234 * interrupt mode which is supported by the platform, kernel, and device in
10235 * the order of:
10236 * MSI-X -> MSI -> IRQ.
10237 *
10238 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010239 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040010240 * other values - error
10241 **/
10242static uint32_t
10243lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
10244{
10245 uint32_t intr_mode = LPFC_INTR_ERROR;
James Smart895427b2017-02-12 13:52:30 -080010246 int retval, idx;
James Smartda0436e2009-05-22 14:51:39 -040010247
10248 if (cfg_mode == 2) {
10249 /* Preparation before conf_msi mbox cmd */
10250 retval = 0;
10251 if (!retval) {
10252 /* Now, try to enable MSI-X interrupt mode */
10253 retval = lpfc_sli4_enable_msix(phba);
10254 if (!retval) {
10255 /* Indicate initialization to MSI-X mode */
10256 phba->intr_type = MSIX;
10257 intr_mode = 2;
10258 }
10259 }
10260 }
10261
10262 /* Fallback to MSI if MSI-X initialization failed */
10263 if (cfg_mode >= 1 && phba->intr_type == NONE) {
10264 retval = lpfc_sli4_enable_msi(phba);
10265 if (!retval) {
10266 /* Indicate initialization to MSI mode */
10267 phba->intr_type = MSI;
10268 intr_mode = 1;
10269 }
10270 }
10271
10272 /* Fallback to INTx if both MSI-X/MSI initalization failed */
10273 if (phba->intr_type == NONE) {
10274 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
10275 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
10276 if (!retval) {
James Smart895427b2017-02-12 13:52:30 -080010277 struct lpfc_hba_eq_hdl *eqhdl;
10278
James Smartda0436e2009-05-22 14:51:39 -040010279 /* Indicate initialization to INTx mode */
10280 phba->intr_type = INTx;
10281 intr_mode = 0;
James Smart895427b2017-02-12 13:52:30 -080010282
10283 for (idx = 0; idx < phba->io_channel_irqs; idx++) {
10284 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
10285 eqhdl->idx = idx;
10286 eqhdl->phba = phba;
10287 atomic_set(&eqhdl->hba_eq_in_use, 1);
James Smartda0436e2009-05-22 14:51:39 -040010288 }
James Smart1ba981f2014-02-20 09:56:45 -050010289 if (phba->cfg_fof) {
James Smart895427b2017-02-12 13:52:30 -080010290 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
10291 eqhdl->idx = idx;
10292 eqhdl->phba = phba;
10293 atomic_set(&eqhdl->hba_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -050010294 }
James Smartda0436e2009-05-22 14:51:39 -040010295 }
10296 }
10297 return intr_mode;
10298}
10299
10300/**
10301 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
10302 * @phba: pointer to lpfc hba data structure.
10303 *
10304 * This routine is invoked to disable device interrupt and disassociate
10305 * the driver's interrupt handler(s) from interrupt vector(s) to device
10306 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
10307 * will release the interrupt vector(s) for the message signaled interrupt.
10308 **/
10309static void
10310lpfc_sli4_disable_intr(struct lpfc_hba *phba)
10311{
10312 /* Disable the currently initialized interrupt mode */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010313 if (phba->intr_type == MSIX) {
10314 int index;
10315
10316 /* Free up MSI-X multi-message vectors */
James Smart895427b2017-02-12 13:52:30 -080010317 for (index = 0; index < phba->io_channel_irqs; index++)
10318 free_irq(pci_irq_vector(phba->pcidev, index),
10319 &phba->sli4_hba.hba_eq_hdl[index]);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010320
10321 if (phba->cfg_fof)
James Smart895427b2017-02-12 13:52:30 -080010322 free_irq(pci_irq_vector(phba->pcidev, index),
10323 &phba->sli4_hba.hba_eq_hdl[index]);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010324 } else {
James Smartda0436e2009-05-22 14:51:39 -040010325 free_irq(phba->pcidev->irq, phba);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010326 }
10327
10328 pci_free_irq_vectors(phba->pcidev);
James Smartda0436e2009-05-22 14:51:39 -040010329
10330 /* Reset interrupt management states */
10331 phba->intr_type = NONE;
10332 phba->sli.slistat.sli_intr = 0;
James Smartda0436e2009-05-22 14:51:39 -040010333}
10334
10335/**
James Smart3772a992009-05-22 14:50:54 -040010336 * lpfc_unset_hba - Unset SLI3 hba device initialization
10337 * @phba: pointer to lpfc hba data structure.
10338 *
10339 * This routine is invoked to unset the HBA device initialization steps to
10340 * a device with SLI-3 interface spec.
10341 **/
10342static void
10343lpfc_unset_hba(struct lpfc_hba *phba)
10344{
10345 struct lpfc_vport *vport = phba->pport;
10346 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
10347
10348 spin_lock_irq(shost->host_lock);
10349 vport->load_flag |= FC_UNLOADING;
10350 spin_unlock_irq(shost->host_lock);
10351
James Smart72859902012-01-18 16:25:38 -050010352 kfree(phba->vpi_bmask);
10353 kfree(phba->vpi_ids);
10354
James Smart3772a992009-05-22 14:50:54 -040010355 lpfc_stop_hba_timers(phba);
10356
10357 phba->pport->work_port_events = 0;
10358
10359 lpfc_sli_hba_down(phba);
10360
10361 lpfc_sli_brdrestart(phba);
10362
10363 lpfc_sli_disable_intr(phba);
10364
10365 return;
10366}
10367
10368/**
James Smart5af5eee2010-10-22 11:06:38 -040010369 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
10370 * @phba: Pointer to HBA context object.
10371 *
10372 * This function is called in the SLI4 code path to wait for completion
10373 * of device's XRIs exchange busy. It will check the XRI exchange busy
10374 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
10375 * that, it will check the XRI exchange busy on outstanding FCP and ELS
10376 * I/Os every 30 seconds, log error message, and wait forever. Only when
10377 * all XRI exchange busy complete, the driver unload shall proceed with
10378 * invoking the function reset ioctl mailbox command to the CNA and the
10379 * the rest of the driver unload resource release.
10380 **/
10381static void
10382lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
10383{
10384 int wait_time = 0;
James Smart895427b2017-02-12 13:52:30 -080010385 int nvme_xri_cmpl = 1;
James Smart86c67372017-04-21 16:05:04 -070010386 int nvmet_xri_cmpl = 1;
James Smart895427b2017-02-12 13:52:30 -080010387 int fcp_xri_cmpl = 1;
James Smart5af5eee2010-10-22 11:06:38 -040010388 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
10389
James Smartc3725bd2017-11-20 16:00:42 -080010390 /* Driver just aborted IOs during the hba_unset process. Pause
10391 * here to give the HBA time to complete the IO and get entries
10392 * into the abts lists.
10393 */
10394 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5);
10395
10396 /* Wait for NVME pending IO to flush back to transport. */
10397 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
10398 lpfc_nvme_wait_for_io_drain(phba);
10399
James Smart895427b2017-02-12 13:52:30 -080010400 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
10401 fcp_xri_cmpl =
10402 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
James Smart86c67372017-04-21 16:05:04 -070010403 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -080010404 nvme_xri_cmpl =
10405 list_empty(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
James Smart86c67372017-04-21 16:05:04 -070010406 nvmet_xri_cmpl =
10407 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
10408 }
James Smart895427b2017-02-12 13:52:30 -080010409
James Smartf358dd02017-02-12 13:52:34 -080010410 while (!fcp_xri_cmpl || !els_xri_cmpl || !nvme_xri_cmpl ||
10411 !nvmet_xri_cmpl) {
James Smart5af5eee2010-10-22 11:06:38 -040010412 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
James Smart68c9b552018-06-26 08:24:25 -070010413 if (!nvmet_xri_cmpl)
10414 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10415 "6424 NVMET XRI exchange busy "
10416 "wait time: %d seconds.\n",
10417 wait_time/1000);
James Smart895427b2017-02-12 13:52:30 -080010418 if (!nvme_xri_cmpl)
10419 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10420 "6100 NVME XRI exchange busy "
10421 "wait time: %d seconds.\n",
10422 wait_time/1000);
James Smart5af5eee2010-10-22 11:06:38 -040010423 if (!fcp_xri_cmpl)
10424 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10425 "2877 FCP XRI exchange busy "
10426 "wait time: %d seconds.\n",
10427 wait_time/1000);
10428 if (!els_xri_cmpl)
10429 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10430 "2878 ELS XRI exchange busy "
10431 "wait time: %d seconds.\n",
10432 wait_time/1000);
10433 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
10434 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
10435 } else {
10436 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
10437 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
10438 }
James Smart86c67372017-04-21 16:05:04 -070010439 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -080010440 nvme_xri_cmpl = list_empty(
10441 &phba->sli4_hba.lpfc_abts_nvme_buf_list);
James Smart86c67372017-04-21 16:05:04 -070010442 nvmet_xri_cmpl = list_empty(
10443 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
10444 }
James Smart895427b2017-02-12 13:52:30 -080010445
10446 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
10447 fcp_xri_cmpl = list_empty(
10448 &phba->sli4_hba.lpfc_abts_scsi_buf_list);
10449
James Smart5af5eee2010-10-22 11:06:38 -040010450 els_xri_cmpl =
10451 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -080010452
James Smart5af5eee2010-10-22 11:06:38 -040010453 }
10454}
10455
10456/**
James Smartda0436e2009-05-22 14:51:39 -040010457 * lpfc_sli4_hba_unset - Unset the fcoe hba
10458 * @phba: Pointer to HBA context object.
10459 *
10460 * This function is called in the SLI4 code path to reset the HBA's FCoE
10461 * function. The caller is not required to hold any lock. This routine
10462 * issues PCI function reset mailbox command to reset the FCoE function.
10463 * At the end of the function, it calls lpfc_hba_down_post function to
10464 * free any pending commands.
10465 **/
10466static void
10467lpfc_sli4_hba_unset(struct lpfc_hba *phba)
10468{
10469 int wait_cnt = 0;
10470 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -040010471 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -040010472
10473 lpfc_stop_hba_timers(phba);
10474 phba->sli4_hba.intr_enable = 0;
10475
10476 /*
10477 * Gracefully wait out the potential current outstanding asynchronous
10478 * mailbox command.
10479 */
10480
10481 /* First, block any pending async mailbox command from posted */
10482 spin_lock_irq(&phba->hbalock);
10483 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
10484 spin_unlock_irq(&phba->hbalock);
10485 /* Now, trying to wait it out if we can */
10486 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
10487 msleep(10);
10488 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
10489 break;
10490 }
10491 /* Forcefully release the outstanding mailbox command if timed out */
10492 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
10493 spin_lock_irq(&phba->hbalock);
10494 mboxq = phba->sli.mbox_active;
10495 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
10496 __lpfc_mbox_cmpl_put(phba, mboxq);
10497 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
10498 phba->sli.mbox_active = NULL;
10499 spin_unlock_irq(&phba->hbalock);
10500 }
10501
James Smart5af5eee2010-10-22 11:06:38 -040010502 /* Abort all iocbs associated with the hba */
10503 lpfc_sli_hba_iocb_abort(phba);
10504
10505 /* Wait for completion of device XRI exchange busy */
10506 lpfc_sli4_xri_exchange_busy_wait(phba);
10507
James Smartda0436e2009-05-22 14:51:39 -040010508 /* Disable PCI subsystem interrupt */
10509 lpfc_sli4_disable_intr(phba);
10510
James Smart912e3ac2011-05-24 11:42:11 -040010511 /* Disable SR-IOV if enabled */
10512 if (phba->cfg_sriov_nr_virtfn)
10513 pci_disable_sriov(pdev);
10514
James Smartda0436e2009-05-22 14:51:39 -040010515 /* Stop kthread signal shall trigger work_done one more time */
10516 kthread_stop(phba->worker_thread);
10517
James Smartd1f525a2017-04-21 16:04:55 -070010518 /* Unset the queues shared with the hardware then release all
10519 * allocated resources.
10520 */
10521 lpfc_sli4_queue_unset(phba);
10522 lpfc_sli4_queue_destroy(phba);
10523
James Smart3677a3a2010-09-29 11:19:14 -040010524 /* Reset SLI4 HBA FCoE function */
10525 lpfc_pci_function_reset(phba);
10526
James Smartda0436e2009-05-22 14:51:39 -040010527 /* Stop the SLI4 device port */
10528 phba->pport->work_port_events = 0;
10529}
10530
James Smart28baac72010-02-12 14:42:03 -050010531 /**
10532 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
10533 * @phba: Pointer to HBA context object.
10534 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10535 *
10536 * This function is called in the SLI4 code path to read the port's
10537 * sli4 capabilities.
10538 *
10539 * This function may be be called from any context that can block-wait
10540 * for the completion. The expectation is that this routine is called
10541 * typically from probe_one or from the online routine.
10542 **/
10543int
10544lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10545{
10546 int rc;
10547 struct lpfc_mqe *mqe;
10548 struct lpfc_pc_sli4_params *sli4_params;
10549 uint32_t mbox_tmo;
10550
10551 rc = 0;
10552 mqe = &mboxq->u.mqe;
10553
10554 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -050010555 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -050010556 if (!phba->sli4_hba.intr_enable)
10557 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10558 else {
James Smarta183a152011-10-10 21:32:43 -040010559 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -050010560 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10561 }
10562
10563 if (unlikely(rc))
10564 return 1;
10565
10566 sli4_params = &phba->sli4_hba.pc_sli4_params;
10567 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
10568 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
10569 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
10570 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
10571 &mqe->un.sli4_params);
10572 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
10573 &mqe->un.sli4_params);
10574 sli4_params->proto_types = mqe->un.sli4_params.word3;
10575 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
10576 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
10577 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
10578 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
10579 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
10580 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
10581 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
10582 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
10583 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
10584 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
10585 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
10586 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
10587 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
10588 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
10589 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
10590 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
10591 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
10592 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
10593 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
10594 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -040010595
10596 /* Make sure that sge_supp_len can be handled by the driver */
10597 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10598 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10599
James Smart28baac72010-02-12 14:42:03 -050010600 return rc;
10601}
10602
James Smartda0436e2009-05-22 14:51:39 -040010603/**
James Smartfedd3b72011-02-16 12:39:24 -050010604 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
10605 * @phba: Pointer to HBA context object.
10606 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10607 *
10608 * This function is called in the SLI4 code path to read the port's
10609 * sli4 capabilities.
10610 *
10611 * This function may be be called from any context that can block-wait
10612 * for the completion. The expectation is that this routine is called
10613 * typically from probe_one or from the online routine.
10614 **/
10615int
10616lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10617{
10618 int rc;
10619 struct lpfc_mqe *mqe = &mboxq->u.mqe;
10620 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -040010621 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -050010622 int length;
James Smartbf316c72018-04-09 14:24:28 -070010623 bool exp_wqcq_pages = true;
James Smartfedd3b72011-02-16 12:39:24 -050010624 struct lpfc_sli4_parameters *mbx_sli4_parameters;
10625
James Smart6d368e52011-05-24 11:44:12 -040010626 /*
10627 * By default, the driver assumes the SLI4 port requires RPI
10628 * header postings. The SLI4_PARAM response will correct this
10629 * assumption.
10630 */
10631 phba->sli4_hba.rpi_hdrs_in_use = 1;
10632
James Smartfedd3b72011-02-16 12:39:24 -050010633 /* Read the port's SLI4 Config Parameters */
10634 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
10635 sizeof(struct lpfc_sli4_cfg_mhdr));
10636 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
10637 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
10638 length, LPFC_SLI4_MBX_EMBED);
10639 if (!phba->sli4_hba.intr_enable)
10640 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -040010641 else {
10642 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
10643 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10644 }
James Smartfedd3b72011-02-16 12:39:24 -050010645 if (unlikely(rc))
10646 return rc;
10647 sli4_params = &phba->sli4_hba.pc_sli4_params;
10648 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
10649 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
10650 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
10651 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
10652 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
10653 mbx_sli4_parameters);
10654 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
10655 mbx_sli4_parameters);
10656 if (bf_get(cfg_phwq, mbx_sli4_parameters))
10657 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
10658 else
10659 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
10660 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
10661 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
James Smart1ba981f2014-02-20 09:56:45 -050010662 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010663 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
10664 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
10665 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
10666 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
James Smart7365f6f2018-02-22 08:18:46 -080010667 sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters);
10668 sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters);
James Smart0c651872013-07-15 18:33:23 -040010669 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
James Smart66e9e6b2018-06-26 08:24:27 -070010670 sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010671 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
10672 mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080010673 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010674 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
10675 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -040010676 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
10677 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080010678 phba->nvme_support = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
10679 bf_get(cfg_xib, mbx_sli4_parameters));
10680
10681 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) ||
10682 !phba->nvme_support) {
10683 phba->nvme_support = 0;
10684 phba->nvmet_support = 0;
James Smartbcb24f62017-11-20 16:00:36 -080010685 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_OFF;
James Smart895427b2017-02-12 13:52:30 -080010686 phba->cfg_nvme_io_channel = 0;
10687 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
10688 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
10689 "6101 Disabling NVME support: "
10690 "Not supported by firmware: %d %d\n",
10691 bf_get(cfg_nvme, mbx_sli4_parameters),
10692 bf_get(cfg_xib, mbx_sli4_parameters));
10693
10694 /* If firmware doesn't support NVME, just use SCSI support */
10695 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
10696 return -ENODEV;
10697 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
10698 }
James Smart05580562011-05-24 11:40:48 -040010699
James Smart414abe02018-06-26 08:24:26 -070010700 /* Only embed PBDE for if_type 6, PBDE support requires xib be set */
10701 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
10702 LPFC_SLI_INTF_IF_TYPE_6) || (!bf_get(cfg_xib, mbx_sli4_parameters)))
10703 phba->cfg_enable_pbde = 0;
James Smart0bc2b7c2018-02-22 08:18:48 -080010704
James Smart20aefac2018-01-30 15:58:58 -080010705 /*
10706 * To support Suppress Response feature we must satisfy 3 conditions.
10707 * lpfc_suppress_rsp module parameter must be set (default).
10708 * In SLI4-Parameters Descriptor:
10709 * Extended Inline Buffers (XIB) must be supported.
10710 * Suppress Response IU Not Supported (SRIUNS) must NOT be supported
10711 * (double negative).
10712 */
10713 if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) &&
10714 !(bf_get(cfg_nosr, mbx_sli4_parameters)))
James Smartf358dd02017-02-12 13:52:34 -080010715 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
James Smart20aefac2018-01-30 15:58:58 -080010716 else
10717 phba->cfg_suppress_rsp = 0;
James Smartf358dd02017-02-12 13:52:34 -080010718
James Smart0cf07f842017-06-01 21:07:10 -070010719 if (bf_get(cfg_eqdr, mbx_sli4_parameters))
10720 phba->sli.sli_flag |= LPFC_SLI_USE_EQDR;
10721
James Smart05580562011-05-24 11:40:48 -040010722 /* Make sure that sge_supp_len can be handled by the driver */
10723 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10724 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10725
James Smartb5c53952016-03-31 14:12:30 -070010726 /*
James Smartc176ffa2018-01-30 15:58:46 -080010727 * Check whether the adapter supports an embedded copy of the
10728 * FCP CMD IU within the WQE for FCP_Ixxx commands. In order
10729 * to use this option, 128-byte WQEs must be used.
James Smartb5c53952016-03-31 14:12:30 -070010730 */
10731 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
10732 phba->fcp_embed_io = 1;
10733 else
10734 phba->fcp_embed_io = 0;
James Smart7bdedb32016-07-06 12:36:00 -070010735
James Smart0bc2b7c2018-02-22 08:18:48 -080010736 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
James Smart414abe02018-06-26 08:24:26 -070010737 "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n",
James Smart0bc2b7c2018-02-22 08:18:48 -080010738 bf_get(cfg_xib, mbx_sli4_parameters),
James Smart414abe02018-06-26 08:24:26 -070010739 phba->cfg_enable_pbde,
10740 phba->fcp_embed_io, phba->nvme_support,
James Smart4e565cf2018-02-22 08:18:50 -080010741 phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp);
James Smart0bc2b7c2018-02-22 08:18:48 -080010742
James Smartbf316c72018-04-09 14:24:28 -070010743 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
10744 LPFC_SLI_INTF_IF_TYPE_2) &&
10745 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
James Smartc2217682018-05-24 21:09:00 -070010746 LPFC_SLI_INTF_FAMILY_LNCR_A0))
James Smartbf316c72018-04-09 14:24:28 -070010747 exp_wqcq_pages = false;
10748
James Smartc176ffa2018-01-30 15:58:46 -080010749 if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) &&
10750 (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) &&
James Smartbf316c72018-04-09 14:24:28 -070010751 exp_wqcq_pages &&
James Smartc176ffa2018-01-30 15:58:46 -080010752 (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT))
10753 phba->enab_exp_wqcq_pages = 1;
10754 else
10755 phba->enab_exp_wqcq_pages = 0;
James Smart7bdedb32016-07-06 12:36:00 -070010756 /*
10757 * Check if the SLI port supports MDS Diagnostics
10758 */
10759 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
10760 phba->mds_diags_support = 1;
10761 else
10762 phba->mds_diags_support = 0;
James Smartfedd3b72011-02-16 12:39:24 -050010763 return 0;
10764}
10765
10766/**
James Smart3772a992009-05-22 14:50:54 -040010767 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
10768 * @pdev: pointer to PCI device
10769 * @pid: pointer to PCI device identifier
10770 *
10771 * This routine is to be called to attach a device with SLI-3 interface spec
10772 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10773 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10774 * information of the device and driver to see if the driver state that it can
10775 * support this kind of device. If the match is successful, the driver core
10776 * invokes this routine. If this routine determines it can claim the HBA, it
10777 * does all the initialization that it needs to do to handle the HBA properly.
10778 *
10779 * Return code
10780 * 0 - driver can claim the device
10781 * negative value - driver can not claim the device
10782 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010783static int
James Smart3772a992009-05-22 14:50:54 -040010784lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
10785{
10786 struct lpfc_hba *phba;
10787 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040010788 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -040010789 int error;
10790 uint32_t cfg_mode, intr_mode;
10791
10792 /* Allocate memory for HBA structure */
10793 phba = lpfc_hba_alloc(pdev);
10794 if (!phba)
10795 return -ENOMEM;
10796
10797 /* Perform generic PCI device enabling operation */
10798 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040010799 if (error)
James Smart3772a992009-05-22 14:50:54 -040010800 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -040010801
10802 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
10803 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
10804 if (error)
10805 goto out_disable_pci_dev;
10806
10807 /* Set up SLI-3 specific device PCI memory space */
10808 error = lpfc_sli_pci_mem_setup(phba);
10809 if (error) {
10810 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10811 "1402 Failed to set up pci memory space.\n");
10812 goto out_disable_pci_dev;
10813 }
10814
James Smart3772a992009-05-22 14:50:54 -040010815 /* Set up SLI-3 specific device driver resources */
10816 error = lpfc_sli_driver_resource_setup(phba);
10817 if (error) {
10818 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10819 "1404 Failed to set up driver resource.\n");
10820 goto out_unset_pci_mem_s3;
10821 }
10822
10823 /* Initialize and populate the iocb list per host */
James Smartd1f525a2017-04-21 16:04:55 -070010824
James Smart3772a992009-05-22 14:50:54 -040010825 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
10826 if (error) {
10827 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10828 "1405 Failed to initialize iocb list.\n");
10829 goto out_unset_driver_resource_s3;
10830 }
10831
10832 /* Set up common device driver resources */
10833 error = lpfc_setup_driver_resource_phase2(phba);
10834 if (error) {
10835 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10836 "1406 Failed to set up driver resource.\n");
10837 goto out_free_iocb_list;
10838 }
10839
James Smart079b5c92011-08-21 21:48:49 -040010840 /* Get the default values for Model Name and Description */
10841 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
10842
James Smart3772a992009-05-22 14:50:54 -040010843 /* Create SCSI host to the physical port */
10844 error = lpfc_create_shost(phba);
10845 if (error) {
10846 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10847 "1407 Failed to create scsi host.\n");
10848 goto out_unset_driver_resource;
10849 }
10850
10851 /* Configure sysfs attributes */
10852 vport = phba->pport;
10853 error = lpfc_alloc_sysfs_attr(vport);
10854 if (error) {
10855 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10856 "1476 Failed to allocate sysfs attr\n");
10857 goto out_destroy_shost;
10858 }
10859
James Smart6669f9b2009-10-02 15:16:45 -040010860 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -040010861 /* Now, trying to enable interrupt and bring up the device */
10862 cfg_mode = phba->cfg_use_msi;
10863 while (true) {
10864 /* Put device to a known state before enabling interrupt */
10865 lpfc_stop_port(phba);
10866 /* Configure and enable interrupt */
10867 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
10868 if (intr_mode == LPFC_INTR_ERROR) {
10869 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10870 "0431 Failed to enable interrupt.\n");
10871 error = -ENODEV;
10872 goto out_free_sysfs_attr;
10873 }
10874 /* SLI-3 HBA setup */
10875 if (lpfc_sli_hba_setup(phba)) {
10876 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10877 "1477 Failed to set up hba\n");
10878 error = -ENODEV;
10879 goto out_remove_device;
10880 }
10881
10882 /* Wait 50ms for the interrupts of previous mailbox commands */
10883 msleep(50);
10884 /* Check active interrupts on message signaled interrupts */
10885 if (intr_mode == 0 ||
10886 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
10887 /* Log the current active interrupt mode */
10888 phba->intr_mode = intr_mode;
10889 lpfc_log_intr_mode(phba, intr_mode);
10890 break;
10891 } else {
10892 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10893 "0447 Configure interrupt mode (%d) "
10894 "failed active interrupt test.\n",
10895 intr_mode);
10896 /* Disable the current interrupt mode */
10897 lpfc_sli_disable_intr(phba);
10898 /* Try next level of interrupt mode */
10899 cfg_mode = --intr_mode;
10900 }
10901 }
10902
10903 /* Perform post initialization setup */
10904 lpfc_post_init_setup(phba);
10905
10906 /* Check if there are static vports to be created. */
10907 lpfc_create_static_vport(phba);
10908
10909 return 0;
10910
10911out_remove_device:
10912 lpfc_unset_hba(phba);
10913out_free_sysfs_attr:
10914 lpfc_free_sysfs_attr(vport);
10915out_destroy_shost:
10916 lpfc_destroy_shost(phba);
10917out_unset_driver_resource:
10918 lpfc_unset_driver_resource_phase2(phba);
10919out_free_iocb_list:
10920 lpfc_free_iocb_list(phba);
10921out_unset_driver_resource_s3:
10922 lpfc_sli_driver_resource_unset(phba);
10923out_unset_pci_mem_s3:
10924 lpfc_sli_pci_mem_unset(phba);
10925out_disable_pci_dev:
10926 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040010927 if (shost)
10928 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -040010929out_free_phba:
10930 lpfc_hba_free(phba);
10931 return error;
10932}
10933
10934/**
10935 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -040010936 * @pdev: pointer to PCI device
10937 *
James Smart3772a992009-05-22 14:50:54 -040010938 * This routine is to be called to disattach a device with SLI-3 interface
10939 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10940 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10941 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -040010942 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010943static void
James Smart3772a992009-05-22 14:50:54 -040010944lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -050010945{
James Smart2e0fef82007-06-17 19:56:36 -050010946 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10947 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -050010948 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -050010949 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -050010950 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -050010951
James Smart549e55c2007-08-02 11:09:51 -040010952 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -040010953 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -040010954 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -050010955
James Smart858c9f62007-06-17 19:56:39 -050010956 lpfc_free_sysfs_attr(vport);
10957
James Smarteada2722008-12-04 22:39:13 -050010958 /* Release all the vports against this physical port */
10959 vports = lpfc_create_vport_work_array(phba);
10960 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040010961 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10962 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
10963 continue;
James Smarteada2722008-12-04 22:39:13 -050010964 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040010965 }
James Smarteada2722008-12-04 22:39:13 -050010966 lpfc_destroy_vport_work_array(phba, vports);
10967
10968 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -050010969 fc_remove_host(shost);
10970 scsi_remove_host(shost);
James Smartd613b6a2017-02-12 13:52:37 -080010971
James Smart87af33f2007-10-27 13:37:43 -040010972 lpfc_cleanup(vport);
10973
James Smart2e0fef82007-06-17 19:56:36 -050010974 /*
10975 * Bring down the SLI Layer. This step disable all interrupts,
10976 * clears the rings, discards all mailbox commands, and resets
10977 * the HBA.
10978 */
James Smarta257bf92009-04-06 18:48:10 -040010979
Justin P. Mattock48e34d02010-12-30 15:07:58 -080010980 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -050010981 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -040010982 /* Stop kthread signal shall trigger work_done one more time */
10983 kthread_stop(phba->worker_thread);
10984 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -050010985 lpfc_sli_brdrestart(phba);
10986
James Smart72859902012-01-18 16:25:38 -050010987 kfree(phba->vpi_bmask);
10988 kfree(phba->vpi_ids);
10989
James Smart3772a992009-05-22 14:50:54 -040010990 lpfc_stop_hba_timers(phba);
James Smart523128e2018-09-10 10:30:46 -070010991 spin_lock_irq(&phba->port_list_lock);
James Smart858c9f62007-06-17 19:56:39 -050010992 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -070010993 spin_unlock_irq(&phba->port_list_lock);
James Smart858c9f62007-06-17 19:56:39 -050010994
James Smart858c9f62007-06-17 19:56:39 -050010995 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -050010996
James Smart912e3ac2011-05-24 11:42:11 -040010997 /* Disable SR-IOV if enabled */
10998 if (phba->cfg_sriov_nr_virtfn)
10999 pci_disable_sriov(pdev);
11000
James Smart5b75da22008-12-04 22:39:35 -050011001 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -040011002 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -050011003
James Smart858c9f62007-06-17 19:56:39 -050011004 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -050011005
11006 /*
11007 * Call scsi_free before mem_free since scsi bufs are released to their
11008 * corresponding pools here.
11009 */
11010 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -040011011 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -050011012
James Smart34b02dc2008-08-24 21:49:55 -040011013 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
11014 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -050011015
James Smart2e0fef82007-06-17 19:56:36 -050011016 /* Free resources associated with SLI2 interface */
11017 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -040011018 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -050011019
11020 /* unmap adapter SLIM and Control Registers */
11021 iounmap(phba->ctrl_regs_memmap_p);
11022 iounmap(phba->slim_memmap_p);
11023
James Smart3772a992009-05-22 14:50:54 -040011024 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -050011025
Johannes Thumshirne0c04832016-06-07 09:44:03 +020011026 pci_release_mem_regions(pdev);
James Smart2e0fef82007-06-17 19:56:36 -050011027 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -050011028}
11029
Linas Vepstas8d63f372007-02-14 14:28:36 -060011030/**
James Smart3772a992009-05-22 14:50:54 -040011031 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050011032 * @pdev: pointer to PCI device
11033 * @msg: power management message
11034 *
James Smart3772a992009-05-22 14:50:54 -040011035 * This routine is to be called from the kernel's PCI subsystem to support
11036 * system Power Management (PM) to device with SLI-3 interface spec. When
11037 * PM invokes this method, it quiesces the device by stopping the driver's
11038 * worker thread for the device, turning off device's interrupt and DMA,
11039 * and bring the device offline. Note that as the driver implements the
11040 * minimum PM requirements to a power-aware driver's PM support for the
11041 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
11042 * to the suspend() method call will be treated as SUSPEND and the driver will
11043 * fully reinitialize its device during resume() method call, the driver will
11044 * set device to PCI_D3hot state in PCI config space instead of setting it
11045 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -050011046 *
11047 * Return code
James Smart3772a992009-05-22 14:50:54 -040011048 * 0 - driver suspended the device
11049 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050011050 **/
11051static int
James Smart3772a992009-05-22 14:50:54 -040011052lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -050011053{
11054 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11055 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11056
11057 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11058 "0473 PCI device Power Management suspend.\n");
11059
11060 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040011061 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -050011062 lpfc_offline(phba);
11063 kthread_stop(phba->worker_thread);
11064
11065 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -040011066 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -050011067
11068 /* Save device state to PCI config space */
11069 pci_save_state(pdev);
11070 pci_set_power_state(pdev, PCI_D3hot);
11071
11072 return 0;
11073}
11074
11075/**
James Smart3772a992009-05-22 14:50:54 -040011076 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050011077 * @pdev: pointer to PCI device
11078 *
James Smart3772a992009-05-22 14:50:54 -040011079 * This routine is to be called from the kernel's PCI subsystem to support
11080 * system Power Management (PM) to device with SLI-3 interface spec. When PM
11081 * invokes this method, it restores the device's PCI config space state and
11082 * fully reinitializes the device and brings it online. Note that as the
11083 * driver implements the minimum PM requirements to a power-aware driver's
11084 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
11085 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
11086 * driver will fully reinitialize its device during resume() method call,
11087 * the device will be set to PCI_D0 directly in PCI config space before
11088 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -050011089 *
11090 * Return code
James Smart3772a992009-05-22 14:50:54 -040011091 * 0 - driver suspended the device
11092 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050011093 **/
11094static int
James Smart3772a992009-05-22 14:50:54 -040011095lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -050011096{
11097 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11098 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -050011099 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050011100 int error;
11101
11102 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11103 "0452 PCI device Power Management resume.\n");
11104
11105 /* Restore device state from PCI config space */
11106 pci_set_power_state(pdev, PCI_D0);
11107 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -040011108
James Smart1dfb5a42010-02-12 14:40:50 -050011109 /*
11110 * As the new kernel behavior of pci_restore_state() API call clears
11111 * device saved_state flag, need to save the restored state again.
11112 */
11113 pci_save_state(pdev);
11114
James Smart3a55b532008-12-04 22:38:54 -050011115 if (pdev->is_busmaster)
11116 pci_set_master(pdev);
11117
11118 /* Startup the kernel thread for this host adapter. */
11119 phba->worker_thread = kthread_run(lpfc_do_work, phba,
11120 "lpfc_worker_%d", phba->brd_no);
11121 if (IS_ERR(phba->worker_thread)) {
11122 error = PTR_ERR(phba->worker_thread);
11123 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11124 "0434 PM resume failed to start worker "
11125 "thread: error=x%x.\n", error);
11126 return error;
11127 }
11128
James Smart5b75da22008-12-04 22:39:35 -050011129 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040011130 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050011131 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -050011132 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -050011133 "0430 PM resume Failed to enable interrupt\n");
11134 return -EIO;
11135 } else
11136 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050011137
11138 /* Restart HBA and bring it online */
11139 lpfc_sli_brdrestart(phba);
11140 lpfc_online(phba);
11141
James Smart5b75da22008-12-04 22:39:35 -050011142 /* Log the current active interrupt mode */
11143 lpfc_log_intr_mode(phba, phba->intr_mode);
11144
James Smart3a55b532008-12-04 22:38:54 -050011145 return 0;
11146}
11147
11148/**
James Smart891478a2009-11-18 15:40:23 -050011149 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
11150 * @phba: pointer to lpfc hba data structure.
11151 *
11152 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -040011153 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -050011154 **/
11155static void
11156lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
11157{
11158 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11159 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -040011160
11161 /*
11162 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
11163 * and let the SCSI mid-layer to retry them to recover.
11164 */
James Smartdb55fba2014-04-04 13:52:02 -040011165 lpfc_sli_abort_fcp_rings(phba);
James Smart891478a2009-11-18 15:40:23 -050011166}
11167
11168/**
James Smart0d878412009-10-02 15:16:56 -040011169 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
11170 * @phba: pointer to lpfc hba data structure.
11171 *
11172 * This routine is called to prepare the SLI3 device for PCI slot reset. It
11173 * disables the device interrupt and pci device, and aborts the internal FCP
11174 * pending I/Os.
11175 **/
11176static void
11177lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
11178{
James Smart0d878412009-10-02 15:16:56 -040011179 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050011180 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -040011181
James Smart75baf692010-06-08 18:31:21 -040011182 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040011183 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040011184
James Smarte2af0d22010-03-15 11:25:32 -040011185 /* Block all SCSI devices' I/Os on the host */
11186 lpfc_scsi_dev_block(phba);
11187
James Smartea714f32013-04-17 20:18:47 -040011188 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
11189 lpfc_sli_flush_fcp_rings(phba);
11190
James Smarte2af0d22010-03-15 11:25:32 -040011191 /* stop all timers */
11192 lpfc_stop_hba_timers(phba);
11193
James Smart0d878412009-10-02 15:16:56 -040011194 /* Disable interrupt and pci device */
11195 lpfc_sli_disable_intr(phba);
11196 pci_disable_device(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -040011197}
11198
11199/**
11200 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
11201 * @phba: pointer to lpfc hba data structure.
11202 *
11203 * This routine is called to prepare the SLI3 device for PCI slot permanently
11204 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
11205 * pending I/Os.
11206 **/
11207static void
James Smart75baf692010-06-08 18:31:21 -040011208lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -040011209{
11210 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050011211 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -040011212 /* Block all SCSI devices' I/Os on the host */
11213 lpfc_scsi_dev_block(phba);
11214
11215 /* stop all timers */
11216 lpfc_stop_hba_timers(phba);
11217
James Smart0d878412009-10-02 15:16:56 -040011218 /* Clean up all driver's outstanding SCSI I/Os */
11219 lpfc_sli_flush_fcp_rings(phba);
11220}
11221
11222/**
James Smart3772a992009-05-22 14:50:54 -040011223 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -040011224 * @pdev: pointer to PCI device.
11225 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -060011226 *
James Smart3772a992009-05-22 14:50:54 -040011227 * This routine is called from the PCI subsystem for I/O error handling to
11228 * device with SLI-3 interface spec. This function is called by the PCI
11229 * subsystem after a PCI bus error affecting this device has been detected.
11230 * When this function is invoked, it will need to stop all the I/Os and
11231 * interrupt(s) to the device. Once that is done, it will return
11232 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
11233 * as desired.
James Smarte59058c2008-08-24 21:49:00 -040011234 *
11235 * Return codes
James Smart0d878412009-10-02 15:16:56 -040011236 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -040011237 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11238 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -040011239 **/
James Smart3772a992009-05-22 14:50:54 -040011240static pci_ers_result_t
11241lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -060011242{
James Smart51ef4c22007-08-02 11:10:31 -040011243 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11244 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011245
James Smart0d878412009-10-02 15:16:56 -040011246 switch (state) {
11247 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -050011248 /* Non-fatal error, prepare for recovery */
11249 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -040011250 return PCI_ERS_RESULT_CAN_RECOVER;
11251 case pci_channel_io_frozen:
11252 /* Fatal error, prepare for slot reset */
11253 lpfc_sli_prep_dev_for_reset(phba);
11254 return PCI_ERS_RESULT_NEED_RESET;
11255 case pci_channel_io_perm_failure:
11256 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -040011257 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011258 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -040011259 default:
11260 /* Unknown state, prepare and request slot reset */
11261 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11262 "0472 Unknown PCI error state: x%x\n", state);
11263 lpfc_sli_prep_dev_for_reset(phba);
11264 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -040011265 }
Linas Vepstas8d63f372007-02-14 14:28:36 -060011266}
11267
11268/**
James Smart3772a992009-05-22 14:50:54 -040011269 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -040011270 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -060011271 *
James Smart3772a992009-05-22 14:50:54 -040011272 * This routine is called from the PCI subsystem for error handling to
11273 * device with SLI-3 interface spec. This is called after PCI bus has been
11274 * reset to restart the PCI card from scratch, as if from a cold-boot.
11275 * During the PCI subsystem error recovery, after driver returns
11276 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
11277 * recovery and then call this routine before calling the .resume method
11278 * to recover the device. This function will initialize the HBA device,
11279 * enable the interrupt, but it will just put the HBA to offline state
11280 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -040011281 *
11282 * Return codes
James Smart3772a992009-05-22 14:50:54 -040011283 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11284 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -060011285 */
James Smart3772a992009-05-22 14:50:54 -040011286static pci_ers_result_t
11287lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060011288{
James Smart51ef4c22007-08-02 11:10:31 -040011289 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11290 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011291 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -050011292 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011293
11294 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +110011295 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -060011296 printk(KERN_ERR "lpfc: Cannot re-enable "
11297 "PCI device after reset.\n");
11298 return PCI_ERS_RESULT_DISCONNECT;
11299 }
11300
James Smart97207482008-12-04 22:39:19 -050011301 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050011302
11303 /*
11304 * As the new kernel behavior of pci_restore_state() API call clears
11305 * device saved_state flag, need to save the restored state again.
11306 */
11307 pci_save_state(pdev);
11308
James Smart97207482008-12-04 22:39:19 -050011309 if (pdev->is_busmaster)
11310 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011311
James Smart92d7f7b2007-06-17 19:56:38 -050011312 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040011313 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -050011314 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011315
James Smart5b75da22008-12-04 22:39:35 -050011316 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040011317 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050011318 if (intr_mode == LPFC_INTR_ERROR) {
11319 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11320 "0427 Cannot re-enable interrupt after "
11321 "slot reset.\n");
11322 return PCI_ERS_RESULT_DISCONNECT;
11323 } else
11324 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011325
James Smart75baf692010-06-08 18:31:21 -040011326 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -040011327 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011328 lpfc_offline(phba);
11329 lpfc_sli_brdrestart(phba);
11330
James Smart5b75da22008-12-04 22:39:35 -050011331 /* Log the current active interrupt mode */
11332 lpfc_log_intr_mode(phba, phba->intr_mode);
11333
Linas Vepstas8d63f372007-02-14 14:28:36 -060011334 return PCI_ERS_RESULT_RECOVERED;
11335}
11336
11337/**
James Smart3772a992009-05-22 14:50:54 -040011338 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -040011339 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -060011340 *
James Smart3772a992009-05-22 14:50:54 -040011341 * This routine is called from the PCI subsystem for error handling to device
11342 * with SLI-3 interface spec. It is called when kernel error recovery tells
11343 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
11344 * error recovery. After this call, traffic can start to flow from this device
11345 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -060011346 */
James Smart3772a992009-05-22 14:50:54 -040011347static void
11348lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060011349{
James Smart51ef4c22007-08-02 11:10:31 -040011350 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11351 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011352
James Smarte2af0d22010-03-15 11:25:32 -040011353 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -040011354 lpfc_online(phba);
James Smart0d878412009-10-02 15:16:56 -040011355
11356 /* Clean up Advanced Error Reporting (AER) if needed */
11357 if (phba->hba_flag & HBA_AER_ENABLED)
11358 pci_cleanup_aer_uncorrect_error_status(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011359}
11360
James Smart3772a992009-05-22 14:50:54 -040011361/**
James Smartda0436e2009-05-22 14:51:39 -040011362 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
11363 * @phba: pointer to lpfc hba data structure.
11364 *
11365 * returns the number of ELS/CT IOCBs to reserve
11366 **/
11367int
11368lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
11369{
11370 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
11371
James Smartf1126682009-06-10 17:22:44 -040011372 if (phba->sli_rev == LPFC_SLI_REV4) {
11373 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -040011374 return 10;
James Smartf1126682009-06-10 17:22:44 -040011375 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -040011376 return 25;
James Smartf1126682009-06-10 17:22:44 -040011377 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -040011378 return 50;
James Smartf1126682009-06-10 17:22:44 -040011379 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -040011380 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -040011381 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -040011382 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -040011383 else if (max_xri <= 2048)
11384 return 200;
11385 else
11386 return 250;
James Smartf1126682009-06-10 17:22:44 -040011387 } else
11388 return 0;
James Smartda0436e2009-05-22 14:51:39 -040011389}
11390
11391/**
James Smart895427b2017-02-12 13:52:30 -080011392 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
11393 * @phba: pointer to lpfc hba data structure.
11394 *
James Smartf358dd02017-02-12 13:52:34 -080011395 * returns the number of ELS/CT + NVMET IOCBs to reserve
James Smart895427b2017-02-12 13:52:30 -080011396 **/
11397int
11398lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
11399{
11400 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
11401
James Smartf358dd02017-02-12 13:52:34 -080011402 if (phba->nvmet_support)
11403 max_xri += LPFC_NVMET_BUF_POST;
James Smart895427b2017-02-12 13:52:30 -080011404 return max_xri;
11405}
11406
11407
James Smart1feb8202018-02-22 08:18:47 -080011408static void
11409lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset,
11410 uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize,
11411 const struct firmware *fw)
11412{
James Smarta72d56b2018-05-04 20:37:52 -070011413 if ((offset == ADD_STATUS_FW_NOT_SUPPORTED) ||
11414 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
11415 magic_number != MAGIC_NUMER_G6) ||
11416 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC &&
11417 magic_number != MAGIC_NUMER_G7))
James Smart1feb8202018-02-22 08:18:47 -080011418 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11419 "3030 This firmware version is not supported on "
11420 "this HBA model. Device:%x Magic:%x Type:%x "
11421 "ID:%x Size %d %zd\n",
11422 phba->pcidev->device, magic_number, ftype, fid,
11423 fsize, fw->size);
11424 else
11425 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11426 "3022 FW Download failed. Device:%x Magic:%x Type:%x "
11427 "ID:%x Size %d %zd\n",
11428 phba->pcidev->device, magic_number, ftype, fid,
11429 fsize, fw->size);
11430}
11431
11432
James Smart895427b2017-02-12 13:52:30 -080011433/**
James Smart52d52442011-05-24 11:42:45 -040011434 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -040011435 * @fw: pointer to firmware image returned from request_firmware.
James Smartce396282012-09-29 11:30:56 -040011436 * @phba: pointer to lpfc hba data structure.
James Smart52d52442011-05-24 11:42:45 -040011437 *
James Smart52d52442011-05-24 11:42:45 -040011438 **/
James Smartce396282012-09-29 11:30:56 -040011439static void
11440lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -040011441{
James Smartce396282012-09-29 11:30:56 -040011442 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -050011443 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -040011444 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -040011445 struct list_head dma_buffer_list;
11446 int i, rc = 0;
11447 struct lpfc_dmabuf *dmabuf, *next;
11448 uint32_t offset = 0, temp_offset = 0;
James Smart6b6ef5d2016-10-13 15:06:17 -070011449 uint32_t magic_number, ftype, fid, fsize;
James Smart52d52442011-05-24 11:42:45 -040011450
James Smartc71ab862012-10-31 14:44:33 -040011451 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -040011452 if (!fw) {
11453 rc = -ENXIO;
11454 goto out;
11455 }
11456 image = (struct lpfc_grp_hdr *)fw->data;
11457
James Smart6b6ef5d2016-10-13 15:06:17 -070011458 magic_number = be32_to_cpu(image->magic_number);
11459 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
James Smart1feb8202018-02-22 08:18:47 -080011460 fid = bf_get_be32(lpfc_grp_hdr_id, image);
James Smart6b6ef5d2016-10-13 15:06:17 -070011461 fsize = be32_to_cpu(image->size);
11462
James Smart52d52442011-05-24 11:42:45 -040011463 INIT_LIST_HEAD(&dma_buffer_list);
James Smart52d52442011-05-24 11:42:45 -040011464 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -040011465 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -040011466 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartce396282012-09-29 11:30:56 -040011467 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -040011468 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -040011469 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -040011470 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
11471 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
11472 GFP_KERNEL);
11473 if (!dmabuf) {
11474 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040011475 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040011476 }
11477 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
11478 SLI4_PAGE_SIZE,
11479 &dmabuf->phys,
11480 GFP_KERNEL);
11481 if (!dmabuf->virt) {
11482 kfree(dmabuf);
11483 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040011484 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040011485 }
11486 list_add_tail(&dmabuf->list, &dma_buffer_list);
11487 }
11488 while (offset < fw->size) {
11489 temp_offset = offset;
11490 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -040011491 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -040011492 memcpy(dmabuf->virt,
11493 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -040011494 fw->size - temp_offset);
11495 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -040011496 break;
11497 }
James Smart52d52442011-05-24 11:42:45 -040011498 memcpy(dmabuf->virt, fw->data + temp_offset,
11499 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -040011500 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -040011501 }
11502 rc = lpfc_wr_object(phba, &dma_buffer_list,
11503 (fw->size - offset), &offset);
James Smart1feb8202018-02-22 08:18:47 -080011504 if (rc) {
11505 lpfc_log_write_firmware_error(phba, offset,
11506 magic_number, ftype, fid, fsize, fw);
James Smartce396282012-09-29 11:30:56 -040011507 goto release_out;
James Smart1feb8202018-02-22 08:18:47 -080011508 }
James Smart52d52442011-05-24 11:42:45 -040011509 }
11510 rc = offset;
James Smart1feb8202018-02-22 08:18:47 -080011511 } else
11512 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11513 "3029 Skipped Firmware update, Current "
11514 "Version:%s New Version:%s\n",
11515 fwrev, image->revision);
James Smartce396282012-09-29 11:30:56 -040011516
11517release_out:
James Smart52d52442011-05-24 11:42:45 -040011518 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
11519 list_del(&dmabuf->list);
11520 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
11521 dmabuf->virt, dmabuf->phys);
11522 kfree(dmabuf);
11523 }
James Smartce396282012-09-29 11:30:56 -040011524 release_firmware(fw);
11525out:
11526 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc71ab862012-10-31 14:44:33 -040011527 "3024 Firmware update done: %d.\n", rc);
James Smartce396282012-09-29 11:30:56 -040011528 return;
James Smart52d52442011-05-24 11:42:45 -040011529}
11530
11531/**
James Smartc71ab862012-10-31 14:44:33 -040011532 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
11533 * @phba: pointer to lpfc hba data structure.
11534 *
11535 * This routine is called to perform Linux generic firmware upgrade on device
11536 * that supports such feature.
11537 **/
11538int
11539lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
11540{
11541 uint8_t file_name[ELX_MODEL_NAME_SIZE];
11542 int ret;
11543 const struct firmware *fw;
11544
11545 /* Only supported on SLI4 interface type 2 for now */
James Smart27d6ac02018-02-22 08:18:42 -080011546 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smartc71ab862012-10-31 14:44:33 -040011547 LPFC_SLI_INTF_IF_TYPE_2)
11548 return -EPERM;
11549
11550 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
11551
11552 if (fw_upgrade == INT_FW_UPGRADE) {
11553 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
11554 file_name, &phba->pcidev->dev,
11555 GFP_KERNEL, (void *)phba,
11556 lpfc_write_firmware);
11557 } else if (fw_upgrade == RUN_FW_UPGRADE) {
11558 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
11559 if (!ret)
11560 lpfc_write_firmware(fw, (void *)phba);
11561 } else {
11562 ret = -EINVAL;
11563 }
11564
11565 return ret;
11566}
11567
11568/**
James Smartda0436e2009-05-22 14:51:39 -040011569 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
11570 * @pdev: pointer to PCI device
11571 * @pid: pointer to PCI device identifier
11572 *
11573 * This routine is called from the kernel's PCI subsystem to device with
11574 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11575 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
11576 * information of the device and driver to see if the driver state that it
11577 * can support this kind of device. If the match is successful, the driver
11578 * core invokes this routine. If this routine determines it can claim the HBA,
11579 * it does all the initialization that it needs to do to handle the HBA
11580 * properly.
11581 *
11582 * Return code
11583 * 0 - driver can claim the device
11584 * negative value - driver can not claim the device
11585 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011586static int
James Smartda0436e2009-05-22 14:51:39 -040011587lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
11588{
11589 struct lpfc_hba *phba;
11590 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040011591 struct Scsi_Host *shost = NULL;
James Smart6c621a22017-05-15 15:20:45 -070011592 int error;
James Smartda0436e2009-05-22 14:51:39 -040011593 uint32_t cfg_mode, intr_mode;
James Smartda0436e2009-05-22 14:51:39 -040011594
11595 /* Allocate memory for HBA structure */
11596 phba = lpfc_hba_alloc(pdev);
11597 if (!phba)
11598 return -ENOMEM;
11599
11600 /* Perform generic PCI device enabling operation */
11601 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040011602 if (error)
James Smartda0436e2009-05-22 14:51:39 -040011603 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -040011604
11605 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
11606 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
11607 if (error)
11608 goto out_disable_pci_dev;
11609
11610 /* Set up SLI-4 specific device PCI memory space */
11611 error = lpfc_sli4_pci_mem_setup(phba);
11612 if (error) {
11613 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11614 "1410 Failed to set up pci memory space.\n");
11615 goto out_disable_pci_dev;
11616 }
11617
James Smartda0436e2009-05-22 14:51:39 -040011618 /* Set up SLI-4 Specific device driver resources */
11619 error = lpfc_sli4_driver_resource_setup(phba);
11620 if (error) {
11621 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11622 "1412 Failed to set up driver resource.\n");
11623 goto out_unset_pci_mem_s4;
11624 }
11625
James Smart19ca7602010-11-20 23:11:55 -050011626 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -040011627 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -050011628
James Smartda0436e2009-05-22 14:51:39 -040011629 /* Set up common device driver resources */
11630 error = lpfc_setup_driver_resource_phase2(phba);
11631 if (error) {
11632 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11633 "1414 Failed to set up driver resource.\n");
James Smart6c621a22017-05-15 15:20:45 -070011634 goto out_unset_driver_resource_s4;
James Smartda0436e2009-05-22 14:51:39 -040011635 }
11636
James Smart079b5c92011-08-21 21:48:49 -040011637 /* Get the default values for Model Name and Description */
11638 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
11639
James Smartda0436e2009-05-22 14:51:39 -040011640 /* Create SCSI host to the physical port */
11641 error = lpfc_create_shost(phba);
11642 if (error) {
11643 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11644 "1415 Failed to create scsi host.\n");
11645 goto out_unset_driver_resource;
11646 }
11647
11648 /* Configure sysfs attributes */
11649 vport = phba->pport;
11650 error = lpfc_alloc_sysfs_attr(vport);
11651 if (error) {
11652 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11653 "1416 Failed to allocate sysfs attr\n");
11654 goto out_destroy_shost;
11655 }
11656
James Smart6669f9b2009-10-02 15:16:45 -040011657 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -040011658 /* Now, trying to enable interrupt and bring up the device */
11659 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -040011660
James Smart7b15db32013-01-03 15:43:29 -050011661 /* Put device to a known state before enabling interrupt */
11662 lpfc_stop_port(phba);
James Smart895427b2017-02-12 13:52:30 -080011663
James Smart7b15db32013-01-03 15:43:29 -050011664 /* Configure and enable interrupt */
11665 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
11666 if (intr_mode == LPFC_INTR_ERROR) {
11667 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11668 "0426 Failed to enable interrupt.\n");
11669 error = -ENODEV;
11670 goto out_free_sysfs_attr;
James Smartda0436e2009-05-22 14:51:39 -040011671 }
James Smart7b15db32013-01-03 15:43:29 -050011672 /* Default to single EQ for non-MSI-X */
James Smart895427b2017-02-12 13:52:30 -080011673 if (phba->intr_type != MSIX) {
11674 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
11675 phba->cfg_fcp_io_channel = 1;
James Smart2d7dbc42017-02-12 13:52:35 -080011676 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -080011677 phba->cfg_nvme_io_channel = 1;
James Smart2d7dbc42017-02-12 13:52:35 -080011678 if (phba->nvmet_support)
11679 phba->cfg_nvmet_mrq = 1;
11680 }
James Smart895427b2017-02-12 13:52:30 -080011681 phba->io_channel_irqs = 1;
11682 }
11683
James Smart7b15db32013-01-03 15:43:29 -050011684 /* Set up SLI-4 HBA */
11685 if (lpfc_sli4_hba_setup(phba)) {
11686 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11687 "1421 Failed to set up hba\n");
11688 error = -ENODEV;
11689 goto out_disable_intr;
11690 }
11691
11692 /* Log the current active interrupt mode */
11693 phba->intr_mode = intr_mode;
11694 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -040011695
11696 /* Perform post initialization setup */
11697 lpfc_post_init_setup(phba);
11698
James Smart01649562017-02-12 13:52:32 -080011699 /* NVME support in FW earlier in the driver load corrects the
11700 * FC4 type making a check for nvme_support unnecessary.
11701 */
11702 if ((phba->nvmet_support == 0) &&
11703 (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
11704 /* Create NVME binding with nvme_fc_transport. This
James Smartd1f525a2017-04-21 16:04:55 -070011705 * ensures the vport is initialized. If the localport
11706 * create fails, it should not unload the driver to
11707 * support field issues.
James Smart01649562017-02-12 13:52:32 -080011708 */
11709 error = lpfc_nvme_create_localport(vport);
11710 if (error) {
11711 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11712 "6004 NVME registration failed, "
11713 "error x%x\n",
11714 error);
James Smart01649562017-02-12 13:52:32 -080011715 }
11716 }
James Smart895427b2017-02-12 13:52:30 -080011717
James Smartc71ab862012-10-31 14:44:33 -040011718 /* check for firmware upgrade or downgrade */
11719 if (phba->cfg_request_firmware_upgrade)
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040011720 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -040011721
James Smart1c6834a2009-07-19 10:01:26 -040011722 /* Check if there are static vports to be created. */
11723 lpfc_create_static_vport(phba);
James Smartda0436e2009-05-22 14:51:39 -040011724 return 0;
11725
11726out_disable_intr:
11727 lpfc_sli4_disable_intr(phba);
11728out_free_sysfs_attr:
11729 lpfc_free_sysfs_attr(vport);
11730out_destroy_shost:
11731 lpfc_destroy_shost(phba);
11732out_unset_driver_resource:
11733 lpfc_unset_driver_resource_phase2(phba);
James Smartda0436e2009-05-22 14:51:39 -040011734out_unset_driver_resource_s4:
11735 lpfc_sli4_driver_resource_unset(phba);
11736out_unset_pci_mem_s4:
11737 lpfc_sli4_pci_mem_unset(phba);
11738out_disable_pci_dev:
11739 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040011740 if (shost)
11741 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -040011742out_free_phba:
11743 lpfc_hba_free(phba);
11744 return error;
11745}
11746
11747/**
11748 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
11749 * @pdev: pointer to PCI device
11750 *
11751 * This routine is called from the kernel's PCI subsystem to device with
11752 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11753 * removed from PCI bus, it performs all the necessary cleanup for the HBA
11754 * device to be removed from the PCI subsystem properly.
11755 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011756static void
James Smartda0436e2009-05-22 14:51:39 -040011757lpfc_pci_remove_one_s4(struct pci_dev *pdev)
11758{
11759 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11760 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
11761 struct lpfc_vport **vports;
11762 struct lpfc_hba *phba = vport->phba;
11763 int i;
11764
11765 /* Mark the device unloading flag */
11766 spin_lock_irq(&phba->hbalock);
11767 vport->load_flag |= FC_UNLOADING;
11768 spin_unlock_irq(&phba->hbalock);
11769
11770 /* Free the HBA sysfs attributes */
11771 lpfc_free_sysfs_attr(vport);
11772
11773 /* Release all the vports against this physical port */
11774 vports = lpfc_create_vport_work_array(phba);
11775 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040011776 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
11777 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
11778 continue;
James Smartda0436e2009-05-22 14:51:39 -040011779 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040011780 }
James Smartda0436e2009-05-22 14:51:39 -040011781 lpfc_destroy_vport_work_array(phba, vports);
11782
11783 /* Remove FC host and then SCSI host with the physical port */
11784 fc_remove_host(shost);
11785 scsi_remove_host(shost);
James Smartda0436e2009-05-22 14:51:39 -040011786
James Smartda0436e2009-05-22 14:51:39 -040011787 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
11788 * localports are destroyed after to cleanup all transport memory.
11789 */
11790 lpfc_cleanup(vport);
11791 lpfc_nvmet_destroy_targetport(phba);
11792 lpfc_nvme_destroy_localport(vport);
11793
James Smart281d6192018-01-30 15:58:47 -080011794 /*
11795 * Bring down the SLI Layer. This step disables all interrupts,
11796 * clears the rings, discards all mailbox commands, and resets
11797 * the HBA FCoE function.
11798 */
11799 lpfc_debugfs_terminate(vport);
11800 lpfc_sli4_hba_unset(phba);
James Smartda0436e2009-05-22 14:51:39 -040011801
Dick Kennedy19017622017-09-29 17:34:27 -070011802 lpfc_stop_hba_timers(phba);
James Smart523128e2018-09-10 10:30:46 -070011803 spin_lock_irq(&phba->port_list_lock);
James Smartda0436e2009-05-22 14:51:39 -040011804 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -070011805 spin_unlock_irq(&phba->port_list_lock);
James Smartda0436e2009-05-22 14:51:39 -040011806
James Smart3677a3a2010-09-29 11:19:14 -040011807 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -040011808 * buffers are released to their corresponding pools here.
11809 */
11810 lpfc_scsi_free(phba);
James Smart895427b2017-02-12 13:52:30 -080011811 lpfc_nvme_free(phba);
James Smart01649562017-02-12 13:52:32 -080011812 lpfc_free_iocb_list(phba);
James Smart67d12732012-08-03 12:36:13 -040011813
James Smart0cdb84e2018-04-09 14:24:26 -070011814 lpfc_unset_driver_resource_phase2(phba);
James Smartda0436e2009-05-22 14:51:39 -040011815 lpfc_sli4_driver_resource_unset(phba);
11816
11817 /* Unmap adapter Control and Doorbell registers */
11818 lpfc_sli4_pci_mem_unset(phba);
11819
11820 /* Release PCI resources and disable device's PCI function */
11821 scsi_host_put(shost);
11822 lpfc_disable_pci_dev(phba);
11823
11824 /* Finally, free the driver's device data structure */
11825 lpfc_hba_free(phba);
11826
11827 return;
11828}
11829
11830/**
11831 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
11832 * @pdev: pointer to PCI device
11833 * @msg: power management message
11834 *
11835 * This routine is called from the kernel's PCI subsystem to support system
11836 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
11837 * this method, it quiesces the device by stopping the driver's worker
11838 * thread for the device, turning off device's interrupt and DMA, and bring
11839 * the device offline. Note that as the driver implements the minimum PM
11840 * requirements to a power-aware driver's PM support for suspend/resume -- all
11841 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
11842 * method call will be treated as SUSPEND and the driver will fully
11843 * reinitialize its device during resume() method call, the driver will set
11844 * device to PCI_D3hot state in PCI config space instead of setting it
11845 * according to the @msg provided by the PM.
11846 *
11847 * Return code
11848 * 0 - driver suspended the device
11849 * Error otherwise
11850 **/
11851static int
11852lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
11853{
11854 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11855 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11856
11857 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -040011858 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -040011859
11860 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040011861 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -040011862 lpfc_offline(phba);
11863 kthread_stop(phba->worker_thread);
11864
11865 /* Disable interrupt from device */
11866 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040011867 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040011868
11869 /* Save device state to PCI config space */
11870 pci_save_state(pdev);
11871 pci_set_power_state(pdev, PCI_D3hot);
11872
11873 return 0;
11874}
11875
11876/**
11877 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
11878 * @pdev: pointer to PCI device
11879 *
11880 * This routine is called from the kernel's PCI subsystem to support system
11881 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
11882 * this method, it restores the device's PCI config space state and fully
11883 * reinitializes the device and brings it online. Note that as the driver
11884 * implements the minimum PM requirements to a power-aware driver's PM for
11885 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
11886 * to the suspend() method call will be treated as SUSPEND and the driver
11887 * will fully reinitialize its device during resume() method call, the device
11888 * will be set to PCI_D0 directly in PCI config space before restoring the
11889 * state.
11890 *
11891 * Return code
11892 * 0 - driver suspended the device
11893 * Error otherwise
11894 **/
11895static int
11896lpfc_pci_resume_one_s4(struct pci_dev *pdev)
11897{
11898 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11899 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11900 uint32_t intr_mode;
11901 int error;
11902
11903 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11904 "0292 PCI device Power Management resume.\n");
11905
11906 /* Restore device state from PCI config space */
11907 pci_set_power_state(pdev, PCI_D0);
11908 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050011909
11910 /*
11911 * As the new kernel behavior of pci_restore_state() API call clears
11912 * device saved_state flag, need to save the restored state again.
11913 */
11914 pci_save_state(pdev);
11915
James Smartda0436e2009-05-22 14:51:39 -040011916 if (pdev->is_busmaster)
11917 pci_set_master(pdev);
11918
11919 /* Startup the kernel thread for this host adapter. */
11920 phba->worker_thread = kthread_run(lpfc_do_work, phba,
11921 "lpfc_worker_%d", phba->brd_no);
11922 if (IS_ERR(phba->worker_thread)) {
11923 error = PTR_ERR(phba->worker_thread);
11924 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11925 "0293 PM resume failed to start worker "
11926 "thread: error=x%x.\n", error);
11927 return error;
11928 }
11929
11930 /* Configure and enable interrupt */
11931 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
11932 if (intr_mode == LPFC_INTR_ERROR) {
11933 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11934 "0294 PM resume Failed to enable interrupt\n");
11935 return -EIO;
11936 } else
11937 phba->intr_mode = intr_mode;
11938
11939 /* Restart HBA and bring it online */
11940 lpfc_sli_brdrestart(phba);
11941 lpfc_online(phba);
11942
11943 /* Log the current active interrupt mode */
11944 lpfc_log_intr_mode(phba, phba->intr_mode);
11945
11946 return 0;
11947}
11948
11949/**
James Smart75baf692010-06-08 18:31:21 -040011950 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
11951 * @phba: pointer to lpfc hba data structure.
11952 *
11953 * This routine is called to prepare the SLI4 device for PCI slot recover. It
11954 * aborts all the outstanding SCSI I/Os to the pci device.
11955 **/
11956static void
11957lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
11958{
James Smart75baf692010-06-08 18:31:21 -040011959 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11960 "2828 PCI channel I/O abort preparing for recovery\n");
11961 /*
11962 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
11963 * and let the SCSI mid-layer to retry them to recover.
11964 */
James Smartdb55fba2014-04-04 13:52:02 -040011965 lpfc_sli_abort_fcp_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040011966}
11967
11968/**
11969 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
11970 * @phba: pointer to lpfc hba data structure.
11971 *
11972 * This routine is called to prepare the SLI4 device for PCI slot reset. It
11973 * disables the device interrupt and pci device, and aborts the internal FCP
11974 * pending I/Os.
11975 **/
11976static void
11977lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
11978{
11979 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11980 "2826 PCI channel disable preparing for reset\n");
11981
11982 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040011983 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -040011984
11985 /* Block all SCSI devices' I/Os on the host */
11986 lpfc_scsi_dev_block(phba);
11987
James Smartea714f32013-04-17 20:18:47 -040011988 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
11989 lpfc_sli_flush_fcp_rings(phba);
11990
James Smartc3725bd2017-11-20 16:00:42 -080011991 /* Flush the outstanding NVME IOs if fc4 type enabled. */
11992 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
11993 lpfc_sli_flush_nvme_rings(phba);
11994
James Smart75baf692010-06-08 18:31:21 -040011995 /* stop all timers */
11996 lpfc_stop_hba_timers(phba);
11997
11998 /* Disable interrupt and pci device */
11999 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040012000 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -040012001 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -040012002}
12003
12004/**
12005 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
12006 * @phba: pointer to lpfc hba data structure.
12007 *
12008 * This routine is called to prepare the SLI4 device for PCI slot permanently
12009 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
12010 * pending I/Os.
12011 **/
12012static void
12013lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
12014{
12015 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12016 "2827 PCI channel permanent disable for failure\n");
12017
12018 /* Block all SCSI devices' I/Os on the host */
12019 lpfc_scsi_dev_block(phba);
12020
12021 /* stop all timers */
12022 lpfc_stop_hba_timers(phba);
12023
12024 /* Clean up all driver's outstanding SCSI I/Os */
12025 lpfc_sli_flush_fcp_rings(phba);
James Smartc3725bd2017-11-20 16:00:42 -080012026
12027 /* Flush the outstanding NVME IOs if fc4 type enabled. */
12028 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
12029 lpfc_sli_flush_nvme_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040012030}
12031
12032/**
James Smartda0436e2009-05-22 14:51:39 -040012033 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
12034 * @pdev: pointer to PCI device.
12035 * @state: the current PCI connection state.
12036 *
12037 * This routine is called from the PCI subsystem for error handling to device
12038 * with SLI-4 interface spec. This function is called by the PCI subsystem
12039 * after a PCI bus error affecting this device has been detected. When this
12040 * function is invoked, it will need to stop all the I/Os and interrupt(s)
12041 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
12042 * for the PCI subsystem to perform proper recovery as desired.
12043 *
12044 * Return codes
12045 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
12046 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12047 **/
12048static pci_ers_result_t
12049lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
12050{
James Smart75baf692010-06-08 18:31:21 -040012051 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12052 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12053
12054 switch (state) {
12055 case pci_channel_io_normal:
12056 /* Non-fatal error, prepare for recovery */
12057 lpfc_sli4_prep_dev_for_recover(phba);
12058 return PCI_ERS_RESULT_CAN_RECOVER;
12059 case pci_channel_io_frozen:
12060 /* Fatal error, prepare for slot reset */
12061 lpfc_sli4_prep_dev_for_reset(phba);
12062 return PCI_ERS_RESULT_NEED_RESET;
12063 case pci_channel_io_perm_failure:
12064 /* Permanent failure, prepare for device down */
12065 lpfc_sli4_prep_dev_for_perm_failure(phba);
12066 return PCI_ERS_RESULT_DISCONNECT;
12067 default:
12068 /* Unknown state, prepare and request slot reset */
12069 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12070 "2825 Unknown PCI error state: x%x\n", state);
12071 lpfc_sli4_prep_dev_for_reset(phba);
12072 return PCI_ERS_RESULT_NEED_RESET;
12073 }
James Smartda0436e2009-05-22 14:51:39 -040012074}
12075
12076/**
12077 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
12078 * @pdev: pointer to PCI device.
12079 *
12080 * This routine is called from the PCI subsystem for error handling to device
12081 * with SLI-4 interface spec. It is called after PCI bus has been reset to
12082 * restart the PCI card from scratch, as if from a cold-boot. During the
12083 * PCI subsystem error recovery, after the driver returns
12084 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
12085 * recovery and then call this routine before calling the .resume method to
12086 * recover the device. This function will initialize the HBA device, enable
12087 * the interrupt, but it will just put the HBA to offline state without
12088 * passing any I/O traffic.
12089 *
12090 * Return codes
12091 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
12092 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12093 */
12094static pci_ers_result_t
12095lpfc_io_slot_reset_s4(struct pci_dev *pdev)
12096{
James Smart75baf692010-06-08 18:31:21 -040012097 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12098 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12099 struct lpfc_sli *psli = &phba->sli;
12100 uint32_t intr_mode;
12101
12102 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
12103 if (pci_enable_device_mem(pdev)) {
12104 printk(KERN_ERR "lpfc: Cannot re-enable "
12105 "PCI device after reset.\n");
12106 return PCI_ERS_RESULT_DISCONNECT;
12107 }
12108
12109 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040012110
12111 /*
12112 * As the new kernel behavior of pci_restore_state() API call clears
12113 * device saved_state flag, need to save the restored state again.
12114 */
12115 pci_save_state(pdev);
12116
James Smart75baf692010-06-08 18:31:21 -040012117 if (pdev->is_busmaster)
12118 pci_set_master(pdev);
12119
12120 spin_lock_irq(&phba->hbalock);
12121 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
12122 spin_unlock_irq(&phba->hbalock);
12123
12124 /* Configure and enable interrupt */
12125 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
12126 if (intr_mode == LPFC_INTR_ERROR) {
12127 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12128 "2824 Cannot re-enable interrupt after "
12129 "slot reset.\n");
12130 return PCI_ERS_RESULT_DISCONNECT;
12131 } else
12132 phba->intr_mode = intr_mode;
12133
12134 /* Log the current active interrupt mode */
12135 lpfc_log_intr_mode(phba, phba->intr_mode);
12136
James Smartda0436e2009-05-22 14:51:39 -040012137 return PCI_ERS_RESULT_RECOVERED;
12138}
12139
12140/**
12141 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
12142 * @pdev: pointer to PCI device
12143 *
12144 * This routine is called from the PCI subsystem for error handling to device
12145 * with SLI-4 interface spec. It is called when kernel error recovery tells
12146 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
12147 * error recovery. After this call, traffic can start to flow from this device
12148 * again.
12149 **/
12150static void
12151lpfc_io_resume_s4(struct pci_dev *pdev)
12152{
James Smart75baf692010-06-08 18:31:21 -040012153 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12154 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12155
12156 /*
12157 * In case of slot reset, as function reset is performed through
12158 * mailbox command which needs DMA to be enabled, this operation
12159 * has to be moved to the io resume phase. Taking device offline
12160 * will perform the necessary cleanup.
12161 */
12162 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
12163 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040012164 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040012165 lpfc_offline(phba);
12166 lpfc_sli_brdrestart(phba);
12167 /* Bring the device back online */
12168 lpfc_online(phba);
12169 }
12170
12171 /* Clean up Advanced Error Reporting (AER) if needed */
12172 if (phba->hba_flag & HBA_AER_ENABLED)
12173 pci_cleanup_aer_uncorrect_error_status(pdev);
James Smartda0436e2009-05-22 14:51:39 -040012174}
12175
12176/**
James Smart3772a992009-05-22 14:50:54 -040012177 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
12178 * @pdev: pointer to PCI device
12179 * @pid: pointer to PCI device identifier
12180 *
12181 * This routine is to be registered to the kernel's PCI subsystem. When an
12182 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
12183 * at PCI device-specific information of the device and driver to see if the
12184 * driver state that it can support this kind of device. If the match is
12185 * successful, the driver core invokes this routine. This routine dispatches
12186 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
12187 * do all the initialization that it needs to do to handle the HBA device
12188 * properly.
12189 *
12190 * Return code
12191 * 0 - driver can claim the device
12192 * negative value - driver can not claim the device
12193 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012194static int
James Smart3772a992009-05-22 14:50:54 -040012195lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
12196{
12197 int rc;
James Smart8fa38512009-07-19 10:01:03 -040012198 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040012199
James Smart28baac72010-02-12 14:42:03 -050012200 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040012201 return -ENODEV;
12202
James Smart8fa38512009-07-19 10:01:03 -040012203 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050012204 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040012205 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040012206 else
James Smart3772a992009-05-22 14:50:54 -040012207 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040012208
James Smart3772a992009-05-22 14:50:54 -040012209 return rc;
12210}
12211
12212/**
12213 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
12214 * @pdev: pointer to PCI device
12215 *
12216 * This routine is to be registered to the kernel's PCI subsystem. When an
12217 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
12218 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
12219 * remove routine, which will perform all the necessary cleanup for the
12220 * device to be removed from the PCI subsystem properly.
12221 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012222static void
James Smart3772a992009-05-22 14:50:54 -040012223lpfc_pci_remove_one(struct pci_dev *pdev)
12224{
12225 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12226 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12227
12228 switch (phba->pci_dev_grp) {
12229 case LPFC_PCI_DEV_LP:
12230 lpfc_pci_remove_one_s3(pdev);
12231 break;
James Smartda0436e2009-05-22 14:51:39 -040012232 case LPFC_PCI_DEV_OC:
12233 lpfc_pci_remove_one_s4(pdev);
12234 break;
James Smart3772a992009-05-22 14:50:54 -040012235 default:
12236 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12237 "1424 Invalid PCI device group: 0x%x\n",
12238 phba->pci_dev_grp);
12239 break;
12240 }
12241 return;
12242}
12243
12244/**
12245 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
12246 * @pdev: pointer to PCI device
12247 * @msg: power management message
12248 *
12249 * This routine is to be registered to the kernel's PCI subsystem to support
12250 * system Power Management (PM). When PM invokes this method, it dispatches
12251 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
12252 * suspend the device.
12253 *
12254 * Return code
12255 * 0 - driver suspended the device
12256 * Error otherwise
12257 **/
12258static int
12259lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
12260{
12261 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12262 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12263 int rc = -ENODEV;
12264
12265 switch (phba->pci_dev_grp) {
12266 case LPFC_PCI_DEV_LP:
12267 rc = lpfc_pci_suspend_one_s3(pdev, msg);
12268 break;
James Smartda0436e2009-05-22 14:51:39 -040012269 case LPFC_PCI_DEV_OC:
12270 rc = lpfc_pci_suspend_one_s4(pdev, msg);
12271 break;
James Smart3772a992009-05-22 14:50:54 -040012272 default:
12273 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12274 "1425 Invalid PCI device group: 0x%x\n",
12275 phba->pci_dev_grp);
12276 break;
12277 }
12278 return rc;
12279}
12280
12281/**
12282 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
12283 * @pdev: pointer to PCI device
12284 *
12285 * This routine is to be registered to the kernel's PCI subsystem to support
12286 * system Power Management (PM). When PM invokes this method, it dispatches
12287 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
12288 * resume the device.
12289 *
12290 * Return code
12291 * 0 - driver suspended the device
12292 * Error otherwise
12293 **/
12294static int
12295lpfc_pci_resume_one(struct pci_dev *pdev)
12296{
12297 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12298 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12299 int rc = -ENODEV;
12300
12301 switch (phba->pci_dev_grp) {
12302 case LPFC_PCI_DEV_LP:
12303 rc = lpfc_pci_resume_one_s3(pdev);
12304 break;
James Smartda0436e2009-05-22 14:51:39 -040012305 case LPFC_PCI_DEV_OC:
12306 rc = lpfc_pci_resume_one_s4(pdev);
12307 break;
James Smart3772a992009-05-22 14:50:54 -040012308 default:
12309 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12310 "1426 Invalid PCI device group: 0x%x\n",
12311 phba->pci_dev_grp);
12312 break;
12313 }
12314 return rc;
12315}
12316
12317/**
12318 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
12319 * @pdev: pointer to PCI device.
12320 * @state: the current PCI connection state.
12321 *
12322 * This routine is registered to the PCI subsystem for error handling. This
12323 * function is called by the PCI subsystem after a PCI bus error affecting
12324 * this device has been detected. When this routine is invoked, it dispatches
12325 * the action to the proper SLI-3 or SLI-4 device error detected handling
12326 * routine, which will perform the proper error detected operation.
12327 *
12328 * Return codes
12329 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
12330 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12331 **/
12332static pci_ers_result_t
12333lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
12334{
12335 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12336 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12337 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
12338
12339 switch (phba->pci_dev_grp) {
12340 case LPFC_PCI_DEV_LP:
12341 rc = lpfc_io_error_detected_s3(pdev, state);
12342 break;
James Smartda0436e2009-05-22 14:51:39 -040012343 case LPFC_PCI_DEV_OC:
12344 rc = lpfc_io_error_detected_s4(pdev, state);
12345 break;
James Smart3772a992009-05-22 14:50:54 -040012346 default:
12347 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12348 "1427 Invalid PCI device group: 0x%x\n",
12349 phba->pci_dev_grp);
12350 break;
12351 }
12352 return rc;
12353}
12354
12355/**
12356 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
12357 * @pdev: pointer to PCI device.
12358 *
12359 * This routine is registered to the PCI subsystem for error handling. This
12360 * function is called after PCI bus has been reset to restart the PCI card
12361 * from scratch, as if from a cold-boot. When this routine is invoked, it
12362 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
12363 * routine, which will perform the proper device reset.
12364 *
12365 * Return codes
12366 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
12367 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12368 **/
12369static pci_ers_result_t
12370lpfc_io_slot_reset(struct pci_dev *pdev)
12371{
12372 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12373 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12374 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
12375
12376 switch (phba->pci_dev_grp) {
12377 case LPFC_PCI_DEV_LP:
12378 rc = lpfc_io_slot_reset_s3(pdev);
12379 break;
James Smartda0436e2009-05-22 14:51:39 -040012380 case LPFC_PCI_DEV_OC:
12381 rc = lpfc_io_slot_reset_s4(pdev);
12382 break;
James Smart3772a992009-05-22 14:50:54 -040012383 default:
12384 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12385 "1428 Invalid PCI device group: 0x%x\n",
12386 phba->pci_dev_grp);
12387 break;
12388 }
12389 return rc;
12390}
12391
12392/**
12393 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
12394 * @pdev: pointer to PCI device
12395 *
12396 * This routine is registered to the PCI subsystem for error handling. It
12397 * is called when kernel error recovery tells the lpfc driver that it is
12398 * OK to resume normal PCI operation after PCI bus error recovery. When
12399 * this routine is invoked, it dispatches the action to the proper SLI-3
12400 * or SLI-4 device io_resume routine, which will resume the device operation.
12401 **/
12402static void
12403lpfc_io_resume(struct pci_dev *pdev)
12404{
12405 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12406 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12407
12408 switch (phba->pci_dev_grp) {
12409 case LPFC_PCI_DEV_LP:
12410 lpfc_io_resume_s3(pdev);
12411 break;
James Smartda0436e2009-05-22 14:51:39 -040012412 case LPFC_PCI_DEV_OC:
12413 lpfc_io_resume_s4(pdev);
12414 break;
James Smart3772a992009-05-22 14:50:54 -040012415 default:
12416 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12417 "1429 Invalid PCI device group: 0x%x\n",
12418 phba->pci_dev_grp);
12419 break;
12420 }
12421 return;
12422}
12423
James Smart1ba981f2014-02-20 09:56:45 -050012424/**
12425 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
12426 * @phba: pointer to lpfc hba data structure.
12427 *
12428 * This routine checks to see if OAS is supported for this adapter. If
12429 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
12430 * the enable oas flag is cleared and the pool created for OAS device data
12431 * is destroyed.
12432 *
12433 **/
12434void
12435lpfc_sli4_oas_verify(struct lpfc_hba *phba)
12436{
12437
12438 if (!phba->cfg_EnableXLane)
12439 return;
12440
12441 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
12442 phba->cfg_fof = 1;
12443 } else {
James Smartf38fa0b2014-04-04 13:52:21 -040012444 phba->cfg_fof = 0;
James Smart1ba981f2014-02-20 09:56:45 -050012445 if (phba->device_data_mem_pool)
12446 mempool_destroy(phba->device_data_mem_pool);
12447 phba->device_data_mem_pool = NULL;
12448 }
12449
12450 return;
12451}
12452
12453/**
12454 * lpfc_fof_queue_setup - Set up all the fof queues
12455 * @phba: pointer to lpfc hba data structure.
12456 *
12457 * This routine is invoked to set up all the fof queues for the FC HBA
12458 * operation.
12459 *
12460 * Return codes
12461 * 0 - successful
12462 * -ENOMEM - No available memory
12463 **/
12464int
12465lpfc_fof_queue_setup(struct lpfc_hba *phba)
12466{
James Smart895427b2017-02-12 13:52:30 -080012467 struct lpfc_sli_ring *pring;
James Smart1ba981f2014-02-20 09:56:45 -050012468 int rc;
12469
12470 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
12471 if (rc)
12472 return -ENOMEM;
12473
James Smartf38fa0b2014-04-04 13:52:21 -040012474 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050012475
12476 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
12477 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
12478 if (rc)
12479 goto out_oas_cq;
12480
12481 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
12482 phba->sli4_hba.oas_cq, LPFC_FCP);
12483 if (rc)
12484 goto out_oas_wq;
12485
James Smart895427b2017-02-12 13:52:30 -080012486 /* Bind this CQ/WQ to the NVME ring */
12487 pring = phba->sli4_hba.oas_wq->pring;
12488 pring->sli.sli4.wqp =
12489 (void *)phba->sli4_hba.oas_wq;
12490 phba->sli4_hba.oas_cq->pring = pring;
James Smart1ba981f2014-02-20 09:56:45 -050012491 }
12492
12493 return 0;
12494
12495out_oas_wq:
James Smartf38fa0b2014-04-04 13:52:21 -040012496 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
James Smart1ba981f2014-02-20 09:56:45 -050012497out_oas_cq:
12498 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
12499 return rc;
12500
12501}
12502
12503/**
12504 * lpfc_fof_queue_create - Create all the fof queues
12505 * @phba: pointer to lpfc hba data structure.
12506 *
12507 * This routine is invoked to allocate all the fof queues for the FC HBA
12508 * operation. For each SLI4 queue type, the parameters such as queue entry
12509 * count (queue depth) shall be taken from the module parameter. For now,
12510 * we just use some constant number as place holder.
12511 *
12512 * Return codes
12513 * 0 - successful
12514 * -ENOMEM - No availble memory
12515 * -EIO - The mailbox failed to complete successfully.
12516 **/
12517int
12518lpfc_fof_queue_create(struct lpfc_hba *phba)
12519{
12520 struct lpfc_queue *qdesc;
James Smartc176ffa2018-01-30 15:58:46 -080012521 uint32_t wqesize;
James Smart1ba981f2014-02-20 09:56:45 -050012522
12523 /* Create FOF EQ */
James Smart81b96ed2017-11-20 16:00:29 -080012524 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
12525 phba->sli4_hba.eq_esize,
James Smart1ba981f2014-02-20 09:56:45 -050012526 phba->sli4_hba.eq_ecount);
12527 if (!qdesc)
12528 goto out_error;
12529
James Smart7365f6f2018-02-22 08:18:46 -080012530 qdesc->qe_valid = 1;
James Smart1ba981f2014-02-20 09:56:45 -050012531 phba->sli4_hba.fof_eq = qdesc;
12532
James Smartf38fa0b2014-04-04 13:52:21 -040012533 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050012534
12535 /* Create OAS CQ */
James Smartc176ffa2018-01-30 15:58:46 -080012536 if (phba->enab_exp_wqcq_pages)
James Smarta51e41b2017-12-08 17:18:06 -080012537 qdesc = lpfc_sli4_queue_alloc(phba,
12538 LPFC_EXPANDED_PAGE_SIZE,
12539 phba->sli4_hba.cq_esize,
12540 LPFC_CQE_EXP_COUNT);
12541 else
12542 qdesc = lpfc_sli4_queue_alloc(phba,
12543 LPFC_DEFAULT_PAGE_SIZE,
12544 phba->sli4_hba.cq_esize,
12545 phba->sli4_hba.cq_ecount);
James Smart1ba981f2014-02-20 09:56:45 -050012546 if (!qdesc)
12547 goto out_error;
12548
James Smart7365f6f2018-02-22 08:18:46 -080012549 qdesc->qe_valid = 1;
James Smart1ba981f2014-02-20 09:56:45 -050012550 phba->sli4_hba.oas_cq = qdesc;
12551
12552 /* Create OAS WQ */
James Smartc176ffa2018-01-30 15:58:46 -080012553 if (phba->enab_exp_wqcq_pages) {
12554 wqesize = (phba->fcp_embed_io) ?
12555 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
James Smarta51e41b2017-12-08 17:18:06 -080012556 qdesc = lpfc_sli4_queue_alloc(phba,
12557 LPFC_EXPANDED_PAGE_SIZE,
James Smartc176ffa2018-01-30 15:58:46 -080012558 wqesize,
James Smarta51e41b2017-12-08 17:18:06 -080012559 LPFC_WQE_EXP_COUNT);
James Smartc176ffa2018-01-30 15:58:46 -080012560 } else
James Smarta51e41b2017-12-08 17:18:06 -080012561 qdesc = lpfc_sli4_queue_alloc(phba,
12562 LPFC_DEFAULT_PAGE_SIZE,
12563 phba->sli4_hba.wq_esize,
12564 phba->sli4_hba.wq_ecount);
James Smartc176ffa2018-01-30 15:58:46 -080012565
James Smart1ba981f2014-02-20 09:56:45 -050012566 if (!qdesc)
12567 goto out_error;
12568
12569 phba->sli4_hba.oas_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -080012570 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
James Smart1ba981f2014-02-20 09:56:45 -050012571
12572 }
12573 return 0;
12574
12575out_error:
12576 lpfc_fof_queue_destroy(phba);
12577 return -ENOMEM;
12578}
12579
12580/**
12581 * lpfc_fof_queue_destroy - Destroy all the fof queues
12582 * @phba: pointer to lpfc hba data structure.
12583 *
12584 * This routine is invoked to release all the SLI4 queues with the FC HBA
12585 * operation.
12586 *
12587 * Return codes
12588 * 0 - successful
12589 **/
12590int
12591lpfc_fof_queue_destroy(struct lpfc_hba *phba)
12592{
12593 /* Release FOF Event queue */
12594 if (phba->sli4_hba.fof_eq != NULL) {
12595 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
12596 phba->sli4_hba.fof_eq = NULL;
12597 }
12598
12599 /* Release OAS Completion queue */
12600 if (phba->sli4_hba.oas_cq != NULL) {
12601 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
12602 phba->sli4_hba.oas_cq = NULL;
12603 }
12604
12605 /* Release OAS Work queue */
12606 if (phba->sli4_hba.oas_wq != NULL) {
12607 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
12608 phba->sli4_hba.oas_wq = NULL;
12609 }
12610 return 0;
12611}
12612
dea31012005-04-17 16:05:31 -050012613MODULE_DEVICE_TABLE(pci, lpfc_id_table);
12614
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070012615static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060012616 .error_detected = lpfc_io_error_detected,
12617 .slot_reset = lpfc_io_slot_reset,
12618 .resume = lpfc_io_resume,
12619};
12620
dea31012005-04-17 16:05:31 -050012621static struct pci_driver lpfc_driver = {
12622 .name = LPFC_DRIVER_NAME,
12623 .id_table = lpfc_id_table,
12624 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012625 .remove = lpfc_pci_remove_one,
Anton Blanchard85e8a232017-02-13 08:49:20 +110012626 .shutdown = lpfc_pci_remove_one,
James Smart3a55b532008-12-04 22:38:54 -050012627 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040012628 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050012629 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050012630};
12631
James Smart3ef6d242012-01-18 16:23:48 -050012632static const struct file_operations lpfc_mgmt_fop = {
Al Viro858feac2013-04-14 22:39:37 -040012633 .owner = THIS_MODULE,
James Smart3ef6d242012-01-18 16:23:48 -050012634};
12635
12636static struct miscdevice lpfc_mgmt_dev = {
12637 .minor = MISC_DYNAMIC_MINOR,
12638 .name = "lpfcmgmt",
12639 .fops = &lpfc_mgmt_fop,
12640};
12641
James Smarte59058c2008-08-24 21:49:00 -040012642/**
James Smart3621a712009-04-06 18:47:14 -040012643 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040012644 *
12645 * This routine is to be invoked when the lpfc module is loaded into the
12646 * kernel. The special kernel macro module_init() is used to indicate the
12647 * role of this routine to the kernel as lpfc module entry point.
12648 *
12649 * Return codes
12650 * 0 - successful
12651 * -ENOMEM - FC attach transport failed
12652 * all others - failed
12653 */
dea31012005-04-17 16:05:31 -050012654static int __init
12655lpfc_init(void)
12656{
12657 int error = 0;
12658
12659 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012660 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050012661
James Smart3ef6d242012-01-18 16:23:48 -050012662 error = misc_register(&lpfc_mgmt_dev);
12663 if (error)
12664 printk(KERN_ERR "Could not register lpfcmgmt device, "
12665 "misc_register returned with status %d", error);
12666
James Smart458c0832016-07-06 12:36:07 -070012667 lpfc_transport_functions.vport_create = lpfc_vport_create;
12668 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
dea31012005-04-17 16:05:31 -050012669 lpfc_transport_template =
12670 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040012671 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050012672 return -ENOMEM;
James Smart458c0832016-07-06 12:36:07 -070012673 lpfc_vport_transport_template =
12674 fc_attach_transport(&lpfc_vport_transport_functions);
12675 if (lpfc_vport_transport_template == NULL) {
12676 fc_release_transport(lpfc_transport_template);
12677 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040012678 }
James Smart5fd11082018-03-05 12:04:04 -080012679 lpfc_nvme_cmd_template();
James Smartbd3061b2018-03-05 12:04:05 -080012680 lpfc_nvmet_cmd_template();
James Smart7bb03bb2013-04-17 20:19:16 -040012681
12682 /* Initialize in case vector mapping is needed */
James Smartb246de12013-05-31 17:03:07 -040012683 lpfc_used_cpu = NULL;
James Smart2ea259e2017-02-12 13:52:27 -080012684 lpfc_present_cpu = num_present_cpus();
James Smart7bb03bb2013-04-17 20:19:16 -040012685
dea31012005-04-17 16:05:31 -050012686 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050012687 if (error) {
dea31012005-04-17 16:05:31 -050012688 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070012689 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050012690 }
dea31012005-04-17 16:05:31 -050012691
12692 return error;
12693}
12694
James Smarte59058c2008-08-24 21:49:00 -040012695/**
James Smart3621a712009-04-06 18:47:14 -040012696 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040012697 *
12698 * This routine is invoked when the lpfc module is removed from the kernel.
12699 * The special kernel macro module_exit() is used to indicate the role of
12700 * this routine to the kernel as lpfc module exit point.
12701 */
dea31012005-04-17 16:05:31 -050012702static void __exit
12703lpfc_exit(void)
12704{
James Smart3ef6d242012-01-18 16:23:48 -050012705 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050012706 pci_unregister_driver(&lpfc_driver);
12707 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070012708 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050012709 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040012710 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
12711 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050012712 (1L << _dump_buf_data_order), _dump_buf_data);
12713 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
12714 }
12715
12716 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040012717 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
12718 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050012719 (1L << _dump_buf_dif_order), _dump_buf_dif);
12720 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
12721 }
James Smartb246de12013-05-31 17:03:07 -040012722 kfree(lpfc_used_cpu);
Johannes Thumshirn79739672015-08-31 16:48:11 -040012723 idr_destroy(&lpfc_hba_index);
dea31012005-04-17 16:05:31 -050012724}
12725
12726module_init(lpfc_init);
12727module_exit(lpfc_exit);
12728MODULE_LICENSE("GPL");
12729MODULE_DESCRIPTION(LPFC_MODULE_DESC);
James Smartd080abe2017-02-12 13:52:39 -080012730MODULE_AUTHOR("Broadcom");
dea31012005-04-17 16:05:31 -050012731MODULE_VERSION("0:" LPFC_DRIVER_VERSION);