blob: 68d62d55a3a50429eb97febc179726300618f151 [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
Martin Wilckdfb75132018-11-12 09:58:37 +0100170 /*
171 * Clear all option bits except LPFC_SLI3_BG_ENABLED,
172 * which was already set in lpfc_get_cfgparam()
173 */
174 phba->sli3_options &= (uint32_t)LPFC_SLI3_BG_ENABLED;
James Smart92d7f7b2007-06-17 19:56:38 -0500175
dea31012005-04-17 16:05:31 -0500176 /* Setup and issue mailbox READ REV command */
177 lpfc_read_rev(phba, pmb);
178 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
179 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500180 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400181 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500182 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500183 mb->mbxCommand, mb->mbxStatus);
184 mempool_free( pmb, phba->mbox_mem_pool);
185 return -ERESTART;
186 }
187
James Smart92d7f7b2007-06-17 19:56:38 -0500188
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500189 /*
190 * The value of rr must be 1 since the driver set the cv field to 1.
191 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500192 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500193 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500194 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500195 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400196 "0440 Adapter failed to init, READ_REV has "
197 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500198 mempool_free(pmb, phba->mbox_mem_pool);
199 return -ERESTART;
dea31012005-04-17 16:05:31 -0500200 }
201
James Smart495a7142008-06-14 22:52:59 -0400202 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
203 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500204 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400205 }
James Smarted957682007-06-17 19:56:37 -0500206
dea31012005-04-17 16:05:31 -0500207 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500208 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500209 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500210 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
211 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
212 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
213 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500214 vp->rev.biuRev = mb->un.varRdRev.biuRev;
215 vp->rev.smRev = mb->un.varRdRev.smRev;
216 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
217 vp->rev.endecRev = mb->un.varRdRev.endecRev;
218 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
219 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
220 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
221 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
222 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
223 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
224
James Smart92d7f7b2007-06-17 19:56:38 -0500225 /* If the sli feature level is less then 9, we must
226 * tear down all RPIs and VPIs on link down if NPIV
227 * is enabled.
228 */
229 if (vp->rev.feaLevelHigh < 9)
230 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
231
dea31012005-04-17 16:05:31 -0500232 if (lpfc_is_LC_HBA(phba->pcidev->device))
233 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
234 sizeof (phba->RandomData));
235
dea31012005-04-17 16:05:31 -0500236 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500237 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
238 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400239 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500240 do {
James Smarta0c87cb2009-07-19 10:01:10 -0400241 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
dea31012005-04-17 16:05:31 -0500242 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
243
244 if (rc != MBX_SUCCESS) {
245 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400246 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500247 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500248 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500249 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500250 }
James Smart04c68492009-05-22 14:52:52 -0400251 /* dump mem may return a zero when finished or we got a
252 * mailbox error, either way we are done.
253 */
254 if (mb->un.varDmp.word_cnt == 0)
255 break;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500256 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
257 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400258 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
259 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500260 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500261 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500262 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
263 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500264
265 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500266out_free_mbox:
267 mempool_free(pmb, phba->mbox_mem_pool);
268 return 0;
269}
270
James Smarte59058c2008-08-24 21:49:00 -0400271/**
James Smart3621a712009-04-06 18:47:14 -0400272 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
James Smarte59058c2008-08-24 21:49:00 -0400273 * @phba: pointer to lpfc hba data structure.
274 * @pmboxq: pointer to the driver internal queue element for mailbox command.
275 *
276 * This is the completion handler for driver's configuring asynchronous event
277 * mailbox command to the device. If the mailbox command returns successfully,
278 * it will set internal async event support flag to 1; otherwise, it will
279 * set internal async event support flag to 0.
280 **/
James Smart57127f12007-10-27 13:37:05 -0400281static void
282lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
283{
James Smart04c68492009-05-22 14:52:52 -0400284 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
James Smart57127f12007-10-27 13:37:05 -0400285 phba->temp_sensor_support = 1;
286 else
287 phba->temp_sensor_support = 0;
288 mempool_free(pmboxq, phba->mbox_mem_pool);
289 return;
290}
291
James Smarte59058c2008-08-24 21:49:00 -0400292/**
James Smart3621a712009-04-06 18:47:14 -0400293 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
James Smart97207482008-12-04 22:39:19 -0500294 * @phba: pointer to lpfc hba data structure.
295 * @pmboxq: pointer to the driver internal queue element for mailbox command.
296 *
297 * This is the completion handler for dump mailbox command for getting
298 * wake up parameters. When this command complete, the response contain
299 * Option rom version of the HBA. This function translate the version number
300 * into a human readable string and store it in OptionROMVersion.
301 **/
302static void
303lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
304{
305 struct prog_id *prg;
306 uint32_t prog_id_word;
307 char dist = ' ';
308 /* character array used for decoding dist type. */
309 char dist_char[] = "nabx";
310
James Smart04c68492009-05-22 14:52:52 -0400311 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
James Smart9f1e1b52008-12-04 22:39:40 -0500312 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500313 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500314 }
James Smart97207482008-12-04 22:39:19 -0500315
316 prg = (struct prog_id *) &prog_id_word;
317
318 /* word 7 contain option rom version */
James Smart04c68492009-05-22 14:52:52 -0400319 prog_id_word = pmboxq->u.mb.un.varWords[7];
James Smart97207482008-12-04 22:39:19 -0500320
321 /* Decode the Option rom version word to a readable string */
322 if (prg->dist < 4)
323 dist = dist_char[prg->dist];
324
325 if ((prg->dist == 3) && (prg->num == 0))
James Smarta2fc4aef2014-09-03 12:57:55 -0400326 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
James Smart97207482008-12-04 22:39:19 -0500327 prg->ver, prg->rev, prg->lev);
328 else
James Smarta2fc4aef2014-09-03 12:57:55 -0400329 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
James Smart97207482008-12-04 22:39:19 -0500330 prg->ver, prg->rev, prg->lev,
331 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500332 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500333 return;
334}
335
336/**
James Smart05580562011-05-24 11:40:48 -0400337 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
338 * cfg_soft_wwnn, cfg_soft_wwpn
339 * @vport: pointer to lpfc vport data structure.
340 *
341 *
342 * Return codes
343 * None.
344 **/
345void
346lpfc_update_vport_wwn(struct lpfc_vport *vport)
347{
James Smartaeb3c812017-04-21 16:05:02 -0700348 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
349 u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0];
350
James Smart05580562011-05-24 11:40:48 -0400351 /* If the soft name exists then update it using the service params */
352 if (vport->phba->cfg_soft_wwnn)
353 u64_to_wwn(vport->phba->cfg_soft_wwnn,
354 vport->fc_sparam.nodeName.u.wwn);
355 if (vport->phba->cfg_soft_wwpn)
356 u64_to_wwn(vport->phba->cfg_soft_wwpn,
357 vport->fc_sparam.portName.u.wwn);
358
359 /*
360 * If the name is empty or there exists a soft name
361 * then copy the service params name, otherwise use the fc name
362 */
363 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
364 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
365 sizeof(struct lpfc_name));
366 else
367 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
368 sizeof(struct lpfc_name));
369
James Smartaeb3c812017-04-21 16:05:02 -0700370 /*
371 * If the port name has changed, then set the Param changes flag
372 * to unreg the login
373 */
374 if (vport->fc_portname.u.wwn[0] != 0 &&
375 memcmp(&vport->fc_portname, &vport->fc_sparam.portName,
376 sizeof(struct lpfc_name)))
377 vport->vport_flag |= FAWWPN_PARAM_CHG;
378
379 if (vport->fc_portname.u.wwn[0] == 0 ||
380 vport->phba->cfg_soft_wwpn ||
381 (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) ||
382 vport->vport_flag & FAWWPN_SET) {
James Smart05580562011-05-24 11:40:48 -0400383 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
384 sizeof(struct lpfc_name));
James Smartaeb3c812017-04-21 16:05:02 -0700385 vport->vport_flag &= ~FAWWPN_SET;
386 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR)
387 vport->vport_flag |= FAWWPN_SET;
388 }
James Smart05580562011-05-24 11:40:48 -0400389 else
390 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
391 sizeof(struct lpfc_name));
392}
393
394/**
James Smart3621a712009-04-06 18:47:14 -0400395 * lpfc_config_port_post - Perform lpfc initialization after config port
James Smarte59058c2008-08-24 21:49:00 -0400396 * @phba: pointer to lpfc hba data structure.
397 *
398 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
399 * command call. It performs all internal resource and state setups on the
400 * port: post IOCB buffers, enable appropriate host interrupt attentions,
401 * ELS ring timers, etc.
402 *
403 * Return codes
404 * 0 - success.
405 * Any other value - error.
406 **/
dea31012005-04-17 16:05:31 -0500407int
James Smart2e0fef82007-06-17 19:56:36 -0500408lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500409{
James Smart2e0fef82007-06-17 19:56:36 -0500410 struct lpfc_vport *vport = phba->pport;
James Smarta257bf92009-04-06 18:48:10 -0400411 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500412 LPFC_MBOXQ_t *pmb;
413 MAILBOX_t *mb;
414 struct lpfc_dmabuf *mp;
415 struct lpfc_sli *psli = &phba->sli;
416 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500417 int i, j;
418 int rc;
dea31012005-04-17 16:05:31 -0500419
James Smart7af67052007-10-27 13:38:11 -0400420 spin_lock_irq(&phba->hbalock);
421 /*
422 * If the Config port completed correctly the HBA is not
423 * over heated any more.
424 */
425 if (phba->over_temp_state == HBA_OVER_TEMP)
426 phba->over_temp_state = HBA_NORMAL_TEMP;
427 spin_unlock_irq(&phba->hbalock);
428
dea31012005-04-17 16:05:31 -0500429 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
430 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500431 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500432 return -ENOMEM;
433 }
James Smart04c68492009-05-22 14:52:52 -0400434 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500435
dea31012005-04-17 16:05:31 -0500436 /* Get login parameters for NID. */
James Smart9f1177a2010-02-26 14:12:57 -0500437 rc = lpfc_read_sparam(phba, pmb, 0);
438 if (rc) {
439 mempool_free(pmb, phba->mbox_mem_pool);
440 return -ENOMEM;
441 }
442
James Smarted957682007-06-17 19:56:37 -0500443 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500444 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500445 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400446 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500447 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500448 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500449 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500450 mp = (struct lpfc_dmabuf *) pmb->context1;
James Smart9f1177a2010-02-26 14:12:57 -0500451 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500452 lpfc_mbuf_free(phba, mp->virt, mp->phys);
453 kfree(mp);
454 return -EIO;
455 }
456
457 mp = (struct lpfc_dmabuf *) pmb->context1;
458
James Smart2e0fef82007-06-17 19:56:36 -0500459 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500460 lpfc_mbuf_free(phba, mp->virt, mp->phys);
461 kfree(mp);
462 pmb->context1 = NULL;
James Smart05580562011-05-24 11:40:48 -0400463 lpfc_update_vport_wwn(vport);
James Smarta257bf92009-04-06 18:48:10 -0400464
465 /* Update the fc_host data structures with new wwn. */
466 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
467 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart21e9a0a2009-05-22 14:53:21 -0400468 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smarta257bf92009-04-06 18:48:10 -0400469
dea31012005-04-17 16:05:31 -0500470 /* If no serial number in VPD data, use low 6 bytes of WWNN */
471 /* This should be consolidated into parse_vpd ? - mr */
472 if (phba->SerialNumber[0] == 0) {
473 uint8_t *outptr;
474
James Smart2e0fef82007-06-17 19:56:36 -0500475 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500476 for (i = 0; i < 12; i++) {
477 status = *outptr++;
478 j = ((status & 0xf0) >> 4);
479 if (j <= 9)
480 phba->SerialNumber[i] =
481 (char)((uint8_t) 0x30 + (uint8_t) j);
482 else
483 phba->SerialNumber[i] =
484 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
485 i++;
486 j = (status & 0xf);
487 if (j <= 9)
488 phba->SerialNumber[i] =
489 (char)((uint8_t) 0x30 + (uint8_t) j);
490 else
491 phba->SerialNumber[i] =
492 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
493 }
494 }
495
dea31012005-04-17 16:05:31 -0500496 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500497 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500498 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500499 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400500 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500501 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500502 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500503 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500504 mempool_free( pmb, phba->mbox_mem_pool);
505 return -EIO;
506 }
507
James Smarta0c87cb2009-07-19 10:01:10 -0400508 /* Check if the port is disabled */
509 lpfc_sli_read_link_ste(phba);
510
dea31012005-04-17 16:05:31 -0500511 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -0400512 i = (mb->un.varRdConfig.max_xri + 1);
513 if (phba->cfg_hba_queue_depth > i) {
514 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
515 "3359 HBA queue depth changed from %d to %d\n",
516 phba->cfg_hba_queue_depth, i);
517 phba->cfg_hba_queue_depth = i;
518 }
519
520 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
521 i = (mb->un.varRdConfig.max_xri >> 3);
522 if (phba->pport->cfg_lun_queue_depth > i) {
523 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
524 "3360 LUN queue depth changed from %d to %d\n",
525 phba->pport->cfg_lun_queue_depth, i);
526 phba->pport->cfg_lun_queue_depth = i;
527 }
dea31012005-04-17 16:05:31 -0500528
529 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500530
531 /* Get the default values for Model Name and Description */
532 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
533
James Smart2e0fef82007-06-17 19:56:36 -0500534 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500535
James Smart0b727fe2007-10-27 13:37:25 -0400536 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smart895427b2017-02-12 13:52:30 -0800537 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
538 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
539 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
540 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500541
542 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500543 if (phba->sli_rev != 3)
544 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500545
James Smart93996272008-08-24 21:50:30 -0400546 /*
547 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
548 */
549 if (phba->intr_type == MSIX) {
550 rc = lpfc_config_msi(phba, pmb);
551 if (rc) {
552 mempool_free(pmb, phba->mbox_mem_pool);
553 return -EIO;
554 }
555 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
556 if (rc != MBX_SUCCESS) {
557 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
558 "0352 Config MSI mailbox command "
559 "failed, mbxCmd x%x, mbxStatus x%x\n",
James Smart04c68492009-05-22 14:52:52 -0400560 pmb->u.mb.mbxCommand,
561 pmb->u.mb.mbxStatus);
James Smart93996272008-08-24 21:50:30 -0400562 mempool_free(pmb, phba->mbox_mem_pool);
563 return -EIO;
564 }
565 }
566
James Smart04c68492009-05-22 14:52:52 -0400567 spin_lock_irq(&phba->hbalock);
James Smart93996272008-08-24 21:50:30 -0400568 /* Initialize ERATT handling flag */
569 phba->hba_flag &= ~HBA_ERATT_HANDLED;
570
dea31012005-04-17 16:05:31 -0500571 /* Enable appropriate host interrupts */
James Smart9940b972011-03-11 16:06:12 -0500572 if (lpfc_readl(phba->HCregaddr, &status)) {
573 spin_unlock_irq(&phba->hbalock);
574 return -EIO;
575 }
dea31012005-04-17 16:05:31 -0500576 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
577 if (psli->num_rings > 0)
578 status |= HC_R0INT_ENA;
579 if (psli->num_rings > 1)
580 status |= HC_R1INT_ENA;
581 if (psli->num_rings > 2)
582 status |= HC_R2INT_ENA;
583 if (psli->num_rings > 3)
584 status |= HC_R3INT_ENA;
585
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500586 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
587 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400588 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500589
dea31012005-04-17 16:05:31 -0500590 writel(status, phba->HCregaddr);
591 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500592 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500593
James Smart93996272008-08-24 21:50:30 -0400594 /* Set up ring-0 (ELS) timer */
595 timeout = phba->fc_ratov * 2;
James Smart256ec0d2013-04-17 20:14:58 -0400596 mod_timer(&vport->els_tmofunc,
597 jiffies + msecs_to_jiffies(1000 * timeout));
James Smart93996272008-08-24 21:50:30 -0400598 /* Set up heart beat (HB) timer */
James Smart256ec0d2013-04-17 20:14:58 -0400599 mod_timer(&phba->hb_tmofunc,
600 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -0500601 phba->hb_outstanding = 0;
602 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400603 /* Set up error attention (ERATT) polling timer */
James Smart256ec0d2013-04-17 20:14:58 -0400604 mod_timer(&phba->eratt_poll,
James Smart65791f12016-07-06 12:35:56 -0700605 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
dea31012005-04-17 16:05:31 -0500606
James Smarta0c87cb2009-07-19 10:01:10 -0400607 if (phba->hba_flag & LINK_DISABLED) {
608 lpfc_printf_log(phba,
609 KERN_ERR, LOG_INIT,
610 "2598 Adapter Link is disabled.\n");
611 lpfc_down_link(phba, pmb);
612 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
613 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
614 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
615 lpfc_printf_log(phba,
616 KERN_ERR, LOG_INIT,
617 "2599 Adapter failed to issue DOWN_LINK"
618 " mbox command rc 0x%x\n", rc);
619
620 mempool_free(pmb, phba->mbox_mem_pool);
621 return -EIO;
622 }
James Smarte40a02c2010-02-26 14:13:54 -0500623 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
James Smart026abb82011-12-13 13:20:45 -0500624 mempool_free(pmb, phba->mbox_mem_pool);
625 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
626 if (rc)
627 return rc;
dea31012005-04-17 16:05:31 -0500628 }
629 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400630 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500631 if (!pmb) {
632 phba->link_state = LPFC_HBA_ERROR;
633 return -ENOMEM;
634 }
635
James Smart57127f12007-10-27 13:37:05 -0400636 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
637 pmb->mbox_cmpl = lpfc_config_async_cmpl;
638 pmb->vport = phba->pport;
639 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500640
James Smart57127f12007-10-27 13:37:05 -0400641 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
642 lpfc_printf_log(phba,
643 KERN_ERR,
644 LOG_INIT,
645 "0456 Adapter failed to issue "
James Smarte4e74272009-07-19 10:01:38 -0400646 "ASYNCEVT_ENABLE mbox status x%x\n",
James Smart57127f12007-10-27 13:37:05 -0400647 rc);
648 mempool_free(pmb, phba->mbox_mem_pool);
649 }
James Smart97207482008-12-04 22:39:19 -0500650
651 /* Get Option rom version */
652 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500653 if (!pmb) {
654 phba->link_state = LPFC_HBA_ERROR;
655 return -ENOMEM;
656 }
657
James Smart97207482008-12-04 22:39:19 -0500658 lpfc_dump_wakeup_param(phba, pmb);
659 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
660 pmb->vport = phba->pport;
661 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
662
663 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
664 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
James Smarte4e74272009-07-19 10:01:38 -0400665 "to get Option ROM version status x%x\n", rc);
James Smart97207482008-12-04 22:39:19 -0500666 mempool_free(pmb, phba->mbox_mem_pool);
667 }
668
James Smartd7c255b2008-08-24 21:50:00 -0400669 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400670}
671
James Smarte59058c2008-08-24 21:49:00 -0400672/**
James Smart84d1b002010-02-12 14:42:33 -0500673 * lpfc_hba_init_link - Initialize the FC link
674 * @phba: pointer to lpfc hba data structure.
James Smart6e7288d2010-06-07 15:23:35 -0400675 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500676 *
677 * This routine will issue the INIT_LINK mailbox command call.
678 * It is available to other drivers through the lpfc_hba data
679 * structure for use as a delayed link up mechanism with the
680 * module parameter lpfc_suppress_link_up.
681 *
682 * Return code
683 * 0 - success
684 * Any other value - error
685 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400686static int
James Smart6e7288d2010-06-07 15:23:35 -0400687lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500688{
James Smart1b511972011-12-13 13:23:09 -0500689 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
690}
691
692/**
693 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
694 * @phba: pointer to lpfc hba data structure.
695 * @fc_topology: desired fc topology.
696 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
697 *
698 * This routine will issue the INIT_LINK mailbox command call.
699 * It is available to other drivers through the lpfc_hba data
700 * structure for use as a delayed link up mechanism with the
701 * module parameter lpfc_suppress_link_up.
702 *
703 * Return code
704 * 0 - success
705 * Any other value - error
706 **/
707int
708lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
709 uint32_t flag)
710{
James Smart84d1b002010-02-12 14:42:33 -0500711 struct lpfc_vport *vport = phba->pport;
712 LPFC_MBOXQ_t *pmb;
713 MAILBOX_t *mb;
714 int rc;
715
716 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
717 if (!pmb) {
718 phba->link_state = LPFC_HBA_ERROR;
719 return -ENOMEM;
720 }
721 mb = &pmb->u.mb;
722 pmb->vport = vport;
723
James Smart026abb82011-12-13 13:20:45 -0500724 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
725 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
726 !(phba->lmt & LMT_1Gb)) ||
727 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
728 !(phba->lmt & LMT_2Gb)) ||
729 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
730 !(phba->lmt & LMT_4Gb)) ||
731 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
732 !(phba->lmt & LMT_8Gb)) ||
733 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
734 !(phba->lmt & LMT_10Gb)) ||
735 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
James Smartd38dd522015-08-31 16:48:17 -0400736 !(phba->lmt & LMT_16Gb)) ||
737 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
James Smartfbd8a6b2018-02-22 08:18:45 -0800738 !(phba->lmt & LMT_32Gb)) ||
739 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) &&
740 !(phba->lmt & LMT_64Gb))) {
James Smart026abb82011-12-13 13:20:45 -0500741 /* Reset link speed to auto */
742 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
743 "1302 Invalid speed for this board:%d "
744 "Reset link speed to auto.\n",
745 phba->cfg_link_speed);
746 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
747 }
James Smart1b511972011-12-13 13:23:09 -0500748 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
James Smart84d1b002010-02-12 14:42:33 -0500749 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart1b511972011-12-13 13:23:09 -0500750 if (phba->sli_rev < LPFC_SLI_REV4)
751 lpfc_set_loopback_flag(phba);
James Smart6e7288d2010-06-07 15:23:35 -0400752 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart76a95d72010-11-20 23:11:48 -0500753 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
James Smart84d1b002010-02-12 14:42:33 -0500754 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
755 "0498 Adapter failed to init, mbxCmd x%x "
756 "INIT_LINK, mbxStatus x%x\n",
757 mb->mbxCommand, mb->mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -0500758 if (phba->sli_rev <= LPFC_SLI_REV3) {
759 /* Clear all interrupt enable conditions */
760 writel(0, phba->HCregaddr);
761 readl(phba->HCregaddr); /* flush */
762 /* Clear all pending interrupts */
763 writel(0xffffffff, phba->HAregaddr);
764 readl(phba->HAregaddr); /* flush */
765 }
James Smart84d1b002010-02-12 14:42:33 -0500766 phba->link_state = LPFC_HBA_ERROR;
James Smart6e7288d2010-06-07 15:23:35 -0400767 if (rc != MBX_BUSY || flag == MBX_POLL)
James Smart84d1b002010-02-12 14:42:33 -0500768 mempool_free(pmb, phba->mbox_mem_pool);
769 return -EIO;
770 }
James Smarte40a02c2010-02-26 14:13:54 -0500771 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
James Smart6e7288d2010-06-07 15:23:35 -0400772 if (flag == MBX_POLL)
773 mempool_free(pmb, phba->mbox_mem_pool);
James Smart84d1b002010-02-12 14:42:33 -0500774
775 return 0;
776}
777
778/**
779 * lpfc_hba_down_link - this routine downs the FC link
James Smart6e7288d2010-06-07 15:23:35 -0400780 * @phba: pointer to lpfc hba data structure.
781 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500782 *
783 * This routine will issue the DOWN_LINK mailbox command call.
784 * It is available to other drivers through the lpfc_hba data
785 * structure for use to stop the link.
786 *
787 * Return code
788 * 0 - success
789 * Any other value - error
790 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400791static int
James Smart6e7288d2010-06-07 15:23:35 -0400792lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500793{
794 LPFC_MBOXQ_t *pmb;
795 int rc;
796
797 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
798 if (!pmb) {
799 phba->link_state = LPFC_HBA_ERROR;
800 return -ENOMEM;
801 }
802
803 lpfc_printf_log(phba,
804 KERN_ERR, LOG_INIT,
805 "0491 Adapter Link is disabled.\n");
806 lpfc_down_link(phba, pmb);
807 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart6e7288d2010-06-07 15:23:35 -0400808 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart84d1b002010-02-12 14:42:33 -0500809 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
810 lpfc_printf_log(phba,
811 KERN_ERR, LOG_INIT,
812 "2522 Adapter failed to issue DOWN_LINK"
813 " mbox command rc 0x%x\n", rc);
814
815 mempool_free(pmb, phba->mbox_mem_pool);
816 return -EIO;
817 }
James Smart6e7288d2010-06-07 15:23:35 -0400818 if (flag == MBX_POLL)
819 mempool_free(pmb, phba->mbox_mem_pool);
820
James Smart84d1b002010-02-12 14:42:33 -0500821 return 0;
822}
823
824/**
James Smart3621a712009-04-06 18:47:14 -0400825 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400826 * @phba: pointer to lpfc HBA data structure.
827 *
828 * This routine will do LPFC uninitialization before the HBA is reset when
829 * bringing down the SLI Layer.
830 *
831 * Return codes
832 * 0 - success.
833 * Any other value - error.
834 **/
dea31012005-04-17 16:05:31 -0500835int
James Smart2e0fef82007-06-17 19:56:36 -0500836lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500837{
James Smart1b32f6a2008-02-08 18:49:39 -0500838 struct lpfc_vport **vports;
839 int i;
James Smart3772a992009-05-22 14:50:54 -0400840
841 if (phba->sli_rev <= LPFC_SLI_REV3) {
842 /* Disable interrupts */
843 writel(0, phba->HCregaddr);
844 readl(phba->HCregaddr); /* flush */
845 }
dea31012005-04-17 16:05:31 -0500846
James Smart1b32f6a2008-02-08 18:49:39 -0500847 if (phba->pport->load_flag & FC_UNLOADING)
848 lpfc_cleanup_discovery_resources(phba->pport);
849 else {
850 vports = lpfc_create_vport_work_array(phba);
851 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -0400852 for (i = 0; i <= phba->max_vports &&
853 vports[i] != NULL; i++)
James Smart1b32f6a2008-02-08 18:49:39 -0500854 lpfc_cleanup_discovery_resources(vports[i]);
855 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500856 }
857 return 0;
dea31012005-04-17 16:05:31 -0500858}
859
James Smarte59058c2008-08-24 21:49:00 -0400860/**
James Smart68e814f2014-05-21 08:04:59 -0400861 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
862 * rspiocb which got deferred
863 *
864 * @phba: pointer to lpfc HBA data structure.
865 *
866 * This routine will cleanup completed slow path events after HBA is reset
867 * when bringing down the SLI Layer.
868 *
869 *
870 * Return codes
871 * void.
872 **/
873static void
874lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
875{
876 struct lpfc_iocbq *rspiocbq;
877 struct hbq_dmabuf *dmabuf;
878 struct lpfc_cq_event *cq_event;
879
880 spin_lock_irq(&phba->hbalock);
881 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
882 spin_unlock_irq(&phba->hbalock);
883
884 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
885 /* Get the response iocb from the head of work queue */
886 spin_lock_irq(&phba->hbalock);
887 list_remove_head(&phba->sli4_hba.sp_queue_event,
888 cq_event, struct lpfc_cq_event, list);
889 spin_unlock_irq(&phba->hbalock);
890
891 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
892 case CQE_CODE_COMPL_WQE:
893 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
894 cq_event);
895 lpfc_sli_release_iocbq(phba, rspiocbq);
896 break;
897 case CQE_CODE_RECEIVE:
898 case CQE_CODE_RECEIVE_V1:
899 dmabuf = container_of(cq_event, struct hbq_dmabuf,
900 cq_event);
901 lpfc_in_buf_free(phba, &dmabuf->dbuf);
902 }
903 }
904}
905
906/**
James Smartbcece5f2014-04-04 13:51:34 -0400907 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
908 * @phba: pointer to lpfc HBA data structure.
909 *
910 * This routine will cleanup posted ELS buffers after the HBA is reset
911 * when bringing down the SLI Layer.
912 *
913 *
914 * Return codes
915 * void.
916 **/
917static void
918lpfc_hba_free_post_buf(struct lpfc_hba *phba)
919{
920 struct lpfc_sli *psli = &phba->sli;
921 struct lpfc_sli_ring *pring;
922 struct lpfc_dmabuf *mp, *next_mp;
James Smart07eab622014-04-04 13:51:44 -0400923 LIST_HEAD(buflist);
924 int count;
James Smartbcece5f2014-04-04 13:51:34 -0400925
926 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
927 lpfc_sli_hbqbuf_free_all(phba);
928 else {
929 /* Cleanup preposted buffers on the ELS ring */
James Smart895427b2017-02-12 13:52:30 -0800930 pring = &psli->sli3_ring[LPFC_ELS_RING];
James Smart07eab622014-04-04 13:51:44 -0400931 spin_lock_irq(&phba->hbalock);
932 list_splice_init(&pring->postbufq, &buflist);
933 spin_unlock_irq(&phba->hbalock);
934
935 count = 0;
936 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
James Smartbcece5f2014-04-04 13:51:34 -0400937 list_del(&mp->list);
James Smart07eab622014-04-04 13:51:44 -0400938 count++;
James Smartbcece5f2014-04-04 13:51:34 -0400939 lpfc_mbuf_free(phba, mp->virt, mp->phys);
940 kfree(mp);
941 }
James Smart07eab622014-04-04 13:51:44 -0400942
943 spin_lock_irq(&phba->hbalock);
944 pring->postbufq_cnt -= count;
James Smartbcece5f2014-04-04 13:51:34 -0400945 spin_unlock_irq(&phba->hbalock);
946 }
947}
948
949/**
950 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
951 * @phba: pointer to lpfc HBA data structure.
952 *
953 * This routine will cleanup the txcmplq after the HBA is reset when bringing
954 * down the SLI Layer.
955 *
956 * Return codes
957 * void
958 **/
959static void
960lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
961{
962 struct lpfc_sli *psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -0800963 struct lpfc_queue *qp = NULL;
James Smartbcece5f2014-04-04 13:51:34 -0400964 struct lpfc_sli_ring *pring;
965 LIST_HEAD(completions);
966 int i;
James Smartc1dd9112018-01-30 15:58:57 -0800967 struct lpfc_iocbq *piocb, *next_iocb;
James Smartbcece5f2014-04-04 13:51:34 -0400968
James Smart895427b2017-02-12 13:52:30 -0800969 if (phba->sli_rev != LPFC_SLI_REV4) {
970 for (i = 0; i < psli->num_rings; i++) {
971 pring = &psli->sli3_ring[i];
James Smartbcece5f2014-04-04 13:51:34 -0400972 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -0800973 /* At this point in time the HBA is either reset or DOA
974 * Nothing should be on txcmplq as it will
975 * NEVER complete.
976 */
977 list_splice_init(&pring->txcmplq, &completions);
978 pring->txcmplq_cnt = 0;
James Smartbcece5f2014-04-04 13:51:34 -0400979 spin_unlock_irq(&phba->hbalock);
980
James Smart895427b2017-02-12 13:52:30 -0800981 lpfc_sli_abort_iocb_ring(phba, pring);
982 }
James Smartbcece5f2014-04-04 13:51:34 -0400983 /* Cancel all the IOCBs from the completions list */
James Smart895427b2017-02-12 13:52:30 -0800984 lpfc_sli_cancel_iocbs(phba, &completions,
985 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
986 return;
987 }
988 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
989 pring = qp->pring;
990 if (!pring)
991 continue;
992 spin_lock_irq(&pring->ring_lock);
James Smartc1dd9112018-01-30 15:58:57 -0800993 list_for_each_entry_safe(piocb, next_iocb,
994 &pring->txcmplq, list)
995 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
James Smart895427b2017-02-12 13:52:30 -0800996 list_splice_init(&pring->txcmplq, &completions);
997 pring->txcmplq_cnt = 0;
998 spin_unlock_irq(&pring->ring_lock);
James Smartbcece5f2014-04-04 13:51:34 -0400999 lpfc_sli_abort_iocb_ring(phba, pring);
1000 }
James Smart895427b2017-02-12 13:52:30 -08001001 /* Cancel all the IOCBs from the completions list */
1002 lpfc_sli_cancel_iocbs(phba, &completions,
1003 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smartbcece5f2014-04-04 13:51:34 -04001004}
1005
1006/**
James Smart3772a992009-05-22 14:50:54 -04001007 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smartbcece5f2014-04-04 13:51:34 -04001008 int i;
James Smarte59058c2008-08-24 21:49:00 -04001009 * @phba: pointer to lpfc HBA data structure.
1010 *
1011 * This routine will do uninitialization after the HBA is reset when bring
1012 * down the SLI Layer.
1013 *
1014 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001015 * 0 - success.
James Smarte59058c2008-08-24 21:49:00 -04001016 * Any other value - error.
1017 **/
James Smart3772a992009-05-22 14:50:54 -04001018static int
1019lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001020{
James Smartbcece5f2014-04-04 13:51:34 -04001021 lpfc_hba_free_post_buf(phba);
1022 lpfc_hba_clean_txcmplq(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001023 return 0;
1024}
James Smart5af5eee2010-10-22 11:06:38 -04001025
James Smartda0436e2009-05-22 14:51:39 -04001026/**
1027 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
1028 * @phba: pointer to lpfc HBA data structure.
1029 *
1030 * This routine will do uninitialization after the HBA is reset when bring
1031 * down the SLI Layer.
1032 *
1033 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001034 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001035 * Any other value - error.
1036 **/
1037static int
1038lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1039{
1040 struct lpfc_scsi_buf *psb, *psb_next;
James Smart86c67372017-04-21 16:05:04 -07001041 struct lpfc_nvmet_rcv_ctx *ctxp, *ctxp_next;
James Smartda0436e2009-05-22 14:51:39 -04001042 LIST_HEAD(aborts);
James Smart895427b2017-02-12 13:52:30 -08001043 LIST_HEAD(nvme_aborts);
James Smart86c67372017-04-21 16:05:04 -07001044 LIST_HEAD(nvmet_aborts);
James Smartda0436e2009-05-22 14:51:39 -04001045 unsigned long iflag = 0;
James Smart0f65ff62010-02-26 14:14:23 -05001046 struct lpfc_sglq *sglq_entry = NULL;
James Smartcf1a1d32017-12-08 17:18:03 -08001047 int cnt;
James Smart0f65ff62010-02-26 14:14:23 -05001048
James Smart895427b2017-02-12 13:52:30 -08001049
1050 lpfc_sli_hbqbuf_free_all(phba);
James Smartbcece5f2014-04-04 13:51:34 -04001051 lpfc_hba_clean_txcmplq(phba);
1052
James Smartda0436e2009-05-22 14:51:39 -04001053 /* At this point in time the HBA is either reset or DOA. Either
1054 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
James Smart895427b2017-02-12 13:52:30 -08001055 * on the lpfc_els_sgl_list so that it can either be freed if the
James Smartda0436e2009-05-22 14:51:39 -04001056 * driver is unloading or reposted if the driver is restarting
1057 * the port.
1058 */
James Smart895427b2017-02-12 13:52:30 -08001059 spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */
James Smartda0436e2009-05-22 14:51:39 -04001060 /* scsl_buf_list */
James Smart895427b2017-02-12 13:52:30 -08001061 /* sgl_list_lock required because worker thread uses this
James Smartda0436e2009-05-22 14:51:39 -04001062 * list.
1063 */
James Smart895427b2017-02-12 13:52:30 -08001064 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05001065 list_for_each_entry(sglq_entry,
1066 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1067 sglq_entry->state = SGL_FREED;
1068
James Smartda0436e2009-05-22 14:51:39 -04001069 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
James Smart895427b2017-02-12 13:52:30 -08001070 &phba->sli4_hba.lpfc_els_sgl_list);
1071
James Smartf358dd02017-02-12 13:52:34 -08001072
James Smart895427b2017-02-12 13:52:30 -08001073 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04001074 /* abts_scsi_buf_list_lock required because worker thread uses this
1075 * list.
1076 */
James Smart895427b2017-02-12 13:52:30 -08001077 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
1078 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1079 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
1080 &aborts);
1081 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1082 }
1083
1084 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1085 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1086 list_splice_init(&phba->sli4_hba.lpfc_abts_nvme_buf_list,
1087 &nvme_aborts);
James Smart86c67372017-04-21 16:05:04 -07001088 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1089 &nvmet_aborts);
James Smart895427b2017-02-12 13:52:30 -08001090 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1091 }
1092
James Smartda0436e2009-05-22 14:51:39 -04001093 spin_unlock_irq(&phba->hbalock);
1094
1095 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1096 psb->pCmd = NULL;
1097 psb->status = IOSTAT_SUCCESS;
1098 }
James Smarta40fc5f2013-04-17 20:17:40 -04001099 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1100 list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
1101 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
James Smart68e814f2014-05-21 08:04:59 -04001102
James Smart86c67372017-04-21 16:05:04 -07001103 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smartcf1a1d32017-12-08 17:18:03 -08001104 cnt = 0;
James Smart86c67372017-04-21 16:05:04 -07001105 list_for_each_entry_safe(psb, psb_next, &nvme_aborts, list) {
1106 psb->pCmd = NULL;
1107 psb->status = IOSTAT_SUCCESS;
James Smartcf1a1d32017-12-08 17:18:03 -08001108 cnt++;
James Smart86c67372017-04-21 16:05:04 -07001109 }
1110 spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag);
James Smartcf1a1d32017-12-08 17:18:03 -08001111 phba->put_nvme_bufs += cnt;
James Smart86c67372017-04-21 16:05:04 -07001112 list_splice(&nvme_aborts, &phba->lpfc_nvme_buf_list_put);
1113 spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag);
1114
1115 list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) {
1116 ctxp->flag &= ~(LPFC_NVMET_XBUSY | LPFC_NVMET_ABORT_OP);
James Smart6c621a22017-05-15 15:20:45 -07001117 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
James Smart86c67372017-04-21 16:05:04 -07001118 }
James Smart895427b2017-02-12 13:52:30 -08001119 }
James Smart895427b2017-02-12 13:52:30 -08001120
James Smart68e814f2014-05-21 08:04:59 -04001121 lpfc_sli4_free_sp_events(phba);
James Smartda0436e2009-05-22 14:51:39 -04001122 return 0;
1123}
1124
1125/**
1126 * lpfc_hba_down_post - Wrapper func for hba down post routine
1127 * @phba: pointer to lpfc HBA data structure.
1128 *
1129 * This routine wraps the actual SLI3 or SLI4 routine for performing
1130 * uninitialization after the HBA is reset when bring down the SLI Layer.
1131 *
1132 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001133 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001134 * Any other value - error.
1135 **/
1136int
1137lpfc_hba_down_post(struct lpfc_hba *phba)
1138{
1139 return (*phba->lpfc_hba_down_post)(phba);
1140}
Jamie Wellnitz41415862006-02-28 19:25:27 -05001141
James Smarte59058c2008-08-24 21:49:00 -04001142/**
James Smart3621a712009-04-06 18:47:14 -04001143 * lpfc_hb_timeout - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001144 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1145 *
1146 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1147 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1148 * work-port-events bitmap and the worker thread is notified. This timeout
1149 * event will be used by the worker thread to invoke the actual timeout
1150 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1151 * be performed in the timeout handler and the HBA timeout event bit shall
1152 * be cleared by the worker thread after it has taken the event bitmap out.
1153 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001154static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07001155lpfc_hb_timeout(struct timer_list *t)
James Smart858c9f62007-06-17 19:56:39 -05001156{
1157 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001158 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -05001159 unsigned long iflag;
1160
Kees Cookf22eb4d2017-09-06 20:24:26 -07001161 phba = from_timer(phba, t, hb_tmofunc);
James Smart93996272008-08-24 21:50:30 -04001162
1163 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -05001164 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001165 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1166 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -05001167 phba->pport->work_port_events |= WORKER_HB_TMO;
1168 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1169
James Smart93996272008-08-24 21:50:30 -04001170 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -04001171 if (!tmo_posted)
1172 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -05001173 return;
1174}
1175
James Smarte59058c2008-08-24 21:49:00 -04001176/**
James Smart19ca7602010-11-20 23:11:55 -05001177 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1178 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1179 *
1180 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1181 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1182 * work-port-events bitmap and the worker thread is notified. This timeout
1183 * event will be used by the worker thread to invoke the actual timeout
1184 * handler routine, lpfc_rrq_handler. Any periodical operations will
1185 * be performed in the timeout handler and the RRQ timeout event bit shall
1186 * be cleared by the worker thread after it has taken the event bitmap out.
1187 **/
1188static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07001189lpfc_rrq_timeout(struct timer_list *t)
James Smart19ca7602010-11-20 23:11:55 -05001190{
1191 struct lpfc_hba *phba;
James Smart19ca7602010-11-20 23:11:55 -05001192 unsigned long iflag;
1193
Kees Cookf22eb4d2017-09-06 20:24:26 -07001194 phba = from_timer(phba, t, rrq_tmr);
James Smart19ca7602010-11-20 23:11:55 -05001195 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001196 if (!(phba->pport->load_flag & FC_UNLOADING))
1197 phba->hba_flag |= HBA_RRQ_ACTIVE;
1198 else
1199 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
James Smart19ca7602010-11-20 23:11:55 -05001200 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001201
1202 if (!(phba->pport->load_flag & FC_UNLOADING))
1203 lpfc_worker_wake_up(phba);
James Smart19ca7602010-11-20 23:11:55 -05001204}
1205
1206/**
James Smart3621a712009-04-06 18:47:14 -04001207 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -04001208 * @phba: pointer to lpfc hba data structure.
1209 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1210 *
1211 * This is the callback function to the lpfc heart-beat mailbox command.
1212 * If configured, the lpfc driver issues the heart-beat mailbox command to
1213 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1214 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1215 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1216 * heart-beat outstanding state. Once the mailbox command comes back and
1217 * no error conditions detected, the heart-beat mailbox command timer is
1218 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1219 * state is cleared for the next heart-beat. If the timer expired with the
1220 * heart-beat outstanding state set, the driver will put the HBA offline.
1221 **/
James Smart858c9f62007-06-17 19:56:39 -05001222static void
1223lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1224{
1225 unsigned long drvr_flag;
1226
1227 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1228 phba->hb_outstanding = 0;
1229 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1230
James Smart93996272008-08-24 21:50:30 -04001231 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -05001232 mempool_free(pmboxq, phba->mbox_mem_pool);
1233 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1234 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -04001235 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -05001236 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001237 jiffies +
1238 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001239 return;
1240}
1241
James Smarte59058c2008-08-24 21:49:00 -04001242/**
James Smart3621a712009-04-06 18:47:14 -04001243 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001244 * @phba: pointer to lpfc hba data structure.
1245 *
1246 * This is the actual HBA-timer timeout handler to be invoked by the worker
1247 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1248 * handler performs any periodic operations needed for the device. If such
1249 * periodic event has already been attended to either in the interrupt handler
1250 * or by processing slow-ring or fast-ring events within the HBA-timer
1251 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1252 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1253 * is configured and there is no heart-beat mailbox command outstanding, a
1254 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1255 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1256 * to offline.
1257 **/
James Smart858c9f62007-06-17 19:56:39 -05001258void
1259lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1260{
James Smart45ed1192009-10-02 15:17:02 -04001261 struct lpfc_vport **vports;
James Smart858c9f62007-06-17 19:56:39 -05001262 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -05001263 struct lpfc_dmabuf *buf_ptr;
James Smart45ed1192009-10-02 15:17:02 -04001264 int retval, i;
James Smart858c9f62007-06-17 19:56:39 -05001265 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -05001266 LIST_HEAD(completions);
James Smart0cf07f842017-06-01 21:07:10 -07001267 struct lpfc_queue *qp;
1268 unsigned long time_elapsed;
1269 uint32_t tick_cqe, max_cqe, val;
1270 uint64_t tot, data1, data2, data3;
Dick Kennedy66d7ce92017-08-23 16:55:42 -07001271 struct lpfc_nvmet_tgtport *tgtp;
James Smart0cf07f842017-06-01 21:07:10 -07001272 struct lpfc_register reg_data;
James Smart66a210f2018-04-09 14:24:23 -07001273 struct nvme_fc_local_port *localport;
1274 struct lpfc_nvme_lport *lport;
1275 struct lpfc_nvme_ctrl_stat *cstat;
James Smart0cf07f842017-06-01 21:07:10 -07001276 void __iomem *eqdreg = phba->sli4_hba.u.if_type2.EQDregaddr;
James Smart858c9f62007-06-17 19:56:39 -05001277
James Smart45ed1192009-10-02 15:17:02 -04001278 vports = lpfc_create_vport_work_array(phba);
1279 if (vports != NULL)
James Smart4258e982015-12-16 18:11:58 -05001280 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart45ed1192009-10-02 15:17:02 -04001281 lpfc_rcv_seq_check_edtov(vports[i]);
James Smart4258e982015-12-16 18:11:58 -05001282 lpfc_fdmi_num_disc_check(vports[i]);
1283 }
James Smart45ed1192009-10-02 15:17:02 -04001284 lpfc_destroy_vport_work_array(phba, vports);
1285
James Smart858c9f62007-06-17 19:56:39 -05001286 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -04001287 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -05001288 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1289 return;
1290
James Smart0cf07f842017-06-01 21:07:10 -07001291 if (phba->cfg_auto_imax) {
1292 if (!phba->last_eqdelay_time) {
1293 phba->last_eqdelay_time = jiffies;
1294 goto skip_eqdelay;
1295 }
1296 time_elapsed = jiffies - phba->last_eqdelay_time;
1297 phba->last_eqdelay_time = jiffies;
1298
1299 tot = 0xffff;
1300 /* Check outstanding IO count */
1301 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1302 if (phba->nvmet_support) {
Dick Kennedy66d7ce92017-08-23 16:55:42 -07001303 tgtp = phba->targetport->private;
1304 /* Calculate outstanding IOs */
1305 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
1306 tot += atomic_read(&tgtp->xmt_fcp_release);
1307 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
James Smart0cf07f842017-06-01 21:07:10 -07001308 } else {
James Smart66a210f2018-04-09 14:24:23 -07001309 localport = phba->pport->localport;
1310 if (!localport || !localport->private)
1311 goto skip_eqdelay;
1312 lport = (struct lpfc_nvme_lport *)
1313 localport->private;
1314 tot = 0;
1315 for (i = 0;
1316 i < phba->cfg_nvme_io_channel; i++) {
1317 cstat = &lport->cstat[i];
1318 data1 = atomic_read(
1319 &cstat->fc4NvmeInputRequests);
1320 data2 = atomic_read(
1321 &cstat->fc4NvmeOutputRequests);
1322 data3 = atomic_read(
1323 &cstat->fc4NvmeControlRequests);
1324 tot += (data1 + data2 + data3);
1325 tot -= atomic_read(
1326 &cstat->fc4NvmeIoCmpls);
1327 }
James Smart0cf07f842017-06-01 21:07:10 -07001328 }
1329 }
1330
1331 /* Interrupts per sec per EQ */
1332 val = phba->cfg_fcp_imax / phba->io_channel_irqs;
1333 tick_cqe = val / CONFIG_HZ; /* Per tick per EQ */
1334
1335 /* Assume 1 CQE/ISR, calc max CQEs allowed for time duration */
1336 max_cqe = time_elapsed * tick_cqe;
1337
1338 for (i = 0; i < phba->io_channel_irqs; i++) {
1339 /* Fast-path EQ */
1340 qp = phba->sli4_hba.hba_eq[i];
1341 if (!qp)
1342 continue;
1343
1344 /* Use no EQ delay if we don't have many outstanding
1345 * IOs, or if we are only processing 1 CQE/ISR or less.
1346 * Otherwise, assume we can process up to lpfc_fcp_imax
1347 * interrupts per HBA.
1348 */
1349 if (tot < LPFC_NODELAY_MAX_IO ||
1350 qp->EQ_cqe_cnt <= max_cqe)
1351 val = 0;
1352 else
1353 val = phba->cfg_fcp_imax;
1354
1355 if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) {
1356 /* Use EQ Delay Register method */
1357
1358 /* Convert for EQ Delay register */
1359 if (val) {
1360 /* First, interrupts per sec per EQ */
1361 val = phba->cfg_fcp_imax /
1362 phba->io_channel_irqs;
1363
1364 /* us delay between each interrupt */
1365 val = LPFC_SEC_TO_USEC / val;
1366 }
1367 if (val != qp->q_mode) {
1368 reg_data.word0 = 0;
1369 bf_set(lpfc_sliport_eqdelay_id,
1370 &reg_data, qp->queue_id);
1371 bf_set(lpfc_sliport_eqdelay_delay,
1372 &reg_data, val);
1373 writel(reg_data.word0, eqdreg);
1374 }
1375 } else {
1376 /* Use mbox command method */
1377 if (val != qp->q_mode)
1378 lpfc_modify_hba_eq_delay(phba, i,
1379 1, val);
1380 }
1381
1382 /*
1383 * val is cfg_fcp_imax or 0 for mbox delay or us delay
1384 * between interrupts for EQDR.
1385 */
1386 qp->q_mode = val;
1387 qp->EQ_cqe_cnt = 0;
1388 }
1389 }
1390
1391skip_eqdelay:
James Smart858c9f62007-06-17 19:56:39 -05001392 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -05001393
James Smart256ec0d2013-04-17 20:14:58 -04001394 if (time_after(phba->last_completion_time +
1395 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1396 jiffies)) {
James Smart858c9f62007-06-17 19:56:39 -05001397 spin_unlock_irq(&phba->pport->work_port_lock);
1398 if (!phba->hb_outstanding)
1399 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001400 jiffies +
1401 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001402 else
1403 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001404 jiffies +
1405 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001406 return;
1407 }
1408 spin_unlock_irq(&phba->pport->work_port_lock);
1409
James Smart0ff10d42008-01-11 01:52:36 -05001410 if (phba->elsbuf_cnt &&
1411 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1412 spin_lock_irq(&phba->hbalock);
1413 list_splice_init(&phba->elsbuf, &completions);
1414 phba->elsbuf_cnt = 0;
1415 phba->elsbuf_prev_cnt = 0;
1416 spin_unlock_irq(&phba->hbalock);
1417
1418 while (!list_empty(&completions)) {
1419 list_remove_head(&completions, buf_ptr,
1420 struct lpfc_dmabuf, list);
1421 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1422 kfree(buf_ptr);
1423 }
1424 }
1425 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1426
James Smart858c9f62007-06-17 19:56:39 -05001427 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -05001428 if (phba->cfg_enable_hba_heartbeat) {
1429 if (!phba->hb_outstanding) {
James Smartbc739052010-08-04 16:11:18 -04001430 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1431 (list_empty(&psli->mboxq))) {
1432 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1433 GFP_KERNEL);
1434 if (!pmboxq) {
1435 mod_timer(&phba->hb_tmofunc,
1436 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001437 msecs_to_jiffies(1000 *
1438 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001439 return;
1440 }
James Smart13815c82008-01-11 01:52:48 -05001441
James Smartbc739052010-08-04 16:11:18 -04001442 lpfc_heart_beat(phba, pmboxq);
1443 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1444 pmboxq->vport = phba->pport;
1445 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1446 MBX_NOWAIT);
James Smart13815c82008-01-11 01:52:48 -05001447
James Smartbc739052010-08-04 16:11:18 -04001448 if (retval != MBX_BUSY &&
1449 retval != MBX_SUCCESS) {
1450 mempool_free(pmboxq,
1451 phba->mbox_mem_pool);
1452 mod_timer(&phba->hb_tmofunc,
1453 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001454 msecs_to_jiffies(1000 *
1455 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001456 return;
1457 }
1458 phba->skipped_hb = 0;
1459 phba->hb_outstanding = 1;
1460 } else if (time_before_eq(phba->last_completion_time,
1461 phba->skipped_hb)) {
1462 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1463 "2857 Last completion time not "
1464 " updated in %d ms\n",
1465 jiffies_to_msecs(jiffies
1466 - phba->last_completion_time));
1467 } else
1468 phba->skipped_hb = jiffies;
1469
James Smart858c9f62007-06-17 19:56:39 -05001470 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001471 jiffies +
1472 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001473 return;
James Smart13815c82008-01-11 01:52:48 -05001474 } else {
1475 /*
1476 * If heart beat timeout called with hb_outstanding set
James Smartdcf2a4e2010-09-29 11:18:53 -04001477 * we need to give the hb mailbox cmd a chance to
1478 * complete or TMO.
James Smart13815c82008-01-11 01:52:48 -05001479 */
James Smartdcf2a4e2010-09-29 11:18:53 -04001480 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1481 "0459 Adapter heartbeat still out"
1482 "standing:last compl time was %d ms.\n",
1483 jiffies_to_msecs(jiffies
1484 - phba->last_completion_time));
1485 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001486 jiffies +
1487 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001488 }
James Smart4258e982015-12-16 18:11:58 -05001489 } else {
1490 mod_timer(&phba->hb_tmofunc,
1491 jiffies +
1492 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001493 }
1494}
1495
James Smarte59058c2008-08-24 21:49:00 -04001496/**
James Smart3621a712009-04-06 18:47:14 -04001497 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -04001498 * @phba: pointer to lpfc hba data structure.
1499 *
1500 * This routine is called to bring the HBA offline when HBA hardware error
1501 * other than Port Error 6 has been detected.
1502 **/
James Smart09372822008-01-11 01:52:54 -05001503static void
1504lpfc_offline_eratt(struct lpfc_hba *phba)
1505{
1506 struct lpfc_sli *psli = &phba->sli;
1507
1508 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001509 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -05001510 spin_unlock_irq(&phba->hbalock);
James Smart618a5232012-06-12 13:54:36 -04001511 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart09372822008-01-11 01:52:54 -05001512
1513 lpfc_offline(phba);
1514 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001515 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001516 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001517 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001518 lpfc_hba_down_post(phba);
1519 lpfc_sli_brdready(phba, HS_MBRDY);
1520 lpfc_unblock_mgmt_io(phba);
1521 phba->link_state = LPFC_HBA_ERROR;
1522 return;
1523}
1524
James Smarte59058c2008-08-24 21:49:00 -04001525/**
James Smartda0436e2009-05-22 14:51:39 -04001526 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1527 * @phba: pointer to lpfc hba data structure.
1528 *
1529 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1530 * other than Port Error 6 has been detected.
1531 **/
James Smarta88dbb62013-04-17 20:18:39 -04001532void
James Smartda0436e2009-05-22 14:51:39 -04001533lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1534{
James Smart946727d2015-04-07 15:07:09 -04001535 spin_lock_irq(&phba->hbalock);
1536 phba->link_state = LPFC_HBA_ERROR;
1537 spin_unlock_irq(&phba->hbalock);
1538
James Smart618a5232012-06-12 13:54:36 -04001539 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smartda0436e2009-05-22 14:51:39 -04001540 lpfc_offline(phba);
James Smartda0436e2009-05-22 14:51:39 -04001541 lpfc_hba_down_post(phba);
James Smartda0436e2009-05-22 14:51:39 -04001542 lpfc_unblock_mgmt_io(phba);
James Smartda0436e2009-05-22 14:51:39 -04001543}
1544
1545/**
James Smarta257bf92009-04-06 18:48:10 -04001546 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1547 * @phba: pointer to lpfc hba data structure.
1548 *
1549 * This routine is invoked to handle the deferred HBA hardware error
1550 * conditions. This type of error is indicated by HBA by setting ER1
1551 * and another ER bit in the host status register. The driver will
1552 * wait until the ER1 bit clears before handling the error condition.
1553 **/
1554static void
1555lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1556{
1557 uint32_t old_host_status = phba->work_hs;
James Smarta257bf92009-04-06 18:48:10 -04001558 struct lpfc_sli *psli = &phba->sli;
1559
James Smartf4b4c682009-05-22 14:53:12 -04001560 /* If the pci channel is offline, ignore possible errors,
1561 * since we cannot communicate with the pci card anyway.
1562 */
1563 if (pci_channel_offline(phba->pcidev)) {
1564 spin_lock_irq(&phba->hbalock);
1565 phba->hba_flag &= ~DEFER_ERATT;
1566 spin_unlock_irq(&phba->hbalock);
1567 return;
1568 }
1569
James Smarta257bf92009-04-06 18:48:10 -04001570 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1571 "0479 Deferred Adapter Hardware Error "
1572 "Data: x%x x%x x%x\n",
1573 phba->work_hs,
1574 phba->work_status[0], phba->work_status[1]);
1575
1576 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001577 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001578 spin_unlock_irq(&phba->hbalock);
1579
1580
1581 /*
1582 * Firmware stops when it triggred erratt. That could cause the I/Os
1583 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1584 * SCSI layer retry it after re-establishing link.
1585 */
James Smartdb55fba2014-04-04 13:52:02 -04001586 lpfc_sli_abort_fcp_rings(phba);
James Smarta257bf92009-04-06 18:48:10 -04001587
1588 /*
1589 * There was a firmware error. Take the hba offline and then
1590 * attempt to restart it.
1591 */
James Smart618a5232012-06-12 13:54:36 -04001592 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smarta257bf92009-04-06 18:48:10 -04001593 lpfc_offline(phba);
1594
1595 /* Wait for the ER1 bit to clear.*/
1596 while (phba->work_hs & HS_FFER1) {
1597 msleep(100);
James Smart9940b972011-03-11 16:06:12 -05001598 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1599 phba->work_hs = UNPLUG_ERR ;
1600 break;
1601 }
James Smarta257bf92009-04-06 18:48:10 -04001602 /* If driver is unloading let the worker thread continue */
1603 if (phba->pport->load_flag & FC_UNLOADING) {
1604 phba->work_hs = 0;
1605 break;
1606 }
1607 }
1608
1609 /*
1610 * This is to ptrotect against a race condition in which
1611 * first write to the host attention register clear the
1612 * host status register.
1613 */
1614 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1615 phba->work_hs = old_host_status & ~HS_FFER1;
1616
James Smart3772a992009-05-22 14:50:54 -04001617 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001618 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001619 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001620 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1621 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1622}
1623
James Smart3772a992009-05-22 14:50:54 -04001624static void
1625lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1626{
1627 struct lpfc_board_event_header board_event;
1628 struct Scsi_Host *shost;
1629
1630 board_event.event_type = FC_REG_BOARD_EVENT;
1631 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1632 shost = lpfc_shost_from_vport(phba->pport);
1633 fc_host_post_vendor_event(shost, fc_get_event_number(),
1634 sizeof(board_event),
1635 (char *) &board_event,
1636 LPFC_NL_VENDOR_ID);
1637}
1638
James Smarta257bf92009-04-06 18:48:10 -04001639/**
James Smart3772a992009-05-22 14:50:54 -04001640 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001641 * @phba: pointer to lpfc hba data structure.
1642 *
1643 * This routine is invoked to handle the following HBA hardware error
1644 * conditions:
1645 * 1 - HBA error attention interrupt
1646 * 2 - DMA ring index out of range
1647 * 3 - Mailbox command came back as unknown
1648 **/
James Smart3772a992009-05-22 14:50:54 -04001649static void
1650lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001651{
James Smart2e0fef82007-06-17 19:56:36 -05001652 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001653 struct lpfc_sli *psli = &phba->sli;
James Smartd2873e42006-08-18 17:46:43 -04001654 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001655 unsigned long temperature;
1656 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001657 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001658
Linas Vepstas8d63f372007-02-14 14:28:36 -06001659 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001660 * since we cannot communicate with the pci card anyway.
1661 */
1662 if (pci_channel_offline(phba->pcidev)) {
1663 spin_lock_irq(&phba->hbalock);
1664 phba->hba_flag &= ~DEFER_ERATT;
1665 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001666 return;
James Smart3772a992009-05-22 14:50:54 -04001667 }
1668
James Smart13815c82008-01-11 01:52:48 -05001669 /* If resets are disabled then leave the HBA alone and return */
1670 if (!phba->cfg_enable_hba_reset)
1671 return;
dea31012005-04-17 16:05:31 -05001672
James Smartea2151b2008-09-07 11:52:10 -04001673 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001674 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001675
James Smarta257bf92009-04-06 18:48:10 -04001676 if (phba->hba_flag & DEFER_ERATT)
1677 lpfc_handle_deferred_eratt(phba);
1678
James Smartdcf2a4e2010-09-29 11:18:53 -04001679 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1680 if (phba->work_hs & HS_FFER6)
1681 /* Re-establishing Link */
1682 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1683 "1301 Re-establishing Link "
1684 "Data: x%x x%x x%x\n",
1685 phba->work_hs, phba->work_status[0],
1686 phba->work_status[1]);
1687 if (phba->work_hs & HS_FFER8)
1688 /* Device Zeroization */
1689 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1690 "2861 Host Authentication device "
1691 "zeroization Data:x%x x%x x%x\n",
1692 phba->work_hs, phba->work_status[0],
1693 phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001694
James Smart92d7f7b2007-06-17 19:56:38 -05001695 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001696 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001697 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001698
1699 /*
1700 * Firmware stops when it triggled erratt with HS_FFER6.
1701 * That could cause the I/Os dropped by the firmware.
1702 * Error iocb (I/O) on txcmplq and let the SCSI layer
1703 * retry it after re-establishing link.
1704 */
James Smartdb55fba2014-04-04 13:52:02 -04001705 lpfc_sli_abort_fcp_rings(phba);
dea31012005-04-17 16:05:31 -05001706
dea31012005-04-17 16:05:31 -05001707 /*
1708 * There was a firmware error. Take the hba offline and then
1709 * attempt to restart it.
1710 */
James Smart618a5232012-06-12 13:54:36 -04001711 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
dea31012005-04-17 16:05:31 -05001712 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001713 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001714 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001715 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001716 return;
1717 }
James Smart46fa3112007-04-25 09:51:45 -04001718 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001719 } else if (phba->work_hs & HS_CRIT_TEMP) {
1720 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1721 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1722 temp_event_data.event_code = LPFC_CRIT_TEMP;
1723 temp_event_data.data = (uint32_t)temperature;
1724
1725 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001726 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001727 "(%ld), taking this port offline "
1728 "Data: x%x x%x x%x\n",
1729 temperature, phba->work_hs,
1730 phba->work_status[0], phba->work_status[1]);
1731
1732 shost = lpfc_shost_from_vport(phba->pport);
1733 fc_host_post_vendor_event(shost, fc_get_event_number(),
1734 sizeof(temp_event_data),
1735 (char *) &temp_event_data,
1736 SCSI_NL_VID_TYPE_PCI
1737 | PCI_VENDOR_ID_EMULEX);
1738
James Smart7af67052007-10-27 13:38:11 -04001739 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001740 phba->over_temp_state = HBA_OVER_TEMP;
1741 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001742 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001743
dea31012005-04-17 16:05:31 -05001744 } else {
1745 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001746 * failure is a value other than FFER6. Do not call the offline
1747 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001748 */
1749 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001750 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001751 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001752 phba->work_hs,
dea31012005-04-17 16:05:31 -05001753 phba->work_status[0], phba->work_status[1]);
1754
James Smartd2873e42006-08-18 17:46:43 -04001755 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001756 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001757 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001758 sizeof(event_data), (char *) &event_data,
1759 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1760
James Smart09372822008-01-11 01:52:54 -05001761 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001762 }
James Smart93996272008-08-24 21:50:30 -04001763 return;
dea31012005-04-17 16:05:31 -05001764}
1765
James Smarte59058c2008-08-24 21:49:00 -04001766/**
James Smart618a5232012-06-12 13:54:36 -04001767 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1768 * @phba: pointer to lpfc hba data structure.
1769 * @mbx_action: flag for mailbox shutdown action.
1770 *
1771 * This routine is invoked to perform an SLI4 port PCI function reset in
1772 * response to port status register polling attention. It waits for port
1773 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1774 * During this process, interrupt vectors are freed and later requested
1775 * for handling possible port resource change.
1776 **/
1777static int
James Smarte10b2022014-02-20 09:57:43 -05001778lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1779 bool en_rn_msg)
James Smart618a5232012-06-12 13:54:36 -04001780{
1781 int rc;
1782 uint32_t intr_mode;
1783
James Smart27d6ac02018-02-22 08:18:42 -08001784 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
James Smart65791f12016-07-06 12:35:56 -07001785 LPFC_SLI_INTF_IF_TYPE_2) {
1786 /*
1787 * On error status condition, driver need to wait for port
1788 * ready before performing reset.
1789 */
1790 rc = lpfc_sli4_pdev_status_reg_wait(phba);
James Smart0e916ee2016-07-06 12:36:06 -07001791 if (rc)
James Smart65791f12016-07-06 12:35:56 -07001792 return rc;
James Smart618a5232012-06-12 13:54:36 -04001793 }
James Smart0e916ee2016-07-06 12:36:06 -07001794
James Smart65791f12016-07-06 12:35:56 -07001795 /* need reset: attempt for port recovery */
1796 if (en_rn_msg)
1797 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1798 "2887 Reset Needed: Attempting Port "
1799 "Recovery...\n");
1800 lpfc_offline_prep(phba, mbx_action);
1801 lpfc_offline(phba);
1802 /* release interrupt for possible resource change */
1803 lpfc_sli4_disable_intr(phba);
1804 lpfc_sli_brdrestart(phba);
1805 /* request and enable interrupt */
1806 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1807 if (intr_mode == LPFC_INTR_ERROR) {
1808 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1809 "3175 Failed to enable interrupt\n");
1810 return -EIO;
1811 }
1812 phba->intr_mode = intr_mode;
1813 rc = lpfc_online(phba);
1814 if (rc == 0)
1815 lpfc_unblock_mgmt_io(phba);
1816
James Smart618a5232012-06-12 13:54:36 -04001817 return rc;
1818}
1819
1820/**
James Smartda0436e2009-05-22 14:51:39 -04001821 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1822 * @phba: pointer to lpfc hba data structure.
1823 *
1824 * This routine is invoked to handle the SLI4 HBA hardware error attention
1825 * conditions.
1826 **/
1827static void
1828lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1829{
1830 struct lpfc_vport *vport = phba->pport;
1831 uint32_t event_data;
1832 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001833 uint32_t if_type;
James Smart2e90f4b2011-12-13 13:22:37 -05001834 struct lpfc_register portstat_reg = {0};
1835 uint32_t reg_err1, reg_err2;
1836 uint32_t uerrlo_reg, uemasklo_reg;
James Smart65791f12016-07-06 12:35:56 -07001837 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
James Smarte10b2022014-02-20 09:57:43 -05001838 bool en_rn_msg = true;
James Smart946727d2015-04-07 15:07:09 -04001839 struct temp_event temp_event_data;
James Smart65791f12016-07-06 12:35:56 -07001840 struct lpfc_register portsmphr_reg;
1841 int rc, i;
James Smartda0436e2009-05-22 14:51:39 -04001842
1843 /* If the pci channel is offline, ignore possible errors, since
1844 * we cannot communicate with the pci card anyway.
1845 */
1846 if (pci_channel_offline(phba->pcidev))
1847 return;
James Smartda0436e2009-05-22 14:51:39 -04001848
James Smart65791f12016-07-06 12:35:56 -07001849 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
James Smart2fcee4b2010-12-15 17:57:46 -05001850 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1851 switch (if_type) {
1852 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart2e90f4b2011-12-13 13:22:37 -05001853 pci_rd_rc1 = lpfc_readl(
1854 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1855 &uerrlo_reg);
1856 pci_rd_rc2 = lpfc_readl(
1857 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1858 &uemasklo_reg);
1859 /* consider PCI bus read error as pci_channel_offline */
1860 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1861 return;
James Smart65791f12016-07-06 12:35:56 -07001862 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
1863 lpfc_sli4_offline_eratt(phba);
1864 return;
1865 }
1866 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1867 "7623 Checking UE recoverable");
1868
1869 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
1870 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1871 &portsmphr_reg.word0))
1872 continue;
1873
1874 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
1875 &portsmphr_reg);
1876 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1877 LPFC_PORT_SEM_UE_RECOVERABLE)
1878 break;
1879 /*Sleep for 1Sec, before checking SEMAPHORE */
1880 msleep(1000);
1881 }
1882
1883 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1884 "4827 smphr_port_status x%x : Waited %dSec",
1885 smphr_port_status, i);
1886
1887 /* Recoverable UE, reset the HBA device */
1888 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1889 LPFC_PORT_SEM_UE_RECOVERABLE) {
1890 for (i = 0; i < 20; i++) {
1891 msleep(1000);
1892 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1893 &portsmphr_reg.word0) &&
1894 (LPFC_POST_STAGE_PORT_READY ==
1895 bf_get(lpfc_port_smphr_port_status,
1896 &portsmphr_reg))) {
1897 rc = lpfc_sli4_port_sta_fn_reset(phba,
1898 LPFC_MBX_NO_WAIT, en_rn_msg);
1899 if (rc == 0)
1900 return;
1901 lpfc_printf_log(phba,
1902 KERN_ERR, LOG_INIT,
1903 "4215 Failed to recover UE");
1904 break;
1905 }
1906 }
1907 }
1908 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1909 "7624 Firmware not ready: Failing UE recovery,"
1910 " waited %dSec", i);
James Smart2fcee4b2010-12-15 17:57:46 -05001911 lpfc_sli4_offline_eratt(phba);
1912 break;
James Smart946727d2015-04-07 15:07:09 -04001913
James Smart2fcee4b2010-12-15 17:57:46 -05001914 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08001915 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2e90f4b2011-12-13 13:22:37 -05001916 pci_rd_rc1 = lpfc_readl(
1917 phba->sli4_hba.u.if_type2.STATUSregaddr,
1918 &portstat_reg.word0);
1919 /* consider PCI bus read error as pci_channel_offline */
James Smart6b5151f2012-01-18 16:24:06 -05001920 if (pci_rd_rc1 == -EIO) {
1921 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1922 "3151 PCI bus read access failure: x%x\n",
1923 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
James Smart2e90f4b2011-12-13 13:22:37 -05001924 return;
James Smart6b5151f2012-01-18 16:24:06 -05001925 }
James Smart2e90f4b2011-12-13 13:22:37 -05001926 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1927 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
James Smart2fcee4b2010-12-15 17:57:46 -05001928 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
James Smart2fcee4b2010-12-15 17:57:46 -05001929 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1930 "2889 Port Overtemperature event, "
James Smart946727d2015-04-07 15:07:09 -04001931 "taking port offline Data: x%x x%x\n",
1932 reg_err1, reg_err2);
1933
James Smart310429e2016-07-06 12:35:54 -07001934 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04001935 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1936 temp_event_data.event_code = LPFC_CRIT_TEMP;
1937 temp_event_data.data = 0xFFFFFFFF;
1938
1939 shost = lpfc_shost_from_vport(phba->pport);
1940 fc_host_post_vendor_event(shost, fc_get_event_number(),
1941 sizeof(temp_event_data),
1942 (char *)&temp_event_data,
1943 SCSI_NL_VID_TYPE_PCI
1944 | PCI_VENDOR_ID_EMULEX);
1945
James Smart2fcee4b2010-12-15 17:57:46 -05001946 spin_lock_irq(&phba->hbalock);
1947 phba->over_temp_state = HBA_OVER_TEMP;
1948 spin_unlock_irq(&phba->hbalock);
1949 lpfc_sli4_offline_eratt(phba);
James Smart946727d2015-04-07 15:07:09 -04001950 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001951 }
James Smart2e90f4b2011-12-13 13:22:37 -05001952 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smarte10b2022014-02-20 09:57:43 -05001953 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
James Smart2e90f4b2011-12-13 13:22:37 -05001954 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte10b2022014-02-20 09:57:43 -05001955 "3143 Port Down: Firmware Update "
1956 "Detected\n");
1957 en_rn_msg = false;
1958 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smart2e90f4b2011-12-13 13:22:37 -05001959 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1960 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1961 "3144 Port Down: Debug Dump\n");
1962 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1963 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1964 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1965 "3145 Port Down: Provisioning\n");
James Smart618a5232012-06-12 13:54:36 -04001966
James Smart946727d2015-04-07 15:07:09 -04001967 /* If resets are disabled then leave the HBA alone and return */
1968 if (!phba->cfg_enable_hba_reset)
1969 return;
1970
James Smart618a5232012-06-12 13:54:36 -04001971 /* Check port status register for function reset */
James Smarte10b2022014-02-20 09:57:43 -05001972 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1973 en_rn_msg);
James Smart618a5232012-06-12 13:54:36 -04001974 if (rc == 0) {
1975 /* don't report event on forced debug dump */
1976 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1977 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1978 return;
1979 else
1980 break;
James Smart2fcee4b2010-12-15 17:57:46 -05001981 }
James Smart618a5232012-06-12 13:54:36 -04001982 /* fall through for not able to recover */
James Smart6b5151f2012-01-18 16:24:06 -05001983 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1984 "3152 Unrecoverable error, bring the port "
1985 "offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05001986 lpfc_sli4_offline_eratt(phba);
1987 break;
1988 case LPFC_SLI_INTF_IF_TYPE_1:
1989 default:
1990 break;
1991 }
James Smart2e90f4b2011-12-13 13:22:37 -05001992 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1993 "3123 Report dump event to upper layer\n");
1994 /* Send an internal error event to mgmt application */
1995 lpfc_board_errevt_to_mgmt(phba);
1996
1997 event_data = FC_REG_DUMP_EVENT;
1998 shost = lpfc_shost_from_vport(vport);
1999 fc_host_post_vendor_event(shost, fc_get_event_number(),
2000 sizeof(event_data), (char *) &event_data,
2001 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
James Smartda0436e2009-05-22 14:51:39 -04002002}
2003
2004/**
2005 * lpfc_handle_eratt - Wrapper func for handling hba error attention
2006 * @phba: pointer to lpfc HBA data structure.
2007 *
2008 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
2009 * routine from the API jump table function pointer from the lpfc_hba struct.
2010 *
2011 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02002012 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04002013 * Any other value - error.
2014 **/
2015void
2016lpfc_handle_eratt(struct lpfc_hba *phba)
2017{
2018 (*phba->lpfc_handle_eratt)(phba);
2019}
2020
2021/**
James Smart3621a712009-04-06 18:47:14 -04002022 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04002023 * @phba: pointer to lpfc hba data structure.
2024 *
2025 * This routine is invoked from the worker thread to handle a HBA host
James Smart895427b2017-02-12 13:52:30 -08002026 * attention link event. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002027 **/
dea31012005-04-17 16:05:31 -05002028void
James Smart2e0fef82007-06-17 19:56:36 -05002029lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002030{
James Smart2e0fef82007-06-17 19:56:36 -05002031 struct lpfc_vport *vport = phba->pport;
2032 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05002033 LPFC_MBOXQ_t *pmb;
2034 volatile uint32_t control;
2035 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05002036 int rc = 0;
dea31012005-04-17 16:05:31 -05002037
2038 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05002039 if (!pmb) {
2040 rc = 1;
dea31012005-04-17 16:05:31 -05002041 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05002042 }
dea31012005-04-17 16:05:31 -05002043
2044 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05002045 if (!mp) {
2046 rc = 2;
dea31012005-04-17 16:05:31 -05002047 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05002048 }
dea31012005-04-17 16:05:31 -05002049
2050 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05002051 if (!mp->virt) {
2052 rc = 3;
dea31012005-04-17 16:05:31 -05002053 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05002054 }
dea31012005-04-17 16:05:31 -05002055
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05002056 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04002057 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05002058
2059 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05002060 lpfc_read_topology(phba, pmb, mp);
2061 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05002062 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04002063 /* Block ELS IOCBs until we have processed this mbox command */
James Smart895427b2017-02-12 13:52:30 -08002064 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04002065 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05002066 if (rc == MBX_NOT_FINISHED) {
2067 rc = 4;
James Smart14691152006-12-02 13:34:28 -05002068 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05002069 }
dea31012005-04-17 16:05:31 -05002070
2071 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05002072 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002073 writel(HA_LATT, phba->HAregaddr);
2074 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05002075 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002076
2077 return;
2078
James Smart14691152006-12-02 13:34:28 -05002079lpfc_handle_latt_free_mbuf:
James Smart895427b2017-02-12 13:52:30 -08002080 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05002081 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05002082lpfc_handle_latt_free_mp:
2083 kfree(mp);
2084lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04002085 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002086lpfc_handle_latt_err_exit:
2087 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05002088 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002089 psli->sli_flag |= LPFC_PROCESS_LA;
2090 control = readl(phba->HCregaddr);
2091 control |= HC_LAINT_ENA;
2092 writel(control, phba->HCregaddr);
2093 readl(phba->HCregaddr); /* flush */
2094
2095 /* Clear Link Attention in HA REG */
2096 writel(HA_LATT, phba->HAregaddr);
2097 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05002098 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002099 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002100 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002101
James Smart09372822008-01-11 01:52:54 -05002102 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
2103 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05002104
2105 return;
2106}
2107
James Smarte59058c2008-08-24 21:49:00 -04002108/**
James Smart3621a712009-04-06 18:47:14 -04002109 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04002110 * @phba: pointer to lpfc hba data structure.
2111 * @vpd: pointer to the vital product data.
2112 * @len: length of the vital product data in bytes.
2113 *
2114 * This routine parses the Vital Product Data (VPD). The VPD is treated as
2115 * an array of characters. In this routine, the ModelName, ProgramType, and
2116 * ModelDesc, etc. fields of the phba data structure will be populated.
2117 *
2118 * Return codes
2119 * 0 - pointer to the VPD passed in is NULL
2120 * 1 - success
2121 **/
James Smart3772a992009-05-22 14:50:54 -04002122int
James Smart2e0fef82007-06-17 19:56:36 -05002123lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05002124{
2125 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05002126 int Length;
dea31012005-04-17 16:05:31 -05002127 int i, j;
2128 int finished = 0;
2129 int index = 0;
2130
2131 if (!vpd)
2132 return 0;
2133
2134 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05002135 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002136 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05002137 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
2138 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002139 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05002140 switch (vpd[index]) {
2141 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002142 case 0x91:
dea31012005-04-17 16:05:31 -05002143 index += 1;
2144 lenlo = vpd[index];
2145 index += 1;
2146 lenhi = vpd[index];
2147 index += 1;
2148 i = ((((unsigned short)lenhi) << 8) + lenlo);
2149 index += i;
2150 break;
2151 case 0x90:
2152 index += 1;
2153 lenlo = vpd[index];
2154 index += 1;
2155 lenhi = vpd[index];
2156 index += 1;
2157 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002158 if (Length > len - index)
2159 Length = len - index;
dea31012005-04-17 16:05:31 -05002160 while (Length > 0) {
2161 /* Look for Serial Number */
2162 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
2163 index += 2;
2164 i = vpd[index];
2165 index += 1;
2166 j = 0;
2167 Length -= (3+i);
2168 while(i--) {
2169 phba->SerialNumber[j++] = vpd[index++];
2170 if (j == 31)
2171 break;
2172 }
2173 phba->SerialNumber[j] = 0;
2174 continue;
2175 }
2176 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
2177 phba->vpd_flag |= VPD_MODEL_DESC;
2178 index += 2;
2179 i = vpd[index];
2180 index += 1;
2181 j = 0;
2182 Length -= (3+i);
2183 while(i--) {
2184 phba->ModelDesc[j++] = vpd[index++];
2185 if (j == 255)
2186 break;
2187 }
2188 phba->ModelDesc[j] = 0;
2189 continue;
2190 }
2191 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
2192 phba->vpd_flag |= VPD_MODEL_NAME;
2193 index += 2;
2194 i = vpd[index];
2195 index += 1;
2196 j = 0;
2197 Length -= (3+i);
2198 while(i--) {
2199 phba->ModelName[j++] = vpd[index++];
2200 if (j == 79)
2201 break;
2202 }
2203 phba->ModelName[j] = 0;
2204 continue;
2205 }
2206 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2207 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2208 index += 2;
2209 i = vpd[index];
2210 index += 1;
2211 j = 0;
2212 Length -= (3+i);
2213 while(i--) {
2214 phba->ProgramType[j++] = vpd[index++];
2215 if (j == 255)
2216 break;
2217 }
2218 phba->ProgramType[j] = 0;
2219 continue;
2220 }
2221 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2222 phba->vpd_flag |= VPD_PORT;
2223 index += 2;
2224 i = vpd[index];
2225 index += 1;
2226 j = 0;
2227 Length -= (3+i);
2228 while(i--) {
James Smartcd1c8302011-10-10 21:33:25 -04002229 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2230 (phba->sli4_hba.pport_name_sta ==
2231 LPFC_SLI4_PPNAME_GET)) {
2232 j++;
2233 index++;
2234 } else
2235 phba->Port[j++] = vpd[index++];
2236 if (j == 19)
2237 break;
dea31012005-04-17 16:05:31 -05002238 }
James Smartcd1c8302011-10-10 21:33:25 -04002239 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2240 (phba->sli4_hba.pport_name_sta ==
2241 LPFC_SLI4_PPNAME_NON))
2242 phba->Port[j] = 0;
dea31012005-04-17 16:05:31 -05002243 continue;
2244 }
2245 else {
2246 index += 2;
2247 i = vpd[index];
2248 index += 1;
2249 index += i;
2250 Length -= (3 + i);
2251 }
2252 }
2253 finished = 0;
2254 break;
2255 case 0x78:
2256 finished = 1;
2257 break;
2258 default:
2259 index ++;
2260 break;
2261 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002262 }
dea31012005-04-17 16:05:31 -05002263
2264 return(1);
2265}
2266
James Smarte59058c2008-08-24 21:49:00 -04002267/**
James Smart3621a712009-04-06 18:47:14 -04002268 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04002269 * @phba: pointer to lpfc hba data structure.
2270 * @mdp: pointer to the data structure to hold the derived model name.
2271 * @descp: pointer to the data structure to hold the derived description.
2272 *
2273 * This routine retrieves HBA's description based on its registered PCI device
2274 * ID. The @descp passed into this function points to an array of 256 chars. It
2275 * shall be returned with the model name, maximum speed, and the host bus type.
2276 * The @mdp passed into this function points to an array of 80 chars. When the
2277 * function returns, the @mdp will be filled with the model name.
2278 **/
dea31012005-04-17 16:05:31 -05002279static void
James Smart2e0fef82007-06-17 19:56:36 -05002280lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05002281{
2282 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05002283 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002284 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04002285 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04002286 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002287 struct {
James Smarta747c9c2009-11-18 15:41:10 -05002288 char *name;
2289 char *bus;
2290 char *function;
2291 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002292
2293 if (mdp && mdp[0] != '\0'
2294 && descp && descp[0] != '\0')
2295 return;
2296
James Smartfbd8a6b2018-02-22 08:18:45 -08002297 if (phba->lmt & LMT_64Gb)
2298 max_speed = 64;
2299 else if (phba->lmt & LMT_32Gb)
James Smartd38dd522015-08-31 16:48:17 -04002300 max_speed = 32;
2301 else if (phba->lmt & LMT_16Gb)
James Smartc0c11512011-05-24 11:41:34 -04002302 max_speed = 16;
2303 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002304 max_speed = 10;
2305 else if (phba->lmt & LMT_8Gb)
2306 max_speed = 8;
2307 else if (phba->lmt & LMT_4Gb)
2308 max_speed = 4;
2309 else if (phba->lmt & LMT_2Gb)
2310 max_speed = 2;
James Smart4169d862012-09-29 11:32:09 -04002311 else if (phba->lmt & LMT_1Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002312 max_speed = 1;
James Smart4169d862012-09-29 11:32:09 -04002313 else
2314 max_speed = 0;
dea31012005-04-17 16:05:31 -05002315
2316 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05002317
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002318 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002319 case PCI_DEVICE_ID_FIREFLY:
James Smart12222f42014-05-21 08:05:19 -04002320 m = (typeof(m)){"LP6000", "PCI",
2321 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002322 break;
dea31012005-04-17 16:05:31 -05002323 case PCI_DEVICE_ID_SUPERFLY:
2324 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart12222f42014-05-21 08:05:19 -04002325 m = (typeof(m)){"LP7000", "PCI", ""};
dea31012005-04-17 16:05:31 -05002326 else
James Smart12222f42014-05-21 08:05:19 -04002327 m = (typeof(m)){"LP7000E", "PCI", ""};
2328 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002329 break;
2330 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002331 m = (typeof(m)){"LP8000", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002332 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002333 break;
2334 case PCI_DEVICE_ID_CENTAUR:
2335 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart12222f42014-05-21 08:05:19 -04002336 m = (typeof(m)){"LP9002", "PCI", ""};
dea31012005-04-17 16:05:31 -05002337 else
James Smart12222f42014-05-21 08:05:19 -04002338 m = (typeof(m)){"LP9000", "PCI", ""};
2339 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002340 break;
2341 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002342 m = (typeof(m)){"LP952", "PCI",
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_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05002346 m = (typeof(m)){"LP9802", "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_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05002350 m = (typeof(m)){"LP10000", "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_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05002354 m = (typeof(m)){"LPX1000", "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_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002358 m = (typeof(m)){"LP982", "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_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002362 m = (typeof(m)){"LP1050", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002363 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002364 break;
2365 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05002366 m = (typeof(m)){"LP11000", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002367 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002368 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002369 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002370 m = (typeof(m)){"LP11000-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_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002374 m = (typeof(m)){"LP11002-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002375 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002376 break;
2377 case PCI_DEVICE_ID_NEPTUNE:
James Smart12222f42014-05-21 08:05:19 -04002378 m = (typeof(m)){"LPe1000", "PCIe",
2379 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002380 break;
2381 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart12222f42014-05-21 08:05:19 -04002382 m = (typeof(m)){"LPe1000-SP", "PCIe",
2383 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002384 break;
2385 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart12222f42014-05-21 08:05:19 -04002386 m = (typeof(m)){"LPe1002-SP", "PCIe",
2387 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002388 break;
dea31012005-04-17 16:05:31 -05002389 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05002390 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002391 break;
2392 case PCI_DEVICE_ID_BSMB:
James Smart12222f42014-05-21 08:05:19 -04002393 m = (typeof(m)){"LP111", "PCI-X2",
2394 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002395 break;
2396 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05002397 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002398 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002399 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002400 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002401 break;
2402 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002403 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04002404 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002405 break;
dea31012005-04-17 16:05:31 -05002406 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05002407 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002408 break;
2409 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05002410 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002411 break;
2412 case PCI_DEVICE_ID_LP101:
James Smart12222f42014-05-21 08:05:19 -04002413 m = (typeof(m)){"LP101", "PCI-X",
2414 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002415 break;
2416 case PCI_DEVICE_ID_LP10000S:
James Smart12222f42014-05-21 08:05:19 -04002417 m = (typeof(m)){"LP10000-S", "PCI",
2418 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002419 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002420 case PCI_DEVICE_ID_LP11000S:
James Smart12222f42014-05-21 08:05:19 -04002421 m = (typeof(m)){"LP11000-S", "PCI-X2",
2422 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05002423 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002424 case PCI_DEVICE_ID_LPE11000S:
James Smart12222f42014-05-21 08:05:19 -04002425 m = (typeof(m)){"LPe11000-S", "PCIe",
2426 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002427 break;
James Smartb87eab32007-04-25 09:53:28 -04002428 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05002429 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002430 break;
2431 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05002432 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002433 break;
2434 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05002435 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002436 break;
2437 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002438 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002439 break;
2440 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002441 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002442 break;
2443 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05002444 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002445 break;
James Smart84774a42008-08-24 21:50:06 -04002446 case PCI_DEVICE_ID_HORNET:
James Smart12222f42014-05-21 08:05:19 -04002447 m = (typeof(m)){"LP21000", "PCIe",
2448 "Obsolete, Unsupported FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002449 GE = 1;
2450 break;
2451 case PCI_DEVICE_ID_PROTEUS_VF:
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_PF:
James Smarta747c9c2009-11-18 15:41:10 -05002456 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002457 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002458 break;
2459 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05002460 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002461 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002462 break;
James Smartda0436e2009-05-22 14:51:39 -04002463 case PCI_DEVICE_ID_TIGERSHARK:
2464 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002465 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04002466 break;
James Smarta747c9c2009-11-18 15:41:10 -05002467 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04002468 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002469 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2470 break;
2471 case PCI_DEVICE_ID_FALCON:
2472 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2473 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04002474 break;
James Smart98fc5dd2010-06-07 15:24:29 -04002475 case PCI_DEVICE_ID_BALIUS:
2476 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
James Smart12222f42014-05-21 08:05:19 -04002477 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart98fc5dd2010-06-07 15:24:29 -04002478 break;
James Smart085c6472010-11-20 23:11:37 -05002479 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04002480 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05002481 break;
James Smart12222f42014-05-21 08:05:19 -04002482 case PCI_DEVICE_ID_LANCER_FC_VF:
2483 m = (typeof(m)){"LPe16000", "PCIe",
2484 "Obsolete, Unsupported Fibre Channel Adapter"};
2485 break;
James Smart085c6472010-11-20 23:11:37 -05002486 case PCI_DEVICE_ID_LANCER_FCOE:
2487 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04002488 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05002489 break;
James Smart12222f42014-05-21 08:05:19 -04002490 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2491 oneConnect = 1;
2492 m = (typeof(m)){"OCe15100", "PCIe",
2493 "Obsolete, Unsupported FCoE"};
2494 break;
James Smartd38dd522015-08-31 16:48:17 -04002495 case PCI_DEVICE_ID_LANCER_G6_FC:
2496 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2497 break;
James Smartc238b9b2018-02-22 08:18:44 -08002498 case PCI_DEVICE_ID_LANCER_G7_FC:
2499 m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"};
2500 break;
James Smartf8cafd32012-08-03 12:42:51 -04002501 case PCI_DEVICE_ID_SKYHAWK:
2502 case PCI_DEVICE_ID_SKYHAWK_VF:
2503 oneConnect = 1;
2504 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2505 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002506 default:
James Smarta747c9c2009-11-18 15:41:10 -05002507 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002508 break;
dea31012005-04-17 16:05:31 -05002509 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002510
2511 if (mdp && mdp[0] == '\0')
2512 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04002513 /*
2514 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04002515 * and we put the port number on the end
2516 */
2517 if (descp && descp[0] == '\0') {
2518 if (oneConnect)
2519 snprintf(descp, 255,
James Smart4169d862012-09-29 11:32:09 -04002520 "Emulex OneConnect %s, %s Initiator %s",
James Smarta747c9c2009-11-18 15:41:10 -05002521 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04002522 phba->Port);
James Smart4169d862012-09-29 11:32:09 -04002523 else if (max_speed == 0)
2524 snprintf(descp, 255,
Sebastian Herbszt290237d2015-08-31 16:48:08 -04002525 "Emulex %s %s %s",
James Smart4169d862012-09-29 11:32:09 -04002526 m.name, m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002527 else
2528 snprintf(descp, 255,
2529 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05002530 m.name, max_speed, (GE) ? "GE" : "Gb",
2531 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002532 }
dea31012005-04-17 16:05:31 -05002533}
2534
James Smarte59058c2008-08-24 21:49:00 -04002535/**
James Smart3621a712009-04-06 18:47:14 -04002536 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04002537 * @phba: pointer to lpfc hba data structure.
2538 * @pring: pointer to a IOCB ring.
2539 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2540 *
2541 * This routine posts a given number of IOCBs with the associated DMA buffer
2542 * descriptors specified by the cnt argument to the given IOCB ring.
2543 *
2544 * Return codes
2545 * The number of IOCBs NOT able to be posted to the IOCB ring.
2546 **/
dea31012005-04-17 16:05:31 -05002547int
James Smart495a7142008-06-14 22:52:59 -04002548lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002549{
2550 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002551 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002552 struct lpfc_dmabuf *mp1, *mp2;
2553
2554 cnt += pring->missbufcnt;
2555
2556 /* While there are buffers to post */
2557 while (cnt > 0) {
2558 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002559 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002560 if (iocb == NULL) {
2561 pring->missbufcnt = cnt;
2562 return cnt;
2563 }
dea31012005-04-17 16:05:31 -05002564 icmd = &iocb->iocb;
2565
2566 /* 2 buffers can be posted per command */
2567 /* Allocate buffer to post */
2568 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2569 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002570 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2571 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002572 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002573 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002574 pring->missbufcnt = cnt;
2575 return cnt;
2576 }
2577
2578 INIT_LIST_HEAD(&mp1->list);
2579 /* Allocate buffer to post */
2580 if (cnt > 1) {
2581 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2582 if (mp2)
2583 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2584 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002585 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002586 kfree(mp2);
dea31012005-04-17 16:05:31 -05002587 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2588 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002589 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002590 pring->missbufcnt = cnt;
2591 return cnt;
2592 }
2593
2594 INIT_LIST_HEAD(&mp2->list);
2595 } else {
2596 mp2 = NULL;
2597 }
2598
2599 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2600 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2601 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2602 icmd->ulpBdeCount = 1;
2603 cnt--;
2604 if (mp2) {
2605 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2606 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2607 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2608 cnt--;
2609 icmd->ulpBdeCount = 2;
2610 }
2611
2612 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2613 icmd->ulpLe = 1;
2614
James Smart3772a992009-05-22 14:50:54 -04002615 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2616 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002617 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2618 kfree(mp1);
2619 cnt++;
2620 if (mp2) {
2621 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2622 kfree(mp2);
2623 cnt++;
2624 }
James Bottomley604a3e32005-10-29 10:28:33 -05002625 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002626 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002627 return cnt;
2628 }
dea31012005-04-17 16:05:31 -05002629 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002630 if (mp2)
dea31012005-04-17 16:05:31 -05002631 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002632 }
2633 pring->missbufcnt = 0;
2634 return 0;
2635}
2636
James Smarte59058c2008-08-24 21:49:00 -04002637/**
James Smart3621a712009-04-06 18:47:14 -04002638 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002639 * @phba: pointer to lpfc hba data structure.
2640 *
2641 * This routine posts initial receive IOCB buffers to the ELS ring. The
2642 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
James Smart895427b2017-02-12 13:52:30 -08002643 * set to 64 IOCBs. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002644 *
2645 * Return codes
2646 * 0 - success (currently always success)
2647 **/
dea31012005-04-17 16:05:31 -05002648static int
James Smart2e0fef82007-06-17 19:56:36 -05002649lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002650{
2651 struct lpfc_sli *psli = &phba->sli;
2652
2653 /* Ring 0, ELS / CT buffers */
James Smart895427b2017-02-12 13:52:30 -08002654 lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002655 /* Ring 2 - FCP no buffers needed */
2656
2657 return 0;
2658}
2659
2660#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2661
James Smarte59058c2008-08-24 21:49:00 -04002662/**
James Smart3621a712009-04-06 18:47:14 -04002663 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002664 * @HashResultPointer: pointer to an array as hash table.
2665 *
2666 * This routine sets up the initial values to the array of hash table entries
2667 * for the LC HBAs.
2668 **/
dea31012005-04-17 16:05:31 -05002669static void
2670lpfc_sha_init(uint32_t * HashResultPointer)
2671{
2672 HashResultPointer[0] = 0x67452301;
2673 HashResultPointer[1] = 0xEFCDAB89;
2674 HashResultPointer[2] = 0x98BADCFE;
2675 HashResultPointer[3] = 0x10325476;
2676 HashResultPointer[4] = 0xC3D2E1F0;
2677}
2678
James Smarte59058c2008-08-24 21:49:00 -04002679/**
James Smart3621a712009-04-06 18:47:14 -04002680 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002681 * @HashResultPointer: pointer to an initial/result hash table.
2682 * @HashWorkingPointer: pointer to an working hash table.
2683 *
2684 * This routine iterates an initial hash table pointed by @HashResultPointer
2685 * with the values from the working hash table pointeed by @HashWorkingPointer.
2686 * The results are putting back to the initial hash table, returned through
2687 * the @HashResultPointer as the result hash table.
2688 **/
dea31012005-04-17 16:05:31 -05002689static void
2690lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2691{
2692 int t;
2693 uint32_t TEMP;
2694 uint32_t A, B, C, D, E;
2695 t = 16;
2696 do {
2697 HashWorkingPointer[t] =
2698 S(1,
2699 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2700 8] ^
2701 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2702 } while (++t <= 79);
2703 t = 0;
2704 A = HashResultPointer[0];
2705 B = HashResultPointer[1];
2706 C = HashResultPointer[2];
2707 D = HashResultPointer[3];
2708 E = HashResultPointer[4];
2709
2710 do {
2711 if (t < 20) {
2712 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2713 } else if (t < 40) {
2714 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2715 } else if (t < 60) {
2716 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2717 } else {
2718 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2719 }
2720 TEMP += S(5, A) + E + HashWorkingPointer[t];
2721 E = D;
2722 D = C;
2723 C = S(30, B);
2724 B = A;
2725 A = TEMP;
2726 } while (++t <= 79);
2727
2728 HashResultPointer[0] += A;
2729 HashResultPointer[1] += B;
2730 HashResultPointer[2] += C;
2731 HashResultPointer[3] += D;
2732 HashResultPointer[4] += E;
2733
2734}
2735
James Smarte59058c2008-08-24 21:49:00 -04002736/**
James Smart3621a712009-04-06 18:47:14 -04002737 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002738 * @RandomChallenge: pointer to the entry of host challenge random number array.
2739 * @HashWorking: pointer to the entry of the working hash array.
2740 *
2741 * This routine calculates the working hash array referred by @HashWorking
2742 * from the challenge random numbers associated with the host, referred by
2743 * @RandomChallenge. The result is put into the entry of the working hash
2744 * array and returned by reference through @HashWorking.
2745 **/
dea31012005-04-17 16:05:31 -05002746static void
2747lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2748{
2749 *HashWorking = (*RandomChallenge ^ *HashWorking);
2750}
2751
James Smarte59058c2008-08-24 21:49:00 -04002752/**
James Smart3621a712009-04-06 18:47:14 -04002753 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002754 * @phba: pointer to lpfc hba data structure.
2755 * @hbainit: pointer to an array of unsigned 32-bit integers.
2756 *
2757 * This routine performs the special handling for LC HBA initialization.
2758 **/
dea31012005-04-17 16:05:31 -05002759void
2760lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2761{
2762 int t;
2763 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002764 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002765
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002766 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002767 if (!HashWorking)
2768 return;
2769
dea31012005-04-17 16:05:31 -05002770 HashWorking[0] = HashWorking[78] = *pwwnn++;
2771 HashWorking[1] = HashWorking[79] = *pwwnn;
2772
2773 for (t = 0; t < 7; t++)
2774 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2775
2776 lpfc_sha_init(hbainit);
2777 lpfc_sha_iterate(hbainit, HashWorking);
2778 kfree(HashWorking);
2779}
2780
James Smarte59058c2008-08-24 21:49:00 -04002781/**
James Smart3621a712009-04-06 18:47:14 -04002782 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002783 * @vport: pointer to a virtual N_Port data structure.
2784 *
2785 * This routine performs the necessary cleanups before deleting the @vport.
2786 * It invokes the discovery state machine to perform necessary state
2787 * transitions and to release the ndlps associated with the @vport. Note,
2788 * the physical port is treated as @vport 0.
2789 **/
James Smart87af33f2007-10-27 13:37:43 -04002790void
James Smart2e0fef82007-06-17 19:56:36 -05002791lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002792{
James Smart87af33f2007-10-27 13:37:43 -04002793 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002794 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002795 int i = 0;
dea31012005-04-17 16:05:31 -05002796
James Smart87af33f2007-10-27 13:37:43 -04002797 if (phba->link_state > LPFC_LINK_DOWN)
2798 lpfc_port_link_failure(vport);
2799
2800 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002801 if (!NLP_CHK_NODE_ACT(ndlp)) {
2802 ndlp = lpfc_enable_node(vport, ndlp,
2803 NLP_STE_UNUSED_NODE);
2804 if (!ndlp)
2805 continue;
2806 spin_lock_irq(&phba->ndlp_lock);
2807 NLP_SET_FREE_REQ(ndlp);
2808 spin_unlock_irq(&phba->ndlp_lock);
2809 /* Trigger the release of the ndlp memory */
2810 lpfc_nlp_put(ndlp);
2811 continue;
2812 }
2813 spin_lock_irq(&phba->ndlp_lock);
2814 if (NLP_CHK_FREE_REQ(ndlp)) {
2815 /* The ndlp should not be in memory free mode already */
2816 spin_unlock_irq(&phba->ndlp_lock);
2817 continue;
2818 } else
2819 /* Indicate request for freeing ndlp memory */
2820 NLP_SET_FREE_REQ(ndlp);
2821 spin_unlock_irq(&phba->ndlp_lock);
2822
James Smart58da1ff2008-04-07 10:15:56 -04002823 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2824 ndlp->nlp_DID == Fabric_DID) {
2825 /* Just free up ndlp with Fabric_DID for vports */
2826 lpfc_nlp_put(ndlp);
2827 continue;
2828 }
2829
James Smarteff4a012012-01-18 16:25:25 -05002830 /* take care of nodes in unused state before the state
2831 * machine taking action.
2832 */
2833 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2834 lpfc_nlp_put(ndlp);
2835 continue;
2836 }
2837
James Smart87af33f2007-10-27 13:37:43 -04002838 if (ndlp->nlp_type & NLP_FABRIC)
2839 lpfc_disc_state_machine(vport, ndlp, NULL,
2840 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002841
James Smart87af33f2007-10-27 13:37:43 -04002842 lpfc_disc_state_machine(vport, ndlp, NULL,
2843 NLP_EVT_DEVICE_RM);
2844 }
2845
James Smarta8adb832007-10-27 13:37:53 -04002846 /* At this point, ALL ndlp's should be gone
2847 * because of the previous NLP_EVT_DEVICE_RM.
2848 * Lets wait for this to happen, if needed.
2849 */
James Smart87af33f2007-10-27 13:37:43 -04002850 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002851 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04002852 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04002853 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002854 list_for_each_entry_safe(ndlp, next_ndlp,
2855 &vport->fc_nodes, nlp_listp) {
2856 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2857 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04002858 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05002859 "usgmap:x%x refcnt:%d\n",
2860 ndlp->nlp_DID, (void *)ndlp,
2861 ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01002862 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05002863 }
James Smarta8adb832007-10-27 13:37:53 -04002864 break;
James Smart87af33f2007-10-27 13:37:43 -04002865 }
James Smarta8adb832007-10-27 13:37:53 -04002866
2867 /* Wait for any activity on ndlps to settle */
2868 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002869 }
James Smart1151e3e2011-02-16 12:39:35 -05002870 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002871}
2872
James Smarte59058c2008-08-24 21:49:00 -04002873/**
James Smart3621a712009-04-06 18:47:14 -04002874 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002875 * @vport: pointer to a virtual N_Port data structure.
2876 *
2877 * This routine stops all the timers associated with a @vport. This function
2878 * is invoked before disabling or deleting a @vport. Note that the physical
2879 * port is treated as @vport 0.
2880 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002881void
2882lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002883{
James Smart92d7f7b2007-06-17 19:56:38 -05002884 del_timer_sync(&vport->els_tmofunc);
James Smart92494142011-02-16 12:39:44 -05002885 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002886 lpfc_can_disctmo(vport);
2887 return;
dea31012005-04-17 16:05:31 -05002888}
2889
James Smarte59058c2008-08-24 21:49:00 -04002890/**
James Smartecfd03c2010-02-12 14:41:27 -05002891 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2892 * @phba: pointer to lpfc hba data structure.
2893 *
2894 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2895 * caller of this routine should already hold the host lock.
2896 **/
2897void
2898__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2899{
James Smart5ac6b302010-10-22 11:05:36 -04002900 /* Clear pending FCF rediscovery wait flag */
2901 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2902
James Smartecfd03c2010-02-12 14:41:27 -05002903 /* Now, try to stop the timer */
2904 del_timer(&phba->fcf.redisc_wait);
2905}
2906
2907/**
2908 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2909 * @phba: pointer to lpfc hba data structure.
2910 *
2911 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2912 * checks whether the FCF rediscovery wait timer is pending with the host
2913 * lock held before proceeding with disabling the timer and clearing the
2914 * wait timer pendig flag.
2915 **/
2916void
2917lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2918{
2919 spin_lock_irq(&phba->hbalock);
2920 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2921 /* FCF rediscovery timer already fired or stopped */
2922 spin_unlock_irq(&phba->hbalock);
2923 return;
2924 }
2925 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002926 /* Clear failover in progress flags */
2927 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002928 spin_unlock_irq(&phba->hbalock);
2929}
2930
2931/**
James Smart3772a992009-05-22 14:50:54 -04002932 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002933 * @phba: pointer to lpfc hba data structure.
2934 *
2935 * This routine stops all the timers associated with a HBA. This function is
2936 * invoked before either putting a HBA offline or unloading the driver.
2937 **/
James Smart3772a992009-05-22 14:50:54 -04002938void
2939lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002940{
James Smart51ef4c22007-08-02 11:10:31 -04002941 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05002942 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002943 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002944 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002945 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002946 if (phba->sli_rev == LPFC_SLI_REV4) {
2947 del_timer_sync(&phba->rrq_tmr);
2948 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2949 }
James Smart3772a992009-05-22 14:50:54 -04002950 phba->hb_outstanding = 0;
2951
2952 switch (phba->pci_dev_grp) {
2953 case LPFC_PCI_DEV_LP:
2954 /* Stop any LightPulse device specific driver timers */
2955 del_timer_sync(&phba->fcp_poll_timer);
2956 break;
2957 case LPFC_PCI_DEV_OC:
2958 /* Stop any OneConnect device sepcific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002959 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002960 break;
2961 default:
2962 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2963 "0297 Invalid device group (x%x)\n",
2964 phba->pci_dev_grp);
2965 break;
2966 }
James Smart2e0fef82007-06-17 19:56:36 -05002967 return;
dea31012005-04-17 16:05:31 -05002968}
2969
James Smarte59058c2008-08-24 21:49:00 -04002970/**
James Smart3621a712009-04-06 18:47:14 -04002971 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002972 * @phba: pointer to lpfc hba data structure.
2973 *
2974 * This routine marks a HBA's management interface as blocked. Once the HBA's
2975 * management interface is marked as blocked, all the user space access to
2976 * the HBA, whether they are from sysfs interface or libdfc interface will
2977 * all be blocked. The HBA is set to block the management interface when the
2978 * driver prepares the HBA interface for online or offline.
2979 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01002980static void
James Smart618a5232012-06-12 13:54:36 -04002981lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
Adrian Bunka6ababd2007-11-05 18:07:33 +01002982{
2983 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04002984 uint8_t actcmd = MBX_HEARTBEAT;
2985 unsigned long timeout;
2986
Adrian Bunka6ababd2007-11-05 18:07:33 +01002987 spin_lock_irqsave(&phba->hbalock, iflag);
2988 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart618a5232012-06-12 13:54:36 -04002989 spin_unlock_irqrestore(&phba->hbalock, iflag);
2990 if (mbx_action == LPFC_MBX_NO_WAIT)
2991 return;
2992 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2993 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002994 if (phba->sli.mbox_active) {
James Smart6e7288d2010-06-07 15:23:35 -04002995 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
James Smarta183a152011-10-10 21:32:43 -04002996 /* Determine how long we might wait for the active mailbox
2997 * command to be gracefully completed by firmware.
2998 */
2999 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
3000 phba->sli.mbox_active) * 1000) + jiffies;
3001 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01003002 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04003003
James Smart6e7288d2010-06-07 15:23:35 -04003004 /* Wait for the outstnading mailbox command to complete */
3005 while (phba->sli.mbox_active) {
3006 /* Check active mailbox complete status every 2ms */
3007 msleep(2);
3008 if (time_after(jiffies, timeout)) {
3009 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3010 "2813 Mgmt IO is Blocked %x "
3011 "- mbox cmd %x still active\n",
3012 phba->sli.sli_flag, actcmd);
3013 break;
3014 }
3015 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01003016}
3017
James Smarte59058c2008-08-24 21:49:00 -04003018/**
James Smart6b5151f2012-01-18 16:24:06 -05003019 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
3020 * @phba: pointer to lpfc hba data structure.
3021 *
3022 * Allocate RPIs for all active remote nodes. This is needed whenever
3023 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
3024 * is to fixup the temporary rpi assignments.
3025 **/
3026void
3027lpfc_sli4_node_prep(struct lpfc_hba *phba)
3028{
3029 struct lpfc_nodelist *ndlp, *next_ndlp;
3030 struct lpfc_vport **vports;
James Smart9d3d3402017-04-21 16:05:00 -07003031 int i, rpi;
3032 unsigned long flags;
James Smart6b5151f2012-01-18 16:24:06 -05003033
3034 if (phba->sli_rev != LPFC_SLI_REV4)
3035 return;
3036
3037 vports = lpfc_create_vport_work_array(phba);
James Smart9d3d3402017-04-21 16:05:00 -07003038 if (vports == NULL)
3039 return;
James Smart6b5151f2012-01-18 16:24:06 -05003040
James Smart9d3d3402017-04-21 16:05:00 -07003041 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3042 if (vports[i]->load_flag & FC_UNLOADING)
3043 continue;
3044
3045 list_for_each_entry_safe(ndlp, next_ndlp,
3046 &vports[i]->fc_nodes,
3047 nlp_listp) {
3048 if (!NLP_CHK_NODE_ACT(ndlp))
3049 continue;
3050 rpi = lpfc_sli4_alloc_rpi(phba);
3051 if (rpi == LPFC_RPI_ALLOC_ERROR) {
3052 spin_lock_irqsave(&phba->ndlp_lock, flags);
3053 NLP_CLR_NODE_ACT(ndlp);
3054 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3055 continue;
James Smart6b5151f2012-01-18 16:24:06 -05003056 }
James Smart9d3d3402017-04-21 16:05:00 -07003057 ndlp->nlp_rpi = rpi;
3058 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3059 "0009 rpi:%x DID:%x "
3060 "flg:%x map:%x %p\n", ndlp->nlp_rpi,
3061 ndlp->nlp_DID, ndlp->nlp_flag,
3062 ndlp->nlp_usg_map, ndlp);
James Smart6b5151f2012-01-18 16:24:06 -05003063 }
3064 }
3065 lpfc_destroy_vport_work_array(phba, vports);
3066}
3067
3068/**
James Smart3621a712009-04-06 18:47:14 -04003069 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04003070 * @phba: pointer to lpfc hba data structure.
3071 *
3072 * This routine initializes the HBA and brings a HBA online. During this
3073 * process, the management interface is blocked to prevent user space access
3074 * to the HBA interfering with the driver initialization.
3075 *
3076 * Return codes
3077 * 0 - successful
3078 * 1 - failed
3079 **/
dea31012005-04-17 16:05:31 -05003080int
James Smart2e0fef82007-06-17 19:56:36 -05003081lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003082{
Julia Lawall372bd282008-12-16 16:15:08 +01003083 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04003084 struct lpfc_vport **vports;
Dick Kennedya145fda2017-08-23 16:55:44 -07003085 int i, error = 0;
James Smart16a3a202013-04-17 20:14:38 -04003086 bool vpis_cleared = false;
James Smart2e0fef82007-06-17 19:56:36 -05003087
dea31012005-04-17 16:05:31 -05003088 if (!phba)
3089 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01003090 vport = phba->pport;
dea31012005-04-17 16:05:31 -05003091
James Smart2e0fef82007-06-17 19:56:36 -05003092 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05003093 return 0;
3094
James Smarted957682007-06-17 19:56:37 -05003095 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003096 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05003097
James Smart618a5232012-06-12 13:54:36 -04003098 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05003099
James Smartda0436e2009-05-22 14:51:39 -04003100 if (phba->sli_rev == LPFC_SLI_REV4) {
3101 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
3102 lpfc_unblock_mgmt_io(phba);
3103 return 1;
3104 }
James Smart16a3a202013-04-17 20:14:38 -04003105 spin_lock_irq(&phba->hbalock);
3106 if (!phba->sli4_hba.max_cfg_param.vpi_used)
3107 vpis_cleared = true;
3108 spin_unlock_irq(&phba->hbalock);
Dick Kennedya145fda2017-08-23 16:55:44 -07003109
3110 /* Reestablish the local initiator port.
3111 * The offline process destroyed the previous lport.
3112 */
3113 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
3114 !phba->nvmet_support) {
3115 error = lpfc_nvme_create_localport(phba->pport);
3116 if (error)
3117 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3118 "6132 NVME restore reg failed "
3119 "on nvmei error x%x\n", error);
3120 }
James Smartda0436e2009-05-22 14:51:39 -04003121 } else {
James Smart895427b2017-02-12 13:52:30 -08003122 lpfc_sli_queue_init(phba);
James Smartda0436e2009-05-22 14:51:39 -04003123 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
3124 lpfc_unblock_mgmt_io(phba);
3125 return 1;
3126 }
James Smart46fa3112007-04-25 09:51:45 -04003127 }
dea31012005-04-17 16:05:31 -05003128
James Smart549e55c2007-08-02 11:09:51 -04003129 vports = lpfc_create_vport_work_array(phba);
Arnd Bergmannaeb66412016-03-14 15:29:44 +01003130 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003131 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003132 struct Scsi_Host *shost;
3133 shost = lpfc_shost_from_vport(vports[i]);
3134 spin_lock_irq(shost->host_lock);
3135 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
3136 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
3137 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart16a3a202013-04-17 20:14:38 -04003138 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart1c6834a2009-07-19 10:01:26 -04003139 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart16a3a202013-04-17 20:14:38 -04003140 if ((vpis_cleared) &&
3141 (vports[i]->port_type !=
3142 LPFC_PHYSICAL_PORT))
3143 vports[i]->vpi = 0;
3144 }
James Smart549e55c2007-08-02 11:09:51 -04003145 spin_unlock_irq(shost->host_lock);
3146 }
Arnd Bergmannaeb66412016-03-14 15:29:44 +01003147 }
3148 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003149
James Smart46fa3112007-04-25 09:51:45 -04003150 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05003151 return 0;
3152}
3153
James Smarte59058c2008-08-24 21:49:00 -04003154/**
James Smart3621a712009-04-06 18:47:14 -04003155 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04003156 * @phba: pointer to lpfc hba data structure.
3157 *
3158 * This routine marks a HBA's management interface as not blocked. Once the
3159 * HBA's management interface is marked as not blocked, all the user space
3160 * access to the HBA, whether they are from sysfs interface or libdfc
3161 * interface will be allowed. The HBA is set to block the management interface
3162 * when the driver prepares the HBA interface for online or offline and then
3163 * set to unblock the management interface afterwards.
3164 **/
James Smart46fa3112007-04-25 09:51:45 -04003165void
James Smart46fa3112007-04-25 09:51:45 -04003166lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
3167{
3168 unsigned long iflag;
3169
James Smart2e0fef82007-06-17 19:56:36 -05003170 spin_lock_irqsave(&phba->hbalock, iflag);
3171 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3172 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04003173}
3174
James Smarte59058c2008-08-24 21:49:00 -04003175/**
James Smart3621a712009-04-06 18:47:14 -04003176 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04003177 * @phba: pointer to lpfc hba data structure.
3178 *
3179 * This routine is invoked to prepare a HBA to be brought offline. It performs
3180 * unregistration login to all the nodes on all vports and flushes the mailbox
3181 * queue to make it ready to be brought offline.
3182 **/
James Smart46fa3112007-04-25 09:51:45 -04003183void
James Smart618a5232012-06-12 13:54:36 -04003184lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04003185{
James Smart2e0fef82007-06-17 19:56:36 -05003186 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04003187 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04003188 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05003189 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04003190 int i;
dea31012005-04-17 16:05:31 -05003191
James Smart2e0fef82007-06-17 19:56:36 -05003192 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003193 return;
dea31012005-04-17 16:05:31 -05003194
James Smart618a5232012-06-12 13:54:36 -04003195 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05003196
3197 lpfc_linkdown(phba);
3198
James Smart87af33f2007-10-27 13:37:43 -04003199 /* Issue an unreg_login to all nodes on all vports */
3200 vports = lpfc_create_vport_work_array(phba);
3201 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003202 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04003203 if (vports[i]->load_flag & FC_UNLOADING)
3204 continue;
James Smart72100cc2010-02-12 14:43:01 -05003205 shost = lpfc_shost_from_vport(vports[i]);
3206 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003207 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003208 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3209 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05003210 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05003211
James Smart87af33f2007-10-27 13:37:43 -04003212 shost = lpfc_shost_from_vport(vports[i]);
3213 list_for_each_entry_safe(ndlp, next_ndlp,
3214 &vports[i]->fc_nodes,
3215 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003216 if (!NLP_CHK_NODE_ACT(ndlp))
3217 continue;
James Smart87af33f2007-10-27 13:37:43 -04003218 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3219 continue;
3220 if (ndlp->nlp_type & NLP_FABRIC) {
3221 lpfc_disc_state_machine(vports[i], ndlp,
3222 NULL, NLP_EVT_DEVICE_RECOVERY);
3223 lpfc_disc_state_machine(vports[i], ndlp,
3224 NULL, NLP_EVT_DEVICE_RM);
3225 }
3226 spin_lock_irq(shost->host_lock);
3227 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart401ee0c2012-03-01 22:35:34 -05003228 spin_unlock_irq(shost->host_lock);
James Smart6b5151f2012-01-18 16:24:06 -05003229 /*
3230 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05003231 * RPI. Get a new RPI when the adapter port
3232 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05003233 */
James Smartbe6bb942015-04-07 15:07:22 -04003234 if (phba->sli_rev == LPFC_SLI_REV4) {
3235 lpfc_printf_vlog(ndlp->vport,
3236 KERN_INFO, LOG_NODE,
3237 "0011 lpfc_offline: "
3238 "ndlp:x%p did %x "
3239 "usgmap:x%x rpi:%x\n",
3240 ndlp, ndlp->nlp_DID,
3241 ndlp->nlp_usg_map,
3242 ndlp->nlp_rpi);
3243
James Smart6b5151f2012-01-18 16:24:06 -05003244 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smartbe6bb942015-04-07 15:07:22 -04003245 }
James Smart87af33f2007-10-27 13:37:43 -04003246 lpfc_unreg_rpi(vports[i], ndlp);
3247 }
3248 }
3249 }
James Smart09372822008-01-11 01:52:54 -05003250 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003251
James Smart618a5232012-06-12 13:54:36 -04003252 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
Dick Kennedyf485c182017-09-29 17:34:34 -07003253
3254 if (phba->wq)
3255 flush_workqueue(phba->wq);
James Smart46fa3112007-04-25 09:51:45 -04003256}
3257
James Smarte59058c2008-08-24 21:49:00 -04003258/**
James Smart3621a712009-04-06 18:47:14 -04003259 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04003260 * @phba: pointer to lpfc hba data structure.
3261 *
3262 * This routine actually brings a HBA offline. It stops all the timers
3263 * associated with the HBA, brings down the SLI layer, and eventually
3264 * marks the HBA as in offline state for the upper layer protocol.
3265 **/
James Smart46fa3112007-04-25 09:51:45 -04003266void
James Smart2e0fef82007-06-17 19:56:36 -05003267lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04003268{
James Smart549e55c2007-08-02 11:09:51 -04003269 struct Scsi_Host *shost;
3270 struct lpfc_vport **vports;
3271 int i;
James Smart46fa3112007-04-25 09:51:45 -04003272
James Smart549e55c2007-08-02 11:09:51 -04003273 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003274 return;
James Smart688a8862006-07-06 15:49:56 -04003275
James Smartda0436e2009-05-22 14:51:39 -04003276 /* stop port and all timers associated with this hba */
3277 lpfc_stop_port(phba);
Dick Kennedy4b40d022017-08-23 16:55:38 -07003278
3279 /* Tear down the local and target port registrations. The
3280 * nvme transports need to cleanup.
3281 */
3282 lpfc_nvmet_destroy_targetport(phba);
3283 lpfc_nvme_destroy_localport(phba->pport);
3284
James Smart51ef4c22007-08-02 11:10:31 -04003285 vports = lpfc_create_vport_work_array(phba);
3286 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003287 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04003288 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05003289 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05003290 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003291 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05003292 /* Bring down the SLI Layer and cleanup. The HBA is offline
3293 now. */
3294 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003295 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04003296 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003297 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04003298 vports = lpfc_create_vport_work_array(phba);
3299 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003300 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003301 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04003302 spin_lock_irq(shost->host_lock);
3303 vports[i]->work_port_events = 0;
3304 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3305 spin_unlock_irq(shost->host_lock);
3306 }
James Smart09372822008-01-11 01:52:54 -05003307 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003308}
3309
James Smarte59058c2008-08-24 21:49:00 -04003310/**
James Smart3621a712009-04-06 18:47:14 -04003311 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04003312 * @phba: pointer to lpfc hba data structure.
3313 *
3314 * This routine is to free all the SCSI buffers and IOCBs from the driver
3315 * list back to kernel. It is called from lpfc_pci_remove_one to free
3316 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04003317 **/
James Smart8a9d2e82012-05-09 21:16:12 -04003318static void
James Smart2e0fef82007-06-17 19:56:36 -05003319lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003320{
3321 struct lpfc_scsi_buf *sb, *sb_next;
dea31012005-04-17 16:05:31 -05003322
James Smart895427b2017-02-12 13:52:30 -08003323 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3324 return;
3325
James Smart2e0fef82007-06-17 19:56:36 -05003326 spin_lock_irq(&phba->hbalock);
James Smarta40fc5f2013-04-17 20:17:40 -04003327
dea31012005-04-17 16:05:31 -05003328 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smarta40fc5f2013-04-17 20:17:40 -04003329
3330 spin_lock(&phba->scsi_buf_list_put_lock);
3331 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3332 list) {
dea31012005-04-17 16:05:31 -05003333 list_del(&sb->list);
Romain Perier771db5c2017-07-06 10:13:05 +02003334 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05003335 sb->dma_handle);
dea31012005-04-17 16:05:31 -05003336 kfree(sb);
3337 phba->total_scsi_bufs--;
3338 }
James Smarta40fc5f2013-04-17 20:17:40 -04003339 spin_unlock(&phba->scsi_buf_list_put_lock);
3340
3341 spin_lock(&phba->scsi_buf_list_get_lock);
3342 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3343 list) {
3344 list_del(&sb->list);
Romain Perier771db5c2017-07-06 10:13:05 +02003345 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smarta40fc5f2013-04-17 20:17:40 -04003346 sb->dma_handle);
3347 kfree(sb);
3348 phba->total_scsi_bufs--;
3349 }
3350 spin_unlock(&phba->scsi_buf_list_get_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003351 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003352}
James Smart8a9d2e82012-05-09 21:16:12 -04003353/**
James Smart895427b2017-02-12 13:52:30 -08003354 * lpfc_nvme_free - Free all the NVME buffers and IOCBs from driver lists
3355 * @phba: pointer to lpfc hba data structure.
3356 *
3357 * This routine is to free all the NVME buffers and IOCBs from the driver
3358 * list back to kernel. It is called from lpfc_pci_remove_one to free
3359 * the internal resources before the device is removed from the system.
3360 **/
3361static void
3362lpfc_nvme_free(struct lpfc_hba *phba)
3363{
3364 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
James Smart895427b2017-02-12 13:52:30 -08003365
3366 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3367 return;
3368
3369 spin_lock_irq(&phba->hbalock);
3370
3371 /* Release all the lpfc_nvme_bufs maintained by this host. */
3372 spin_lock(&phba->nvme_buf_list_put_lock);
3373 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3374 &phba->lpfc_nvme_buf_list_put, list) {
3375 list_del(&lpfc_ncmd->list);
James Smartcf1a1d32017-12-08 17:18:03 -08003376 phba->put_nvme_bufs--;
Romain Perier771db5c2017-07-06 10:13:05 +02003377 dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
James Smart895427b2017-02-12 13:52:30 -08003378 lpfc_ncmd->dma_handle);
3379 kfree(lpfc_ncmd);
3380 phba->total_nvme_bufs--;
3381 }
3382 spin_unlock(&phba->nvme_buf_list_put_lock);
3383
3384 spin_lock(&phba->nvme_buf_list_get_lock);
3385 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3386 &phba->lpfc_nvme_buf_list_get, list) {
3387 list_del(&lpfc_ncmd->list);
James Smartcf1a1d32017-12-08 17:18:03 -08003388 phba->get_nvme_bufs--;
Romain Perier771db5c2017-07-06 10:13:05 +02003389 dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
James Smart895427b2017-02-12 13:52:30 -08003390 lpfc_ncmd->dma_handle);
3391 kfree(lpfc_ncmd);
3392 phba->total_nvme_bufs--;
3393 }
3394 spin_unlock(&phba->nvme_buf_list_get_lock);
James Smart895427b2017-02-12 13:52:30 -08003395 spin_unlock_irq(&phba->hbalock);
3396}
3397/**
3398 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
James Smart8a9d2e82012-05-09 21:16:12 -04003399 * @phba: pointer to lpfc hba data structure.
3400 *
3401 * This routine first calculates the sizes of the current els and allocated
3402 * scsi sgl lists, and then goes through all sgls to updates the physical
3403 * XRIs assigned due to port function reset. During port initialization, the
3404 * current els and allocated scsi sgl lists are 0s.
3405 *
3406 * Return codes
3407 * 0 - successful (for now, it always returns 0)
3408 **/
3409int
James Smart895427b2017-02-12 13:52:30 -08003410lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
James Smart8a9d2e82012-05-09 21:16:12 -04003411{
3412 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
James Smart895427b2017-02-12 13:52:30 -08003413 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart8a9d2e82012-05-09 21:16:12 -04003414 LIST_HEAD(els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003415 int rc;
3416
3417 /*
3418 * update on pci function's els xri-sgl list
3419 */
3420 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart895427b2017-02-12 13:52:30 -08003421
James Smart8a9d2e82012-05-09 21:16:12 -04003422 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3423 /* els xri-sgl expanded */
3424 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3425 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3426 "3157 ELS xri-sgl count increased from "
3427 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3428 els_xri_cnt);
3429 /* allocate the additional els sgls */
3430 for (i = 0; i < xri_cnt; i++) {
3431 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3432 GFP_KERNEL);
3433 if (sglq_entry == NULL) {
3434 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3435 "2562 Failure to allocate an "
3436 "ELS sgl entry:%d\n", i);
3437 rc = -ENOMEM;
3438 goto out_free_mem;
3439 }
3440 sglq_entry->buff_type = GEN_BUFF_TYPE;
3441 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3442 &sglq_entry->phys);
3443 if (sglq_entry->virt == NULL) {
3444 kfree(sglq_entry);
3445 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3446 "2563 Failure to allocate an "
3447 "ELS mbuf:%d\n", i);
3448 rc = -ENOMEM;
3449 goto out_free_mem;
3450 }
3451 sglq_entry->sgl = sglq_entry->virt;
3452 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3453 sglq_entry->state = SGL_FREED;
3454 list_add_tail(&sglq_entry->list, &els_sgl_list);
3455 }
James Smart38c20672013-03-01 16:37:44 -05003456 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003457 spin_lock(&phba->sli4_hba.sgl_list_lock);
3458 list_splice_init(&els_sgl_list,
3459 &phba->sli4_hba.lpfc_els_sgl_list);
3460 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart38c20672013-03-01 16:37:44 -05003461 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003462 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3463 /* els xri-sgl shrinked */
3464 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3465 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3466 "3158 ELS xri-sgl count decreased from "
3467 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3468 els_xri_cnt);
3469 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003470 spin_lock(&phba->sli4_hba.sgl_list_lock);
3471 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
3472 &els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003473 /* release extra els sgls from list */
3474 for (i = 0; i < xri_cnt; i++) {
3475 list_remove_head(&els_sgl_list,
3476 sglq_entry, struct lpfc_sglq, list);
3477 if (sglq_entry) {
James Smart895427b2017-02-12 13:52:30 -08003478 __lpfc_mbuf_free(phba, sglq_entry->virt,
3479 sglq_entry->phys);
James Smart8a9d2e82012-05-09 21:16:12 -04003480 kfree(sglq_entry);
3481 }
3482 }
James Smart895427b2017-02-12 13:52:30 -08003483 list_splice_init(&els_sgl_list,
3484 &phba->sli4_hba.lpfc_els_sgl_list);
3485 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003486 spin_unlock_irq(&phba->hbalock);
3487 } else
3488 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3489 "3163 ELS xri-sgl count unchanged: %d\n",
3490 els_xri_cnt);
3491 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3492
3493 /* update xris to els sgls on the list */
3494 sglq_entry = NULL;
3495 sglq_entry_next = NULL;
3496 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
James Smart895427b2017-02-12 13:52:30 -08003497 &phba->sli4_hba.lpfc_els_sgl_list, list) {
James Smart8a9d2e82012-05-09 21:16:12 -04003498 lxri = lpfc_sli4_next_xritag(phba);
3499 if (lxri == NO_XRI) {
3500 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3501 "2400 Failed to allocate xri for "
3502 "ELS sgl\n");
3503 rc = -ENOMEM;
3504 goto out_free_mem;
3505 }
3506 sglq_entry->sli4_lxritag = lxri;
3507 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3508 }
James Smart895427b2017-02-12 13:52:30 -08003509 return 0;
3510
3511out_free_mem:
3512 lpfc_free_els_sgl_list(phba);
3513 return rc;
3514}
3515
3516/**
James Smartf358dd02017-02-12 13:52:34 -08003517 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
3518 * @phba: pointer to lpfc hba data structure.
3519 *
3520 * This routine first calculates the sizes of the current els and allocated
3521 * scsi sgl lists, and then goes through all sgls to updates the physical
3522 * XRIs assigned due to port function reset. During port initialization, the
3523 * current els and allocated scsi sgl lists are 0s.
3524 *
3525 * Return codes
3526 * 0 - successful (for now, it always returns 0)
3527 **/
3528int
3529lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
3530{
3531 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3532 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart6c621a22017-05-15 15:20:45 -07003533 uint16_t nvmet_xri_cnt;
James Smartf358dd02017-02-12 13:52:34 -08003534 LIST_HEAD(nvmet_sgl_list);
3535 int rc;
3536
3537 /*
3538 * update on pci function's nvmet xri-sgl list
3539 */
3540 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart61f3d4b2017-05-15 15:20:41 -07003541
James Smart6c621a22017-05-15 15:20:45 -07003542 /* For NVMET, ALL remaining XRIs are dedicated for IO processing */
3543 nvmet_xri_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
James Smartf358dd02017-02-12 13:52:34 -08003544 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
3545 /* els xri-sgl expanded */
3546 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
3547 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3548 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
3549 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
3550 /* allocate the additional nvmet sgls */
3551 for (i = 0; i < xri_cnt; i++) {
3552 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3553 GFP_KERNEL);
3554 if (sglq_entry == NULL) {
3555 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3556 "6303 Failure to allocate an "
3557 "NVMET sgl entry:%d\n", i);
3558 rc = -ENOMEM;
3559 goto out_free_mem;
3560 }
3561 sglq_entry->buff_type = NVMET_BUFF_TYPE;
3562 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
3563 &sglq_entry->phys);
3564 if (sglq_entry->virt == NULL) {
3565 kfree(sglq_entry);
3566 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3567 "6304 Failure to allocate an "
3568 "NVMET buf:%d\n", i);
3569 rc = -ENOMEM;
3570 goto out_free_mem;
3571 }
3572 sglq_entry->sgl = sglq_entry->virt;
3573 memset(sglq_entry->sgl, 0,
3574 phba->cfg_sg_dma_buf_size);
3575 sglq_entry->state = SGL_FREED;
3576 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
3577 }
3578 spin_lock_irq(&phba->hbalock);
3579 spin_lock(&phba->sli4_hba.sgl_list_lock);
3580 list_splice_init(&nvmet_sgl_list,
3581 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3582 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3583 spin_unlock_irq(&phba->hbalock);
3584 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
3585 /* nvmet xri-sgl shrunk */
3586 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
3587 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3588 "6305 NVMET xri-sgl count decreased from "
3589 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
3590 nvmet_xri_cnt);
3591 spin_lock_irq(&phba->hbalock);
3592 spin_lock(&phba->sli4_hba.sgl_list_lock);
3593 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
3594 &nvmet_sgl_list);
3595 /* release extra nvmet sgls from list */
3596 for (i = 0; i < xri_cnt; i++) {
3597 list_remove_head(&nvmet_sgl_list,
3598 sglq_entry, struct lpfc_sglq, list);
3599 if (sglq_entry) {
3600 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
3601 sglq_entry->phys);
3602 kfree(sglq_entry);
3603 }
3604 }
3605 list_splice_init(&nvmet_sgl_list,
3606 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3607 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3608 spin_unlock_irq(&phba->hbalock);
3609 } else
3610 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3611 "6306 NVMET xri-sgl count unchanged: %d\n",
3612 nvmet_xri_cnt);
3613 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
3614
3615 /* update xris to nvmet sgls on the list */
3616 sglq_entry = NULL;
3617 sglq_entry_next = NULL;
3618 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3619 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
3620 lxri = lpfc_sli4_next_xritag(phba);
3621 if (lxri == NO_XRI) {
3622 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3623 "6307 Failed to allocate xri for "
3624 "NVMET sgl\n");
3625 rc = -ENOMEM;
3626 goto out_free_mem;
3627 }
3628 sglq_entry->sli4_lxritag = lxri;
3629 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3630 }
3631 return 0;
3632
3633out_free_mem:
3634 lpfc_free_nvmet_sgl_list(phba);
3635 return rc;
3636}
3637
3638/**
James Smart895427b2017-02-12 13:52:30 -08003639 * lpfc_sli4_scsi_sgl_update - update xri-sgl sizing and mapping
3640 * @phba: pointer to lpfc hba data structure.
3641 *
3642 * This routine first calculates the sizes of the current els and allocated
3643 * scsi sgl lists, and then goes through all sgls to updates the physical
3644 * XRIs assigned due to port function reset. During port initialization, the
3645 * current els and allocated scsi sgl lists are 0s.
3646 *
3647 * Return codes
3648 * 0 - successful (for now, it always returns 0)
3649 **/
3650int
3651lpfc_sli4_scsi_sgl_update(struct lpfc_hba *phba)
3652{
3653 struct lpfc_scsi_buf *psb, *psb_next;
3654 uint16_t i, lxri, els_xri_cnt, scsi_xri_cnt;
3655 LIST_HEAD(scsi_sgl_list);
3656 int rc;
3657
3658 /*
3659 * update on pci function's els xri-sgl list
3660 */
3661 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3662 phba->total_scsi_bufs = 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003663
3664 /*
3665 * update on pci function's allocated scsi xri-sgl list
3666 */
James Smart8a9d2e82012-05-09 21:16:12 -04003667 /* maximum number of xris available for scsi buffers */
3668 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3669 els_xri_cnt;
3670
James Smart895427b2017-02-12 13:52:30 -08003671 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3672 return 0;
3673
3674 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3675 phba->sli4_hba.scsi_xri_max = /* Split them up */
3676 (phba->sli4_hba.scsi_xri_max *
3677 phba->cfg_xri_split) / 100;
James Smart8a9d2e82012-05-09 21:16:12 -04003678
James Smarta40fc5f2013-04-17 20:17:40 -04003679 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003680 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003681 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3682 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
James Smart164cecd2013-09-06 12:22:38 -04003683 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003684 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003685
James Smarte8c0a772017-04-21 16:04:49 -07003686 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3687 "6060 Current allocated SCSI xri-sgl count:%d, "
3688 "maximum SCSI xri count:%d (split:%d)\n",
3689 phba->sli4_hba.scsi_xri_cnt,
3690 phba->sli4_hba.scsi_xri_max, phba->cfg_xri_split);
3691
James Smart8a9d2e82012-05-09 21:16:12 -04003692 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3693 /* max scsi xri shrinked below the allocated scsi buffers */
3694 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3695 phba->sli4_hba.scsi_xri_max;
3696 /* release the extra allocated scsi buffers */
3697 for (i = 0; i < scsi_xri_cnt; i++) {
3698 list_remove_head(&scsi_sgl_list, psb,
3699 struct lpfc_scsi_buf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04003700 if (psb) {
Romain Perier771db5c2017-07-06 10:13:05 +02003701 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
James Smarta2fc4aef2014-09-03 12:57:55 -04003702 psb->data, psb->dma_handle);
3703 kfree(psb);
3704 }
James Smart8a9d2e82012-05-09 21:16:12 -04003705 }
James Smarta40fc5f2013-04-17 20:17:40 -04003706 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003707 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
James Smarta40fc5f2013-04-17 20:17:40 -04003708 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003709 }
3710
3711 /* update xris associated to remaining allocated scsi buffers */
3712 psb = NULL;
3713 psb_next = NULL;
3714 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3715 lxri = lpfc_sli4_next_xritag(phba);
3716 if (lxri == NO_XRI) {
3717 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3718 "2560 Failed to allocate xri for "
3719 "scsi buffer\n");
3720 rc = -ENOMEM;
3721 goto out_free_mem;
3722 }
3723 psb->cur_iocbq.sli4_lxritag = lxri;
3724 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3725 }
James Smarta40fc5f2013-04-17 20:17:40 -04003726 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003727 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003728 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3729 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
James Smart164cecd2013-09-06 12:22:38 -04003730 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003731 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
dea31012005-04-17 16:05:31 -05003732 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003733
3734out_free_mem:
James Smart8a9d2e82012-05-09 21:16:12 -04003735 lpfc_scsi_free(phba);
3736 return rc;
dea31012005-04-17 16:05:31 -05003737}
3738
James Smart96418b52017-03-04 09:30:31 -08003739static uint64_t
3740lpfc_get_wwpn(struct lpfc_hba *phba)
3741{
3742 uint64_t wwn;
3743 int rc;
3744 LPFC_MBOXQ_t *mboxq;
3745 MAILBOX_t *mb;
3746
James Smart96418b52017-03-04 09:30:31 -08003747 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
3748 GFP_KERNEL);
3749 if (!mboxq)
3750 return (uint64_t)-1;
3751
3752 /* First get WWN of HBA instance */
3753 lpfc_read_nv(phba, mboxq);
3754 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
3755 if (rc != MBX_SUCCESS) {
3756 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3757 "6019 Mailbox failed , mbxCmd x%x "
3758 "READ_NV, mbxStatus x%x\n",
3759 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
3760 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
3761 mempool_free(mboxq, phba->mbox_mem_pool);
3762 return (uint64_t) -1;
3763 }
3764 mb = &mboxq->u.mb;
3765 memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
3766 /* wwn is WWPN of HBA instance */
3767 mempool_free(mboxq, phba->mbox_mem_pool);
3768 if (phba->sli_rev == LPFC_SLI_REV4)
3769 return be64_to_cpu(wwn);
3770 else
Maurizio Lombardi286871a2017-08-23 16:55:48 -07003771 return rol64(wwn, 32);
James Smart96418b52017-03-04 09:30:31 -08003772}
3773
James Smarte59058c2008-08-24 21:49:00 -04003774/**
James Smart895427b2017-02-12 13:52:30 -08003775 * lpfc_sli4_nvme_sgl_update - update xri-sgl sizing and mapping
3776 * @phba: pointer to lpfc hba data structure.
3777 *
3778 * This routine first calculates the sizes of the current els and allocated
3779 * scsi sgl lists, and then goes through all sgls to updates the physical
3780 * XRIs assigned due to port function reset. During port initialization, the
3781 * current els and allocated scsi sgl lists are 0s.
3782 *
3783 * Return codes
3784 * 0 - successful (for now, it always returns 0)
3785 **/
3786int
3787lpfc_sli4_nvme_sgl_update(struct lpfc_hba *phba)
3788{
3789 struct lpfc_nvme_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
3790 uint16_t i, lxri, els_xri_cnt;
3791 uint16_t nvme_xri_cnt, nvme_xri_max;
3792 LIST_HEAD(nvme_sgl_list);
James Smartcf1a1d32017-12-08 17:18:03 -08003793 int rc, cnt;
James Smart895427b2017-02-12 13:52:30 -08003794
3795 phba->total_nvme_bufs = 0;
James Smartcf1a1d32017-12-08 17:18:03 -08003796 phba->get_nvme_bufs = 0;
3797 phba->put_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08003798
3799 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3800 return 0;
3801 /*
3802 * update on pci function's allocated nvme xri-sgl list
3803 */
3804
3805 /* maximum number of xris available for nvme buffers */
3806 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3807 nvme_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3808 phba->sli4_hba.nvme_xri_max = nvme_xri_max;
3809 phba->sli4_hba.nvme_xri_max -= phba->sli4_hba.scsi_xri_max;
3810
3811 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3812 "6074 Current allocated NVME xri-sgl count:%d, "
3813 "maximum NVME xri count:%d\n",
3814 phba->sli4_hba.nvme_xri_cnt,
3815 phba->sli4_hba.nvme_xri_max);
3816
3817 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3818 spin_lock(&phba->nvme_buf_list_put_lock);
3819 list_splice_init(&phba->lpfc_nvme_buf_list_get, &nvme_sgl_list);
3820 list_splice(&phba->lpfc_nvme_buf_list_put, &nvme_sgl_list);
James Smartcf1a1d32017-12-08 17:18:03 -08003821 cnt = phba->get_nvme_bufs + phba->put_nvme_bufs;
3822 phba->get_nvme_bufs = 0;
3823 phba->put_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08003824 spin_unlock(&phba->nvme_buf_list_put_lock);
3825 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3826
3827 if (phba->sli4_hba.nvme_xri_cnt > phba->sli4_hba.nvme_xri_max) {
3828 /* max nvme xri shrunk below the allocated nvme buffers */
3829 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3830 nvme_xri_cnt = phba->sli4_hba.nvme_xri_cnt -
3831 phba->sli4_hba.nvme_xri_max;
3832 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3833 /* release the extra allocated nvme buffers */
3834 for (i = 0; i < nvme_xri_cnt; i++) {
3835 list_remove_head(&nvme_sgl_list, lpfc_ncmd,
3836 struct lpfc_nvme_buf, list);
3837 if (lpfc_ncmd) {
Romain Perier771db5c2017-07-06 10:13:05 +02003838 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
James Smart895427b2017-02-12 13:52:30 -08003839 lpfc_ncmd->data,
3840 lpfc_ncmd->dma_handle);
3841 kfree(lpfc_ncmd);
3842 }
3843 }
3844 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3845 phba->sli4_hba.nvme_xri_cnt -= nvme_xri_cnt;
3846 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3847 }
3848
3849 /* update xris associated to remaining allocated nvme buffers */
3850 lpfc_ncmd = NULL;
3851 lpfc_ncmd_next = NULL;
3852 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3853 &nvme_sgl_list, list) {
3854 lxri = lpfc_sli4_next_xritag(phba);
3855 if (lxri == NO_XRI) {
3856 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3857 "6075 Failed to allocate xri for "
3858 "nvme buffer\n");
3859 rc = -ENOMEM;
3860 goto out_free_mem;
3861 }
3862 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
3863 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3864 }
3865 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3866 spin_lock(&phba->nvme_buf_list_put_lock);
3867 list_splice_init(&nvme_sgl_list, &phba->lpfc_nvme_buf_list_get);
James Smartcf1a1d32017-12-08 17:18:03 -08003868 phba->get_nvme_bufs = cnt;
James Smart895427b2017-02-12 13:52:30 -08003869 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
3870 spin_unlock(&phba->nvme_buf_list_put_lock);
3871 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3872 return 0;
3873
3874out_free_mem:
3875 lpfc_nvme_free(phba);
3876 return rc;
3877}
3878
3879/**
James Smart3621a712009-04-06 18:47:14 -04003880 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04003881 * @phba: pointer to lpfc hba data structure.
3882 * @instance: a unique integer ID to this FC port.
3883 * @dev: pointer to the device data structure.
3884 *
3885 * This routine creates a FC port for the upper layer protocol. The FC port
3886 * can be created on top of either a physical port or a virtual port provided
3887 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3888 * and associates the FC port created before adding the shost into the SCSI
3889 * layer.
3890 *
3891 * Return codes
3892 * @vport - pointer to the virtual N_Port data structure.
3893 * NULL - port create failed.
3894 **/
James Smart2e0fef82007-06-17 19:56:36 -05003895struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04003896lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04003897{
James Smart2e0fef82007-06-17 19:56:36 -05003898 struct lpfc_vport *vport;
James Smart895427b2017-02-12 13:52:30 -08003899 struct Scsi_Host *shost = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003900 int error = 0;
James Smart96418b52017-03-04 09:30:31 -08003901 int i;
3902 uint64_t wwn;
3903 bool use_no_reset_hba = false;
James Smart56bc8022017-06-15 22:56:43 -07003904 int rc;
James Smart96418b52017-03-04 09:30:31 -08003905
James Smart56bc8022017-06-15 22:56:43 -07003906 if (lpfc_no_hba_reset_cnt) {
3907 if (phba->sli_rev < LPFC_SLI_REV4 &&
3908 dev == &phba->pcidev->dev) {
3909 /* Reset the port first */
3910 lpfc_sli_brdrestart(phba);
3911 rc = lpfc_sli_chipset_init(phba);
3912 if (rc)
3913 return NULL;
3914 }
3915 wwn = lpfc_get_wwpn(phba);
3916 }
James Smart96418b52017-03-04 09:30:31 -08003917
3918 for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
3919 if (wwn == lpfc_no_hba_reset[i]) {
3920 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3921 "6020 Setting use_no_reset port=%llx\n",
3922 wwn);
3923 use_no_reset_hba = true;
3924 break;
3925 }
3926 }
James Smart47a86172007-04-25 09:53:22 -04003927
James Smart895427b2017-02-12 13:52:30 -08003928 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
3929 if (dev != &phba->pcidev->dev) {
3930 shost = scsi_host_alloc(&lpfc_vport_template,
3931 sizeof(struct lpfc_vport));
3932 } else {
James Smart96418b52017-03-04 09:30:31 -08003933 if (!use_no_reset_hba)
James Smart895427b2017-02-12 13:52:30 -08003934 shost = scsi_host_alloc(&lpfc_template,
3935 sizeof(struct lpfc_vport));
3936 else
James Smart96418b52017-03-04 09:30:31 -08003937 shost = scsi_host_alloc(&lpfc_template_no_hr,
James Smart895427b2017-02-12 13:52:30 -08003938 sizeof(struct lpfc_vport));
3939 }
3940 } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
3941 shost = scsi_host_alloc(&lpfc_template_nvme,
James Smartea4142f2015-04-07 15:07:13 -04003942 sizeof(struct lpfc_vport));
3943 }
James Smart2e0fef82007-06-17 19:56:36 -05003944 if (!shost)
3945 goto out;
James Smart47a86172007-04-25 09:53:22 -04003946
James Smart2e0fef82007-06-17 19:56:36 -05003947 vport = (struct lpfc_vport *) shost->hostdata;
3948 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05003949 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05003950 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05003951 vport->fc_rscn_flush = 0;
James Smart3de2a652007-08-02 11:09:59 -04003952 lpfc_get_vport_cfgparam(vport);
James Smart895427b2017-02-12 13:52:30 -08003953
James Smart2e0fef82007-06-17 19:56:36 -05003954 shost->unique_id = instance;
3955 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04003956 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05003957 shost->this_id = -1;
3958 shost->max_cmd_len = 16;
James Smart8b0dff12015-05-22 10:42:38 -04003959 shost->nr_hw_queues = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04003960 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05003961 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04003962 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smart5b9e70b2018-09-10 10:30:42 -07003963 shost->sg_tablesize = phba->cfg_scsi_seg_cnt;
James Smartda0436e2009-05-22 14:51:39 -04003964 }
James Smart81301a92008-12-04 22:39:46 -05003965
James Smart47a86172007-04-25 09:53:22 -04003966 /*
James Smart2e0fef82007-06-17 19:56:36 -05003967 * Set initial can_queue value since 0 is no longer supported and
3968 * scsi_add_host will fail. This will be adjusted later based on the
3969 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04003970 */
James Smart2e0fef82007-06-17 19:56:36 -05003971 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04003972 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05003973 shost->transportt = lpfc_vport_transport_template;
3974 vport->port_type = LPFC_NPIV_PORT;
3975 } else {
3976 shost->transportt = lpfc_transport_template;
3977 vport->port_type = LPFC_PHYSICAL_PORT;
3978 }
James Smart47a86172007-04-25 09:53:22 -04003979
James Smart2e0fef82007-06-17 19:56:36 -05003980 /* Initialize all internally managed lists. */
3981 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04003982 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05003983 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04003984
Kees Cookf22eb4d2017-09-06 20:24:26 -07003985 timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0);
James Smart47a86172007-04-25 09:53:22 -04003986
Kees Cookf22eb4d2017-09-06 20:24:26 -07003987 timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0);
James Smart92494142011-02-16 12:39:44 -05003988
Kees Cookf22eb4d2017-09-06 20:24:26 -07003989 timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0);
James Smart92494142011-02-16 12:39:44 -05003990
James Bottomleyd139b9b2009-11-05 13:33:12 -06003991 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05003992 if (error)
3993 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04003994
James Smart523128e2018-09-10 10:30:46 -07003995 spin_lock_irq(&phba->port_list_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003996 list_add_tail(&vport->listentry, &phba->port_list);
James Smart523128e2018-09-10 10:30:46 -07003997 spin_unlock_irq(&phba->port_list_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003998 return vport;
James Smart47a86172007-04-25 09:53:22 -04003999
James Smart2e0fef82007-06-17 19:56:36 -05004000out_put_shost:
4001 scsi_host_put(shost);
4002out:
4003 return NULL;
James Smart47a86172007-04-25 09:53:22 -04004004}
4005
James Smarte59058c2008-08-24 21:49:00 -04004006/**
James Smart3621a712009-04-06 18:47:14 -04004007 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04004008 * @vport: pointer to an lpfc virtual N_Port data structure.
4009 *
4010 * This routine destroys a FC port from the upper layer protocol. All the
4011 * resources associated with the port are released.
4012 **/
James Smart2e0fef82007-06-17 19:56:36 -05004013void
4014destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04004015{
James Smart92d7f7b2007-06-17 19:56:38 -05004016 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4017 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04004018
James Smart858c9f62007-06-17 19:56:39 -05004019 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05004020 fc_remove_host(shost);
4021 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04004022
James Smart523128e2018-09-10 10:30:46 -07004023 spin_lock_irq(&phba->port_list_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004024 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -07004025 spin_unlock_irq(&phba->port_list_lock);
James Smart47a86172007-04-25 09:53:22 -04004026
James Smart92d7f7b2007-06-17 19:56:38 -05004027 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04004028 return;
James Smart47a86172007-04-25 09:53:22 -04004029}
4030
James Smarte59058c2008-08-24 21:49:00 -04004031/**
James Smart3621a712009-04-06 18:47:14 -04004032 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04004033 *
4034 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
4035 * uses the kernel idr facility to perform the task.
4036 *
4037 * Return codes:
4038 * instance - a unique integer ID allocated as the new instance.
4039 * -1 - lpfc get instance failed.
4040 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004041int
4042lpfc_get_instance(void)
4043{
Tejun Heoab516032013-02-27 17:04:44 -08004044 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05004045
Tejun Heoab516032013-02-27 17:04:44 -08004046 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
4047 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05004048}
4049
James Smarte59058c2008-08-24 21:49:00 -04004050/**
James Smart3621a712009-04-06 18:47:14 -04004051 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04004052 * @shost: pointer to SCSI host data structure.
4053 * @time: elapsed time of the scan in jiffies.
4054 *
4055 * This routine is called by the SCSI layer with a SCSI host to determine
4056 * whether the scan host is finished.
4057 *
4058 * Note: there is no scan_start function as adapter initialization will have
4059 * asynchronously kicked off the link initialization.
4060 *
4061 * Return codes
4062 * 0 - SCSI host scan is not over yet.
4063 * 1 - SCSI host scan is over.
4064 **/
James Smart47a86172007-04-25 09:53:22 -04004065int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
4066{
James Smart2e0fef82007-06-17 19:56:36 -05004067 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4068 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05004069 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04004070
James Smart858c9f62007-06-17 19:56:39 -05004071 spin_lock_irq(shost->host_lock);
4072
James Smart51ef4c22007-08-02 11:10:31 -04004073 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05004074 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004075 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05004076 }
James Smart256ec0d2013-04-17 20:14:58 -04004077 if (time >= msecs_to_jiffies(30 * 1000)) {
James Smart2e0fef82007-06-17 19:56:36 -05004078 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004079 "0461 Scanning longer than 30 "
4080 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05004081 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004082 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004083 }
James Smart256ec0d2013-04-17 20:14:58 -04004084 if (time >= msecs_to_jiffies(15 * 1000) &&
4085 phba->link_state <= LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05004086 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004087 "0465 Link down longer than 15 "
4088 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05004089 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05004090 goto finished;
James Smart47a86172007-04-25 09:53:22 -04004091 }
4092
James Smart2e0fef82007-06-17 19:56:36 -05004093 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05004094 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004095 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05004096 goto finished;
James Smart256ec0d2013-04-17 20:14:58 -04004097 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
James Smart858c9f62007-06-17 19:56:39 -05004098 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004099 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05004100 goto finished;
4101
4102 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004103
4104finished:
James Smart858c9f62007-06-17 19:56:39 -05004105 spin_unlock_irq(shost->host_lock);
4106 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05004107}
4108
James Smarte59058c2008-08-24 21:49:00 -04004109/**
James Smart3621a712009-04-06 18:47:14 -04004110 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04004111 * @shost: pointer to SCSI host data structure.
4112 *
4113 * This routine initializes a given SCSI host attributes on a FC port. The
4114 * SCSI host can be either on top of a physical port or a virtual port.
4115 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004116void lpfc_host_attrib_init(struct Scsi_Host *shost)
4117{
4118 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4119 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04004120 /*
James Smart2e0fef82007-06-17 19:56:36 -05004121 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04004122 */
4123
James Smart2e0fef82007-06-17 19:56:36 -05004124 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
4125 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04004126 fc_host_supported_classes(shost) = FC_COS_CLASS3;
4127
4128 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05004129 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04004130 fc_host_supported_fc4s(shost)[2] = 1;
4131 fc_host_supported_fc4s(shost)[7] = 1;
4132
James Smart92d7f7b2007-06-17 19:56:38 -05004133 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
4134 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04004135
4136 fc_host_supported_speeds(shost) = 0;
James Smartfbd8a6b2018-02-22 08:18:45 -08004137 if (phba->lmt & LMT_64Gb)
4138 fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT;
James Smartd38dd522015-08-31 16:48:17 -04004139 if (phba->lmt & LMT_32Gb)
4140 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
James Smart88a2cfb2011-07-22 18:36:33 -04004141 if (phba->lmt & LMT_16Gb)
4142 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
James Smart47a86172007-04-25 09:53:22 -04004143 if (phba->lmt & LMT_10Gb)
4144 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04004145 if (phba->lmt & LMT_8Gb)
4146 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04004147 if (phba->lmt & LMT_4Gb)
4148 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
4149 if (phba->lmt & LMT_2Gb)
4150 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
4151 if (phba->lmt & LMT_1Gb)
4152 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
4153
4154 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05004155 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
4156 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04004157
Mike Christie0af5d702010-09-15 16:52:31 -05004158 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
4159
James Smart47a86172007-04-25 09:53:22 -04004160 /* This value is also unchanging */
4161 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05004162 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04004163 fc_host_active_fc4s(shost)[2] = 1;
4164 fc_host_active_fc4s(shost)[7] = 1;
4165
James Smart92d7f7b2007-06-17 19:56:38 -05004166 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04004167 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04004168 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04004169 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04004170}
dea31012005-04-17 16:05:31 -05004171
James Smarte59058c2008-08-24 21:49:00 -04004172/**
James Smartda0436e2009-05-22 14:51:39 -04004173 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04004174 * @phba: pointer to lpfc hba data structure.
4175 *
James Smartda0436e2009-05-22 14:51:39 -04004176 * This routine is invoked to stop an SLI3 device port, it stops the device
4177 * from generating interrupts and stops the device driver's timers for the
4178 * device.
James Smarte59058c2008-08-24 21:49:00 -04004179 **/
James Smartdb2378e2008-02-08 18:49:51 -05004180static void
James Smartda0436e2009-05-22 14:51:39 -04004181lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05004182{
James Smartda0436e2009-05-22 14:51:39 -04004183 /* Clear all interrupt enable conditions */
4184 writel(0, phba->HCregaddr);
4185 readl(phba->HCregaddr); /* flush */
4186 /* Clear all pending interrupts */
4187 writel(0xffffffff, phba->HAregaddr);
4188 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04004189
James Smartda0436e2009-05-22 14:51:39 -04004190 /* Reset some HBA SLI setup states */
4191 lpfc_stop_hba_timers(phba);
4192 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05004193}
4194
James Smarte59058c2008-08-24 21:49:00 -04004195/**
James Smartda0436e2009-05-22 14:51:39 -04004196 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05004197 * @phba: pointer to lpfc hba data structure.
4198 *
James Smartda0436e2009-05-22 14:51:39 -04004199 * This routine is invoked to stop an SLI4 device port, it stops the device
4200 * from generating interrupts and stops the device driver's timers for the
4201 * device.
4202 **/
4203static void
4204lpfc_stop_port_s4(struct lpfc_hba *phba)
4205{
4206 /* Reset some HBA SLI4 setup states */
4207 lpfc_stop_hba_timers(phba);
4208 phba->pport->work_port_events = 0;
4209 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04004210}
4211
4212/**
4213 * lpfc_stop_port - Wrapper function for stopping hba port
4214 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05004215 *
James Smartda0436e2009-05-22 14:51:39 -04004216 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
4217 * the API jump table function pointer from the lpfc_hba struct.
4218 **/
4219void
4220lpfc_stop_port(struct lpfc_hba *phba)
4221{
4222 phba->lpfc_stop_port(phba);
Dick Kennedyf485c182017-09-29 17:34:34 -07004223
4224 if (phba->wq)
4225 flush_workqueue(phba->wq);
James Smartda0436e2009-05-22 14:51:39 -04004226}
4227
4228/**
James Smartecfd03c2010-02-12 14:41:27 -05004229 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
4230 * @phba: Pointer to hba for which this call is being executed.
4231 *
4232 * This routine starts the timer waiting for the FCF rediscovery to complete.
4233 **/
4234void
4235lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
4236{
4237 unsigned long fcf_redisc_wait_tmo =
4238 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
4239 /* Start fcf rediscovery wait period timer */
4240 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
4241 spin_lock_irq(&phba->hbalock);
4242 /* Allow action to new fcf asynchronous event */
4243 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
4244 /* Mark the FCF rediscovery pending state */
4245 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
4246 spin_unlock_irq(&phba->hbalock);
4247}
4248
4249/**
4250 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
4251 * @ptr: Map to lpfc_hba data structure pointer.
4252 *
4253 * This routine is invoked when waiting for FCF table rediscover has been
4254 * timed out. If new FCF record(s) has (have) been discovered during the
4255 * wait period, a new FCF event shall be added to the FCOE async event
4256 * list, and then worker thread shall be waked up for processing from the
4257 * worker thread context.
4258 **/
Rashika Kheriae399b222014-09-03 12:55:28 -04004259static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07004260lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t)
James Smartecfd03c2010-02-12 14:41:27 -05004261{
Kees Cookf22eb4d2017-09-06 20:24:26 -07004262 struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait);
James Smartecfd03c2010-02-12 14:41:27 -05004263
4264 /* Don't send FCF rediscovery event if timer cancelled */
4265 spin_lock_irq(&phba->hbalock);
4266 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
4267 spin_unlock_irq(&phba->hbalock);
4268 return;
4269 }
4270 /* Clear FCF rediscovery timer pending flag */
4271 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
4272 /* FCF rediscovery event to worker thread */
4273 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
4274 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004275 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04004276 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05004277 /* wake up worker thread */
4278 lpfc_worker_wake_up(phba);
4279}
4280
4281/**
James Smartda0436e2009-05-22 14:51:39 -04004282 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
4283 * @phba: pointer to lpfc hba data structure.
4284 * @acqe_link: pointer to the async link completion queue entry.
4285 *
James Smart23288b72018-05-04 20:37:53 -07004286 * This routine is to parse the SLI4 link-attention link fault code.
James Smartda0436e2009-05-22 14:51:39 -04004287 **/
James Smart23288b72018-05-04 20:37:53 -07004288static void
James Smartda0436e2009-05-22 14:51:39 -04004289lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
4290 struct lpfc_acqe_link *acqe_link)
4291{
James Smartda0436e2009-05-22 14:51:39 -04004292 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
4293 case LPFC_ASYNC_LINK_FAULT_NONE:
4294 case LPFC_ASYNC_LINK_FAULT_LOCAL:
4295 case LPFC_ASYNC_LINK_FAULT_REMOTE:
James Smart23288b72018-05-04 20:37:53 -07004296 case LPFC_ASYNC_LINK_FAULT_LR_LRR:
James Smartda0436e2009-05-22 14:51:39 -04004297 break;
4298 default:
4299 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart23288b72018-05-04 20:37:53 -07004300 "0398 Unknown link fault code: x%x\n",
James Smartda0436e2009-05-22 14:51:39 -04004301 bf_get(lpfc_acqe_link_fault, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04004302 break;
4303 }
James Smartda0436e2009-05-22 14:51:39 -04004304}
4305
4306/**
4307 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
4308 * @phba: pointer to lpfc hba data structure.
4309 * @acqe_link: pointer to the async link completion queue entry.
4310 *
4311 * This routine is to parse the SLI4 link attention type and translate it
4312 * into the base driver's link attention type coding.
4313 *
4314 * Return: Link attention type in terms of base driver's coding.
4315 **/
4316static uint8_t
4317lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
4318 struct lpfc_acqe_link *acqe_link)
4319{
4320 uint8_t att_type;
4321
4322 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
4323 case LPFC_ASYNC_LINK_STATUS_DOWN:
4324 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05004325 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04004326 break;
4327 case LPFC_ASYNC_LINK_STATUS_UP:
4328 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05004329 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004330 break;
4331 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05004332 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04004333 break;
4334 default:
4335 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4336 "0399 Invalid link attention type: x%x\n",
4337 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05004338 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004339 break;
4340 }
4341 return att_type;
4342}
4343
4344/**
James Smart8b68cd52012-09-29 11:32:37 -04004345 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
4346 * @phba: pointer to lpfc hba data structure.
4347 *
4348 * This routine is to get an SLI3 FC port's link speed in Mbps.
4349 *
4350 * Return: link speed in terms of Mbps.
4351 **/
4352uint32_t
4353lpfc_sli_port_speed_get(struct lpfc_hba *phba)
4354{
4355 uint32_t link_speed;
4356
4357 if (!lpfc_is_link_up(phba))
4358 return 0;
4359
James Smarta085e872015-12-16 18:12:02 -05004360 if (phba->sli_rev <= LPFC_SLI_REV3) {
4361 switch (phba->fc_linkspeed) {
4362 case LPFC_LINK_SPEED_1GHZ:
4363 link_speed = 1000;
4364 break;
4365 case LPFC_LINK_SPEED_2GHZ:
4366 link_speed = 2000;
4367 break;
4368 case LPFC_LINK_SPEED_4GHZ:
4369 link_speed = 4000;
4370 break;
4371 case LPFC_LINK_SPEED_8GHZ:
4372 link_speed = 8000;
4373 break;
4374 case LPFC_LINK_SPEED_10GHZ:
4375 link_speed = 10000;
4376 break;
4377 case LPFC_LINK_SPEED_16GHZ:
4378 link_speed = 16000;
4379 break;
4380 default:
4381 link_speed = 0;
4382 }
4383 } else {
4384 if (phba->sli4_hba.link_state.logical_speed)
4385 link_speed =
4386 phba->sli4_hba.link_state.logical_speed;
4387 else
4388 link_speed = phba->sli4_hba.link_state.speed;
James Smart8b68cd52012-09-29 11:32:37 -04004389 }
4390 return link_speed;
4391}
4392
4393/**
4394 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
4395 * @phba: pointer to lpfc hba data structure.
4396 * @evt_code: asynchronous event code.
4397 * @speed_code: asynchronous event link speed code.
4398 *
4399 * This routine is to parse the giving SLI4 async event link speed code into
4400 * value of Mbps for the link speed.
4401 *
4402 * Return: link speed in terms of Mbps.
4403 **/
4404static uint32_t
4405lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
4406 uint8_t speed_code)
4407{
4408 uint32_t port_speed;
4409
4410 switch (evt_code) {
4411 case LPFC_TRAILER_CODE_LINK:
4412 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004413 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smart8b68cd52012-09-29 11:32:37 -04004414 port_speed = 0;
4415 break;
James Smart26d830e2015-04-07 15:07:17 -04004416 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004417 port_speed = 10;
4418 break;
James Smart26d830e2015-04-07 15:07:17 -04004419 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004420 port_speed = 100;
4421 break;
James Smart26d830e2015-04-07 15:07:17 -04004422 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004423 port_speed = 1000;
4424 break;
James Smart26d830e2015-04-07 15:07:17 -04004425 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004426 port_speed = 10000;
4427 break;
James Smart26d830e2015-04-07 15:07:17 -04004428 case LPFC_ASYNC_LINK_SPEED_20GBPS:
4429 port_speed = 20000;
4430 break;
4431 case LPFC_ASYNC_LINK_SPEED_25GBPS:
4432 port_speed = 25000;
4433 break;
4434 case LPFC_ASYNC_LINK_SPEED_40GBPS:
4435 port_speed = 40000;
4436 break;
James Smart8b68cd52012-09-29 11:32:37 -04004437 default:
4438 port_speed = 0;
4439 }
4440 break;
4441 case LPFC_TRAILER_CODE_FC:
4442 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004443 case LPFC_FC_LA_SPEED_UNKNOWN:
James Smart8b68cd52012-09-29 11:32:37 -04004444 port_speed = 0;
4445 break;
James Smart26d830e2015-04-07 15:07:17 -04004446 case LPFC_FC_LA_SPEED_1G:
James Smart8b68cd52012-09-29 11:32:37 -04004447 port_speed = 1000;
4448 break;
James Smart26d830e2015-04-07 15:07:17 -04004449 case LPFC_FC_LA_SPEED_2G:
James Smart8b68cd52012-09-29 11:32:37 -04004450 port_speed = 2000;
4451 break;
James Smart26d830e2015-04-07 15:07:17 -04004452 case LPFC_FC_LA_SPEED_4G:
James Smart8b68cd52012-09-29 11:32:37 -04004453 port_speed = 4000;
4454 break;
James Smart26d830e2015-04-07 15:07:17 -04004455 case LPFC_FC_LA_SPEED_8G:
James Smart8b68cd52012-09-29 11:32:37 -04004456 port_speed = 8000;
4457 break;
James Smart26d830e2015-04-07 15:07:17 -04004458 case LPFC_FC_LA_SPEED_10G:
James Smart8b68cd52012-09-29 11:32:37 -04004459 port_speed = 10000;
4460 break;
James Smart26d830e2015-04-07 15:07:17 -04004461 case LPFC_FC_LA_SPEED_16G:
James Smart8b68cd52012-09-29 11:32:37 -04004462 port_speed = 16000;
4463 break;
James Smartd38dd522015-08-31 16:48:17 -04004464 case LPFC_FC_LA_SPEED_32G:
4465 port_speed = 32000;
4466 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08004467 case LPFC_FC_LA_SPEED_64G:
4468 port_speed = 64000;
4469 break;
James Smart8b68cd52012-09-29 11:32:37 -04004470 default:
4471 port_speed = 0;
4472 }
4473 break;
4474 default:
4475 port_speed = 0;
4476 }
4477 return port_speed;
4478}
4479
4480/**
James Smart70f3c072010-12-15 17:57:33 -05004481 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04004482 * @phba: pointer to lpfc hba data structure.
4483 * @acqe_link: pointer to the async link completion queue entry.
4484 *
James Smart70f3c072010-12-15 17:57:33 -05004485 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04004486 **/
4487static void
4488lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
4489 struct lpfc_acqe_link *acqe_link)
4490{
4491 struct lpfc_dmabuf *mp;
4492 LPFC_MBOXQ_t *pmb;
4493 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05004494 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04004495 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05004496 int rc;
James Smartda0436e2009-05-22 14:51:39 -04004497
4498 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05004499 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04004500 return;
James Smart32b97932009-07-19 10:01:21 -04004501 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004502 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4503 if (!pmb) {
4504 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4505 "0395 The mboxq allocation failed\n");
4506 return;
4507 }
4508 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4509 if (!mp) {
4510 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4511 "0396 The lpfc_dmabuf allocation failed\n");
4512 goto out_free_pmb;
4513 }
4514 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4515 if (!mp->virt) {
4516 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4517 "0397 The mbuf allocation failed\n");
4518 goto out_free_dmabuf;
4519 }
4520
4521 /* Cleanup any outstanding ELS commands */
4522 lpfc_els_flush_all_cmd(phba);
4523
4524 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004525 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smartda0436e2009-05-22 14:51:39 -04004526
4527 /* Update link event statistics */
4528 phba->sli.slistat.link_event++;
4529
James Smart76a95d72010-11-20 23:11:48 -05004530 /* Create lpfc_handle_latt mailbox command from link ACQE */
4531 lpfc_read_topology(phba, pmb, mp);
4532 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04004533 pmb->vport = phba->pport;
4534
James Smartda0436e2009-05-22 14:51:39 -04004535 /* Keep the link status for extra SLI4 state machine reference */
4536 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004537 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
4538 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04004539 phba->sli4_hba.link_state.duplex =
4540 bf_get(lpfc_acqe_link_duplex, acqe_link);
4541 phba->sli4_hba.link_state.status =
4542 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05004543 phba->sli4_hba.link_state.type =
4544 bf_get(lpfc_acqe_link_type, acqe_link);
4545 phba->sli4_hba.link_state.number =
4546 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04004547 phba->sli4_hba.link_state.fault =
4548 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05004549 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004550 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
4551
James Smart70f3c072010-12-15 17:57:33 -05004552 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04004553 "2900 Async FC/FCoE Link event - Speed:%dGBit "
4554 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
4555 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05004556 phba->sli4_hba.link_state.speed,
4557 phba->sli4_hba.link_state.topology,
4558 phba->sli4_hba.link_state.status,
4559 phba->sli4_hba.link_state.type,
4560 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004561 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004562 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05004563 /*
4564 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
4565 * topology info. Note: Optional for non FC-AL ports.
4566 */
4567 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
4568 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4569 if (rc == MBX_NOT_FINISHED)
4570 goto out_free_dmabuf;
4571 return;
4572 }
4573 /*
4574 * For FCoE Mode: fill in all the topology information we need and call
4575 * the READ_TOPOLOGY completion routine to continue without actually
4576 * sending the READ_TOPOLOGY mailbox command to the port.
4577 */
James Smart23288b72018-05-04 20:37:53 -07004578 /* Initialize completion status */
James Smart76a95d72010-11-20 23:11:48 -05004579 mb = &pmb->u.mb;
James Smart23288b72018-05-04 20:37:53 -07004580 mb->mbxStatus = MBX_SUCCESS;
4581
4582 /* Parse port fault information field */
4583 lpfc_sli4_parse_latt_fault(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05004584
4585 /* Parse and translate link attention fields */
4586 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
4587 la->eventTag = acqe_link->event_tag;
4588 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
4589 bf_set(lpfc_mbx_read_top_link_spd, la,
James Smarta085e872015-12-16 18:12:02 -05004590 (bf_get(lpfc_acqe_link_speed, acqe_link)));
James Smart76a95d72010-11-20 23:11:48 -05004591
4592 /* Fake the the following irrelvant fields */
4593 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
4594 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
4595 bf_set(lpfc_mbx_read_top_il, la, 0);
4596 bf_set(lpfc_mbx_read_top_pb, la, 0);
4597 bf_set(lpfc_mbx_read_top_fa, la, 0);
4598 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04004599
4600 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05004601 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04004602
4603 return;
4604
4605out_free_dmabuf:
4606 kfree(mp);
4607out_free_pmb:
4608 mempool_free(pmb, phba->mbox_mem_pool);
4609}
4610
4611/**
James Smart70f3c072010-12-15 17:57:33 -05004612 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
4613 * @phba: pointer to lpfc hba data structure.
4614 * @acqe_fc: pointer to the async fc completion queue entry.
4615 *
4616 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
4617 * that the event was received and then issue a read_topology mailbox command so
4618 * that the rest of the driver will treat it the same as SLI3.
4619 **/
4620static void
4621lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
4622{
4623 struct lpfc_dmabuf *mp;
4624 LPFC_MBOXQ_t *pmb;
James Smart7bdedb32016-07-06 12:36:00 -07004625 MAILBOX_t *mb;
4626 struct lpfc_mbx_read_top *la;
James Smart70f3c072010-12-15 17:57:33 -05004627 int rc;
4628
4629 if (bf_get(lpfc_trailer_type, acqe_fc) !=
4630 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
4631 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4632 "2895 Non FC link Event detected.(%d)\n",
4633 bf_get(lpfc_trailer_type, acqe_fc));
4634 return;
4635 }
4636 /* Keep the link status for extra SLI4 state machine reference */
4637 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004638 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
4639 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05004640 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
4641 phba->sli4_hba.link_state.topology =
4642 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
4643 phba->sli4_hba.link_state.status =
4644 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
4645 phba->sli4_hba.link_state.type =
4646 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
4647 phba->sli4_hba.link_state.number =
4648 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
4649 phba->sli4_hba.link_state.fault =
4650 bf_get(lpfc_acqe_link_fault, acqe_fc);
4651 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004652 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart70f3c072010-12-15 17:57:33 -05004653 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4654 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4655 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4656 "%dMbps Fault:%d\n",
4657 phba->sli4_hba.link_state.speed,
4658 phba->sli4_hba.link_state.topology,
4659 phba->sli4_hba.link_state.status,
4660 phba->sli4_hba.link_state.type,
4661 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004662 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004663 phba->sli4_hba.link_state.fault);
4664 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4665 if (!pmb) {
4666 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4667 "2897 The mboxq allocation failed\n");
4668 return;
4669 }
4670 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4671 if (!mp) {
4672 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4673 "2898 The lpfc_dmabuf allocation failed\n");
4674 goto out_free_pmb;
4675 }
4676 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4677 if (!mp->virt) {
4678 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4679 "2899 The mbuf allocation failed\n");
4680 goto out_free_dmabuf;
4681 }
4682
4683 /* Cleanup any outstanding ELS commands */
4684 lpfc_els_flush_all_cmd(phba);
4685
4686 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004687 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smart70f3c072010-12-15 17:57:33 -05004688
4689 /* Update link event statistics */
4690 phba->sli.slistat.link_event++;
4691
4692 /* Create lpfc_handle_latt mailbox command from link ACQE */
4693 lpfc_read_topology(phba, pmb, mp);
4694 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4695 pmb->vport = phba->pport;
4696
James Smart7bdedb32016-07-06 12:36:00 -07004697 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
James Smartae9e28f2017-05-15 15:20:51 -07004698 phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK);
4699
4700 switch (phba->sli4_hba.link_state.status) {
4701 case LPFC_FC_LA_TYPE_MDS_LINK_DOWN:
4702 phba->link_flag |= LS_MDS_LINK_DOWN;
4703 break;
4704 case LPFC_FC_LA_TYPE_MDS_LOOPBACK:
4705 phba->link_flag |= LS_MDS_LOOPBACK;
4706 break;
4707 default:
4708 break;
4709 }
4710
James Smart23288b72018-05-04 20:37:53 -07004711 /* Initialize completion status */
James Smart7bdedb32016-07-06 12:36:00 -07004712 mb = &pmb->u.mb;
James Smart23288b72018-05-04 20:37:53 -07004713 mb->mbxStatus = MBX_SUCCESS;
4714
4715 /* Parse port fault information field */
4716 lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc);
James Smart7bdedb32016-07-06 12:36:00 -07004717
4718 /* Parse and translate link attention fields */
4719 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
4720 la->eventTag = acqe_fc->event_tag;
James Smart7bdedb32016-07-06 12:36:00 -07004721
James Smartaeb3c812017-04-21 16:05:02 -07004722 if (phba->sli4_hba.link_state.status ==
4723 LPFC_FC_LA_TYPE_UNEXP_WWPN) {
4724 bf_set(lpfc_mbx_read_top_att_type, la,
4725 LPFC_FC_LA_TYPE_UNEXP_WWPN);
4726 } else {
4727 bf_set(lpfc_mbx_read_top_att_type, la,
4728 LPFC_FC_LA_TYPE_LINK_DOWN);
4729 }
James Smart7bdedb32016-07-06 12:36:00 -07004730 /* Invoke the mailbox command callback function */
4731 lpfc_mbx_cmpl_read_topology(phba, pmb);
4732
4733 return;
4734 }
4735
James Smart70f3c072010-12-15 17:57:33 -05004736 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4737 if (rc == MBX_NOT_FINISHED)
4738 goto out_free_dmabuf;
4739 return;
4740
4741out_free_dmabuf:
4742 kfree(mp);
4743out_free_pmb:
4744 mempool_free(pmb, phba->mbox_mem_pool);
4745}
4746
4747/**
4748 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4749 * @phba: pointer to lpfc hba data structure.
4750 * @acqe_fc: pointer to the async SLI completion queue entry.
4751 *
4752 * This routine is to handle the SLI4 asynchronous SLI events.
4753 **/
4754static void
4755lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
4756{
James Smart4b8bae02012-06-12 13:55:07 -04004757 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04004758 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04004759 uint8_t status;
James Smart946727d2015-04-07 15:07:09 -04004760 uint8_t evt_type;
James Smart448193b2015-12-16 18:12:05 -05004761 uint8_t operational = 0;
James Smart946727d2015-04-07 15:07:09 -04004762 struct temp_event temp_event_data;
James Smart4b8bae02012-06-12 13:55:07 -04004763 struct lpfc_acqe_misconfigured_event *misconfigured;
James Smart946727d2015-04-07 15:07:09 -04004764 struct Scsi_Host *shost;
James Smart4b8bae02012-06-12 13:55:07 -04004765
James Smart946727d2015-04-07 15:07:09 -04004766 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
4767
James Smart448193b2015-12-16 18:12:05 -05004768 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4769 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4770 "x%08x SLI Event Type:%d\n",
4771 acqe_sli->event_data1, acqe_sli->event_data2,
4772 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004773
4774 port_name = phba->Port[0];
4775 if (port_name == 0x00)
4776 port_name = '?'; /* get port name is empty */
4777
James Smart946727d2015-04-07 15:07:09 -04004778 switch (evt_type) {
4779 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
4780 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4781 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
4782 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4783
4784 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4785 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4786 acqe_sli->event_data1, port_name);
4787
James Smart310429e2016-07-06 12:35:54 -07004788 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04004789 shost = lpfc_shost_from_vport(phba->pport);
4790 fc_host_post_vendor_event(shost, fc_get_event_number(),
4791 sizeof(temp_event_data),
4792 (char *)&temp_event_data,
4793 SCSI_NL_VID_TYPE_PCI
4794 | PCI_VENDOR_ID_EMULEX);
4795 break;
4796 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
4797 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4798 temp_event_data.event_code = LPFC_NORMAL_TEMP;
4799 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4800
4801 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4802 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4803 acqe_sli->event_data1, port_name);
4804
4805 shost = lpfc_shost_from_vport(phba->pport);
4806 fc_host_post_vendor_event(shost, fc_get_event_number(),
4807 sizeof(temp_event_data),
4808 (char *)&temp_event_data,
4809 SCSI_NL_VID_TYPE_PCI
4810 | PCI_VENDOR_ID_EMULEX);
4811 break;
4812 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
4813 misconfigured = (struct lpfc_acqe_misconfigured_event *)
James Smart4b8bae02012-06-12 13:55:07 -04004814 &acqe_sli->event_data1;
4815
James Smart946727d2015-04-07 15:07:09 -04004816 /* fetch the status for this port */
4817 switch (phba->sli4_hba.lnk_info.lnk_no) {
4818 case LPFC_LINK_NUMBER_0:
James Smart448193b2015-12-16 18:12:05 -05004819 status = bf_get(lpfc_sli_misconfigured_port0_state,
4820 &misconfigured->theEvent);
4821 operational = bf_get(lpfc_sli_misconfigured_port0_op,
James Smart4b8bae02012-06-12 13:55:07 -04004822 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004823 break;
4824 case LPFC_LINK_NUMBER_1:
James Smart448193b2015-12-16 18:12:05 -05004825 status = bf_get(lpfc_sli_misconfigured_port1_state,
4826 &misconfigured->theEvent);
4827 operational = bf_get(lpfc_sli_misconfigured_port1_op,
James Smart4b8bae02012-06-12 13:55:07 -04004828 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004829 break;
4830 case LPFC_LINK_NUMBER_2:
James Smart448193b2015-12-16 18:12:05 -05004831 status = bf_get(lpfc_sli_misconfigured_port2_state,
4832 &misconfigured->theEvent);
4833 operational = bf_get(lpfc_sli_misconfigured_port2_op,
James Smart4b8bae02012-06-12 13:55:07 -04004834 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004835 break;
4836 case LPFC_LINK_NUMBER_3:
James Smart448193b2015-12-16 18:12:05 -05004837 status = bf_get(lpfc_sli_misconfigured_port3_state,
4838 &misconfigured->theEvent);
4839 operational = bf_get(lpfc_sli_misconfigured_port3_op,
James Smart4b8bae02012-06-12 13:55:07 -04004840 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004841 break;
4842 default:
James Smart448193b2015-12-16 18:12:05 -05004843 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4844 "3296 "
4845 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
4846 "event: Invalid link %d",
4847 phba->sli4_hba.lnk_info.lnk_no);
4848 return;
James Smart946727d2015-04-07 15:07:09 -04004849 }
James Smart4b8bae02012-06-12 13:55:07 -04004850
James Smart448193b2015-12-16 18:12:05 -05004851 /* Skip if optic state unchanged */
4852 if (phba->sli4_hba.lnk_info.optic_state == status)
4853 return;
4854
James Smart946727d2015-04-07 15:07:09 -04004855 switch (status) {
4856 case LPFC_SLI_EVENT_STATUS_VALID:
James Smart448193b2015-12-16 18:12:05 -05004857 sprintf(message, "Physical Link is functional");
4858 break;
James Smart946727d2015-04-07 15:07:09 -04004859 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
4860 sprintf(message, "Optics faulted/incorrectly "
4861 "installed/not installed - Reseat optics, "
4862 "if issue not resolved, replace.");
4863 break;
4864 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
4865 sprintf(message,
4866 "Optics of two types installed - Remove one "
4867 "optic or install matching pair of optics.");
4868 break;
4869 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
4870 sprintf(message, "Incompatible optics - Replace with "
James Smart292098b2012-09-29 11:31:41 -04004871 "compatible optics for card to function.");
James Smart946727d2015-04-07 15:07:09 -04004872 break;
James Smart448193b2015-12-16 18:12:05 -05004873 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
4874 sprintf(message, "Unqualified optics - Replace with "
4875 "Avago optics for Warranty and Technical "
4876 "Support - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08004877 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05004878 break;
4879 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
4880 sprintf(message, "Uncertified optics - Replace with "
4881 "Avago-certified optics to enable link "
4882 "operation - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08004883 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05004884 break;
James Smart946727d2015-04-07 15:07:09 -04004885 default:
4886 /* firmware is reporting a status we don't know about */
4887 sprintf(message, "Unknown event status x%02x", status);
4888 break;
4889 }
James Smart448193b2015-12-16 18:12:05 -05004890 phba->sli4_hba.lnk_info.optic_state = status;
James Smart946727d2015-04-07 15:07:09 -04004891 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart448193b2015-12-16 18:12:05 -05004892 "3176 Port Name %c %s\n", port_name, message);
James Smart946727d2015-04-07 15:07:09 -04004893 break;
4894 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
4895 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4896 "3192 Remote DPort Test Initiated - "
4897 "Event Data1:x%08x Event Data2: x%08x\n",
4898 acqe_sli->event_data1, acqe_sli->event_data2);
James Smart4b8bae02012-06-12 13:55:07 -04004899 break;
4900 default:
James Smart946727d2015-04-07 15:07:09 -04004901 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4902 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
4903 "x%08x SLI Event Type:%d\n",
4904 acqe_sli->event_data1, acqe_sli->event_data2,
4905 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004906 break;
4907 }
James Smart70f3c072010-12-15 17:57:33 -05004908}
4909
4910/**
James Smartfc2b9892010-02-26 14:15:29 -05004911 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
4912 * @vport: pointer to vport data structure.
4913 *
4914 * This routine is to perform Clear Virtual Link (CVL) on a vport in
4915 * response to a CVL event.
4916 *
4917 * Return the pointer to the ndlp with the vport if successful, otherwise
4918 * return NULL.
4919 **/
4920static struct lpfc_nodelist *
4921lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
4922{
4923 struct lpfc_nodelist *ndlp;
4924 struct Scsi_Host *shost;
4925 struct lpfc_hba *phba;
4926
4927 if (!vport)
4928 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05004929 phba = vport->phba;
4930 if (!phba)
4931 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04004932 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4933 if (!ndlp) {
4934 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07004935 ndlp = lpfc_nlp_init(vport, Fabric_DID);
James Smart78730cf2010-04-06 15:06:30 -04004936 if (!ndlp)
4937 return 0;
James Smart78730cf2010-04-06 15:06:30 -04004938 /* Set the node type */
4939 ndlp->nlp_type |= NLP_FABRIC;
4940 /* Put ndlp onto node list */
4941 lpfc_enqueue_node(vport, ndlp);
4942 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4943 /* re-setup ndlp without removing from node list */
4944 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4945 if (!ndlp)
4946 return 0;
4947 }
James Smart63e801c2010-11-20 23:14:19 -05004948 if ((phba->pport->port_state < LPFC_FLOGI) &&
4949 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004950 return NULL;
4951 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05004952 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
4953 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004954 return NULL;
4955 shost = lpfc_shost_from_vport(vport);
4956 if (!shost)
4957 return NULL;
4958 lpfc_linkdown_port(vport);
4959 lpfc_cleanup_pending_mbox(vport);
4960 spin_lock_irq(shost->host_lock);
4961 vport->fc_flag |= FC_VPORT_CVL_RCVD;
4962 spin_unlock_irq(shost->host_lock);
4963
4964 return ndlp;
4965}
4966
4967/**
4968 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4969 * @vport: pointer to lpfc hba data structure.
4970 *
4971 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4972 * response to a FCF dead event.
4973 **/
4974static void
4975lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
4976{
4977 struct lpfc_vport **vports;
4978 int i;
4979
4980 vports = lpfc_create_vport_work_array(phba);
4981 if (vports)
4982 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4983 lpfc_sli4_perform_vport_cvl(vports[i]);
4984 lpfc_destroy_vport_work_array(phba, vports);
4985}
4986
4987/**
James Smart76a95d72010-11-20 23:11:48 -05004988 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04004989 * @phba: pointer to lpfc hba data structure.
4990 * @acqe_link: pointer to the async fcoe completion queue entry.
4991 *
4992 * This routine is to handle the SLI4 asynchronous fcoe event.
4993 **/
4994static void
James Smart76a95d72010-11-20 23:11:48 -05004995lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05004996 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04004997{
James Smart70f3c072010-12-15 17:57:33 -05004998 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004999 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04005000 struct lpfc_vport *vport;
5001 struct lpfc_nodelist *ndlp;
5002 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05005003 int active_vlink_present;
5004 struct lpfc_vport **vports;
5005 int i;
James Smartda0436e2009-05-22 14:51:39 -04005006
James Smart70f3c072010-12-15 17:57:33 -05005007 phba->fc_eventTag = acqe_fip->event_tag;
5008 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04005009 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05005010 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
5011 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
5012 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04005013 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5014 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005015 "2546 New FCF event, evt_tag:x%x, "
5016 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005017 acqe_fip->event_tag,
5018 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04005019 else
5020 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
5021 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005022 "2788 FCF param modified event, "
5023 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005024 acqe_fip->event_tag,
5025 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04005026 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05005027 /*
5028 * During period of FCF discovery, read the FCF
5029 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04005030 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05005031 */
5032 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5033 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005034 "2779 Read FCF (x%x) for updating "
5035 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05005036 acqe_fip->index);
5037 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05005038 }
James Smart38b92ef2010-08-04 16:11:39 -04005039
5040 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04005041 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04005042 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04005043 spin_unlock_irq(&phba->hbalock);
5044 break;
5045 }
5046 /* If fast FCF failover rescan event is pending, do nothing */
5047 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
5048 spin_unlock_irq(&phba->hbalock);
5049 break;
5050 }
5051
James Smartc2b97122013-05-31 17:05:36 -04005052 /* If the FCF has been in discovered state, do nothing. */
5053 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
James Smart3804dc82010-07-14 15:31:37 -04005054 spin_unlock_irq(&phba->hbalock);
5055 break;
5056 }
5057 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04005058
James Smart0c9ab6f2010-02-26 14:15:57 -05005059 /* Otherwise, scan the entire FCF table and re-discover SAN */
5060 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005061 "2770 Start FCF table scan per async FCF "
5062 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005063 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05005064 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
5065 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04005066 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05005067 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5068 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04005069 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04005070 break;
5071
James Smart70f3c072010-12-15 17:57:33 -05005072 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04005073 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04005074 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005075 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
5076 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04005077 break;
5078
James Smart70f3c072010-12-15 17:57:33 -05005079 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05005080 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05005081 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005082 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05005083 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04005084 /*
5085 * If we are in the middle of FCF failover process, clear
5086 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04005087 */
James Smartfc2b9892010-02-26 14:15:29 -05005088 spin_lock_irq(&phba->hbalock);
James Smarta1cadfe2016-07-06 12:36:02 -07005089 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
5090 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
James Smartfc2b9892010-02-26 14:15:29 -05005091 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005092 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05005093 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05005094 break;
5095 }
James Smart38b92ef2010-08-04 16:11:39 -04005096 spin_unlock_irq(&phba->hbalock);
5097
5098 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05005099 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04005100 break;
5101
5102 /*
5103 * Otherwise, request the port to rediscover the entire FCF
5104 * table for a fast recovery from case that the current FCF
5105 * is no longer valid as we are not in the middle of FCF
5106 * failover process already.
5107 */
James Smartc2b97122013-05-31 17:05:36 -04005108 spin_lock_irq(&phba->hbalock);
5109 /* Mark the fast failover process in progress */
5110 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
5111 spin_unlock_irq(&phba->hbalock);
5112
5113 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
5114 "2771 Start FCF fast failover process due to "
5115 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
5116 "\n", acqe_fip->event_tag, acqe_fip->index);
5117 rc = lpfc_sli4_redisc_fcf_table(phba);
5118 if (rc) {
5119 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5120 LOG_DISCOVERY,
Colin Ian King7afc0ce2018-05-03 10:26:12 +01005121 "2772 Issue FCF rediscover mailbox "
James Smartc2b97122013-05-31 17:05:36 -04005122 "command failed, fail through to FCF "
5123 "dead event\n");
5124 spin_lock_irq(&phba->hbalock);
5125 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
5126 spin_unlock_irq(&phba->hbalock);
5127 /*
5128 * Last resort will fail over by treating this
5129 * as a link down to FCF registration.
5130 */
5131 lpfc_sli4_fcf_dead_failthrough(phba);
5132 } else {
5133 /* Reset FCF roundrobin bmask for new discovery */
5134 lpfc_sli4_clear_fcf_rr_bmask(phba);
5135 /*
5136 * Handling fast FCF failover to a DEAD FCF event is
5137 * considered equalivant to receiving CVL to all vports.
5138 */
5139 lpfc_sli4_perform_all_vport_cvl(phba);
5140 }
James Smartda0436e2009-05-22 14:51:39 -04005141 break;
James Smart70f3c072010-12-15 17:57:33 -05005142 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05005143 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05005144 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04005145 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05005146 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04005147
James Smart6669f9b2009-10-02 15:16:45 -04005148 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04005149 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05005150 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04005151 if (!ndlp)
5152 break;
James Smart695a8142010-01-26 23:08:03 -05005153 active_vlink_present = 0;
5154
5155 vports = lpfc_create_vport_work_array(phba);
5156 if (vports) {
5157 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
5158 i++) {
5159 if ((!(vports[i]->fc_flag &
5160 FC_VPORT_CVL_RCVD)) &&
5161 (vports[i]->port_state > LPFC_FDISC)) {
5162 active_vlink_present = 1;
5163 break;
5164 }
5165 }
5166 lpfc_destroy_vport_work_array(phba, vports);
5167 }
5168
James Smartcc823552015-05-21 13:55:26 -04005169 /*
5170 * Don't re-instantiate if vport is marked for deletion.
5171 * If we are here first then vport_delete is going to wait
5172 * for discovery to complete.
5173 */
5174 if (!(vport->load_flag & FC_UNLOADING) &&
5175 active_vlink_present) {
James Smart695a8142010-01-26 23:08:03 -05005176 /*
5177 * If there are other active VLinks present,
5178 * re-instantiate the Vlink using FDISC.
5179 */
James Smart256ec0d2013-04-17 20:14:58 -04005180 mod_timer(&ndlp->nlp_delayfunc,
5181 jiffies + msecs_to_jiffies(1000));
James Smartfc2b9892010-02-26 14:15:29 -05005182 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04005183 spin_lock_irq(shost->host_lock);
5184 ndlp->nlp_flag |= NLP_DELAY_TMO;
5185 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05005186 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
5187 vport->port_state = LPFC_FDISC;
5188 } else {
James Smartecfd03c2010-02-12 14:41:27 -05005189 /*
5190 * Otherwise, we request port to rediscover
5191 * the entire FCF table for a fast recovery
5192 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05005193 * is no longer valid if we are not already
5194 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05005195 */
James Smartfc2b9892010-02-26 14:15:29 -05005196 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005197 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05005198 spin_unlock_irq(&phba->hbalock);
5199 break;
5200 }
5201 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05005202 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05005203 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005204 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5205 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005206 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05005207 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05005208 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05005209 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05005210 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5211 LOG_DISCOVERY,
5212 "2774 Issue FCF rediscover "
Colin Ian King7afc0ce2018-05-03 10:26:12 +01005213 "mailbox command failed, "
James Smart0c9ab6f2010-02-26 14:15:57 -05005214 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05005215 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005216 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05005217 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05005218 /*
5219 * Last resort will be re-try on the
5220 * the current registered FCF entry.
5221 */
5222 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04005223 } else
5224 /*
5225 * Reset FCF roundrobin bmask for new
5226 * discovery.
5227 */
James Smart7d791df2011-07-22 18:37:52 -04005228 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04005229 }
5230 break;
James Smartda0436e2009-05-22 14:51:39 -04005231 default:
5232 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5233 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05005234 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04005235 break;
5236 }
5237}
5238
5239/**
5240 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
5241 * @phba: pointer to lpfc hba data structure.
5242 * @acqe_link: pointer to the async dcbx completion queue entry.
5243 *
5244 * This routine is to handle the SLI4 asynchronous dcbx event.
5245 **/
5246static void
5247lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
5248 struct lpfc_acqe_dcbx *acqe_dcbx)
5249{
James Smart4d9ab992009-10-02 15:16:39 -04005250 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04005251 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5252 "0290 The SLI4 DCBX asynchronous event is not "
5253 "handled yet\n");
5254}
5255
5256/**
James Smartb19a0612010-04-06 14:48:51 -04005257 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
5258 * @phba: pointer to lpfc hba data structure.
5259 * @acqe_link: pointer to the async grp5 completion queue entry.
5260 *
5261 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
5262 * is an asynchronous notified of a logical link speed change. The Port
5263 * reports the logical link speed in units of 10Mbps.
5264 **/
5265static void
5266lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
5267 struct lpfc_acqe_grp5 *acqe_grp5)
5268{
5269 uint16_t prev_ll_spd;
5270
5271 phba->fc_eventTag = acqe_grp5->event_tag;
5272 phba->fcoe_eventtag = acqe_grp5->event_tag;
5273 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
5274 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04005275 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04005276 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5277 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04005278 "from %dMbps to %dMbps\n", prev_ll_spd,
5279 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04005280}
5281
5282/**
James Smartda0436e2009-05-22 14:51:39 -04005283 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
5284 * @phba: pointer to lpfc hba data structure.
5285 *
5286 * This routine is invoked by the worker thread to process all the pending
5287 * SLI4 asynchronous events.
5288 **/
5289void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
5290{
5291 struct lpfc_cq_event *cq_event;
5292
5293 /* First, declare the async event has been handled */
5294 spin_lock_irq(&phba->hbalock);
5295 phba->hba_flag &= ~ASYNC_EVENT;
5296 spin_unlock_irq(&phba->hbalock);
5297 /* Now, handle all the async events */
5298 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
5299 /* Get the first event from the head of the event queue */
5300 spin_lock_irq(&phba->hbalock);
5301 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
5302 cq_event, struct lpfc_cq_event, list);
5303 spin_unlock_irq(&phba->hbalock);
5304 /* Process the asynchronous event */
5305 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
5306 case LPFC_TRAILER_CODE_LINK:
5307 lpfc_sli4_async_link_evt(phba,
5308 &cq_event->cqe.acqe_link);
5309 break;
5310 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05005311 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04005312 break;
5313 case LPFC_TRAILER_CODE_DCBX:
5314 lpfc_sli4_async_dcbx_evt(phba,
5315 &cq_event->cqe.acqe_dcbx);
5316 break;
James Smartb19a0612010-04-06 14:48:51 -04005317 case LPFC_TRAILER_CODE_GRP5:
5318 lpfc_sli4_async_grp5_evt(phba,
5319 &cq_event->cqe.acqe_grp5);
5320 break;
James Smart70f3c072010-12-15 17:57:33 -05005321 case LPFC_TRAILER_CODE_FC:
5322 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
5323 break;
5324 case LPFC_TRAILER_CODE_SLI:
5325 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
5326 break;
James Smartda0436e2009-05-22 14:51:39 -04005327 default:
5328 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5329 "1804 Invalid asynchrous event code: "
5330 "x%x\n", bf_get(lpfc_trailer_code,
5331 &cq_event->cqe.mcqe_cmpl));
5332 break;
5333 }
5334 /* Free the completion event processed to the free pool */
5335 lpfc_sli4_cq_event_release(phba, cq_event);
5336 }
5337}
5338
5339/**
James Smartecfd03c2010-02-12 14:41:27 -05005340 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
5341 * @phba: pointer to lpfc hba data structure.
5342 *
5343 * This routine is invoked by the worker thread to process FCF table
5344 * rediscovery pending completion event.
5345 **/
5346void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
5347{
5348 int rc;
5349
5350 spin_lock_irq(&phba->hbalock);
5351 /* Clear FCF rediscovery timeout event */
5352 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
5353 /* Clear driver fast failover FCF record flag */
5354 phba->fcf.failover_rec.flag = 0;
5355 /* Set state for FCF fast failover */
5356 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
5357 spin_unlock_irq(&phba->hbalock);
5358
5359 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05005360 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005361 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05005362 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05005363 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05005364 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5365 "2747 Issue FCF scan read FCF mailbox "
5366 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05005367}
5368
5369/**
James Smartda0436e2009-05-22 14:51:39 -04005370 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
5371 * @phba: pointer to lpfc hba data structure.
5372 * @dev_grp: The HBA PCI-Device group number.
5373 *
5374 * This routine is invoked to set up the per HBA PCI-Device group function
5375 * API jump table entries.
5376 *
5377 * Return: 0 if success, otherwise -ENODEV
5378 **/
5379int
5380lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05005381{
5382 int rc;
5383
James Smartda0436e2009-05-22 14:51:39 -04005384 /* Set up lpfc PCI-device group */
5385 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05005386
James Smartda0436e2009-05-22 14:51:39 -04005387 /* The LPFC_PCI_DEV_OC uses SLI4 */
5388 if (dev_grp == LPFC_PCI_DEV_OC)
5389 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05005390
James Smartda0436e2009-05-22 14:51:39 -04005391 /* Set up device INIT API function jump table */
5392 rc = lpfc_init_api_table_setup(phba, dev_grp);
5393 if (rc)
5394 return -ENODEV;
5395 /* Set up SCSI API function jump table */
5396 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
5397 if (rc)
5398 return -ENODEV;
5399 /* Set up SLI API function jump table */
5400 rc = lpfc_sli_api_table_setup(phba, dev_grp);
5401 if (rc)
5402 return -ENODEV;
5403 /* Set up MBOX API function jump table */
5404 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
5405 if (rc)
5406 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05005407
James Smartda0436e2009-05-22 14:51:39 -04005408 return 0;
James Smart5b75da22008-12-04 22:39:35 -05005409}
5410
5411/**
James Smart3621a712009-04-06 18:47:14 -04005412 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05005413 * @phba: pointer to lpfc hba data structure.
5414 * @intr_mode: active interrupt mode adopted.
5415 *
5416 * This routine it invoked to log the currently used active interrupt mode
5417 * to the device.
James Smart3772a992009-05-22 14:50:54 -04005418 **/
5419static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05005420{
5421 switch (intr_mode) {
5422 case 0:
5423 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5424 "0470 Enable INTx interrupt mode.\n");
5425 break;
5426 case 1:
5427 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5428 "0481 Enabled MSI interrupt mode.\n");
5429 break;
5430 case 2:
5431 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5432 "0480 Enabled MSI-X interrupt mode.\n");
5433 break;
5434 default:
5435 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5436 "0482 Illegal interrupt mode.\n");
5437 break;
5438 }
5439 return;
5440}
5441
James Smart5b75da22008-12-04 22:39:35 -05005442/**
James Smart3772a992009-05-22 14:50:54 -04005443 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05005444 * @phba: pointer to lpfc hba data structure.
5445 *
James Smart3772a992009-05-22 14:50:54 -04005446 * This routine is invoked to enable the PCI device that is common to all
5447 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05005448 *
5449 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005450 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005451 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05005452 **/
James Smart3772a992009-05-22 14:50:54 -04005453static int
5454lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05005455{
James Smart3772a992009-05-22 14:50:54 -04005456 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05005457
James Smart3772a992009-05-22 14:50:54 -04005458 /* Obtain PCI device reference */
5459 if (!phba->pcidev)
5460 goto out_error;
5461 else
5462 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04005463 /* Enable PCI device */
5464 if (pci_enable_device_mem(pdev))
5465 goto out_error;
5466 /* Request PCI resource for the device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005467 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
James Smart3772a992009-05-22 14:50:54 -04005468 goto out_disable_device;
5469 /* Set up device as PCI master and save state for EEH */
5470 pci_set_master(pdev);
5471 pci_try_set_mwi(pdev);
5472 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05005473
James Smart05580562011-05-24 11:40:48 -04005474 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
Jon Mason453193e2013-09-11 15:38:13 -07005475 if (pci_is_pcie(pdev))
James Smart05580562011-05-24 11:40:48 -04005476 pdev->needs_freset = 1;
5477
James Smart3772a992009-05-22 14:50:54 -04005478 return 0;
James Smart5b75da22008-12-04 22:39:35 -05005479
James Smart3772a992009-05-22 14:50:54 -04005480out_disable_device:
5481 pci_disable_device(pdev);
5482out_error:
James Smart079b5c92011-08-21 21:48:49 -04005483 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005484 "1401 Failed to enable pci device\n");
James Smart3772a992009-05-22 14:50:54 -04005485 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05005486}
5487
5488/**
James Smart3772a992009-05-22 14:50:54 -04005489 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05005490 * @phba: pointer to lpfc hba data structure.
5491 *
James Smart3772a992009-05-22 14:50:54 -04005492 * This routine is invoked to disable the PCI device that is common to all
5493 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05005494 **/
5495static void
James Smart3772a992009-05-22 14:50:54 -04005496lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05005497{
James Smart3772a992009-05-22 14:50:54 -04005498 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05005499
James Smart3772a992009-05-22 14:50:54 -04005500 /* Obtain PCI device reference */
5501 if (!phba->pcidev)
5502 return;
5503 else
5504 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04005505 /* Release PCI resource and disable PCI device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005506 pci_release_mem_regions(pdev);
James Smart3772a992009-05-22 14:50:54 -04005507 pci_disable_device(pdev);
James Smart5b75da22008-12-04 22:39:35 -05005508
5509 return;
5510}
5511
5512/**
James Smart3772a992009-05-22 14:50:54 -04005513 * lpfc_reset_hba - Reset a hba
5514 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04005515 *
James Smart3772a992009-05-22 14:50:54 -04005516 * This routine is invoked to reset a hba device. It brings the HBA
5517 * offline, performs a board restart, and then brings the board back
5518 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
5519 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04005520 **/
James Smart3772a992009-05-22 14:50:54 -04005521void
5522lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05005523{
James Smart3772a992009-05-22 14:50:54 -04005524 /* If resets are disabled then set error state and return. */
5525 if (!phba->cfg_enable_hba_reset) {
5526 phba->link_state = LPFC_HBA_ERROR;
5527 return;
5528 }
James Smartee620212014-04-04 13:51:53 -04005529 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
5530 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
5531 else
5532 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart3772a992009-05-22 14:50:54 -04005533 lpfc_offline(phba);
5534 lpfc_sli_brdrestart(phba);
5535 lpfc_online(phba);
5536 lpfc_unblock_mgmt_io(phba);
5537}
dea31012005-04-17 16:05:31 -05005538
James Smart3772a992009-05-22 14:50:54 -04005539/**
James Smart0a96e972011-07-22 18:37:28 -04005540 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
5541 * @phba: pointer to lpfc hba data structure.
5542 *
5543 * This function enables the PCI SR-IOV virtual functions to a physical
5544 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5545 * enable the number of virtual functions to the physical function. As
5546 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5547 * API call does not considered as an error condition for most of the device.
5548 **/
5549uint16_t
5550lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
5551{
5552 struct pci_dev *pdev = phba->pcidev;
5553 uint16_t nr_virtfn;
5554 int pos;
5555
James Smart0a96e972011-07-22 18:37:28 -04005556 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
5557 if (pos == 0)
5558 return 0;
5559
5560 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
5561 return nr_virtfn;
5562}
5563
5564/**
James Smart912e3ac2011-05-24 11:42:11 -04005565 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
5566 * @phba: pointer to lpfc hba data structure.
5567 * @nr_vfn: number of virtual functions to be enabled.
5568 *
5569 * This function enables the PCI SR-IOV virtual functions to a physical
5570 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5571 * enable the number of virtual functions to the physical function. As
5572 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5573 * API call does not considered as an error condition for most of the device.
5574 **/
5575int
5576lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
5577{
5578 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04005579 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04005580 int rc;
5581
James Smart0a96e972011-07-22 18:37:28 -04005582 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
5583 if (nr_vfn > max_nr_vfn) {
5584 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5585 "3057 Requested vfs (%d) greater than "
5586 "supported vfs (%d)", nr_vfn, max_nr_vfn);
5587 return -EINVAL;
5588 }
5589
James Smart912e3ac2011-05-24 11:42:11 -04005590 rc = pci_enable_sriov(pdev, nr_vfn);
5591 if (rc) {
5592 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5593 "2806 Failed to enable sriov on this device "
5594 "with vfn number nr_vf:%d, rc:%d\n",
5595 nr_vfn, rc);
5596 } else
5597 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5598 "2807 Successful enable sriov on this device "
5599 "with vfn number nr_vf:%d\n", nr_vfn);
5600 return rc;
5601}
5602
5603/**
James Smart895427b2017-02-12 13:52:30 -08005604 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
James Smart3772a992009-05-22 14:50:54 -04005605 * @phba: pointer to lpfc hba data structure.
5606 *
James Smart895427b2017-02-12 13:52:30 -08005607 * This routine is invoked to set up the driver internal resources before the
5608 * device specific resource setup to support the HBA device it attached to.
James Smart3772a992009-05-22 14:50:54 -04005609 *
5610 * Return codes
James Smart895427b2017-02-12 13:52:30 -08005611 * 0 - successful
5612 * other values - error
James Smart3772a992009-05-22 14:50:54 -04005613 **/
5614static int
James Smart895427b2017-02-12 13:52:30 -08005615lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
James Smart3772a992009-05-22 14:50:54 -04005616{
James Smart895427b2017-02-12 13:52:30 -08005617 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05005618
James Smart3772a992009-05-22 14:50:54 -04005619 /*
James Smart895427b2017-02-12 13:52:30 -08005620 * Driver resources common to all SLI revisions
James Smart3772a992009-05-22 14:50:54 -04005621 */
James Smart895427b2017-02-12 13:52:30 -08005622 atomic_set(&phba->fast_event_count, 0);
5623 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005624
James Smart895427b2017-02-12 13:52:30 -08005625 /* Initialize ndlp management spinlock */
5626 spin_lock_init(&phba->ndlp_lock);
James Smart3772a992009-05-22 14:50:54 -04005627
James Smart523128e2018-09-10 10:30:46 -07005628 /* Initialize port_list spinlock */
5629 spin_lock_init(&phba->port_list_lock);
James Smart895427b2017-02-12 13:52:30 -08005630 INIT_LIST_HEAD(&phba->port_list);
James Smart523128e2018-09-10 10:30:46 -07005631
James Smart895427b2017-02-12 13:52:30 -08005632 INIT_LIST_HEAD(&phba->work_list);
5633 init_waitqueue_head(&phba->wait_4_mlo_m_q);
5634
5635 /* Initialize the wait queue head for the kernel thread */
5636 init_waitqueue_head(&phba->work_waitq);
5637
5638 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartf358dd02017-02-12 13:52:34 -08005639 "1403 Protocols supported %s %s %s\n",
James Smart895427b2017-02-12 13:52:30 -08005640 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
5641 "SCSI" : " "),
5642 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
James Smartf358dd02017-02-12 13:52:34 -08005643 "NVME" : " "),
5644 (phba->nvmet_support ? "NVMET" : " "));
James Smart895427b2017-02-12 13:52:30 -08005645
5646 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5647 /* Initialize the scsi buffer list used by driver for scsi IO */
5648 spin_lock_init(&phba->scsi_buf_list_get_lock);
5649 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5650 spin_lock_init(&phba->scsi_buf_list_put_lock);
5651 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
5652 }
5653
5654 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
5655 (phba->nvmet_support == 0)) {
5656 /* Initialize the NVME buffer list used by driver for NVME IO */
5657 spin_lock_init(&phba->nvme_buf_list_get_lock);
5658 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_get);
James Smartcf1a1d32017-12-08 17:18:03 -08005659 phba->get_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08005660 spin_lock_init(&phba->nvme_buf_list_put_lock);
5661 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
James Smartcf1a1d32017-12-08 17:18:03 -08005662 phba->put_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08005663 }
5664
5665 /* Initialize the fabric iocb list */
5666 INIT_LIST_HEAD(&phba->fabric_iocb_list);
5667
5668 /* Initialize list to save ELS buffers */
5669 INIT_LIST_HEAD(&phba->elsbuf);
5670
5671 /* Initialize FCF connection rec list */
5672 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
5673
5674 /* Initialize OAS configuration list */
5675 spin_lock_init(&phba->devicelock);
5676 INIT_LIST_HEAD(&phba->luns);
5677
James Smart3772a992009-05-22 14:50:54 -04005678 /* MBOX heartbeat timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005679 timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04005680 /* Fabric block timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005681 timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04005682 /* EA polling mode timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005683 timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0);
James Smart895427b2017-02-12 13:52:30 -08005684 /* Heartbeat timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005685 timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0);
James Smart895427b2017-02-12 13:52:30 -08005686
5687 return 0;
5688}
5689
5690/**
5691 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
5692 * @phba: pointer to lpfc hba data structure.
5693 *
5694 * This routine is invoked to set up the driver internal resources specific to
5695 * support the SLI-3 HBA device it attached to.
5696 *
5697 * Return codes
5698 * 0 - successful
5699 * other values - error
5700 **/
5701static int
5702lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
5703{
5704 int rc;
5705
5706 /*
5707 * Initialize timers used by driver
5708 */
5709
5710 /* FCP polling mode timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005711 timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04005712
5713 /* Host attention work mask setup */
5714 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
5715 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
5716
5717 /* Get all the module params for configuring this host */
5718 lpfc_get_cfgparam(phba);
James Smart895427b2017-02-12 13:52:30 -08005719 /* Set up phase-1 common device driver resources */
5720
5721 rc = lpfc_setup_driver_resource_phase1(phba);
5722 if (rc)
5723 return -ENODEV;
5724
James Smart49198b32010-04-06 15:04:33 -04005725 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
5726 phba->menlo_flag |= HBA_MENLO_SUPPORT;
5727 /* check for menlo minimum sg count */
5728 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
5729 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
5730 }
5731
James Smart895427b2017-02-12 13:52:30 -08005732 if (!phba->sli.sli3_ring)
Kees Cook6396bb22018-06-12 14:03:40 -07005733 phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING,
5734 sizeof(struct lpfc_sli_ring),
5735 GFP_KERNEL);
James Smart895427b2017-02-12 13:52:30 -08005736 if (!phba->sli.sli3_ring)
James Smart2a76a282012-08-03 12:35:54 -04005737 return -ENOMEM;
5738
James Smart3772a992009-05-22 14:50:54 -04005739 /*
James Smart96f70772013-04-17 20:16:15 -04005740 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smart3772a992009-05-22 14:50:54 -04005741 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart3772a992009-05-22 14:50:54 -04005742 */
James Smart3772a992009-05-22 14:50:54 -04005743
James Smart96f70772013-04-17 20:16:15 -04005744 /* Initialize the host templates the configured values. */
James Smart3772a992009-05-22 14:50:54 -04005745 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart96418b52017-03-04 09:30:31 -08005746 lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt;
5747 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart3772a992009-05-22 14:50:54 -04005748
James Smart96f70772013-04-17 20:16:15 -04005749 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
5750 if (phba->cfg_enable_bg) {
5751 /*
5752 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5753 * the FCP rsp, and a BDE for each. Sice we have no control
5754 * over how many protection data segments the SCSI Layer
5755 * will hand us (ie: there could be one for every block
5756 * in the IO), we just allocate enough BDEs to accomidate
5757 * our max amount and we need to limit lpfc_sg_seg_cnt to
5758 * minimize the risk of running out.
5759 */
5760 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5761 sizeof(struct fcp_rsp) +
5762 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
5763
5764 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
5765 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
5766
5767 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
5768 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
5769 } else {
5770 /*
5771 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5772 * the FCP rsp, a BDE for each, and a BDE for up to
5773 * cfg_sg_seg_cnt data segments.
5774 */
5775 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5776 sizeof(struct fcp_rsp) +
5777 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
5778
5779 /* Total BDEs in BPL for scsi_sg_list */
5780 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5781 }
5782
5783 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5784 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
5785 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5786 phba->cfg_total_seg_cnt);
5787
James Smart3772a992009-05-22 14:50:54 -04005788 phba->max_vpi = LPFC_MAX_VPI;
5789 /* This will be set to correct value after config_port mbox */
5790 phba->max_vports = 0;
5791
5792 /*
5793 * Initialize the SLI Layer to run with lpfc HBAs.
5794 */
5795 lpfc_sli_setup(phba);
James Smart895427b2017-02-12 13:52:30 -08005796 lpfc_sli_queue_init(phba);
James Smart3772a992009-05-22 14:50:54 -04005797
5798 /* Allocate device driver memory */
5799 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
5800 return -ENOMEM;
5801
James Smart912e3ac2011-05-24 11:42:11 -04005802 /*
5803 * Enable sr-iov virtual functions if supported and configured
5804 * through the module parameter.
5805 */
5806 if (phba->cfg_sriov_nr_virtfn > 0) {
5807 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5808 phba->cfg_sriov_nr_virtfn);
5809 if (rc) {
5810 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5811 "2808 Requested number of SR-IOV "
5812 "virtual functions (%d) is not "
5813 "supported\n",
5814 phba->cfg_sriov_nr_virtfn);
5815 phba->cfg_sriov_nr_virtfn = 0;
5816 }
5817 }
5818
James Smart3772a992009-05-22 14:50:54 -04005819 return 0;
5820}
5821
5822/**
5823 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
5824 * @phba: pointer to lpfc hba data structure.
5825 *
5826 * This routine is invoked to unset the driver internal resources set up
5827 * specific for supporting the SLI-3 HBA device it attached to.
5828 **/
5829static void
5830lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
5831{
5832 /* Free device driver memory allocated */
5833 lpfc_mem_free_all(phba);
5834
5835 return;
5836}
5837
5838/**
James Smartda0436e2009-05-22 14:51:39 -04005839 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
5840 * @phba: pointer to lpfc hba data structure.
5841 *
5842 * This routine is invoked to set up the driver internal resources specific to
5843 * support the SLI-4 HBA device it attached to.
5844 *
5845 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005846 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04005847 * other values - error
5848 **/
5849static int
5850lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5851{
James Smart28baac72010-02-12 14:42:03 -05005852 LPFC_MBOXQ_t *mboxq;
James Smartf358dd02017-02-12 13:52:34 -08005853 MAILBOX_t *mb;
James Smart895427b2017-02-12 13:52:30 -08005854 int rc, i, max_buf_size;
James Smart28baac72010-02-12 14:42:03 -05005855 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
5856 struct lpfc_mqe *mqe;
James Smart09294d42013-04-17 20:16:05 -04005857 int longs;
James Smart1ba981f2014-02-20 09:56:45 -05005858 int fof_vectors = 0;
James Smart81e6a632017-11-20 16:00:43 -08005859 int extra;
James Smartf358dd02017-02-12 13:52:34 -08005860 uint64_t wwn;
James Smartb92dc722018-05-24 21:09:01 -07005861 u32 if_type;
5862 u32 if_fam;
James Smartda0436e2009-05-22 14:51:39 -04005863
James Smart895427b2017-02-12 13:52:30 -08005864 phba->sli4_hba.num_online_cpu = num_online_cpus();
5865 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
5866 phba->sli4_hba.curr_disp_cpu = 0;
5867
James Smart716d3bc2013-09-06 12:18:28 -04005868 /* Get all the module params for configuring this host */
5869 lpfc_get_cfgparam(phba);
5870
James Smart895427b2017-02-12 13:52:30 -08005871 /* Set up phase-1 common device driver resources */
5872 rc = lpfc_setup_driver_resource_phase1(phba);
5873 if (rc)
5874 return -ENODEV;
5875
James Smartda0436e2009-05-22 14:51:39 -04005876 /* Before proceed, wait for POST done and device ready */
5877 rc = lpfc_sli4_post_status_check(phba);
5878 if (rc)
5879 return -ENODEV;
5880
5881 /*
5882 * Initialize timers used by driver
5883 */
5884
Kees Cookf22eb4d2017-09-06 20:24:26 -07005885 timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0);
James Smartda0436e2009-05-22 14:51:39 -04005886
James Smartecfd03c2010-02-12 14:41:27 -05005887 /* FCF rediscover timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005888 timer_setup(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo, 0);
James Smartecfd03c2010-02-12 14:41:27 -05005889
James Smartda0436e2009-05-22 14:51:39 -04005890 /*
James Smart7ad20aa2011-05-24 11:44:28 -04005891 * Control structure for handling external multi-buffer mailbox
5892 * command pass-through.
5893 */
5894 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
5895 sizeof(struct lpfc_mbox_ext_buf_ctx));
5896 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
5897
James Smartda0436e2009-05-22 14:51:39 -04005898 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04005899
James Smartda0436e2009-05-22 14:51:39 -04005900 /* This will be set to correct value after the read_config mbox */
5901 phba->max_vports = 0;
5902
5903 /* Program the default value of vlan_id and fc_map */
5904 phba->valid_vlan = 0;
5905 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5906 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5907 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5908
5909 /*
James Smart2a76a282012-08-03 12:35:54 -04005910 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
James Smart895427b2017-02-12 13:52:30 -08005911 * we will associate a new ring, for each EQ/CQ/WQ tuple.
5912 * The WQ create will allocate the ring.
James Smart2a76a282012-08-03 12:35:54 -04005913 */
James Smart085c6472010-11-20 23:11:37 -05005914
James Smart09294d42013-04-17 20:16:05 -04005915 /*
James Smart81e6a632017-11-20 16:00:43 -08005916 * 1 for cmd, 1 for rsp, NVME adds an extra one
5917 * for boundary conditions in its max_sgl_segment template.
5918 */
5919 extra = 2;
5920 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
5921 extra++;
5922
5923 /*
James Smart09294d42013-04-17 20:16:05 -04005924 * It doesn't matter what family our adapter is in, we are
5925 * limited to 2 Pages, 512 SGEs, for our SGL.
5926 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
5927 */
5928 max_buf_size = (2 * SLI4_PAGE_SIZE);
James Smart09294d42013-04-17 20:16:05 -04005929
James Smartda0436e2009-05-22 14:51:39 -04005930 /*
James Smart895427b2017-02-12 13:52:30 -08005931 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
5932 * used to create the sg_dma_buf_pool must be calculated.
James Smart28baac72010-02-12 14:42:03 -05005933 */
James Smartf44ac122018-03-05 12:04:08 -08005934 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
James Smart96f70772013-04-17 20:16:15 -04005935 /*
James Smart895427b2017-02-12 13:52:30 -08005936 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
5937 * the FCP rsp, and a SGE. Sice we have no control
5938 * over how many protection segments the SCSI Layer
James Smart96f70772013-04-17 20:16:15 -04005939 * will hand us (ie: there could be one for every block
James Smart895427b2017-02-12 13:52:30 -08005940 * in the IO), just allocate enough SGEs to accomidate
5941 * our max amount and we need to limit lpfc_sg_seg_cnt
5942 * to minimize the risk of running out.
James Smart96f70772013-04-17 20:16:15 -04005943 */
5944 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08005945 sizeof(struct fcp_rsp) + max_buf_size;
James Smart96f70772013-04-17 20:16:15 -04005946
5947 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
5948 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
5949
James Smart5b9e70b2018-09-10 10:30:42 -07005950 /*
5951 * If supporting DIF, reduce the seg count for scsi to
5952 * allow room for the DIF sges.
5953 */
5954 if (phba->cfg_enable_bg &&
5955 phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF)
5956 phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF;
5957 else
5958 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
5959
James Smart96f70772013-04-17 20:16:15 -04005960 } else {
5961 /*
James Smart895427b2017-02-12 13:52:30 -08005962 * The scsi_buf for a regular I/O holds the FCP cmnd,
James Smart96f70772013-04-17 20:16:15 -04005963 * the FCP rsp, a SGE for each, and a SGE for up to
5964 * cfg_sg_seg_cnt data segments.
5965 */
5966 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08005967 sizeof(struct fcp_rsp) +
James Smart81e6a632017-11-20 16:00:43 -08005968 ((phba->cfg_sg_seg_cnt + extra) *
James Smart895427b2017-02-12 13:52:30 -08005969 sizeof(struct sli4_sge));
James Smart96f70772013-04-17 20:16:15 -04005970
5971 /* Total SGEs for scsi_sg_list */
James Smart81e6a632017-11-20 16:00:43 -08005972 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra;
James Smart5b9e70b2018-09-10 10:30:42 -07005973 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
James Smart895427b2017-02-12 13:52:30 -08005974
James Smart96f70772013-04-17 20:16:15 -04005975 /*
James Smart81e6a632017-11-20 16:00:43 -08005976 * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only
James Smart895427b2017-02-12 13:52:30 -08005977 * need to post 1 page for the SGL.
James Smart96f70772013-04-17 20:16:15 -04005978 */
James Smart085c6472010-11-20 23:11:37 -05005979 }
James Smartacd68592012-01-18 16:25:09 -05005980
James Smart5b9e70b2018-09-10 10:30:42 -07005981 /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */
5982 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
5983 if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) {
5984 lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT,
5985 "6300 Reducing NVME sg segment "
5986 "cnt to %d\n",
5987 LPFC_MAX_NVME_SEG_CNT);
5988 phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
5989 } else
5990 phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt;
5991 }
5992
James Smart96f70772013-04-17 20:16:15 -04005993 /* Initialize the host templates with the updated values. */
James Smart5b9e70b2018-09-10 10:30:42 -07005994 lpfc_vport_template.sg_tablesize = phba->cfg_scsi_seg_cnt;
5995 lpfc_template.sg_tablesize = phba->cfg_scsi_seg_cnt;
5996 lpfc_template_no_hr.sg_tablesize = phba->cfg_scsi_seg_cnt;
James Smart96f70772013-04-17 20:16:15 -04005997
5998 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
5999 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
6000 else
6001 phba->cfg_sg_dma_buf_size =
6002 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
6003
6004 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
James Smart5b9e70b2018-09-10 10:30:42 -07006005 "9087 sg_seg_cnt:%d dmabuf_size:%d "
6006 "total:%d scsi:%d nvme:%d\n",
James Smart96f70772013-04-17 20:16:15 -04006007 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
James Smart5b9e70b2018-09-10 10:30:42 -07006008 phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt,
6009 phba->cfg_nvme_seg_cnt);
James Smartda0436e2009-05-22 14:51:39 -04006010
6011 /* Initialize buffer queue management fields */
James Smart895427b2017-02-12 13:52:30 -08006012 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
James Smartda0436e2009-05-22 14:51:39 -04006013 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
6014 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
6015
6016 /*
6017 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
6018 */
James Smart895427b2017-02-12 13:52:30 -08006019 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
6020 /* Initialize the Abort scsi buffer list used by driver */
6021 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
6022 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
6023 }
6024
6025 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
6026 /* Initialize the Abort nvme buffer list used by driver */
6027 spin_lock_init(&phba->sli4_hba.abts_nvme_buf_list_lock);
6028 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
James Smart86c67372017-04-21 16:05:04 -07006029 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
James Smarta8cf5df2017-05-15 15:20:46 -07006030 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list);
James Smart895427b2017-02-12 13:52:30 -08006031 }
6032
James Smartda0436e2009-05-22 14:51:39 -04006033 /* This abort list used by worker thread */
James Smart895427b2017-02-12 13:52:30 -08006034 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
James Smarta8cf5df2017-05-15 15:20:46 -07006035 spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock);
James Smartda0436e2009-05-22 14:51:39 -04006036
6037 /*
James Smart6d368e52011-05-24 11:44:12 -04006038 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04006039 */
6040
6041 /* Driver internel slow-path CQ Event pool */
6042 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
6043 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04006044 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04006045 /* Asynchronous event CQ Event work queue list */
6046 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
6047 /* Fast-path XRI aborted CQ Event work queue list */
6048 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
6049 /* Slow-path XRI aborted CQ Event work queue list */
6050 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
6051 /* Receive queue CQ Event work queue list */
6052 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
6053
James Smart6d368e52011-05-24 11:44:12 -04006054 /* Initialize extent block lists. */
6055 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
6056 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
6057 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
6058 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
6059
James Smartd1f525a2017-04-21 16:04:55 -07006060 /* Initialize mboxq lists. If the early init routines fail
6061 * these lists need to be correctly initialized.
6062 */
6063 INIT_LIST_HEAD(&phba->sli.mboxq);
6064 INIT_LIST_HEAD(&phba->sli.mboxq_cmpl);
6065
James Smart448193b2015-12-16 18:12:05 -05006066 /* initialize optic_state to 0xFF */
6067 phba->sli4_hba.lnk_info.optic_state = 0xff;
6068
James Smartda0436e2009-05-22 14:51:39 -04006069 /* Allocate device driver memory */
6070 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
6071 if (rc)
6072 return -ENOMEM;
6073
James Smart2fcee4b2010-12-15 17:57:46 -05006074 /* IF Type 2 ports get initialized now. */
James Smart27d6ac02018-02-22 08:18:42 -08006075 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
James Smart2fcee4b2010-12-15 17:57:46 -05006076 LPFC_SLI_INTF_IF_TYPE_2) {
6077 rc = lpfc_pci_function_reset(phba);
James Smart895427b2017-02-12 13:52:30 -08006078 if (unlikely(rc)) {
6079 rc = -ENODEV;
6080 goto out_free_mem;
6081 }
James Smart946727d2015-04-07 15:07:09 -04006082 phba->temp_sensor_support = 1;
James Smart2fcee4b2010-12-15 17:57:46 -05006083 }
6084
James Smartda0436e2009-05-22 14:51:39 -04006085 /* Create the bootstrap mailbox command */
6086 rc = lpfc_create_bootstrap_mbox(phba);
6087 if (unlikely(rc))
6088 goto out_free_mem;
6089
6090 /* Set up the host's endian order with the device. */
6091 rc = lpfc_setup_endian_order(phba);
6092 if (unlikely(rc))
6093 goto out_free_bsmbx;
6094
6095 /* Set up the hba's configuration parameters. */
6096 rc = lpfc_sli4_read_config(phba);
6097 if (unlikely(rc))
6098 goto out_free_bsmbx;
James Smartcff261f2013-12-17 20:29:47 -05006099 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
6100 if (unlikely(rc))
6101 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04006102
James Smart2fcee4b2010-12-15 17:57:46 -05006103 /* IF Type 0 ports get initialized now. */
6104 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
6105 LPFC_SLI_INTF_IF_TYPE_0) {
6106 rc = lpfc_pci_function_reset(phba);
6107 if (unlikely(rc))
6108 goto out_free_bsmbx;
6109 }
James Smartda0436e2009-05-22 14:51:39 -04006110
James Smartcb5172e2010-03-15 11:25:07 -04006111 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
6112 GFP_KERNEL);
6113 if (!mboxq) {
6114 rc = -ENOMEM;
6115 goto out_free_bsmbx;
6116 }
6117
James Smartf358dd02017-02-12 13:52:34 -08006118 /* Check for NVMET being configured */
James Smart895427b2017-02-12 13:52:30 -08006119 phba->nvmet_support = 0;
James Smartf358dd02017-02-12 13:52:34 -08006120 if (lpfc_enable_nvmet_cnt) {
6121
6122 /* First get WWN of HBA instance */
6123 lpfc_read_nv(phba, mboxq);
6124 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6125 if (rc != MBX_SUCCESS) {
6126 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6127 "6016 Mailbox failed , mbxCmd x%x "
6128 "READ_NV, mbxStatus x%x\n",
6129 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
6130 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
James Smartd1f525a2017-04-21 16:04:55 -07006131 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartf358dd02017-02-12 13:52:34 -08006132 rc = -EIO;
6133 goto out_free_bsmbx;
6134 }
6135 mb = &mboxq->u.mb;
6136 memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
6137 sizeof(uint64_t));
6138 wwn = cpu_to_be64(wwn);
6139 phba->sli4_hba.wwnn.u.name = wwn;
6140 memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
6141 sizeof(uint64_t));
6142 /* wwn is WWPN of HBA instance */
6143 wwn = cpu_to_be64(wwn);
6144 phba->sli4_hba.wwpn.u.name = wwn;
6145
6146 /* Check to see if it matches any module parameter */
6147 for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
6148 if (wwn == lpfc_enable_nvmet[i]) {
James Smart7d708032017-03-08 14:36:01 -08006149#if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
James Smart3c603be2017-05-15 15:20:44 -07006150 if (lpfc_nvmet_mem_alloc(phba))
6151 break;
6152
6153 phba->nvmet_support = 1; /* a match */
6154
James Smartf358dd02017-02-12 13:52:34 -08006155 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6156 "6017 NVME Target %016llx\n",
6157 wwn);
James Smart7d708032017-03-08 14:36:01 -08006158#else
6159 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6160 "6021 Can't enable NVME Target."
6161 " NVME_TARGET_FC infrastructure"
6162 " is not in kernel\n");
6163#endif
James Smart3c603be2017-05-15 15:20:44 -07006164 break;
James Smartf358dd02017-02-12 13:52:34 -08006165 }
6166 }
6167 }
James Smart895427b2017-02-12 13:52:30 -08006168
6169 lpfc_nvme_mod_param_dep(phba);
6170
James Smartfedd3b72011-02-16 12:39:24 -05006171 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04006172 lpfc_supported_pages(mboxq);
6173 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05006174 if (!rc) {
6175 mqe = &mboxq->u.mqe;
6176 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
6177 LPFC_MAX_SUPPORTED_PAGES);
6178 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
6179 switch (pn_page[i]) {
6180 case LPFC_SLI4_PARAMETERS:
6181 phba->sli4_hba.pc_sli4_params.supported = 1;
6182 break;
6183 default:
6184 break;
6185 }
6186 }
6187 /* Read the port's SLI4 Parameters capabilities if supported. */
6188 if (phba->sli4_hba.pc_sli4_params.supported)
6189 rc = lpfc_pc_sli4_params_get(phba, mboxq);
6190 if (rc) {
6191 mempool_free(mboxq, phba->mbox_mem_pool);
6192 rc = -EIO;
6193 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04006194 }
6195 }
James Smart65791f12016-07-06 12:35:56 -07006196
James Smartfedd3b72011-02-16 12:39:24 -05006197 /*
6198 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04006199 * If this call fails, it isn't critical unless the SLI4 parameters come
6200 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05006201 */
James Smart6d368e52011-05-24 11:44:12 -04006202 rc = lpfc_get_sli4_parameters(phba, mboxq);
6203 if (rc) {
James Smartb92dc722018-05-24 21:09:01 -07006204 if_type = bf_get(lpfc_sli_intf_if_type,
6205 &phba->sli4_hba.sli_intf);
6206 if_fam = bf_get(lpfc_sli_intf_sli_family,
6207 &phba->sli4_hba.sli_intf);
James Smart6d368e52011-05-24 11:44:12 -04006208 if (phba->sli4_hba.extents_in_use &&
6209 phba->sli4_hba.rpi_hdrs_in_use) {
6210 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6211 "2999 Unsupported SLI4 Parameters "
6212 "Extents and RPI headers enabled.\n");
James Smartb92dc722018-05-24 21:09:01 -07006213 if (if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
6214 if_fam == LPFC_SLI_INTF_FAMILY_BE2) {
6215 mempool_free(mboxq, phba->mbox_mem_pool);
6216 rc = -EIO;
6217 goto out_free_bsmbx;
6218 }
James Smart6d368e52011-05-24 11:44:12 -04006219 }
James Smartb92dc722018-05-24 21:09:01 -07006220 if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
6221 if_fam == LPFC_SLI_INTF_FAMILY_BE2)) {
6222 mempool_free(mboxq, phba->mbox_mem_pool);
6223 rc = -EIO;
6224 goto out_free_bsmbx;
6225 }
James Smart6d368e52011-05-24 11:44:12 -04006226 }
James Smart895427b2017-02-12 13:52:30 -08006227
James Smartcb5172e2010-03-15 11:25:07 -04006228 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -05006229
6230 /* Verify OAS is supported */
6231 lpfc_sli4_oas_verify(phba);
6232 if (phba->cfg_fof)
6233 fof_vectors = 1;
6234
James Smartd2cc9bc2018-09-10 10:30:50 -07006235 /* Verify RAS support on adapter */
6236 lpfc_sli4_ras_init(phba);
6237
James Smart5350d872011-10-10 21:33:49 -04006238 /* Verify all the SLI4 queues */
6239 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04006240 if (rc)
6241 goto out_free_bsmbx;
6242
6243 /* Create driver internal CQE event pool */
6244 rc = lpfc_sli4_cq_event_pool_create(phba);
6245 if (rc)
James Smart5350d872011-10-10 21:33:49 -04006246 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04006247
James Smart8a9d2e82012-05-09 21:16:12 -04006248 /* Initialize sgl lists per host */
6249 lpfc_init_sgl_list(phba);
6250
6251 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04006252 rc = lpfc_init_active_sgl_array(phba);
6253 if (rc) {
6254 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6255 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04006256 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04006257 }
James Smartda0436e2009-05-22 14:51:39 -04006258 rc = lpfc_sli4_init_rpi_hdrs(phba);
6259 if (rc) {
6260 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6261 "1432 Failed to initialize rpi headers.\n");
6262 goto out_free_active_sgl;
6263 }
6264
James Smarta93ff372010-10-22 11:06:08 -04006265 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05006266 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
Kees Cook6396bb22018-06-12 14:03:40 -07006267 phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long),
James Smart0c9ab6f2010-02-26 14:15:57 -05006268 GFP_KERNEL);
6269 if (!phba->fcf.fcf_rr_bmask) {
6270 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6271 "2759 Failed allocate memory for FCF round "
6272 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04006273 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05006274 goto out_remove_rpi_hdrs;
6275 }
6276
James Smart895427b2017-02-12 13:52:30 -08006277 phba->sli4_hba.hba_eq_hdl = kcalloc(fof_vectors + phba->io_channel_irqs,
6278 sizeof(struct lpfc_hba_eq_hdl),
6279 GFP_KERNEL);
6280 if (!phba->sli4_hba.hba_eq_hdl) {
James Smart67d12732012-08-03 12:36:13 -04006281 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6282 "2572 Failed allocate memory for "
6283 "fast-path per-EQ handle array\n");
6284 rc = -ENOMEM;
6285 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04006286 }
6287
James Smart895427b2017-02-12 13:52:30 -08006288 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_present_cpu,
6289 sizeof(struct lpfc_vector_map_info),
6290 GFP_KERNEL);
James Smart7bb03bb2013-04-17 20:19:16 -04006291 if (!phba->sli4_hba.cpu_map) {
6292 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6293 "3327 Failed allocate memory for msi-x "
6294 "interrupt vector mapping\n");
6295 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08006296 goto out_free_hba_eq_hdl;
James Smart7bb03bb2013-04-17 20:19:16 -04006297 }
James Smartb246de12013-05-31 17:03:07 -04006298 if (lpfc_used_cpu == NULL) {
James Smart895427b2017-02-12 13:52:30 -08006299 lpfc_used_cpu = kcalloc(lpfc_present_cpu, sizeof(uint16_t),
6300 GFP_KERNEL);
James Smartb246de12013-05-31 17:03:07 -04006301 if (!lpfc_used_cpu) {
6302 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6303 "3335 Failed allocate memory for msi-x "
6304 "interrupt vector mapping\n");
6305 kfree(phba->sli4_hba.cpu_map);
6306 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08006307 goto out_free_hba_eq_hdl;
James Smartb246de12013-05-31 17:03:07 -04006308 }
6309 for (i = 0; i < lpfc_present_cpu; i++)
6310 lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
6311 }
6312
James Smart912e3ac2011-05-24 11:42:11 -04006313 /*
6314 * Enable sr-iov virtual functions if supported and configured
6315 * through the module parameter.
6316 */
6317 if (phba->cfg_sriov_nr_virtfn > 0) {
6318 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
6319 phba->cfg_sriov_nr_virtfn);
6320 if (rc) {
6321 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6322 "3020 Requested number of SR-IOV "
6323 "virtual functions (%d) is not "
6324 "supported\n",
6325 phba->cfg_sriov_nr_virtfn);
6326 phba->cfg_sriov_nr_virtfn = 0;
6327 }
6328 }
6329
James Smart5248a742011-07-22 18:37:06 -04006330 return 0;
James Smartda0436e2009-05-22 14:51:39 -04006331
James Smart895427b2017-02-12 13:52:30 -08006332out_free_hba_eq_hdl:
6333 kfree(phba->sli4_hba.hba_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05006334out_free_fcf_rr_bmask:
6335 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04006336out_remove_rpi_hdrs:
6337 lpfc_sli4_remove_rpi_hdrs(phba);
6338out_free_active_sgl:
6339 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04006340out_destroy_cq_event_pool:
6341 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04006342out_free_bsmbx:
6343 lpfc_destroy_bootstrap_mbox(phba);
6344out_free_mem:
6345 lpfc_mem_free(phba);
6346 return rc;
6347}
6348
6349/**
6350 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
6351 * @phba: pointer to lpfc hba data structure.
6352 *
6353 * This routine is invoked to unset the driver internal resources set up
6354 * specific for supporting the SLI-4 HBA device it attached to.
6355 **/
6356static void
6357lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
6358{
6359 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6360
James Smart7bb03bb2013-04-17 20:19:16 -04006361 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
6362 kfree(phba->sli4_hba.cpu_map);
6363 phba->sli4_hba.num_present_cpu = 0;
6364 phba->sli4_hba.num_online_cpu = 0;
James Smart76fd07a2014-02-20 09:57:18 -05006365 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04006366
James Smartda0436e2009-05-22 14:51:39 -04006367 /* Free memory allocated for fast-path work queue handles */
James Smart895427b2017-02-12 13:52:30 -08006368 kfree(phba->sli4_hba.hba_eq_hdl);
James Smartda0436e2009-05-22 14:51:39 -04006369
6370 /* Free the allocated rpi headers. */
6371 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04006372 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04006373
James Smart0c9ab6f2010-02-26 14:15:57 -05006374 /* Free eligible FCF index bmask */
6375 kfree(phba->fcf.fcf_rr_bmask);
6376
James Smartda0436e2009-05-22 14:51:39 -04006377 /* Free the ELS sgl list */
6378 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04006379 lpfc_free_els_sgl_list(phba);
James Smartf358dd02017-02-12 13:52:34 -08006380 lpfc_free_nvmet_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04006381
James Smartda0436e2009-05-22 14:51:39 -04006382 /* Free the completion queue EQ event pool */
6383 lpfc_sli4_cq_event_release_all(phba);
6384 lpfc_sli4_cq_event_pool_destroy(phba);
6385
James Smart6d368e52011-05-24 11:44:12 -04006386 /* Release resource identifiers. */
6387 lpfc_sli4_dealloc_resource_identifiers(phba);
6388
James Smartda0436e2009-05-22 14:51:39 -04006389 /* Free the bsmbx region. */
6390 lpfc_destroy_bootstrap_mbox(phba);
6391
6392 /* Free the SLI Layer memory with SLI4 HBAs */
6393 lpfc_mem_free_all(phba);
6394
6395 /* Free the current connect table */
6396 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04006397 &phba->fcf_conn_rec_list, list) {
6398 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04006399 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04006400 }
James Smartda0436e2009-05-22 14:51:39 -04006401
6402 return;
6403}
6404
6405/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006406 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04006407 * @phba: The hba struct for which this call is being executed.
6408 * @dev_grp: The HBA PCI-Device group number.
6409 *
6410 * This routine sets up the device INIT interface API function jump table
6411 * in @phba struct.
6412 *
6413 * Returns: 0 - success, -ENODEV - failure.
6414 **/
6415int
6416lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
6417{
James Smart84d1b002010-02-12 14:42:33 -05006418 phba->lpfc_hba_init_link = lpfc_hba_init_link;
6419 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05006420 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04006421 switch (dev_grp) {
6422 case LPFC_PCI_DEV_LP:
6423 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
6424 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
6425 phba->lpfc_stop_port = lpfc_stop_port_s3;
6426 break;
James Smartda0436e2009-05-22 14:51:39 -04006427 case LPFC_PCI_DEV_OC:
6428 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
6429 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
6430 phba->lpfc_stop_port = lpfc_stop_port_s4;
6431 break;
James Smart3772a992009-05-22 14:50:54 -04006432 default:
6433 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6434 "1431 Invalid HBA PCI-device group: 0x%x\n",
6435 dev_grp);
6436 return -ENODEV;
6437 break;
6438 }
6439 return 0;
6440}
6441
6442/**
James Smart3772a992009-05-22 14:50:54 -04006443 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
6444 * @phba: pointer to lpfc hba data structure.
6445 *
6446 * This routine is invoked to set up the driver internal resources after the
6447 * device specific resource setup to support the HBA device it attached to.
6448 *
6449 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006450 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006451 * other values - error
6452 **/
6453static int
6454lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
6455{
6456 int error;
6457
6458 /* Startup the kernel thread for this host adapter. */
6459 phba->worker_thread = kthread_run(lpfc_do_work, phba,
6460 "lpfc_worker_%d", phba->brd_no);
6461 if (IS_ERR(phba->worker_thread)) {
6462 error = PTR_ERR(phba->worker_thread);
6463 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006464 }
6465
James Smart0cdb84e2018-04-09 14:24:26 -07006466 /* The lpfc_wq workqueue for deferred irq use, is only used for SLI4 */
6467 if (phba->sli_rev == LPFC_SLI_REV4)
6468 phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0);
6469 else
6470 phba->wq = NULL;
Dick Kennedyf485c182017-09-29 17:34:34 -07006471
James Smart3772a992009-05-22 14:50:54 -04006472 return 0;
6473}
6474
6475/**
6476 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
6477 * @phba: pointer to lpfc hba data structure.
6478 *
6479 * This routine is invoked to unset the driver internal resources set up after
6480 * the device specific resource setup for supporting the HBA device it
6481 * attached to.
6482 **/
6483static void
6484lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
6485{
Dick Kennedyf485c182017-09-29 17:34:34 -07006486 if (phba->wq) {
6487 flush_workqueue(phba->wq);
6488 destroy_workqueue(phba->wq);
6489 phba->wq = NULL;
6490 }
6491
James Smart3772a992009-05-22 14:50:54 -04006492 /* Stop kernel worker thread */
James Smart0cdb84e2018-04-09 14:24:26 -07006493 if (phba->worker_thread)
6494 kthread_stop(phba->worker_thread);
James Smart3772a992009-05-22 14:50:54 -04006495}
6496
6497/**
6498 * lpfc_free_iocb_list - Free iocb list.
6499 * @phba: pointer to lpfc hba data structure.
6500 *
6501 * This routine is invoked to free the driver's IOCB list and memory.
6502 **/
James Smart6c621a22017-05-15 15:20:45 -07006503void
James Smart3772a992009-05-22 14:50:54 -04006504lpfc_free_iocb_list(struct lpfc_hba *phba)
6505{
6506 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
6507
6508 spin_lock_irq(&phba->hbalock);
6509 list_for_each_entry_safe(iocbq_entry, iocbq_next,
6510 &phba->lpfc_iocb_list, list) {
6511 list_del(&iocbq_entry->list);
6512 kfree(iocbq_entry);
6513 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006514 }
James Smart3772a992009-05-22 14:50:54 -04006515 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006516
James Smart3772a992009-05-22 14:50:54 -04006517 return;
6518}
dea31012005-04-17 16:05:31 -05006519
James Smart3772a992009-05-22 14:50:54 -04006520/**
6521 * lpfc_init_iocb_list - Allocate and initialize iocb list.
6522 * @phba: pointer to lpfc hba data structure.
6523 *
6524 * This routine is invoked to allocate and initizlize the driver's IOCB
6525 * list and set up the IOCB tag array accordingly.
6526 *
6527 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006528 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006529 * other values - error
6530 **/
James Smart6c621a22017-05-15 15:20:45 -07006531int
James Smart3772a992009-05-22 14:50:54 -04006532lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
6533{
6534 struct lpfc_iocbq *iocbq_entry = NULL;
6535 uint16_t iotag;
6536 int i;
dea31012005-04-17 16:05:31 -05006537
6538 /* Initialize and populate the iocb list per host. */
6539 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04006540 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07006541 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05006542 if (iocbq_entry == NULL) {
6543 printk(KERN_ERR "%s: only allocated %d iocbs of "
6544 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07006545 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05006546 goto out_free_iocbq;
6547 }
6548
James Bottomley604a3e32005-10-29 10:28:33 -05006549 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
6550 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04006551 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05006552 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04006553 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05006554 goto out_free_iocbq;
6555 }
James Smart6d368e52011-05-24 11:44:12 -04006556 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04006557 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05006558
6559 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006560 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
6561 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05006562 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006563 }
6564
James Smart3772a992009-05-22 14:50:54 -04006565 return 0;
6566
6567out_free_iocbq:
6568 lpfc_free_iocb_list(phba);
6569
6570 return -ENOMEM;
6571}
6572
6573/**
James Smart8a9d2e82012-05-09 21:16:12 -04006574 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04006575 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04006576 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04006577 *
James Smart8a9d2e82012-05-09 21:16:12 -04006578 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04006579 **/
James Smart8a9d2e82012-05-09 21:16:12 -04006580void
6581lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04006582{
6583 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04006584
6585 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
6586 list_del(&sglq_entry->list);
6587 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
6588 kfree(sglq_entry);
6589 }
6590}
6591
6592/**
6593 * lpfc_free_els_sgl_list - Free els sgl list.
6594 * @phba: pointer to lpfc hba data structure.
6595 *
6596 * This routine is invoked to free the driver's els sgl list and memory.
6597 **/
6598static void
6599lpfc_free_els_sgl_list(struct lpfc_hba *phba)
6600{
James Smartda0436e2009-05-22 14:51:39 -04006601 LIST_HEAD(sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04006602
James Smart8a9d2e82012-05-09 21:16:12 -04006603 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04006604 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08006605 spin_lock(&phba->sli4_hba.sgl_list_lock);
6606 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
6607 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04006608 spin_unlock_irq(&phba->hbalock);
6609
James Smart8a9d2e82012-05-09 21:16:12 -04006610 /* Now free the sgl list */
6611 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04006612}
6613
6614/**
James Smartf358dd02017-02-12 13:52:34 -08006615 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
6616 * @phba: pointer to lpfc hba data structure.
6617 *
6618 * This routine is invoked to free the driver's nvmet sgl list and memory.
6619 **/
6620static void
6621lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
6622{
6623 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6624 LIST_HEAD(sglq_list);
6625
6626 /* Retrieve all nvmet sgls from driver list */
6627 spin_lock_irq(&phba->hbalock);
6628 spin_lock(&phba->sli4_hba.sgl_list_lock);
6629 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
6630 spin_unlock(&phba->sli4_hba.sgl_list_lock);
6631 spin_unlock_irq(&phba->hbalock);
6632
6633 /* Now free the sgl list */
6634 list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
6635 list_del(&sglq_entry->list);
6636 lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
6637 kfree(sglq_entry);
6638 }
Dick Kennedy4b40d022017-08-23 16:55:38 -07006639
6640 /* Update the nvmet_xri_cnt to reflect no current sgls.
6641 * The next initialization cycle sets the count and allocates
6642 * the sgls over again.
6643 */
6644 phba->sli4_hba.nvmet_xri_cnt = 0;
James Smartf358dd02017-02-12 13:52:34 -08006645}
6646
6647/**
James Smartda0436e2009-05-22 14:51:39 -04006648 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
6649 * @phba: pointer to lpfc hba data structure.
6650 *
6651 * This routine is invoked to allocate the driver's active sgl memory.
6652 * This array will hold the sglq_entry's for active IOs.
6653 **/
6654static int
6655lpfc_init_active_sgl_array(struct lpfc_hba *phba)
6656{
6657 int size;
6658 size = sizeof(struct lpfc_sglq *);
6659 size *= phba->sli4_hba.max_cfg_param.max_xri;
6660
6661 phba->sli4_hba.lpfc_sglq_active_list =
6662 kzalloc(size, GFP_KERNEL);
6663 if (!phba->sli4_hba.lpfc_sglq_active_list)
6664 return -ENOMEM;
6665 return 0;
6666}
6667
6668/**
6669 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
6670 * @phba: pointer to lpfc hba data structure.
6671 *
6672 * This routine is invoked to walk through the array of active sglq entries
6673 * and free all of the resources.
6674 * This is just a place holder for now.
6675 **/
6676static void
6677lpfc_free_active_sgl(struct lpfc_hba *phba)
6678{
6679 kfree(phba->sli4_hba.lpfc_sglq_active_list);
6680}
6681
6682/**
6683 * lpfc_init_sgl_list - Allocate and initialize sgl list.
6684 * @phba: pointer to lpfc hba data structure.
6685 *
6686 * This routine is invoked to allocate and initizlize the driver's sgl
6687 * list and set up the sgl xritag tag array accordingly.
6688 *
James Smartda0436e2009-05-22 14:51:39 -04006689 **/
James Smart8a9d2e82012-05-09 21:16:12 -04006690static void
James Smartda0436e2009-05-22 14:51:39 -04006691lpfc_init_sgl_list(struct lpfc_hba *phba)
6692{
James Smartda0436e2009-05-22 14:51:39 -04006693 /* Initialize and populate the sglq list per host/VF. */
James Smart895427b2017-02-12 13:52:30 -08006694 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
James Smartda0436e2009-05-22 14:51:39 -04006695 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -08006696 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
James Smart86c67372017-04-21 16:05:04 -07006697 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
James Smartda0436e2009-05-22 14:51:39 -04006698
James Smart8a9d2e82012-05-09 21:16:12 -04006699 /* els xri-sgl book keeping */
6700 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04006701
James Smart8a9d2e82012-05-09 21:16:12 -04006702 /* scsi xri-buffer book keeping */
James Smartda0436e2009-05-22 14:51:39 -04006703 phba->sli4_hba.scsi_xri_cnt = 0;
James Smart895427b2017-02-12 13:52:30 -08006704
6705 /* nvme xri-buffer book keeping */
6706 phba->sli4_hba.nvme_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04006707}
6708
6709/**
6710 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
6711 * @phba: pointer to lpfc hba data structure.
6712 *
6713 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04006714 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04006715 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04006716 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
6717 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04006718 *
6719 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006720 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04006721 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04006722 **/
6723int
6724lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
6725{
6726 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04006727 struct lpfc_rpi_hdr *rpi_hdr;
6728
6729 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05006730 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04006731 return rc;
James Smart6d368e52011-05-24 11:44:12 -04006732 if (phba->sli4_hba.extents_in_use)
6733 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04006734
6735 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
6736 if (!rpi_hdr) {
6737 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6738 "0391 Error during rpi post operation\n");
6739 lpfc_sli4_remove_rpis(phba);
6740 rc = -ENODEV;
6741 }
6742
6743 return rc;
6744}
6745
6746/**
6747 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
6748 * @phba: pointer to lpfc hba data structure.
6749 *
6750 * This routine is invoked to allocate a single 4KB memory region to
6751 * support rpis and stores them in the phba. This single region
6752 * provides support for up to 64 rpis. The region is used globally
6753 * by the device.
6754 *
6755 * Returns:
6756 * A valid rpi hdr on success.
6757 * A NULL pointer on any failure.
6758 **/
6759struct lpfc_rpi_hdr *
6760lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
6761{
6762 uint16_t rpi_limit, curr_rpi_range;
6763 struct lpfc_dmabuf *dmabuf;
6764 struct lpfc_rpi_hdr *rpi_hdr;
6765
James Smart6d368e52011-05-24 11:44:12 -04006766 /*
6767 * If the SLI4 port supports extents, posting the rpi header isn't
6768 * required. Set the expected maximum count and let the actual value
6769 * get set when extents are fully allocated.
6770 */
6771 if (!phba->sli4_hba.rpi_hdrs_in_use)
6772 return NULL;
6773 if (phba->sli4_hba.extents_in_use)
6774 return NULL;
6775
6776 /* The limit on the logical index is just the max_rpi count. */
James Smart845d9e82017-05-15 15:20:38 -07006777 rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi;
James Smartda0436e2009-05-22 14:51:39 -04006778
6779 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006780 /*
6781 * Establish the starting RPI in this header block. The starting
6782 * rpi is normalized to a zero base because the physical rpi is
6783 * port based.
6784 */
James Smart97f2ecf2012-03-01 22:35:23 -05006785 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04006786 spin_unlock_irq(&phba->hbalock);
6787
James Smart845d9e82017-05-15 15:20:38 -07006788 /* Reached full RPI range */
6789 if (curr_rpi_range == rpi_limit)
James Smart6d368e52011-05-24 11:44:12 -04006790 return NULL;
James Smart845d9e82017-05-15 15:20:38 -07006791
James Smartda0436e2009-05-22 14:51:39 -04006792 /*
6793 * First allocate the protocol header region for the port. The
6794 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
6795 */
6796 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6797 if (!dmabuf)
6798 return NULL;
6799
Joe Perches1aee3832014-09-03 12:56:12 -04006800 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
6801 LPFC_HDR_TEMPLATE_SIZE,
6802 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04006803 if (!dmabuf->virt) {
6804 rpi_hdr = NULL;
6805 goto err_free_dmabuf;
6806 }
6807
James Smartda0436e2009-05-22 14:51:39 -04006808 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
6809 rpi_hdr = NULL;
6810 goto err_free_coherent;
6811 }
6812
6813 /* Save the rpi header data for cleanup later. */
6814 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
6815 if (!rpi_hdr)
6816 goto err_free_coherent;
6817
6818 rpi_hdr->dmabuf = dmabuf;
6819 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
6820 rpi_hdr->page_count = 1;
6821 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006822
6823 /* The rpi_hdr stores the logical index only. */
6824 rpi_hdr->start_rpi = curr_rpi_range;
James Smart845d9e82017-05-15 15:20:38 -07006825 rpi_hdr->next_rpi = phba->sli4_hba.next_rpi + LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04006826 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
6827
James Smartda0436e2009-05-22 14:51:39 -04006828 spin_unlock_irq(&phba->hbalock);
6829 return rpi_hdr;
6830
6831 err_free_coherent:
6832 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
6833 dmabuf->virt, dmabuf->phys);
6834 err_free_dmabuf:
6835 kfree(dmabuf);
6836 return NULL;
6837}
6838
6839/**
6840 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
6841 * @phba: pointer to lpfc hba data structure.
6842 *
6843 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04006844 * to support rpis for SLI4 ports not supporting extents. This routine
6845 * presumes the caller has released all rpis consumed by fabric or port
6846 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04006847 **/
6848void
6849lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
6850{
6851 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
6852
James Smart6d368e52011-05-24 11:44:12 -04006853 if (!phba->sli4_hba.rpi_hdrs_in_use)
6854 goto exit;
6855
James Smartda0436e2009-05-22 14:51:39 -04006856 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
6857 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
6858 list_del(&rpi_hdr->list);
6859 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
6860 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
6861 kfree(rpi_hdr->dmabuf);
6862 kfree(rpi_hdr);
6863 }
James Smart6d368e52011-05-24 11:44:12 -04006864 exit:
6865 /* There are no rpis available to the port now. */
6866 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04006867}
6868
6869/**
James Smart3772a992009-05-22 14:50:54 -04006870 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
6871 * @pdev: pointer to pci device data structure.
6872 *
6873 * This routine is invoked to allocate the driver hba data structure for an
6874 * HBA device. If the allocation is successful, the phba reference to the
6875 * PCI device data structure is set.
6876 *
6877 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006878 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04006879 * NULL - error
6880 **/
6881static struct lpfc_hba *
6882lpfc_hba_alloc(struct pci_dev *pdev)
6883{
6884 struct lpfc_hba *phba;
6885
6886 /* Allocate memory for HBA structure */
6887 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
6888 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02006889 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04006890 return NULL;
6891 }
6892
6893 /* Set reference to PCI device in HBA structure */
6894 phba->pcidev = pdev;
6895
6896 /* Assign an unused board number */
6897 phba->brd_no = lpfc_get_instance();
6898 if (phba->brd_no < 0) {
6899 kfree(phba);
6900 return NULL;
6901 }
James Smart65791f12016-07-06 12:35:56 -07006902 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
James Smart3772a992009-05-22 14:50:54 -04006903
James Smart4fede782010-01-26 23:08:55 -05006904 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04006905 INIT_LIST_HEAD(&phba->ct_ev_waiters);
6906
James Smart3772a992009-05-22 14:50:54 -04006907 return phba;
6908}
6909
6910/**
6911 * lpfc_hba_free - Free driver hba data structure with a device.
6912 * @phba: pointer to lpfc hba data structure.
6913 *
6914 * This routine is invoked to free the driver hba data structure with an
6915 * HBA device.
6916 **/
6917static void
6918lpfc_hba_free(struct lpfc_hba *phba)
6919{
6920 /* Release the driver assigned board number */
6921 idr_remove(&lpfc_hba_index, phba->brd_no);
6922
James Smart895427b2017-02-12 13:52:30 -08006923 /* Free memory allocated with sli3 rings */
6924 kfree(phba->sli.sli3_ring);
6925 phba->sli.sli3_ring = NULL;
James Smart2a76a282012-08-03 12:35:54 -04006926
James Smart3772a992009-05-22 14:50:54 -04006927 kfree(phba);
6928 return;
6929}
6930
6931/**
6932 * lpfc_create_shost - Create hba physical port with associated scsi host.
6933 * @phba: pointer to lpfc hba data structure.
6934 *
6935 * This routine is invoked to create HBA physical port and associate a SCSI
6936 * host with it.
6937 *
6938 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006939 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006940 * other values - error
6941 **/
6942static int
6943lpfc_create_shost(struct lpfc_hba *phba)
6944{
6945 struct lpfc_vport *vport;
6946 struct Scsi_Host *shost;
6947
6948 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05006949 phba->fc_edtov = FF_DEF_EDTOV;
6950 phba->fc_ratov = FF_DEF_RATOV;
6951 phba->fc_altov = FF_DEF_ALTOV;
6952 phba->fc_arbtov = FF_DEF_ARBTOV;
6953
James Smartd7c47992010-06-08 18:31:54 -04006954 atomic_set(&phba->sdev_cnt, 0);
James Smart2cee7802017-06-01 21:07:02 -07006955 atomic_set(&phba->fc4ScsiInputRequests, 0);
6956 atomic_set(&phba->fc4ScsiOutputRequests, 0);
6957 atomic_set(&phba->fc4ScsiControlRequests, 0);
6958 atomic_set(&phba->fc4ScsiIoCmpls, 0);
James Smart3de2a652007-08-02 11:09:59 -04006959 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05006960 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04006961 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05006962
6963 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05006964 phba->pport = vport;
James Smart2ea259e2017-02-12 13:52:27 -08006965
James Smartf358dd02017-02-12 13:52:34 -08006966 if (phba->nvmet_support) {
6967 /* Only 1 vport (pport) will support NVME target */
6968 if (phba->txrdy_payload_pool == NULL) {
Romain Perier771db5c2017-07-06 10:13:05 +02006969 phba->txrdy_payload_pool = dma_pool_create(
6970 "txrdy_pool", &phba->pcidev->dev,
James Smartf358dd02017-02-12 13:52:34 -08006971 TXRDY_PAYLOAD_LEN, 16, 0);
6972 if (phba->txrdy_payload_pool) {
6973 phba->targetport = NULL;
6974 phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
6975 lpfc_printf_log(phba, KERN_INFO,
6976 LOG_INIT | LOG_NVME_DISC,
6977 "6076 NVME Target Found\n");
6978 }
6979 }
6980 }
6981
James Smart858c9f62007-06-17 19:56:39 -05006982 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04006983 /* Put reference to SCSI host to driver's device private data */
6984 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05006985
James Smart4258e982015-12-16 18:11:58 -05006986 /*
6987 * At this point we are fully registered with PSA. In addition,
6988 * any initial discovery should be completed.
6989 */
6990 vport->load_flag |= FC_ALLOW_FDMI;
James Smart8663cbb2016-03-31 14:12:33 -07006991 if (phba->cfg_enable_SmartSAN ||
6992 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -05006993
6994 /* Setup appropriate attribute masks */
6995 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -07006996 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -05006997 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
6998 else
6999 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
7000 }
James Smart3772a992009-05-22 14:50:54 -04007001 return 0;
7002}
dea31012005-04-17 16:05:31 -05007003
James Smart3772a992009-05-22 14:50:54 -04007004/**
7005 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
7006 * @phba: pointer to lpfc hba data structure.
7007 *
7008 * This routine is invoked to destroy HBA physical port and the associated
7009 * SCSI host.
7010 **/
7011static void
7012lpfc_destroy_shost(struct lpfc_hba *phba)
7013{
7014 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04007015
James Smart3772a992009-05-22 14:50:54 -04007016 /* Destroy physical port that associated with the SCSI host */
7017 destroy_port(vport);
7018
7019 return;
7020}
7021
7022/**
7023 * lpfc_setup_bg - Setup Block guard structures and debug areas.
7024 * @phba: pointer to lpfc hba data structure.
7025 * @shost: the shost to be used to detect Block guard settings.
7026 *
7027 * This routine sets up the local Block guard protocol settings for @shost.
7028 * This routine also allocates memory for debugging bg buffers.
7029 **/
7030static void
7031lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
7032{
James Smartbbeb79b2012-06-12 13:54:27 -04007033 uint32_t old_mask;
7034 uint32_t old_guard;
7035
James Smart3772a992009-05-22 14:50:54 -04007036 int pagecnt = 10;
James Smartb3b98b72016-10-13 15:06:06 -07007037 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
James Smart3772a992009-05-22 14:50:54 -04007038 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7039 "1478 Registering BlockGuard with the "
7040 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04007041
James Smartb3b98b72016-10-13 15:06:06 -07007042 old_mask = phba->cfg_prot_mask;
7043 old_guard = phba->cfg_prot_guard;
James Smartbbeb79b2012-06-12 13:54:27 -04007044
7045 /* Only allow supported values */
James Smartb3b98b72016-10-13 15:06:06 -07007046 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
James Smartbbeb79b2012-06-12 13:54:27 -04007047 SHOST_DIX_TYPE0_PROTECTION |
7048 SHOST_DIX_TYPE1_PROTECTION);
James Smartb3b98b72016-10-13 15:06:06 -07007049 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
7050 SHOST_DIX_GUARD_CRC);
James Smartbbeb79b2012-06-12 13:54:27 -04007051
7052 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
James Smartb3b98b72016-10-13 15:06:06 -07007053 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
7054 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
James Smartbbeb79b2012-06-12 13:54:27 -04007055
James Smartb3b98b72016-10-13 15:06:06 -07007056 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
7057 if ((old_mask != phba->cfg_prot_mask) ||
7058 (old_guard != phba->cfg_prot_guard))
James Smartbbeb79b2012-06-12 13:54:27 -04007059 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7060 "1475 Registering BlockGuard with the "
7061 "SCSI layer: mask %d guard %d\n",
James Smartb3b98b72016-10-13 15:06:06 -07007062 phba->cfg_prot_mask,
7063 phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04007064
James Smartb3b98b72016-10-13 15:06:06 -07007065 scsi_host_set_prot(shost, phba->cfg_prot_mask);
7066 scsi_host_set_guard(shost, phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04007067 } else
7068 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7069 "1479 Not Registering BlockGuard with the SCSI "
7070 "layer, Bad protection parameters: %d %d\n",
7071 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04007072 }
James Smartbbeb79b2012-06-12 13:54:27 -04007073
James Smart81301a92008-12-04 22:39:46 -05007074 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05007075 while (pagecnt) {
7076 spin_lock_init(&_dump_buf_lock);
7077 _dump_buf_data =
7078 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
7079 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04007080 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7081 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04007082 "_dump_buf_data at 0x%p\n",
7083 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05007084 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04007085 memset(_dump_buf_data, 0,
7086 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05007087 break;
James Smart3772a992009-05-22 14:50:54 -04007088 } else
James Smart81301a92008-12-04 22:39:46 -05007089 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05007090 }
James Smart81301a92008-12-04 22:39:46 -05007091 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04007092 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7093 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04007094 "memory for hexdump\n");
7095 } else
James Smart6a9c52c2009-10-02 15:16:51 -04007096 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7097 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05007098 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05007099 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05007100 while (pagecnt) {
7101 _dump_buf_dif =
7102 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
7103 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04007104 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7105 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04007106 "_dump_buf_dif at 0x%p\n",
7107 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05007108 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04007109 memset(_dump_buf_dif, 0,
7110 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05007111 break;
James Smart3772a992009-05-22 14:50:54 -04007112 } else
James Smart81301a92008-12-04 22:39:46 -05007113 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05007114 }
James Smart81301a92008-12-04 22:39:46 -05007115 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04007116 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7117 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04007118 "memory for hexdump\n");
7119 } else
James Smart6a9c52c2009-10-02 15:16:51 -04007120 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7121 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04007122 _dump_buf_dif);
7123}
7124
7125/**
7126 * lpfc_post_init_setup - Perform necessary device post initialization setup.
7127 * @phba: pointer to lpfc hba data structure.
7128 *
7129 * This routine is invoked to perform all the necessary post initialization
7130 * setup for the device.
7131 **/
7132static void
7133lpfc_post_init_setup(struct lpfc_hba *phba)
7134{
7135 struct Scsi_Host *shost;
7136 struct lpfc_adapter_event_header adapter_event;
7137
7138 /* Get the default values for Model Name and Description */
7139 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
7140
7141 /*
7142 * hba setup may have changed the hba_queue_depth so we need to
7143 * adjust the value of can_queue.
7144 */
7145 shost = pci_get_drvdata(phba->pcidev);
7146 shost->can_queue = phba->cfg_hba_queue_depth - 10;
7147 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
7148 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05007149
7150 lpfc_host_attrib_init(shost);
7151
James Smart2e0fef82007-06-17 19:56:36 -05007152 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
7153 spin_lock_irq(shost->host_lock);
7154 lpfc_poll_start_timer(phba);
7155 spin_unlock_irq(shost->host_lock);
7156 }
James Smart8f6d98d2006-08-01 07:34:00 -04007157
James Smart93996272008-08-24 21:50:30 -04007158 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7159 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04007160 /* Send board arrival event to upper layer */
7161 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
7162 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
7163 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04007164 sizeof(adapter_event),
7165 (char *) &adapter_event,
7166 LPFC_NL_VENDOR_ID);
7167 return;
7168}
7169
7170/**
7171 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
7172 * @phba: pointer to lpfc hba data structure.
7173 *
7174 * This routine is invoked to set up the PCI device memory space for device
7175 * with SLI-3 interface spec.
7176 *
7177 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007178 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007179 * other values - error
7180 **/
7181static int
7182lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
7183{
7184 struct pci_dev *pdev;
7185 unsigned long bar0map_len, bar2map_len;
7186 int i, hbq_count;
7187 void *ptr;
7188 int error = -ENODEV;
7189
7190 /* Obtain PCI device reference */
7191 if (!phba->pcidev)
7192 return error;
7193 else
7194 pdev = phba->pcidev;
7195
7196 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05007197 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
7198 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
7199 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
7200 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smart3772a992009-05-22 14:50:54 -04007201 return error;
Michael Reed8e685972009-09-18 12:02:05 -05007202 }
7203 }
James Smart3772a992009-05-22 14:50:54 -04007204
7205 /* Get the bus address of Bar0 and Bar2 and the number of bytes
7206 * required by each mapping.
7207 */
7208 phba->pci_bar0_map = pci_resource_start(pdev, 0);
7209 bar0map_len = pci_resource_len(pdev, 0);
7210
7211 phba->pci_bar2_map = pci_resource_start(pdev, 2);
7212 bar2map_len = pci_resource_len(pdev, 2);
7213
7214 /* Map HBA SLIM to a kernel virtual address. */
7215 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
7216 if (!phba->slim_memmap_p) {
7217 dev_printk(KERN_ERR, &pdev->dev,
7218 "ioremap failed for SLIM memory.\n");
7219 goto out;
7220 }
7221
7222 /* Map HBA Control Registers to a kernel virtual address. */
7223 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
7224 if (!phba->ctrl_regs_memmap_p) {
7225 dev_printk(KERN_ERR, &pdev->dev,
7226 "ioremap failed for HBA control registers.\n");
7227 goto out_iounmap_slim;
7228 }
7229
7230 /* Allocate memory for SLI-2 structures */
Joe Perches1aee3832014-09-03 12:56:12 -04007231 phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7232 &phba->slim2p.phys, GFP_KERNEL);
James Smart3772a992009-05-22 14:50:54 -04007233 if (!phba->slim2p.virt)
7234 goto out_iounmap;
7235
James Smart3772a992009-05-22 14:50:54 -04007236 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04007237 phba->mbox_ext = (phba->slim2p.virt +
7238 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04007239 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
7240 phba->IOCBs = (phba->slim2p.virt +
7241 offsetof(struct lpfc_sli2_slim, IOCBs));
7242
7243 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
7244 lpfc_sli_hbq_size(),
7245 &phba->hbqslimp.phys,
7246 GFP_KERNEL);
7247 if (!phba->hbqslimp.virt)
7248 goto out_free_slim;
7249
7250 hbq_count = lpfc_sli_hbq_count();
7251 ptr = phba->hbqslimp.virt;
7252 for (i = 0; i < hbq_count; ++i) {
7253 phba->hbqs[i].hbq_virt = ptr;
7254 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
7255 ptr += (lpfc_hbq_defs[i]->entry_count *
7256 sizeof(struct lpfc_hbq_entry));
7257 }
7258 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
7259 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
7260
7261 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
7262
James Smart3772a992009-05-22 14:50:54 -04007263 phba->MBslimaddr = phba->slim_memmap_p;
7264 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
7265 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
7266 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
7267 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04007268
dea31012005-04-17 16:05:31 -05007269 return 0;
7270
dea31012005-04-17 16:05:31 -05007271out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04007272 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7273 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05007274out_iounmap:
7275 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05007276out_iounmap_slim:
dea31012005-04-17 16:05:31 -05007277 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05007278out:
7279 return error;
7280}
7281
James Smarte59058c2008-08-24 21:49:00 -04007282/**
James Smart3772a992009-05-22 14:50:54 -04007283 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
7284 * @phba: pointer to lpfc hba data structure.
7285 *
7286 * This routine is invoked to unset the PCI device memory space for device
7287 * with SLI-3 interface spec.
7288 **/
7289static void
7290lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
7291{
7292 struct pci_dev *pdev;
7293
7294 /* Obtain PCI device reference */
7295 if (!phba->pcidev)
7296 return;
7297 else
7298 pdev = phba->pcidev;
7299
7300 /* Free coherent DMA memory allocated */
7301 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
7302 phba->hbqslimp.virt, phba->hbqslimp.phys);
7303 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7304 phba->slim2p.virt, phba->slim2p.phys);
7305
7306 /* I/O memory unmap */
7307 iounmap(phba->ctrl_regs_memmap_p);
7308 iounmap(phba->slim_memmap_p);
7309
7310 return;
7311}
7312
7313/**
James Smartda0436e2009-05-22 14:51:39 -04007314 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
7315 * @phba: pointer to lpfc hba data structure.
7316 *
7317 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
7318 * done and check status.
7319 *
7320 * Return 0 if successful, otherwise -ENODEV.
7321 **/
7322int
7323lpfc_sli4_post_status_check(struct lpfc_hba *phba)
7324{
James Smart2fcee4b2010-12-15 17:57:46 -05007325 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
7326 struct lpfc_register reg_data;
7327 int i, port_error = 0;
7328 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04007329
James Smart9940b972011-03-11 16:06:12 -05007330 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
7331 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05007332 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04007333 return -ENODEV;
7334
James Smartda0436e2009-05-22 14:51:39 -04007335 /* Wait up to 30 seconds for the SLI Port POST done and ready */
7336 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05007337 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
7338 &portsmphr_reg.word0) ||
7339 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007340 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04007341 port_error = -ENODEV;
7342 break;
7343 }
James Smart2fcee4b2010-12-15 17:57:46 -05007344 if (LPFC_POST_STAGE_PORT_READY ==
7345 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04007346 break;
James Smartda0436e2009-05-22 14:51:39 -04007347 msleep(10);
7348 }
7349
James Smart2fcee4b2010-12-15 17:57:46 -05007350 /*
7351 * If there was a port error during POST, then don't proceed with
7352 * other register reads as the data may not be valid. Just exit.
7353 */
7354 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04007355 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05007356 "1408 Port Failed POST - portsmphr=0x%x, "
7357 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
7358 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
7359 portsmphr_reg.word0,
7360 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
7361 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
7362 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
7363 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
7364 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
7365 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
7366 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
7367 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
7368 } else {
James Smart28baac72010-02-12 14:42:03 -05007369 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05007370 "2534 Device Info: SLIFamily=0x%x, "
7371 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
7372 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05007373 bf_get(lpfc_sli_intf_sli_family,
7374 &phba->sli4_hba.sli_intf),
7375 bf_get(lpfc_sli_intf_slirev,
7376 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05007377 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05007378 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05007379 bf_get(lpfc_sli_intf_sli_hint1,
7380 &phba->sli4_hba.sli_intf),
7381 bf_get(lpfc_sli_intf_sli_hint2,
7382 &phba->sli4_hba.sli_intf),
7383 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05007384 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05007385 /*
7386 * Check for other Port errors during the initialization
7387 * process. Fail the load if the port did not come up
7388 * correctly.
7389 */
7390 if_type = bf_get(lpfc_sli_intf_if_type,
7391 &phba->sli4_hba.sli_intf);
7392 switch (if_type) {
7393 case LPFC_SLI_INTF_IF_TYPE_0:
7394 phba->sli4_hba.ue_mask_lo =
7395 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
7396 phba->sli4_hba.ue_mask_hi =
7397 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
7398 uerrlo_reg.word0 =
7399 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
7400 uerrhi_reg.word0 =
7401 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
7402 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
7403 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
7404 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7405 "1422 Unrecoverable Error "
7406 "Detected during POST "
7407 "uerr_lo_reg=0x%x, "
7408 "uerr_hi_reg=0x%x, "
7409 "ue_mask_lo_reg=0x%x, "
7410 "ue_mask_hi_reg=0x%x\n",
7411 uerrlo_reg.word0,
7412 uerrhi_reg.word0,
7413 phba->sli4_hba.ue_mask_lo,
7414 phba->sli4_hba.ue_mask_hi);
7415 port_error = -ENODEV;
7416 }
7417 break;
7418 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08007419 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2fcee4b2010-12-15 17:57:46 -05007420 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05007421 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
7422 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04007423 (bf_get(lpfc_sliport_status_err, &reg_data) &&
7424 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007425 phba->work_status[0] =
7426 readl(phba->sli4_hba.u.if_type2.
7427 ERR1regaddr);
7428 phba->work_status[1] =
7429 readl(phba->sli4_hba.u.if_type2.
7430 ERR2regaddr);
7431 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05007432 "2888 Unrecoverable port error "
7433 "following POST: port status reg "
7434 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05007435 "error 1=0x%x, error 2=0x%x\n",
7436 reg_data.word0,
7437 portsmphr_reg.word0,
7438 phba->work_status[0],
7439 phba->work_status[1]);
7440 port_error = -ENODEV;
7441 }
7442 break;
7443 case LPFC_SLI_INTF_IF_TYPE_1:
7444 default:
7445 break;
7446 }
James Smart28baac72010-02-12 14:42:03 -05007447 }
James Smartda0436e2009-05-22 14:51:39 -04007448 return port_error;
7449}
7450
7451/**
7452 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
7453 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05007454 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04007455 *
7456 * This routine is invoked to set up SLI4 BAR0 PCI config space register
7457 * memory map.
7458 **/
7459static void
James Smart2fcee4b2010-12-15 17:57:46 -05007460lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04007461{
James Smart2fcee4b2010-12-15 17:57:46 -05007462 switch (if_type) {
7463 case LPFC_SLI_INTF_IF_TYPE_0:
7464 phba->sli4_hba.u.if_type0.UERRLOregaddr =
7465 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
7466 phba->sli4_hba.u.if_type0.UERRHIregaddr =
7467 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
7468 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
7469 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
7470 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
7471 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
7472 phba->sli4_hba.SLIINTFregaddr =
7473 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7474 break;
7475 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart0cf07f842017-06-01 21:07:10 -07007476 phba->sli4_hba.u.if_type2.EQDregaddr =
7477 phba->sli4_hba.conf_regs_memmap_p +
7478 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007479 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007480 phba->sli4_hba.conf_regs_memmap_p +
7481 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007482 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007483 phba->sli4_hba.conf_regs_memmap_p +
7484 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007485 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007486 phba->sli4_hba.conf_regs_memmap_p +
7487 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007488 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007489 phba->sli4_hba.conf_regs_memmap_p +
7490 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007491 phba->sli4_hba.SLIINTFregaddr =
7492 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7493 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007494 phba->sli4_hba.conf_regs_memmap_p +
7495 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007496 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05007497 phba->sli4_hba.conf_regs_memmap_p +
7498 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05007499 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05007500 phba->sli4_hba.conf_regs_memmap_p +
7501 LPFC_ULP0_WQ_DOORBELL;
James Smart9dd35422018-02-22 08:18:41 -08007502 phba->sli4_hba.CQDBregaddr =
James Smart2fcee4b2010-12-15 17:57:46 -05007503 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
James Smart9dd35422018-02-22 08:18:41 -08007504 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
James Smart2fcee4b2010-12-15 17:57:46 -05007505 phba->sli4_hba.MQDBregaddr =
7506 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
7507 phba->sli4_hba.BMBXregaddr =
7508 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
7509 break;
James Smart27d6ac02018-02-22 08:18:42 -08007510 case LPFC_SLI_INTF_IF_TYPE_6:
7511 phba->sli4_hba.u.if_type2.EQDregaddr =
7512 phba->sli4_hba.conf_regs_memmap_p +
7513 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
7514 phba->sli4_hba.u.if_type2.ERR1regaddr =
7515 phba->sli4_hba.conf_regs_memmap_p +
7516 LPFC_CTL_PORT_ER1_OFFSET;
7517 phba->sli4_hba.u.if_type2.ERR2regaddr =
7518 phba->sli4_hba.conf_regs_memmap_p +
7519 LPFC_CTL_PORT_ER2_OFFSET;
7520 phba->sli4_hba.u.if_type2.CTRLregaddr =
7521 phba->sli4_hba.conf_regs_memmap_p +
7522 LPFC_CTL_PORT_CTL_OFFSET;
7523 phba->sli4_hba.u.if_type2.STATUSregaddr =
7524 phba->sli4_hba.conf_regs_memmap_p +
7525 LPFC_CTL_PORT_STA_OFFSET;
7526 phba->sli4_hba.PSMPHRregaddr =
7527 phba->sli4_hba.conf_regs_memmap_p +
7528 LPFC_CTL_PORT_SEM_OFFSET;
7529 phba->sli4_hba.BMBXregaddr =
7530 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
7531 break;
James Smart2fcee4b2010-12-15 17:57:46 -05007532 case LPFC_SLI_INTF_IF_TYPE_1:
7533 default:
7534 dev_printk(KERN_ERR, &phba->pcidev->dev,
7535 "FATAL - unsupported SLI4 interface type - %d\n",
7536 if_type);
7537 break;
7538 }
James Smartda0436e2009-05-22 14:51:39 -04007539}
7540
7541/**
7542 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
7543 * @phba: pointer to lpfc hba data structure.
7544 *
James Smart27d6ac02018-02-22 08:18:42 -08007545 * This routine is invoked to set up SLI4 BAR1 register memory map.
James Smartda0436e2009-05-22 14:51:39 -04007546 **/
7547static void
James Smart27d6ac02018-02-22 08:18:42 -08007548lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04007549{
James Smart27d6ac02018-02-22 08:18:42 -08007550 switch (if_type) {
7551 case LPFC_SLI_INTF_IF_TYPE_0:
7552 phba->sli4_hba.PSMPHRregaddr =
7553 phba->sli4_hba.ctrl_regs_memmap_p +
7554 LPFC_SLIPORT_IF0_SMPHR;
7555 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7556 LPFC_HST_ISR0;
7557 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7558 LPFC_HST_IMR0;
7559 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7560 LPFC_HST_ISCR0;
7561 break;
7562 case LPFC_SLI_INTF_IF_TYPE_6:
7563 phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7564 LPFC_IF6_RQ_DOORBELL;
7565 phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7566 LPFC_IF6_WQ_DOORBELL;
7567 phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7568 LPFC_IF6_CQ_DOORBELL;
7569 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7570 LPFC_IF6_EQ_DOORBELL;
7571 phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7572 LPFC_IF6_MQ_DOORBELL;
7573 break;
7574 case LPFC_SLI_INTF_IF_TYPE_2:
7575 case LPFC_SLI_INTF_IF_TYPE_1:
7576 default:
7577 dev_err(&phba->pcidev->dev,
7578 "FATAL - unsupported SLI4 interface type - %d\n",
7579 if_type);
7580 break;
7581 }
James Smartda0436e2009-05-22 14:51:39 -04007582}
7583
7584/**
7585 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
7586 * @phba: pointer to lpfc hba data structure.
7587 * @vf: virtual function number
7588 *
7589 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
7590 * based on the given viftual function number, @vf.
7591 *
7592 * Return 0 if successful, otherwise -ENODEV.
7593 **/
7594static int
7595lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
7596{
7597 if (vf > LPFC_VIR_FUNC_MAX)
7598 return -ENODEV;
7599
7600 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05007601 vf * LPFC_VFR_PAGE_SIZE +
7602 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04007603 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05007604 vf * LPFC_VFR_PAGE_SIZE +
7605 LPFC_ULP0_WQ_DOORBELL);
James Smart9dd35422018-02-22 08:18:41 -08007606 phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7607 vf * LPFC_VFR_PAGE_SIZE +
7608 LPFC_EQCQ_DOORBELL);
7609 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
James Smartda0436e2009-05-22 14:51:39 -04007610 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7611 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
7612 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7613 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
7614 return 0;
7615}
7616
7617/**
7618 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
7619 * @phba: pointer to lpfc hba data structure.
7620 *
7621 * This routine is invoked to create the bootstrap mailbox
7622 * region consistent with the SLI-4 interface spec. This
7623 * routine allocates all memory necessary to communicate
7624 * mailbox commands to the port and sets up all alignment
7625 * needs. No locks are expected to be held when calling
7626 * this routine.
7627 *
7628 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007629 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04007630 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04007631 **/
7632static int
7633lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
7634{
7635 uint32_t bmbx_size;
7636 struct lpfc_dmabuf *dmabuf;
7637 struct dma_address *dma_address;
7638 uint32_t pa_addr;
7639 uint64_t phys_addr;
7640
7641 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
7642 if (!dmabuf)
7643 return -ENOMEM;
7644
7645 /*
7646 * The bootstrap mailbox region is comprised of 2 parts
7647 * plus an alignment restriction of 16 bytes.
7648 */
7649 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
Joe Perches1aee3832014-09-03 12:56:12 -04007650 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
7651 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04007652 if (!dmabuf->virt) {
7653 kfree(dmabuf);
7654 return -ENOMEM;
7655 }
James Smartda0436e2009-05-22 14:51:39 -04007656
7657 /*
7658 * Initialize the bootstrap mailbox pointers now so that the register
7659 * operations are simple later. The mailbox dma address is required
7660 * to be 16-byte aligned. Also align the virtual memory as each
7661 * maibox is copied into the bmbx mailbox region before issuing the
7662 * command to the port.
7663 */
7664 phba->sli4_hba.bmbx.dmabuf = dmabuf;
7665 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
7666
7667 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
7668 LPFC_ALIGN_16_BYTE);
7669 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
7670 LPFC_ALIGN_16_BYTE);
7671
7672 /*
7673 * Set the high and low physical addresses now. The SLI4 alignment
7674 * requirement is 16 bytes and the mailbox is posted to the port
7675 * as two 30-bit addresses. The other data is a bit marking whether
7676 * the 30-bit address is the high or low address.
7677 * Upcast bmbx aphys to 64bits so shift instruction compiles
7678 * clean on 32 bit machines.
7679 */
7680 dma_address = &phba->sli4_hba.bmbx.dma_address;
7681 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
7682 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
7683 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
7684 LPFC_BMBX_BIT1_ADDR_HI);
7685
7686 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
7687 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
7688 LPFC_BMBX_BIT1_ADDR_LO);
7689 return 0;
7690}
7691
7692/**
7693 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
7694 * @phba: pointer to lpfc hba data structure.
7695 *
7696 * This routine is invoked to teardown the bootstrap mailbox
7697 * region and release all host resources. This routine requires
7698 * the caller to ensure all mailbox commands recovered, no
7699 * additional mailbox comands are sent, and interrupts are disabled
7700 * before calling this routine.
7701 *
7702 **/
7703static void
7704lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
7705{
7706 dma_free_coherent(&phba->pcidev->dev,
7707 phba->sli4_hba.bmbx.bmbx_size,
7708 phba->sli4_hba.bmbx.dmabuf->virt,
7709 phba->sli4_hba.bmbx.dmabuf->phys);
7710
7711 kfree(phba->sli4_hba.bmbx.dmabuf);
7712 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
7713}
7714
7715/**
7716 * lpfc_sli4_read_config - Get the config parameters.
7717 * @phba: pointer to lpfc hba data structure.
7718 *
7719 * This routine is invoked to read the configuration parameters from the HBA.
7720 * The configuration parameters are used to set the base and maximum values
7721 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
7722 * allocation for the port.
7723 *
7724 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007725 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007726 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007727 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007728 **/
James Smartff78d8f2011-12-13 13:21:35 -05007729int
James Smartda0436e2009-05-22 14:51:39 -04007730lpfc_sli4_read_config(struct lpfc_hba *phba)
7731{
7732 LPFC_MBOXQ_t *pmb;
7733 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04007734 union lpfc_sli4_cfg_shdr *shdr;
7735 uint32_t shdr_status, shdr_add_status;
7736 struct lpfc_mbx_get_func_cfg *get_func_cfg;
7737 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04007738 char *pdesc_0;
James Smartc6918162016-10-13 15:06:16 -07007739 uint16_t forced_link_speed;
7740 uint32_t if_type;
James Smart8aa134a2012-08-14 14:25:29 -04007741 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04007742
7743 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7744 if (!pmb) {
7745 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7746 "2011 Unable to allocate memory for issuing "
7747 "SLI_CONFIG_SPECIAL mailbox command\n");
7748 return -ENOMEM;
7749 }
7750
7751 lpfc_read_config(phba, pmb);
7752
7753 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
7754 if (rc != MBX_SUCCESS) {
7755 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7756 "2012 Mailbox failed , mbxCmd x%x "
7757 "READ_CONFIG, mbxStatus x%x\n",
7758 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7759 bf_get(lpfc_mqe_status, &pmb->u.mqe));
7760 rc = -EIO;
7761 } else {
7762 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05007763 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
7764 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
7765 phba->sli4_hba.lnk_info.lnk_tp =
7766 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
7767 phba->sli4_hba.lnk_info.lnk_no =
7768 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
7769 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7770 "3081 lnk_type:%d, lnk_numb:%d\n",
7771 phba->sli4_hba.lnk_info.lnk_tp,
7772 phba->sli4_hba.lnk_info.lnk_no);
7773 } else
7774 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
7775 "3082 Mailbox (x%x) returned ldv:x0\n",
7776 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart44fd7fe2017-08-23 16:55:47 -07007777 if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) {
7778 phba->bbcredit_support = 1;
7779 phba->sli4_hba.bbscn_params.word0 = rd_config->word8;
7780 }
7781
James Smart6d368e52011-05-24 11:44:12 -04007782 phba->sli4_hba.extents_in_use =
7783 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04007784 phba->sli4_hba.max_cfg_param.max_xri =
7785 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
7786 phba->sli4_hba.max_cfg_param.xri_base =
7787 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
7788 phba->sli4_hba.max_cfg_param.max_vpi =
7789 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
7790 phba->sli4_hba.max_cfg_param.vpi_base =
7791 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
7792 phba->sli4_hba.max_cfg_param.max_rpi =
7793 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
7794 phba->sli4_hba.max_cfg_param.rpi_base =
7795 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
7796 phba->sli4_hba.max_cfg_param.max_vfi =
7797 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
7798 phba->sli4_hba.max_cfg_param.vfi_base =
7799 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
7800 phba->sli4_hba.max_cfg_param.max_fcfi =
7801 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04007802 phba->sli4_hba.max_cfg_param.max_eq =
7803 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
7804 phba->sli4_hba.max_cfg_param.max_rq =
7805 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
7806 phba->sli4_hba.max_cfg_param.max_wq =
7807 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
7808 phba->sli4_hba.max_cfg_param.max_cq =
7809 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
7810 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
7811 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
7812 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
7813 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05007814 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
7815 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04007816 phba->max_vports = phba->max_vpi;
7817 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04007818 "2003 cfg params Extents? %d "
7819 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04007820 "VPI(B:%d M:%d) "
7821 "VFI(B:%d M:%d) "
7822 "RPI(B:%d M:%d) "
James Smart2ea259e2017-02-12 13:52:27 -08007823 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n",
James Smart6d368e52011-05-24 11:44:12 -04007824 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04007825 phba->sli4_hba.max_cfg_param.xri_base,
7826 phba->sli4_hba.max_cfg_param.max_xri,
7827 phba->sli4_hba.max_cfg_param.vpi_base,
7828 phba->sli4_hba.max_cfg_param.max_vpi,
7829 phba->sli4_hba.max_cfg_param.vfi_base,
7830 phba->sli4_hba.max_cfg_param.max_vfi,
7831 phba->sli4_hba.max_cfg_param.rpi_base,
7832 phba->sli4_hba.max_cfg_param.max_rpi,
James Smart2ea259e2017-02-12 13:52:27 -08007833 phba->sli4_hba.max_cfg_param.max_fcfi,
7834 phba->sli4_hba.max_cfg_param.max_eq,
7835 phba->sli4_hba.max_cfg_param.max_cq,
7836 phba->sli4_hba.max_cfg_param.max_wq,
7837 phba->sli4_hba.max_cfg_param.max_rq);
7838
James Smartd38f33b2018-05-04 20:37:54 -07007839 /*
7840 * Calculate NVME queue resources based on how
7841 * many WQ/CQs are available.
7842 */
7843 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
7844 length = phba->sli4_hba.max_cfg_param.max_wq;
7845 if (phba->sli4_hba.max_cfg_param.max_cq <
7846 phba->sli4_hba.max_cfg_param.max_wq)
7847 length = phba->sli4_hba.max_cfg_param.max_cq;
7848
7849 /*
7850 * Whats left after this can go toward NVME.
7851 * The minus 6 accounts for ELS, NVME LS, MBOX
7852 * fof plus a couple extra. When configured for
7853 * NVMET, FCP io channel WQs are not created.
7854 */
7855 length -= 6;
7856 if (!phba->nvmet_support)
7857 length -= phba->cfg_fcp_io_channel;
7858
7859 if (phba->cfg_nvme_io_channel > length) {
7860 lpfc_printf_log(
7861 phba, KERN_ERR, LOG_SLI,
7862 "2005 Reducing NVME IO channel to %d: "
7863 "WQ %d CQ %d NVMEIO %d FCPIO %d\n",
7864 length,
7865 phba->sli4_hba.max_cfg_param.max_wq,
7866 phba->sli4_hba.max_cfg_param.max_cq,
7867 phba->cfg_nvme_io_channel,
7868 phba->cfg_fcp_io_channel);
7869
7870 phba->cfg_nvme_io_channel = length;
7871 }
7872 }
James Smartda0436e2009-05-22 14:51:39 -04007873 }
James Smart912e3ac2011-05-24 11:42:11 -04007874
7875 if (rc)
7876 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04007877
James Smartc6918162016-10-13 15:06:16 -07007878 /* Update link speed if forced link speed is supported */
7879 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smart27d6ac02018-02-22 08:18:42 -08007880 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
James Smartc6918162016-10-13 15:06:16 -07007881 forced_link_speed =
7882 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
7883 if (forced_link_speed) {
7884 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
7885
7886 switch (forced_link_speed) {
7887 case LINK_SPEED_1G:
7888 phba->cfg_link_speed =
7889 LPFC_USER_LINK_SPEED_1G;
7890 break;
7891 case LINK_SPEED_2G:
7892 phba->cfg_link_speed =
7893 LPFC_USER_LINK_SPEED_2G;
7894 break;
7895 case LINK_SPEED_4G:
7896 phba->cfg_link_speed =
7897 LPFC_USER_LINK_SPEED_4G;
7898 break;
7899 case LINK_SPEED_8G:
7900 phba->cfg_link_speed =
7901 LPFC_USER_LINK_SPEED_8G;
7902 break;
7903 case LINK_SPEED_10G:
7904 phba->cfg_link_speed =
7905 LPFC_USER_LINK_SPEED_10G;
7906 break;
7907 case LINK_SPEED_16G:
7908 phba->cfg_link_speed =
7909 LPFC_USER_LINK_SPEED_16G;
7910 break;
7911 case LINK_SPEED_32G:
7912 phba->cfg_link_speed =
7913 LPFC_USER_LINK_SPEED_32G;
7914 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08007915 case LINK_SPEED_64G:
7916 phba->cfg_link_speed =
7917 LPFC_USER_LINK_SPEED_64G;
7918 break;
James Smartc6918162016-10-13 15:06:16 -07007919 case 0xffff:
7920 phba->cfg_link_speed =
7921 LPFC_USER_LINK_SPEED_AUTO;
7922 break;
7923 default:
7924 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7925 "0047 Unrecognized link "
7926 "speed : %d\n",
7927 forced_link_speed);
7928 phba->cfg_link_speed =
7929 LPFC_USER_LINK_SPEED_AUTO;
7930 }
7931 }
7932 }
7933
James Smartda0436e2009-05-22 14:51:39 -04007934 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -04007935 length = phba->sli4_hba.max_cfg_param.max_xri -
7936 lpfc_sli4_get_els_iocb_cnt(phba);
7937 if (phba->cfg_hba_queue_depth > length) {
7938 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7939 "3361 HBA queue depth changed from %d to %d\n",
7940 phba->cfg_hba_queue_depth, length);
7941 phba->cfg_hba_queue_depth = length;
7942 }
James Smart912e3ac2011-05-24 11:42:11 -04007943
James Smart27d6ac02018-02-22 08:18:42 -08007944 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smart912e3ac2011-05-24 11:42:11 -04007945 LPFC_SLI_INTF_IF_TYPE_2)
7946 goto read_cfg_out;
7947
7948 /* get the pf# and vf# for SLI4 if_type 2 port */
7949 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
7950 sizeof(struct lpfc_sli4_cfg_mhdr));
7951 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
7952 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
7953 length, LPFC_SLI4_MBX_EMBED);
7954
James Smart8aa134a2012-08-14 14:25:29 -04007955 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04007956 shdr = (union lpfc_sli4_cfg_shdr *)
7957 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
7958 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7959 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04007960 if (rc2 || shdr_status || shdr_add_status) {
James Smart912e3ac2011-05-24 11:42:11 -04007961 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7962 "3026 Mailbox failed , mbxCmd x%x "
7963 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
7964 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7965 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04007966 goto read_cfg_out;
7967 }
7968
7969 /* search for fc_fcoe resrouce descriptor */
7970 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
James Smart912e3ac2011-05-24 11:42:11 -04007971
James Smart8aa134a2012-08-14 14:25:29 -04007972 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
7973 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
7974 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
7975 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
7976 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
7977 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
7978 goto read_cfg_out;
7979
James Smart912e3ac2011-05-24 11:42:11 -04007980 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04007981 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04007982 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04007983 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04007984 phba->sli4_hba.iov.pf_number =
7985 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
7986 phba->sli4_hba.iov.vf_number =
7987 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
7988 break;
7989 }
7990 }
7991
7992 if (i < LPFC_RSRC_DESC_MAX_NUM)
7993 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7994 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
7995 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
7996 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04007997 else
James Smart912e3ac2011-05-24 11:42:11 -04007998 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7999 "3028 GET_FUNCTION_CONFIG: failed to find "
Colin Ian Kingc4dba182018-10-16 18:28:53 +01008000 "Resource Descriptor:x%x\n",
James Smart912e3ac2011-05-24 11:42:11 -04008001 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04008002
8003read_cfg_out:
8004 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04008005 return rc;
8006}
8007
8008/**
James Smart2fcee4b2010-12-15 17:57:46 -05008009 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04008010 * @phba: pointer to lpfc hba data structure.
8011 *
James Smart2fcee4b2010-12-15 17:57:46 -05008012 * This routine is invoked to setup the port-side endian order when
8013 * the port if_type is 0. This routine has no function for other
8014 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04008015 *
8016 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008017 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008018 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008019 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008020 **/
8021static int
8022lpfc_setup_endian_order(struct lpfc_hba *phba)
8023{
8024 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05008025 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04008026 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
8027 HOST_ENDIAN_HIGH_WORD1};
8028
James Smart2fcee4b2010-12-15 17:57:46 -05008029 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8030 switch (if_type) {
8031 case LPFC_SLI_INTF_IF_TYPE_0:
8032 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8033 GFP_KERNEL);
8034 if (!mboxq) {
8035 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8036 "0492 Unable to allocate memory for "
8037 "issuing SLI_CONFIG_SPECIAL mailbox "
8038 "command\n");
8039 return -ENOMEM;
8040 }
James Smartda0436e2009-05-22 14:51:39 -04008041
James Smart2fcee4b2010-12-15 17:57:46 -05008042 /*
8043 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
8044 * two words to contain special data values and no other data.
8045 */
8046 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
8047 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
8048 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8049 if (rc != MBX_SUCCESS) {
8050 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8051 "0493 SLI_CONFIG_SPECIAL mailbox "
8052 "failed with status x%x\n",
8053 rc);
8054 rc = -EIO;
8055 }
8056 mempool_free(mboxq, phba->mbox_mem_pool);
8057 break;
James Smart27d6ac02018-02-22 08:18:42 -08008058 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2fcee4b2010-12-15 17:57:46 -05008059 case LPFC_SLI_INTF_IF_TYPE_2:
8060 case LPFC_SLI_INTF_IF_TYPE_1:
8061 default:
8062 break;
James Smartda0436e2009-05-22 14:51:39 -04008063 }
James Smartda0436e2009-05-22 14:51:39 -04008064 return rc;
8065}
8066
8067/**
James Smart895427b2017-02-12 13:52:30 -08008068 * lpfc_sli4_queue_verify - Verify and update EQ counts
James Smartda0436e2009-05-22 14:51:39 -04008069 * @phba: pointer to lpfc hba data structure.
8070 *
James Smart895427b2017-02-12 13:52:30 -08008071 * This routine is invoked to check the user settable queue counts for EQs.
8072 * After this routine is called the counts will be set to valid values that
James Smart5350d872011-10-10 21:33:49 -04008073 * adhere to the constraints of the system's interrupt vectors and the port's
8074 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04008075 *
8076 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008077 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008078 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04008079 **/
8080static int
James Smart5350d872011-10-10 21:33:49 -04008081lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04008082{
James Smart895427b2017-02-12 13:52:30 -08008083 int io_channel;
James Smart1ba981f2014-02-20 09:56:45 -05008084 int fof_vectors = phba->cfg_fof ? 1 : 0;
James Smartda0436e2009-05-22 14:51:39 -04008085
8086 /*
James Smart67d12732012-08-03 12:36:13 -04008087 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04008088 * device parameters
8089 */
8090
James Smart67d12732012-08-03 12:36:13 -04008091 /* Sanity check on HBA EQ parameters */
James Smart895427b2017-02-12 13:52:30 -08008092 io_channel = phba->io_channel_irqs;
James Smartda0436e2009-05-22 14:51:39 -04008093
James Smart895427b2017-02-12 13:52:30 -08008094 if (phba->sli4_hba.num_online_cpu < io_channel) {
James Smart82c3e9b2012-09-29 11:29:50 -04008095 lpfc_printf_log(phba,
8096 KERN_ERR, LOG_INIT,
James Smart90695ee2012-08-14 14:25:36 -04008097 "3188 Reducing IO channels to match number of "
James Smart7bb03bb2013-04-17 20:19:16 -04008098 "online CPUs: from %d to %d\n",
James Smart895427b2017-02-12 13:52:30 -08008099 io_channel, phba->sli4_hba.num_online_cpu);
8100 io_channel = phba->sli4_hba.num_online_cpu;
James Smart90695ee2012-08-14 14:25:36 -04008101 }
8102
James Smart895427b2017-02-12 13:52:30 -08008103 if (io_channel + fof_vectors > phba->sli4_hba.max_cfg_param.max_eq) {
James Smart82c3e9b2012-09-29 11:29:50 -04008104 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8105 "2575 Reducing IO channels to match number of "
8106 "available EQs: from %d to %d\n",
James Smart895427b2017-02-12 13:52:30 -08008107 io_channel,
James Smart82c3e9b2012-09-29 11:29:50 -04008108 phba->sli4_hba.max_cfg_param.max_eq);
James Smart895427b2017-02-12 13:52:30 -08008109 io_channel = phba->sli4_hba.max_cfg_param.max_eq - fof_vectors;
James Smartda0436e2009-05-22 14:51:39 -04008110 }
James Smart67d12732012-08-03 12:36:13 -04008111
James Smart895427b2017-02-12 13:52:30 -08008112 /* The actual number of FCP / NVME event queues adopted */
8113 if (io_channel != phba->io_channel_irqs)
8114 phba->io_channel_irqs = io_channel;
8115 if (phba->cfg_fcp_io_channel > io_channel)
8116 phba->cfg_fcp_io_channel = io_channel;
8117 if (phba->cfg_nvme_io_channel > io_channel)
8118 phba->cfg_nvme_io_channel = io_channel;
James Smartbcb24f62017-11-20 16:00:36 -08008119 if (phba->nvmet_support) {
8120 if (phba->cfg_nvme_io_channel < phba->cfg_nvmet_mrq)
8121 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
8122 }
8123 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
8124 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
James Smart895427b2017-02-12 13:52:30 -08008125
8126 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2d7dbc42017-02-12 13:52:35 -08008127 "2574 IO channels: irqs %d fcp %d nvme %d MRQ: %d\n",
James Smart895427b2017-02-12 13:52:30 -08008128 phba->io_channel_irqs, phba->cfg_fcp_io_channel,
James Smart2d7dbc42017-02-12 13:52:35 -08008129 phba->cfg_nvme_io_channel, phba->cfg_nvmet_mrq);
James Smartda0436e2009-05-22 14:51:39 -04008130
James Smartda0436e2009-05-22 14:51:39 -04008131 /* Get EQ depth from module parameter, fake the default for now */
8132 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8133 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8134
James Smart5350d872011-10-10 21:33:49 -04008135 /* Get CQ depth from module parameter, fake the default for now */
8136 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8137 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart5350d872011-10-10 21:33:49 -04008138 return 0;
James Smart895427b2017-02-12 13:52:30 -08008139}
8140
8141static int
8142lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx)
8143{
8144 struct lpfc_queue *qdesc;
James Smart895427b2017-02-12 13:52:30 -08008145
James Smarta51e41b2017-12-08 17:18:06 -08008146 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
James Smart81b96ed2017-11-20 16:00:29 -08008147 phba->sli4_hba.cq_esize,
James Smarta51e41b2017-12-08 17:18:06 -08008148 LPFC_CQE_EXP_COUNT);
James Smart895427b2017-02-12 13:52:30 -08008149 if (!qdesc) {
8150 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8151 "0508 Failed allocate fast-path NVME CQ (%d)\n",
8152 wqidx);
8153 return 1;
8154 }
James Smart7365f6f2018-02-22 08:18:46 -08008155 qdesc->qe_valid = 1;
James Smart895427b2017-02-12 13:52:30 -08008156 phba->sli4_hba.nvme_cq[wqidx] = qdesc;
8157
James Smarta51e41b2017-12-08 17:18:06 -08008158 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8159 LPFC_WQE128_SIZE, LPFC_WQE_EXP_COUNT);
James Smart895427b2017-02-12 13:52:30 -08008160 if (!qdesc) {
8161 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8162 "0509 Failed allocate fast-path NVME WQ (%d)\n",
8163 wqidx);
8164 return 1;
8165 }
8166 phba->sli4_hba.nvme_wq[wqidx] = qdesc;
8167 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8168 return 0;
8169}
8170
8171static int
8172lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx)
8173{
8174 struct lpfc_queue *qdesc;
James Smartc176ffa2018-01-30 15:58:46 -08008175 uint32_t wqesize;
James Smart895427b2017-02-12 13:52:30 -08008176
8177 /* Create Fast Path FCP CQs */
James Smartc176ffa2018-01-30 15:58:46 -08008178 if (phba->enab_exp_wqcq_pages)
James Smarta51e41b2017-12-08 17:18:06 -08008179 /* Increase the CQ size when WQEs contain an embedded cdb */
8180 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8181 phba->sli4_hba.cq_esize,
8182 LPFC_CQE_EXP_COUNT);
8183
8184 else
8185 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8186 phba->sli4_hba.cq_esize,
8187 phba->sli4_hba.cq_ecount);
James Smart895427b2017-02-12 13:52:30 -08008188 if (!qdesc) {
8189 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8190 "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx);
8191 return 1;
8192 }
James Smart7365f6f2018-02-22 08:18:46 -08008193 qdesc->qe_valid = 1;
James Smart895427b2017-02-12 13:52:30 -08008194 phba->sli4_hba.fcp_cq[wqidx] = qdesc;
8195
8196 /* Create Fast Path FCP WQs */
James Smartc176ffa2018-01-30 15:58:46 -08008197 if (phba->enab_exp_wqcq_pages) {
James Smarta51e41b2017-12-08 17:18:06 -08008198 /* Increase the WQ size when WQEs contain an embedded cdb */
James Smartc176ffa2018-01-30 15:58:46 -08008199 wqesize = (phba->fcp_embed_io) ?
8200 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
James Smarta51e41b2017-12-08 17:18:06 -08008201 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
James Smartc176ffa2018-01-30 15:58:46 -08008202 wqesize,
James Smarta51e41b2017-12-08 17:18:06 -08008203 LPFC_WQE_EXP_COUNT);
James Smartc176ffa2018-01-30 15:58:46 -08008204 } else
James Smarta51e41b2017-12-08 17:18:06 -08008205 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8206 phba->sli4_hba.wq_esize,
8207 phba->sli4_hba.wq_ecount);
James Smartc176ffa2018-01-30 15:58:46 -08008208
James Smart895427b2017-02-12 13:52:30 -08008209 if (!qdesc) {
8210 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8211 "0503 Failed allocate fast-path FCP WQ (%d)\n",
8212 wqidx);
8213 return 1;
8214 }
8215 phba->sli4_hba.fcp_wq[wqidx] = qdesc;
8216 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8217 return 0;
James Smart5350d872011-10-10 21:33:49 -04008218}
8219
8220/**
8221 * lpfc_sli4_queue_create - Create all the SLI4 queues
8222 * @phba: pointer to lpfc hba data structure.
8223 *
8224 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
8225 * operation. For each SLI4 queue type, the parameters such as queue entry
8226 * count (queue depth) shall be taken from the module parameter. For now,
8227 * we just use some constant number as place holder.
8228 *
8229 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07008230 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04008231 * -ENOMEM - No availble memory
8232 * -EIO - The mailbox failed to complete successfully.
8233 **/
8234int
8235lpfc_sli4_queue_create(struct lpfc_hba *phba)
8236{
8237 struct lpfc_queue *qdesc;
James Smartd1f525a2017-04-21 16:04:55 -07008238 int idx, io_channel;
James Smart5350d872011-10-10 21:33:49 -04008239
8240 /*
James Smart67d12732012-08-03 12:36:13 -04008241 * Create HBA Record arrays.
James Smart895427b2017-02-12 13:52:30 -08008242 * Both NVME and FCP will share that same vectors / EQs
James Smart5350d872011-10-10 21:33:49 -04008243 */
James Smart895427b2017-02-12 13:52:30 -08008244 io_channel = phba->io_channel_irqs;
8245 if (!io_channel)
James Smart67d12732012-08-03 12:36:13 -04008246 return -ERANGE;
James Smart5350d872011-10-10 21:33:49 -04008247
James Smart67d12732012-08-03 12:36:13 -04008248 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
8249 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
8250 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
8251 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
8252 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
8253 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
James Smart895427b2017-02-12 13:52:30 -08008254 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8255 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8256 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8257 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart67d12732012-08-03 12:36:13 -04008258
James Smart895427b2017-02-12 13:52:30 -08008259 phba->sli4_hba.hba_eq = kcalloc(io_channel,
8260 sizeof(struct lpfc_queue *),
8261 GFP_KERNEL);
James Smart67d12732012-08-03 12:36:13 -04008262 if (!phba->sli4_hba.hba_eq) {
James Smartda0436e2009-05-22 14:51:39 -04008263 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04008264 "2576 Failed allocate memory for "
8265 "fast-path EQ record array\n");
James Smartda0436e2009-05-22 14:51:39 -04008266 goto out_error;
8267 }
James Smart67d12732012-08-03 12:36:13 -04008268
James Smart895427b2017-02-12 13:52:30 -08008269 if (phba->cfg_fcp_io_channel) {
8270 phba->sli4_hba.fcp_cq = kcalloc(phba->cfg_fcp_io_channel,
8271 sizeof(struct lpfc_queue *),
8272 GFP_KERNEL);
8273 if (!phba->sli4_hba.fcp_cq) {
8274 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8275 "2577 Failed allocate memory for "
8276 "fast-path CQ record array\n");
8277 goto out_error;
8278 }
8279 phba->sli4_hba.fcp_wq = kcalloc(phba->cfg_fcp_io_channel,
8280 sizeof(struct lpfc_queue *),
8281 GFP_KERNEL);
8282 if (!phba->sli4_hba.fcp_wq) {
8283 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8284 "2578 Failed allocate memory for "
8285 "fast-path FCP WQ record array\n");
8286 goto out_error;
8287 }
8288 /*
8289 * Since the first EQ can have multiple CQs associated with it,
8290 * this array is used to quickly see if we have a FCP fast-path
8291 * CQ match.
8292 */
8293 phba->sli4_hba.fcp_cq_map = kcalloc(phba->cfg_fcp_io_channel,
8294 sizeof(uint16_t),
8295 GFP_KERNEL);
8296 if (!phba->sli4_hba.fcp_cq_map) {
8297 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8298 "2545 Failed allocate memory for "
8299 "fast-path CQ map\n");
8300 goto out_error;
8301 }
James Smart67d12732012-08-03 12:36:13 -04008302 }
8303
James Smart895427b2017-02-12 13:52:30 -08008304 if (phba->cfg_nvme_io_channel) {
8305 phba->sli4_hba.nvme_cq = kcalloc(phba->cfg_nvme_io_channel,
8306 sizeof(struct lpfc_queue *),
8307 GFP_KERNEL);
8308 if (!phba->sli4_hba.nvme_cq) {
8309 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8310 "6077 Failed allocate memory for "
8311 "fast-path CQ record array\n");
8312 goto out_error;
8313 }
8314
James Smart895427b2017-02-12 13:52:30 -08008315 phba->sli4_hba.nvme_wq = kcalloc(phba->cfg_nvme_io_channel,
8316 sizeof(struct lpfc_queue *),
8317 GFP_KERNEL);
8318 if (!phba->sli4_hba.nvme_wq) {
8319 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8320 "2581 Failed allocate memory for "
8321 "fast-path NVME WQ record array\n");
8322 goto out_error;
8323 }
8324
8325 /*
8326 * Since the first EQ can have multiple CQs associated with it,
8327 * this array is used to quickly see if we have a NVME fast-path
8328 * CQ match.
8329 */
8330 phba->sli4_hba.nvme_cq_map = kcalloc(phba->cfg_nvme_io_channel,
8331 sizeof(uint16_t),
8332 GFP_KERNEL);
8333 if (!phba->sli4_hba.nvme_cq_map) {
8334 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8335 "6078 Failed allocate memory for "
8336 "fast-path CQ map\n");
8337 goto out_error;
8338 }
James Smart2d7dbc42017-02-12 13:52:35 -08008339
8340 if (phba->nvmet_support) {
8341 phba->sli4_hba.nvmet_cqset = kcalloc(
8342 phba->cfg_nvmet_mrq,
8343 sizeof(struct lpfc_queue *),
8344 GFP_KERNEL);
8345 if (!phba->sli4_hba.nvmet_cqset) {
8346 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8347 "3121 Fail allocate memory for "
8348 "fast-path CQ set array\n");
8349 goto out_error;
8350 }
8351 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
8352 phba->cfg_nvmet_mrq,
8353 sizeof(struct lpfc_queue *),
8354 GFP_KERNEL);
8355 if (!phba->sli4_hba.nvmet_mrq_hdr) {
8356 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8357 "3122 Fail allocate memory for "
8358 "fast-path RQ set hdr array\n");
8359 goto out_error;
8360 }
8361 phba->sli4_hba.nvmet_mrq_data = kcalloc(
8362 phba->cfg_nvmet_mrq,
8363 sizeof(struct lpfc_queue *),
8364 GFP_KERNEL);
8365 if (!phba->sli4_hba.nvmet_mrq_data) {
8366 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8367 "3124 Fail allocate memory for "
8368 "fast-path RQ set data array\n");
8369 goto out_error;
8370 }
8371 }
James Smart67d12732012-08-03 12:36:13 -04008372 }
James Smartda0436e2009-05-22 14:51:39 -04008373
James Smart895427b2017-02-12 13:52:30 -08008374 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
James Smart67d12732012-08-03 12:36:13 -04008375
James Smart895427b2017-02-12 13:52:30 -08008376 /* Create HBA Event Queues (EQs) */
8377 for (idx = 0; idx < io_channel; idx++) {
James Smart67d12732012-08-03 12:36:13 -04008378 /* Create EQs */
James Smart81b96ed2017-11-20 16:00:29 -08008379 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8380 phba->sli4_hba.eq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008381 phba->sli4_hba.eq_ecount);
8382 if (!qdesc) {
8383 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04008384 "0497 Failed allocate EQ (%d)\n", idx);
8385 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008386 }
James Smart7365f6f2018-02-22 08:18:46 -08008387 qdesc->qe_valid = 1;
James Smart67d12732012-08-03 12:36:13 -04008388 phba->sli4_hba.hba_eq[idx] = qdesc;
James Smartda0436e2009-05-22 14:51:39 -04008389 }
8390
James Smart895427b2017-02-12 13:52:30 -08008391 /* FCP and NVME io channels are not required to be balanced */
8392
8393 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
8394 if (lpfc_alloc_fcp_wq_cq(phba, idx))
8395 goto out_error;
8396
8397 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
8398 if (lpfc_alloc_nvme_wq_cq(phba, idx))
8399 goto out_error;
James Smart67d12732012-08-03 12:36:13 -04008400
James Smart2d7dbc42017-02-12 13:52:35 -08008401 if (phba->nvmet_support) {
8402 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8403 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08008404 LPFC_DEFAULT_PAGE_SIZE,
8405 phba->sli4_hba.cq_esize,
8406 phba->sli4_hba.cq_ecount);
James Smart2d7dbc42017-02-12 13:52:35 -08008407 if (!qdesc) {
8408 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8409 "3142 Failed allocate NVME "
8410 "CQ Set (%d)\n", idx);
8411 goto out_error;
8412 }
James Smart7365f6f2018-02-22 08:18:46 -08008413 qdesc->qe_valid = 1;
James Smart2d7dbc42017-02-12 13:52:35 -08008414 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
8415 }
8416 }
8417
James Smartda0436e2009-05-22 14:51:39 -04008418 /*
James Smart67d12732012-08-03 12:36:13 -04008419 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04008420 */
8421
James Smartda0436e2009-05-22 14:51:39 -04008422 /* Create slow-path Mailbox Command Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008423 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8424 phba->sli4_hba.cq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008425 phba->sli4_hba.cq_ecount);
8426 if (!qdesc) {
8427 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8428 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04008429 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008430 }
James Smart7365f6f2018-02-22 08:18:46 -08008431 qdesc->qe_valid = 1;
James Smartda0436e2009-05-22 14:51:39 -04008432 phba->sli4_hba.mbx_cq = qdesc;
8433
8434 /* Create slow-path ELS Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008435 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8436 phba->sli4_hba.cq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008437 phba->sli4_hba.cq_ecount);
8438 if (!qdesc) {
8439 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8440 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -04008441 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008442 }
James Smart7365f6f2018-02-22 08:18:46 -08008443 qdesc->qe_valid = 1;
James Smartda0436e2009-05-22 14:51:39 -04008444 phba->sli4_hba.els_cq = qdesc;
8445
James Smartda0436e2009-05-22 14:51:39 -04008446
James Smart5350d872011-10-10 21:33:49 -04008447 /*
James Smart67d12732012-08-03 12:36:13 -04008448 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04008449 */
James Smartda0436e2009-05-22 14:51:39 -04008450
8451 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04008452
James Smart81b96ed2017-11-20 16:00:29 -08008453 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8454 phba->sli4_hba.mq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008455 phba->sli4_hba.mq_ecount);
8456 if (!qdesc) {
8457 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8458 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04008459 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008460 }
8461 phba->sli4_hba.mbx_wq = qdesc;
8462
8463 /*
James Smart67d12732012-08-03 12:36:13 -04008464 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04008465 */
James Smartda0436e2009-05-22 14:51:39 -04008466
8467 /* Create slow-path ELS Work Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008468 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8469 phba->sli4_hba.wq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008470 phba->sli4_hba.wq_ecount);
8471 if (!qdesc) {
8472 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8473 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04008474 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008475 }
8476 phba->sli4_hba.els_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08008477 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8478
8479 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8480 /* Create NVME LS Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008481 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8482 phba->sli4_hba.cq_esize,
James Smart895427b2017-02-12 13:52:30 -08008483 phba->sli4_hba.cq_ecount);
8484 if (!qdesc) {
8485 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8486 "6079 Failed allocate NVME LS CQ\n");
8487 goto out_error;
8488 }
James Smart7365f6f2018-02-22 08:18:46 -08008489 qdesc->qe_valid = 1;
James Smart895427b2017-02-12 13:52:30 -08008490 phba->sli4_hba.nvmels_cq = qdesc;
8491
8492 /* Create NVME LS Work Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008493 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8494 phba->sli4_hba.wq_esize,
James Smart895427b2017-02-12 13:52:30 -08008495 phba->sli4_hba.wq_ecount);
8496 if (!qdesc) {
8497 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8498 "6080 Failed allocate NVME LS WQ\n");
8499 goto out_error;
8500 }
8501 phba->sli4_hba.nvmels_wq = qdesc;
8502 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8503 }
James Smartda0436e2009-05-22 14:51:39 -04008504
James Smartda0436e2009-05-22 14:51:39 -04008505 /*
8506 * Create Receive Queue (RQ)
8507 */
James Smartda0436e2009-05-22 14:51:39 -04008508
8509 /* Create Receive Queue for header */
James Smart81b96ed2017-11-20 16:00:29 -08008510 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8511 phba->sli4_hba.rq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008512 phba->sli4_hba.rq_ecount);
8513 if (!qdesc) {
8514 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8515 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04008516 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008517 }
8518 phba->sli4_hba.hdr_rq = qdesc;
8519
8520 /* Create Receive Queue for data */
James Smart81b96ed2017-11-20 16:00:29 -08008521 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8522 phba->sli4_hba.rq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008523 phba->sli4_hba.rq_ecount);
8524 if (!qdesc) {
8525 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8526 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04008527 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008528 }
8529 phba->sli4_hba.dat_rq = qdesc;
8530
James Smart2d7dbc42017-02-12 13:52:35 -08008531 if (phba->nvmet_support) {
8532 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8533 /* Create NVMET Receive Queue for header */
8534 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08008535 LPFC_DEFAULT_PAGE_SIZE,
James Smart2d7dbc42017-02-12 13:52:35 -08008536 phba->sli4_hba.rq_esize,
James Smart61f3d4b2017-05-15 15:20:41 -07008537 LPFC_NVMET_RQE_DEF_COUNT);
James Smart2d7dbc42017-02-12 13:52:35 -08008538 if (!qdesc) {
8539 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8540 "3146 Failed allocate "
8541 "receive HRQ\n");
8542 goto out_error;
8543 }
8544 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
8545
8546 /* Only needed for header of RQ pair */
8547 qdesc->rqbp = kzalloc(sizeof(struct lpfc_rqb),
8548 GFP_KERNEL);
8549 if (qdesc->rqbp == NULL) {
8550 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8551 "6131 Failed allocate "
8552 "Header RQBP\n");
8553 goto out_error;
8554 }
8555
Dick Kennedy4b40d022017-08-23 16:55:38 -07008556 /* Put list in known state in case driver load fails. */
8557 INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list);
8558
James Smart2d7dbc42017-02-12 13:52:35 -08008559 /* Create NVMET Receive Queue for data */
8560 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08008561 LPFC_DEFAULT_PAGE_SIZE,
James Smart2d7dbc42017-02-12 13:52:35 -08008562 phba->sli4_hba.rq_esize,
James Smart61f3d4b2017-05-15 15:20:41 -07008563 LPFC_NVMET_RQE_DEF_COUNT);
James Smart2d7dbc42017-02-12 13:52:35 -08008564 if (!qdesc) {
8565 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8566 "3156 Failed allocate "
8567 "receive DRQ\n");
8568 goto out_error;
8569 }
8570 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
8571 }
8572 }
8573
James Smart1ba981f2014-02-20 09:56:45 -05008574 /* Create the Queues needed for Flash Optimized Fabric operations */
8575 if (phba->cfg_fof)
8576 lpfc_fof_queue_create(phba);
James Smartda0436e2009-05-22 14:51:39 -04008577 return 0;
8578
James Smartda0436e2009-05-22 14:51:39 -04008579out_error:
James Smart67d12732012-08-03 12:36:13 -04008580 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04008581 return -ENOMEM;
8582}
8583
James Smart895427b2017-02-12 13:52:30 -08008584static inline void
8585__lpfc_sli4_release_queue(struct lpfc_queue **qp)
8586{
8587 if (*qp != NULL) {
8588 lpfc_sli4_queue_free(*qp);
8589 *qp = NULL;
8590 }
8591}
8592
8593static inline void
8594lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
8595{
8596 int idx;
8597
8598 if (*qs == NULL)
8599 return;
8600
8601 for (idx = 0; idx < max; idx++)
8602 __lpfc_sli4_release_queue(&(*qs)[idx]);
8603
8604 kfree(*qs);
8605 *qs = NULL;
8606}
8607
8608static inline void
8609lpfc_sli4_release_queue_map(uint16_t **qmap)
8610{
8611 if (*qmap != NULL) {
8612 kfree(*qmap);
8613 *qmap = NULL;
8614 }
8615}
8616
James Smartda0436e2009-05-22 14:51:39 -04008617/**
8618 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
8619 * @phba: pointer to lpfc hba data structure.
8620 *
8621 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
8622 * operation.
8623 *
8624 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008625 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008626 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008627 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008628 **/
James Smart5350d872011-10-10 21:33:49 -04008629void
James Smartda0436e2009-05-22 14:51:39 -04008630lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
8631{
James Smart1ba981f2014-02-20 09:56:45 -05008632 if (phba->cfg_fof)
8633 lpfc_fof_queue_destroy(phba);
8634
James Smart895427b2017-02-12 13:52:30 -08008635 /* Release HBA eqs */
8636 lpfc_sli4_release_queues(&phba->sli4_hba.hba_eq, phba->io_channel_irqs);
James Smart67d12732012-08-03 12:36:13 -04008637
James Smart895427b2017-02-12 13:52:30 -08008638 /* Release FCP cqs */
8639 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_cq,
James Smartd1f525a2017-04-21 16:04:55 -07008640 phba->cfg_fcp_io_channel);
James Smart67d12732012-08-03 12:36:13 -04008641
James Smart895427b2017-02-12 13:52:30 -08008642 /* Release FCP wqs */
8643 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_wq,
James Smartd1f525a2017-04-21 16:04:55 -07008644 phba->cfg_fcp_io_channel);
James Smart67d12732012-08-03 12:36:13 -04008645
8646 /* Release FCP CQ mapping array */
James Smart895427b2017-02-12 13:52:30 -08008647 lpfc_sli4_release_queue_map(&phba->sli4_hba.fcp_cq_map);
8648
8649 /* Release NVME cqs */
8650 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_cq,
8651 phba->cfg_nvme_io_channel);
8652
8653 /* Release NVME wqs */
8654 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_wq,
8655 phba->cfg_nvme_io_channel);
8656
8657 /* Release NVME CQ mapping array */
8658 lpfc_sli4_release_queue_map(&phba->sli4_hba.nvme_cq_map);
James Smartda0436e2009-05-22 14:51:39 -04008659
James Smartbcb24f62017-11-20 16:00:36 -08008660 if (phba->nvmet_support) {
8661 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
8662 phba->cfg_nvmet_mrq);
James Smart2d7dbc42017-02-12 13:52:35 -08008663
James Smartbcb24f62017-11-20 16:00:36 -08008664 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
8665 phba->cfg_nvmet_mrq);
8666 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
8667 phba->cfg_nvmet_mrq);
8668 }
James Smart2d7dbc42017-02-12 13:52:35 -08008669
James Smartda0436e2009-05-22 14:51:39 -04008670 /* Release mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08008671 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
James Smartda0436e2009-05-22 14:51:39 -04008672
8673 /* Release ELS work queue */
James Smart895427b2017-02-12 13:52:30 -08008674 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
8675
8676 /* Release ELS work queue */
8677 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
James Smartda0436e2009-05-22 14:51:39 -04008678
8679 /* Release unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08008680 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
8681 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
James Smartda0436e2009-05-22 14:51:39 -04008682
James Smartda0436e2009-05-22 14:51:39 -04008683 /* Release ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08008684 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
8685
8686 /* Release NVME LS complete queue */
8687 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
James Smartda0436e2009-05-22 14:51:39 -04008688
8689 /* Release mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08008690 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
8691
8692 /* Everything on this list has been freed */
8693 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
8694}
8695
8696int
James Smart895427b2017-02-12 13:52:30 -08008697lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
8698{
8699 struct lpfc_rqb *rqbp;
8700 struct lpfc_dmabuf *h_buf;
8701 struct rqb_dmabuf *rqb_buffer;
8702
8703 rqbp = rq->rqbp;
8704 while (!list_empty(&rqbp->rqb_buffer_list)) {
8705 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
8706 struct lpfc_dmabuf, list);
8707
8708 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
8709 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
8710 rqbp->buffer_count--;
8711 }
8712 return 1;
8713}
8714
8715static int
8716lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
8717 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
8718 int qidx, uint32_t qtype)
8719{
8720 struct lpfc_sli_ring *pring;
8721 int rc;
8722
8723 if (!eq || !cq || !wq) {
8724 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8725 "6085 Fast-path %s (%d) not allocated\n",
8726 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
8727 return -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04008728 }
James Smartda0436e2009-05-22 14:51:39 -04008729
James Smart895427b2017-02-12 13:52:30 -08008730 /* create the Cq first */
8731 rc = lpfc_cq_create(phba, cq, eq,
8732 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
8733 if (rc) {
8734 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8735 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
8736 qidx, (uint32_t)rc);
8737 return rc;
8738 }
James Smart81b96ed2017-11-20 16:00:29 -08008739 cq->chann = qidx;
James Smart895427b2017-02-12 13:52:30 -08008740
8741 if (qtype != LPFC_MBOX) {
8742 /* Setup nvme_cq_map for fast lookup */
8743 if (cq_map)
8744 *cq_map = cq->queue_id;
8745
8746 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8747 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
8748 qidx, cq->queue_id, qidx, eq->queue_id);
8749
8750 /* create the wq */
8751 rc = lpfc_wq_create(phba, wq, cq, qtype);
8752 if (rc) {
8753 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8754 "6123 Fail setup fastpath WQ (%d), rc = 0x%x\n",
8755 qidx, (uint32_t)rc);
8756 /* no need to tear down cq - caller will do so */
8757 return rc;
8758 }
James Smart81b96ed2017-11-20 16:00:29 -08008759 wq->chann = qidx;
James Smart895427b2017-02-12 13:52:30 -08008760
8761 /* Bind this CQ/WQ to the NVME ring */
8762 pring = wq->pring;
8763 pring->sli.sli4.wqp = (void *)wq;
8764 cq->pring = pring;
8765
8766 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8767 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
8768 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
8769 } else {
8770 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
8771 if (rc) {
8772 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8773 "0539 Failed setup of slow-path MQ: "
8774 "rc = 0x%x\n", rc);
8775 /* no need to tear down cq - caller will do so */
8776 return rc;
8777 }
8778
8779 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8780 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
8781 phba->sli4_hba.mbx_wq->queue_id,
8782 phba->sli4_hba.mbx_cq->queue_id);
8783 }
8784
8785 return 0;
James Smartda0436e2009-05-22 14:51:39 -04008786}
8787
8788/**
8789 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
8790 * @phba: pointer to lpfc hba data structure.
8791 *
8792 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
8793 * operation.
8794 *
8795 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008796 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008797 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008798 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008799 **/
8800int
8801lpfc_sli4_queue_setup(struct lpfc_hba *phba)
8802{
James Smart962bc512013-01-03 15:44:00 -05008803 uint32_t shdr_status, shdr_add_status;
8804 union lpfc_sli4_cfg_shdr *shdr;
8805 LPFC_MBOXQ_t *mboxq;
James Smart895427b2017-02-12 13:52:30 -08008806 int qidx;
8807 uint32_t length, io_channel;
8808 int rc = -ENOMEM;
James Smart962bc512013-01-03 15:44:00 -05008809
8810 /* Check for dual-ULP support */
8811 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8812 if (!mboxq) {
8813 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8814 "3249 Unable to allocate memory for "
8815 "QUERY_FW_CFG mailbox command\n");
8816 return -ENOMEM;
8817 }
8818 length = (sizeof(struct lpfc_mbx_query_fw_config) -
8819 sizeof(struct lpfc_sli4_cfg_mhdr));
8820 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8821 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
8822 length, LPFC_SLI4_MBX_EMBED);
8823
8824 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8825
8826 shdr = (union lpfc_sli4_cfg_shdr *)
8827 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
8828 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8829 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
8830 if (shdr_status || shdr_add_status || rc) {
8831 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8832 "3250 QUERY_FW_CFG mailbox failed with status "
8833 "x%x add_status x%x, mbx status x%x\n",
8834 shdr_status, shdr_add_status, rc);
8835 if (rc != MBX_TIMEOUT)
8836 mempool_free(mboxq, phba->mbox_mem_pool);
8837 rc = -ENXIO;
8838 goto out_error;
8839 }
8840
8841 phba->sli4_hba.fw_func_mode =
8842 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
8843 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
8844 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
James Smart8b017a32015-05-21 13:55:18 -04008845 phba->sli4_hba.physical_port =
8846 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
James Smart962bc512013-01-03 15:44:00 -05008847 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8848 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
8849 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
8850 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
8851
8852 if (rc != MBX_TIMEOUT)
8853 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04008854
8855 /*
James Smart67d12732012-08-03 12:36:13 -04008856 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04008857 */
James Smart895427b2017-02-12 13:52:30 -08008858 io_channel = phba->io_channel_irqs;
James Smartda0436e2009-05-22 14:51:39 -04008859
James Smart67d12732012-08-03 12:36:13 -04008860 /* Set up HBA event queue */
James Smart895427b2017-02-12 13:52:30 -08008861 if (io_channel && !phba->sli4_hba.hba_eq) {
James Smart2e90f4b2011-12-13 13:22:37 -05008862 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8863 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05008864 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04008865 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05008866 }
James Smart895427b2017-02-12 13:52:30 -08008867 for (qidx = 0; qidx < io_channel; qidx++) {
8868 if (!phba->sli4_hba.hba_eq[qidx]) {
James Smartda0436e2009-05-22 14:51:39 -04008869 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8870 "0522 Fast-path EQ (%d) not "
James Smart895427b2017-02-12 13:52:30 -08008871 "allocated\n", qidx);
James Smart1b511972011-12-13 13:23:09 -05008872 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008873 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008874 }
James Smart895427b2017-02-12 13:52:30 -08008875 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[qidx],
8876 phba->cfg_fcp_imax);
James Smartda0436e2009-05-22 14:51:39 -04008877 if (rc) {
8878 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8879 "0523 Failed setup of fast-path EQ "
James Smart895427b2017-02-12 13:52:30 -08008880 "(%d), rc = 0x%x\n", qidx,
James Smarta2fc4aef2014-09-03 12:57:55 -04008881 (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08008882 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008883 }
8884 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008885 "2584 HBA EQ setup: queue[%d]-id=%d\n",
8886 qidx, phba->sli4_hba.hba_eq[qidx]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04008887 }
8888
James Smart895427b2017-02-12 13:52:30 -08008889 if (phba->cfg_nvme_io_channel) {
8890 if (!phba->sli4_hba.nvme_cq || !phba->sli4_hba.nvme_wq) {
James Smart67d12732012-08-03 12:36:13 -04008891 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008892 "6084 Fast-path NVME %s array not allocated\n",
8893 (phba->sli4_hba.nvme_cq) ? "CQ" : "WQ");
James Smart67d12732012-08-03 12:36:13 -04008894 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008895 goto out_destroy;
James Smart67d12732012-08-03 12:36:13 -04008896 }
8897
James Smart895427b2017-02-12 13:52:30 -08008898 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
8899 rc = lpfc_create_wq_cq(phba,
8900 phba->sli4_hba.hba_eq[
8901 qidx % io_channel],
8902 phba->sli4_hba.nvme_cq[qidx],
8903 phba->sli4_hba.nvme_wq[qidx],
8904 &phba->sli4_hba.nvme_cq_map[qidx],
8905 qidx, LPFC_NVME);
8906 if (rc) {
8907 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8908 "6123 Failed to setup fastpath "
8909 "NVME WQ/CQ (%d), rc = 0x%x\n",
8910 qidx, (uint32_t)rc);
8911 goto out_destroy;
8912 }
8913 }
James Smart67d12732012-08-03 12:36:13 -04008914 }
8915
James Smart895427b2017-02-12 13:52:30 -08008916 if (phba->cfg_fcp_io_channel) {
8917 /* Set up fast-path FCP Response Complete Queue */
8918 if (!phba->sli4_hba.fcp_cq || !phba->sli4_hba.fcp_wq) {
James Smart67d12732012-08-03 12:36:13 -04008919 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008920 "3148 Fast-path FCP %s array not allocated\n",
8921 phba->sli4_hba.fcp_cq ? "WQ" : "CQ");
James Smart67d12732012-08-03 12:36:13 -04008922 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008923 goto out_destroy;
James Smart67d12732012-08-03 12:36:13 -04008924 }
8925
James Smart895427b2017-02-12 13:52:30 -08008926 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
8927 rc = lpfc_create_wq_cq(phba,
8928 phba->sli4_hba.hba_eq[
8929 qidx % io_channel],
8930 phba->sli4_hba.fcp_cq[qidx],
8931 phba->sli4_hba.fcp_wq[qidx],
8932 &phba->sli4_hba.fcp_cq_map[qidx],
8933 qidx, LPFC_FCP);
8934 if (rc) {
8935 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8936 "0535 Failed to setup fastpath "
8937 "FCP WQ/CQ (%d), rc = 0x%x\n",
8938 qidx, (uint32_t)rc);
8939 goto out_destroy;
8940 }
8941 }
James Smart67d12732012-08-03 12:36:13 -04008942 }
James Smartda0436e2009-05-22 14:51:39 -04008943
8944 /*
James Smart895427b2017-02-12 13:52:30 -08008945 * Set up Slow Path Complete Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04008946 */
8947
James Smart895427b2017-02-12 13:52:30 -08008948 /* Set up slow-path MBOX CQ/MQ */
8949
8950 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
James Smartda0436e2009-05-22 14:51:39 -04008951 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008952 "0528 %s not allocated\n",
8953 phba->sli4_hba.mbx_cq ?
James Smartd1f525a2017-04-21 16:04:55 -07008954 "Mailbox WQ" : "Mailbox CQ");
James Smart1b511972011-12-13 13:23:09 -05008955 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008956 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008957 }
James Smart895427b2017-02-12 13:52:30 -08008958
8959 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
James Smartd1f525a2017-04-21 16:04:55 -07008960 phba->sli4_hba.mbx_cq,
8961 phba->sli4_hba.mbx_wq,
8962 NULL, 0, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04008963 if (rc) {
8964 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008965 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
8966 (uint32_t)rc);
8967 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008968 }
James Smart2d7dbc42017-02-12 13:52:35 -08008969 if (phba->nvmet_support) {
8970 if (!phba->sli4_hba.nvmet_cqset) {
8971 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8972 "3165 Fast-path NVME CQ Set "
8973 "array not allocated\n");
8974 rc = -ENOMEM;
8975 goto out_destroy;
8976 }
8977 if (phba->cfg_nvmet_mrq > 1) {
8978 rc = lpfc_cq_create_set(phba,
8979 phba->sli4_hba.nvmet_cqset,
8980 phba->sli4_hba.hba_eq,
8981 LPFC_WCQ, LPFC_NVMET);
8982 if (rc) {
8983 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8984 "3164 Failed setup of NVME CQ "
8985 "Set, rc = 0x%x\n",
8986 (uint32_t)rc);
8987 goto out_destroy;
8988 }
8989 } else {
8990 /* Set up NVMET Receive Complete Queue */
8991 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
8992 phba->sli4_hba.hba_eq[0],
8993 LPFC_WCQ, LPFC_NVMET);
8994 if (rc) {
8995 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8996 "6089 Failed setup NVMET CQ: "
8997 "rc = 0x%x\n", (uint32_t)rc);
8998 goto out_destroy;
8999 }
James Smart81b96ed2017-11-20 16:00:29 -08009000 phba->sli4_hba.nvmet_cqset[0]->chann = 0;
9001
James Smart2d7dbc42017-02-12 13:52:35 -08009002 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9003 "6090 NVMET CQ setup: cq-id=%d, "
9004 "parent eq-id=%d\n",
9005 phba->sli4_hba.nvmet_cqset[0]->queue_id,
9006 phba->sli4_hba.hba_eq[0]->queue_id);
9007 }
9008 }
James Smartda0436e2009-05-22 14:51:39 -04009009
James Smart895427b2017-02-12 13:52:30 -08009010 /* Set up slow-path ELS WQ/CQ */
9011 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
James Smartda0436e2009-05-22 14:51:39 -04009012 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009013 "0530 ELS %s not allocated\n",
9014 phba->sli4_hba.els_cq ? "WQ" : "CQ");
James Smart1b511972011-12-13 13:23:09 -05009015 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009016 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009017 }
James Smart895427b2017-02-12 13:52:30 -08009018 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
9019 phba->sli4_hba.els_cq,
9020 phba->sli4_hba.els_wq,
9021 NULL, 0, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04009022 if (rc) {
9023 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009024 "0529 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
9025 (uint32_t)rc);
9026 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009027 }
9028 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9029 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
9030 phba->sli4_hba.els_wq->queue_id,
9031 phba->sli4_hba.els_cq->queue_id);
9032
James Smart895427b2017-02-12 13:52:30 -08009033 if (phba->cfg_nvme_io_channel) {
9034 /* Set up NVME LS Complete Queue */
9035 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
9036 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9037 "6091 LS %s not allocated\n",
9038 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
9039 rc = -ENOMEM;
9040 goto out_destroy;
9041 }
9042 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
9043 phba->sli4_hba.nvmels_cq,
9044 phba->sli4_hba.nvmels_wq,
9045 NULL, 0, LPFC_NVME_LS);
9046 if (rc) {
9047 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9048 "0529 Failed setup of NVVME LS WQ/CQ: "
9049 "rc = 0x%x\n", (uint32_t)rc);
9050 goto out_destroy;
9051 }
9052
9053 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9054 "6096 ELS WQ setup: wq-id=%d, "
9055 "parent cq-id=%d\n",
9056 phba->sli4_hba.nvmels_wq->queue_id,
9057 phba->sli4_hba.nvmels_cq->queue_id);
9058 }
9059
James Smart2d7dbc42017-02-12 13:52:35 -08009060 /*
9061 * Create NVMET Receive Queue (RQ)
9062 */
9063 if (phba->nvmet_support) {
9064 if ((!phba->sli4_hba.nvmet_cqset) ||
9065 (!phba->sli4_hba.nvmet_mrq_hdr) ||
9066 (!phba->sli4_hba.nvmet_mrq_data)) {
9067 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9068 "6130 MRQ CQ Queues not "
9069 "allocated\n");
9070 rc = -ENOMEM;
9071 goto out_destroy;
9072 }
9073 if (phba->cfg_nvmet_mrq > 1) {
9074 rc = lpfc_mrq_create(phba,
9075 phba->sli4_hba.nvmet_mrq_hdr,
9076 phba->sli4_hba.nvmet_mrq_data,
9077 phba->sli4_hba.nvmet_cqset,
9078 LPFC_NVMET);
9079 if (rc) {
9080 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9081 "6098 Failed setup of NVMET "
9082 "MRQ: rc = 0x%x\n",
9083 (uint32_t)rc);
9084 goto out_destroy;
9085 }
9086
9087 } else {
9088 rc = lpfc_rq_create(phba,
9089 phba->sli4_hba.nvmet_mrq_hdr[0],
9090 phba->sli4_hba.nvmet_mrq_data[0],
9091 phba->sli4_hba.nvmet_cqset[0],
9092 LPFC_NVMET);
9093 if (rc) {
9094 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9095 "6057 Failed setup of NVMET "
9096 "Receive Queue: rc = 0x%x\n",
9097 (uint32_t)rc);
9098 goto out_destroy;
9099 }
9100
9101 lpfc_printf_log(
9102 phba, KERN_INFO, LOG_INIT,
9103 "6099 NVMET RQ setup: hdr-rq-id=%d, "
9104 "dat-rq-id=%d parent cq-id=%d\n",
9105 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
9106 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
9107 phba->sli4_hba.nvmet_cqset[0]->queue_id);
9108
9109 }
9110 }
9111
James Smartda0436e2009-05-22 14:51:39 -04009112 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
9113 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9114 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05009115 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009116 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009117 }
James Smart73d91e52011-10-10 21:32:10 -04009118
James Smartda0436e2009-05-22 14:51:39 -04009119 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04009120 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04009121 if (rc) {
9122 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9123 "0541 Failed setup of Receive Queue: "
James Smarta2fc4aef2014-09-03 12:57:55 -04009124 "rc = 0x%x\n", (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08009125 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009126 }
James Smart73d91e52011-10-10 21:32:10 -04009127
James Smartda0436e2009-05-22 14:51:39 -04009128 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9129 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
9130 "parent cq-id=%d\n",
9131 phba->sli4_hba.hdr_rq->queue_id,
9132 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04009133 phba->sli4_hba.els_cq->queue_id);
James Smart1ba981f2014-02-20 09:56:45 -05009134
9135 if (phba->cfg_fof) {
9136 rc = lpfc_fof_queue_setup(phba);
9137 if (rc) {
9138 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9139 "0549 Failed setup of FOF Queues: "
9140 "rc = 0x%x\n", rc);
James Smart895427b2017-02-12 13:52:30 -08009141 goto out_destroy;
James Smart1ba981f2014-02-20 09:56:45 -05009142 }
9143 }
James Smart2c9c5a02015-04-07 15:07:15 -04009144
James Smart43140ca2017-03-04 09:30:34 -08009145 for (qidx = 0; qidx < io_channel; qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
James Smart0cf07f842017-06-01 21:07:10 -07009146 lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT,
9147 phba->cfg_fcp_imax);
James Smart43140ca2017-03-04 09:30:34 -08009148
James Smartda0436e2009-05-22 14:51:39 -04009149 return 0;
9150
James Smart895427b2017-02-12 13:52:30 -08009151out_destroy:
9152 lpfc_sli4_queue_unset(phba);
James Smartda0436e2009-05-22 14:51:39 -04009153out_error:
9154 return rc;
9155}
9156
9157/**
9158 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
9159 * @phba: pointer to lpfc hba data structure.
9160 *
9161 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
9162 * operation.
9163 *
9164 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009165 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009166 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009167 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009168 **/
9169void
9170lpfc_sli4_queue_unset(struct lpfc_hba *phba)
9171{
James Smart895427b2017-02-12 13:52:30 -08009172 int qidx;
James Smartda0436e2009-05-22 14:51:39 -04009173
James Smart1ba981f2014-02-20 09:56:45 -05009174 /* Unset the queues created for Flash Optimized Fabric operations */
9175 if (phba->cfg_fof)
9176 lpfc_fof_queue_destroy(phba);
James Smart895427b2017-02-12 13:52:30 -08009177
James Smartda0436e2009-05-22 14:51:39 -04009178 /* Unset mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08009179 if (phba->sli4_hba.mbx_wq)
9180 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
9181
9182 /* Unset NVME LS work queue */
9183 if (phba->sli4_hba.nvmels_wq)
9184 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
9185
James Smartda0436e2009-05-22 14:51:39 -04009186 /* Unset ELS work queue */
Colin Ian King019c0d62017-05-06 23:13:55 +01009187 if (phba->sli4_hba.els_wq)
James Smart895427b2017-02-12 13:52:30 -08009188 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
9189
James Smartda0436e2009-05-22 14:51:39 -04009190 /* Unset unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08009191 if (phba->sli4_hba.hdr_rq)
9192 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
9193 phba->sli4_hba.dat_rq);
9194
James Smartda0436e2009-05-22 14:51:39 -04009195 /* Unset FCP work queue */
James Smart895427b2017-02-12 13:52:30 -08009196 if (phba->sli4_hba.fcp_wq)
9197 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
9198 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[qidx]);
9199
9200 /* Unset NVME work queue */
9201 if (phba->sli4_hba.nvme_wq) {
9202 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
9203 lpfc_wq_destroy(phba, phba->sli4_hba.nvme_wq[qidx]);
James Smart67d12732012-08-03 12:36:13 -04009204 }
James Smart895427b2017-02-12 13:52:30 -08009205
James Smartda0436e2009-05-22 14:51:39 -04009206 /* Unset mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08009207 if (phba->sli4_hba.mbx_cq)
9208 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
9209
James Smartda0436e2009-05-22 14:51:39 -04009210 /* Unset ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08009211 if (phba->sli4_hba.els_cq)
9212 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
9213
9214 /* Unset NVME LS complete queue */
9215 if (phba->sli4_hba.nvmels_cq)
9216 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
9217
9218 /* Unset NVME response complete queue */
9219 if (phba->sli4_hba.nvme_cq)
9220 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
9221 lpfc_cq_destroy(phba, phba->sli4_hba.nvme_cq[qidx]);
9222
James Smartbcb24f62017-11-20 16:00:36 -08009223 if (phba->nvmet_support) {
9224 /* Unset NVMET MRQ queue */
9225 if (phba->sli4_hba.nvmet_mrq_hdr) {
9226 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9227 lpfc_rq_destroy(
9228 phba,
James Smart2d7dbc42017-02-12 13:52:35 -08009229 phba->sli4_hba.nvmet_mrq_hdr[qidx],
9230 phba->sli4_hba.nvmet_mrq_data[qidx]);
James Smartbcb24f62017-11-20 16:00:36 -08009231 }
James Smart2d7dbc42017-02-12 13:52:35 -08009232
James Smartbcb24f62017-11-20 16:00:36 -08009233 /* Unset NVMET CQ Set complete queue */
9234 if (phba->sli4_hba.nvmet_cqset) {
9235 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9236 lpfc_cq_destroy(
9237 phba, phba->sli4_hba.nvmet_cqset[qidx]);
9238 }
James Smart2d7dbc42017-02-12 13:52:35 -08009239 }
9240
James Smartda0436e2009-05-22 14:51:39 -04009241 /* Unset FCP response complete queue */
James Smart895427b2017-02-12 13:52:30 -08009242 if (phba->sli4_hba.fcp_cq)
9243 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
9244 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[qidx]);
9245
James Smartda0436e2009-05-22 14:51:39 -04009246 /* Unset fast-path event queue */
James Smart895427b2017-02-12 13:52:30 -08009247 if (phba->sli4_hba.hba_eq)
9248 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++)
9249 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[qidx]);
James Smartda0436e2009-05-22 14:51:39 -04009250}
9251
9252/**
9253 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
9254 * @phba: pointer to lpfc hba data structure.
9255 *
9256 * This routine is invoked to allocate and set up a pool of completion queue
9257 * events. The body of the completion queue event is a completion queue entry
9258 * CQE. For now, this pool is used for the interrupt service routine to queue
9259 * the following HBA completion queue events for the worker thread to process:
9260 * - Mailbox asynchronous events
9261 * - Receive queue completion unsolicited events
9262 * Later, this can be used for all the slow-path events.
9263 *
9264 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009265 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009266 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04009267 **/
9268static int
9269lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
9270{
9271 struct lpfc_cq_event *cq_event;
9272 int i;
9273
9274 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
9275 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
9276 if (!cq_event)
9277 goto out_pool_create_fail;
9278 list_add_tail(&cq_event->list,
9279 &phba->sli4_hba.sp_cqe_event_pool);
9280 }
9281 return 0;
9282
9283out_pool_create_fail:
9284 lpfc_sli4_cq_event_pool_destroy(phba);
9285 return -ENOMEM;
9286}
9287
9288/**
9289 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
9290 * @phba: pointer to lpfc hba data structure.
9291 *
9292 * This routine is invoked to free the pool of completion queue events at
9293 * driver unload time. Note that, it is the responsibility of the driver
9294 * cleanup routine to free all the outstanding completion-queue events
9295 * allocated from this pool back into the pool before invoking this routine
9296 * to destroy the pool.
9297 **/
9298static void
9299lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
9300{
9301 struct lpfc_cq_event *cq_event, *next_cq_event;
9302
9303 list_for_each_entry_safe(cq_event, next_cq_event,
9304 &phba->sli4_hba.sp_cqe_event_pool, list) {
9305 list_del(&cq_event->list);
9306 kfree(cq_event);
9307 }
9308}
9309
9310/**
9311 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9312 * @phba: pointer to lpfc hba data structure.
9313 *
9314 * This routine is the lock free version of the API invoked to allocate a
9315 * completion-queue event from the free pool.
9316 *
9317 * Return: Pointer to the newly allocated completion-queue event if successful
9318 * NULL otherwise.
9319 **/
9320struct lpfc_cq_event *
9321__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9322{
9323 struct lpfc_cq_event *cq_event = NULL;
9324
9325 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
9326 struct lpfc_cq_event, list);
9327 return cq_event;
9328}
9329
9330/**
9331 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9332 * @phba: pointer to lpfc hba data structure.
9333 *
9334 * This routine is the lock version of the API invoked to allocate a
9335 * completion-queue event from the free pool.
9336 *
9337 * Return: Pointer to the newly allocated completion-queue event if successful
9338 * NULL otherwise.
9339 **/
9340struct lpfc_cq_event *
9341lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9342{
9343 struct lpfc_cq_event *cq_event;
9344 unsigned long iflags;
9345
9346 spin_lock_irqsave(&phba->hbalock, iflags);
9347 cq_event = __lpfc_sli4_cq_event_alloc(phba);
9348 spin_unlock_irqrestore(&phba->hbalock, iflags);
9349 return cq_event;
9350}
9351
9352/**
9353 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9354 * @phba: pointer to lpfc hba data structure.
9355 * @cq_event: pointer to the completion queue event to be freed.
9356 *
9357 * This routine is the lock free version of the API invoked to release a
9358 * completion-queue event back into the free pool.
9359 **/
9360void
9361__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9362 struct lpfc_cq_event *cq_event)
9363{
9364 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
9365}
9366
9367/**
9368 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9369 * @phba: pointer to lpfc hba data structure.
9370 * @cq_event: pointer to the completion queue event to be freed.
9371 *
9372 * This routine is the lock version of the API invoked to release a
9373 * completion-queue event back into the free pool.
9374 **/
9375void
9376lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9377 struct lpfc_cq_event *cq_event)
9378{
9379 unsigned long iflags;
9380 spin_lock_irqsave(&phba->hbalock, iflags);
9381 __lpfc_sli4_cq_event_release(phba, cq_event);
9382 spin_unlock_irqrestore(&phba->hbalock, iflags);
9383}
9384
9385/**
9386 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
9387 * @phba: pointer to lpfc hba data structure.
9388 *
9389 * This routine is to free all the pending completion-queue events to the
9390 * back into the free pool for device reset.
9391 **/
9392static void
9393lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
9394{
9395 LIST_HEAD(cqelist);
9396 struct lpfc_cq_event *cqe;
9397 unsigned long iflags;
9398
9399 /* Retrieve all the pending WCQEs from pending WCQE lists */
9400 spin_lock_irqsave(&phba->hbalock, iflags);
9401 /* Pending FCP XRI abort events */
9402 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
9403 &cqelist);
9404 /* Pending ELS XRI abort events */
9405 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
9406 &cqelist);
9407 /* Pending asynnc events */
9408 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
9409 &cqelist);
9410 spin_unlock_irqrestore(&phba->hbalock, iflags);
9411
9412 while (!list_empty(&cqelist)) {
9413 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
9414 lpfc_sli4_cq_event_release(phba, cqe);
9415 }
9416}
9417
9418/**
9419 * lpfc_pci_function_reset - Reset pci function.
9420 * @phba: pointer to lpfc hba data structure.
9421 *
9422 * This routine is invoked to request a PCI function reset. It will destroys
9423 * all resources assigned to the PCI function which originates this request.
9424 *
9425 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009426 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009427 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009428 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009429 **/
9430int
9431lpfc_pci_function_reset(struct lpfc_hba *phba)
9432{
9433 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05009434 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04009435 uint32_t shdr_status, shdr_add_status;
James Smart2f6fa2c2014-09-03 12:57:08 -04009436 uint32_t rdy_chk;
9437 uint32_t port_reset = 0;
James Smartda0436e2009-05-22 14:51:39 -04009438 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05009439 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -05009440 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -04009441
James Smart2fcee4b2010-12-15 17:57:46 -05009442 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9443 switch (if_type) {
9444 case LPFC_SLI_INTF_IF_TYPE_0:
9445 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
9446 GFP_KERNEL);
9447 if (!mboxq) {
9448 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9449 "0494 Unable to allocate memory for "
9450 "issuing SLI_FUNCTION_RESET mailbox "
9451 "command\n");
9452 return -ENOMEM;
9453 }
9454
9455 /* Setup PCI function reset mailbox-ioctl command */
9456 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9457 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
9458 LPFC_SLI4_MBX_EMBED);
9459 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9460 shdr = (union lpfc_sli4_cfg_shdr *)
9461 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
9462 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9463 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
9464 &shdr->response);
9465 if (rc != MBX_TIMEOUT)
9466 mempool_free(mboxq, phba->mbox_mem_pool);
9467 if (shdr_status || shdr_add_status || rc) {
9468 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9469 "0495 SLI_FUNCTION_RESET mailbox "
9470 "failed with status x%x add_status x%x,"
9471 " mbx status x%x\n",
9472 shdr_status, shdr_add_status, rc);
9473 rc = -ENXIO;
9474 }
9475 break;
9476 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08009477 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2f6fa2c2014-09-03 12:57:08 -04009478wait:
9479 /*
9480 * Poll the Port Status Register and wait for RDY for
9481 * up to 30 seconds. If the port doesn't respond, treat
9482 * it as an error.
9483 */
James Smart77d093f2015-04-07 15:07:08 -04009484 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
James Smart2f6fa2c2014-09-03 12:57:08 -04009485 if (lpfc_readl(phba->sli4_hba.u.if_type2.
9486 STATUSregaddr, &reg_data.word0)) {
9487 rc = -ENODEV;
9488 goto out;
9489 }
9490 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
9491 break;
9492 msleep(20);
9493 }
9494
9495 if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
9496 phba->work_status[0] = readl(
9497 phba->sli4_hba.u.if_type2.ERR1regaddr);
9498 phba->work_status[1] = readl(
9499 phba->sli4_hba.u.if_type2.ERR2regaddr);
9500 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9501 "2890 Port not ready, port status reg "
9502 "0x%x error 1=0x%x, error 2=0x%x\n",
9503 reg_data.word0,
9504 phba->work_status[0],
9505 phba->work_status[1]);
9506 rc = -ENODEV;
9507 goto out;
9508 }
9509
9510 if (!port_reset) {
9511 /*
9512 * Reset the port now
9513 */
James Smart2fcee4b2010-12-15 17:57:46 -05009514 reg_data.word0 = 0;
9515 bf_set(lpfc_sliport_ctrl_end, &reg_data,
9516 LPFC_SLIPORT_LITTLE_ENDIAN);
9517 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
9518 LPFC_SLIPORT_INIT_PORT);
9519 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
9520 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -05009521 /* flush */
James Smart2b81f942012-03-01 22:37:18 -05009522 pci_read_config_word(phba->pcidev,
9523 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -05009524
James Smart2f6fa2c2014-09-03 12:57:08 -04009525 port_reset = 1;
9526 msleep(20);
9527 goto wait;
9528 } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
9529 rc = -ENODEV;
9530 goto out;
James Smart2fcee4b2010-12-15 17:57:46 -05009531 }
9532 break;
James Smart2f6fa2c2014-09-03 12:57:08 -04009533
James Smart2fcee4b2010-12-15 17:57:46 -05009534 case LPFC_SLI_INTF_IF_TYPE_1:
9535 default:
9536 break;
James Smartda0436e2009-05-22 14:51:39 -04009537 }
9538
James Smart73d91e52011-10-10 21:32:10 -04009539out:
James Smart2fcee4b2010-12-15 17:57:46 -05009540 /* Catch the not-ready port failure after a port reset. */
James Smart2f6fa2c2014-09-03 12:57:08 -04009541 if (rc) {
James Smart229adb02013-04-17 20:16:51 -04009542 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9543 "3317 HBA not functional: IP Reset Failed "
James Smart2f6fa2c2014-09-03 12:57:08 -04009544 "try: echo fw_reset > board_mode\n");
James Smart2fcee4b2010-12-15 17:57:46 -05009545 rc = -ENODEV;
James Smart229adb02013-04-17 20:16:51 -04009546 }
James Smart2fcee4b2010-12-15 17:57:46 -05009547
James Smartda0436e2009-05-22 14:51:39 -04009548 return rc;
9549}
9550
9551/**
James Smartda0436e2009-05-22 14:51:39 -04009552 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
9553 * @phba: pointer to lpfc hba data structure.
9554 *
9555 * This routine is invoked to set up the PCI device memory space for device
9556 * with SLI-4 interface spec.
9557 *
9558 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009559 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009560 * other values - error
9561 **/
9562static int
9563lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
9564{
9565 struct pci_dev *pdev;
9566 unsigned long bar0map_len, bar1map_len, bar2map_len;
9567 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05009568 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04009569
9570 /* Obtain PCI device reference */
9571 if (!phba->pcidev)
9572 return error;
9573 else
9574 pdev = phba->pcidev;
9575
9576 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05009577 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
9578 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
9579 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
9580 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smartda0436e2009-05-22 14:51:39 -04009581 return error;
Michael Reed8e685972009-09-18 12:02:05 -05009582 }
9583 }
James Smartda0436e2009-05-22 14:51:39 -04009584
James Smart2fcee4b2010-12-15 17:57:46 -05009585 /*
9586 * The BARs and register set definitions and offset locations are
9587 * dependent on the if_type.
9588 */
9589 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
9590 &phba->sli4_hba.sli_intf.word0)) {
9591 return error;
9592 }
9593
9594 /* There is no SLI3 failback for SLI4 devices. */
9595 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
9596 LPFC_SLI_INTF_VALID) {
9597 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9598 "2894 SLI_INTF reg contents invalid "
9599 "sli_intf reg 0x%x\n",
9600 phba->sli4_hba.sli_intf.word0);
9601 return error;
9602 }
9603
9604 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9605 /*
9606 * Get the bus address of SLI4 device Bar regions and the
9607 * number of bytes required by each mapping. The mapping of the
9608 * particular PCI BARs regions is dependent on the type of
9609 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04009610 */
James Smartf5ca6f22013-09-06 12:21:09 -04009611 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
9612 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
9613 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
James Smart2fcee4b2010-12-15 17:57:46 -05009614
9615 /*
9616 * Map SLI4 PCI Config Space Register base to a kernel virtual
9617 * addr
9618 */
9619 phba->sli4_hba.conf_regs_memmap_p =
9620 ioremap(phba->pci_bar0_map, bar0map_len);
9621 if (!phba->sli4_hba.conf_regs_memmap_p) {
9622 dev_printk(KERN_ERR, &pdev->dev,
9623 "ioremap failed for SLI4 PCI config "
9624 "registers.\n");
9625 goto out;
9626 }
James Smartf5ca6f22013-09-06 12:21:09 -04009627 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05009628 /* Set up BAR0 PCI config space register memory map */
9629 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05009630 } else {
9631 phba->pci_bar0_map = pci_resource_start(pdev, 1);
9632 bar0map_len = pci_resource_len(pdev, 1);
James Smart27d6ac02018-02-22 08:18:42 -08009633 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
James Smart2fcee4b2010-12-15 17:57:46 -05009634 dev_printk(KERN_ERR, &pdev->dev,
9635 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
9636 goto out;
9637 }
9638 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04009639 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05009640 if (!phba->sli4_hba.conf_regs_memmap_p) {
9641 dev_printk(KERN_ERR, &pdev->dev,
9642 "ioremap failed for SLI4 PCI config "
9643 "registers.\n");
9644 goto out;
9645 }
9646 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04009647 }
9648
James Smarte4b97942017-11-20 16:00:31 -08009649 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
9650 if (pci_resource_start(pdev, PCI_64BIT_BAR2)) {
9651 /*
9652 * Map SLI4 if type 0 HBA Control Register base to a
9653 * kernel virtual address and setup the registers.
9654 */
9655 phba->pci_bar1_map = pci_resource_start(pdev,
9656 PCI_64BIT_BAR2);
9657 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
9658 phba->sli4_hba.ctrl_regs_memmap_p =
9659 ioremap(phba->pci_bar1_map,
9660 bar1map_len);
9661 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
9662 dev_err(&pdev->dev,
9663 "ioremap failed for SLI4 HBA "
9664 "control registers.\n");
9665 error = -ENOMEM;
9666 goto out_iounmap_conf;
9667 }
9668 phba->pci_bar2_memmap_p =
9669 phba->sli4_hba.ctrl_regs_memmap_p;
James Smart27d6ac02018-02-22 08:18:42 -08009670 lpfc_sli4_bar1_register_memmap(phba, if_type);
James Smarte4b97942017-11-20 16:00:31 -08009671 } else {
9672 error = -ENOMEM;
James Smart2fcee4b2010-12-15 17:57:46 -05009673 goto out_iounmap_conf;
9674 }
James Smartda0436e2009-05-22 14:51:39 -04009675 }
9676
James Smart27d6ac02018-02-22 08:18:42 -08009677 if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) &&
9678 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
9679 /*
9680 * Map SLI4 if type 6 HBA Doorbell Register base to a kernel
9681 * virtual address and setup the registers.
9682 */
9683 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
9684 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
9685 phba->sli4_hba.drbl_regs_memmap_p =
9686 ioremap(phba->pci_bar1_map, bar1map_len);
9687 if (!phba->sli4_hba.drbl_regs_memmap_p) {
9688 dev_err(&pdev->dev,
9689 "ioremap failed for SLI4 HBA doorbell registers.\n");
9690 goto out_iounmap_conf;
9691 }
9692 phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
9693 lpfc_sli4_bar1_register_memmap(phba, if_type);
9694 }
9695
James Smarte4b97942017-11-20 16:00:31 -08009696 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
9697 if (pci_resource_start(pdev, PCI_64BIT_BAR4)) {
9698 /*
9699 * Map SLI4 if type 0 HBA Doorbell Register base to
9700 * a kernel virtual address and setup the registers.
9701 */
9702 phba->pci_bar2_map = pci_resource_start(pdev,
9703 PCI_64BIT_BAR4);
9704 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
9705 phba->sli4_hba.drbl_regs_memmap_p =
9706 ioremap(phba->pci_bar2_map,
9707 bar2map_len);
9708 if (!phba->sli4_hba.drbl_regs_memmap_p) {
9709 dev_err(&pdev->dev,
9710 "ioremap failed for SLI4 HBA"
9711 " doorbell registers.\n");
9712 error = -ENOMEM;
9713 goto out_iounmap_ctrl;
9714 }
9715 phba->pci_bar4_memmap_p =
9716 phba->sli4_hba.drbl_regs_memmap_p;
9717 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
9718 if (error)
9719 goto out_iounmap_all;
9720 } else {
9721 error = -ENOMEM;
James Smart2fcee4b2010-12-15 17:57:46 -05009722 goto out_iounmap_all;
James Smarte4b97942017-11-20 16:00:31 -08009723 }
James Smartda0436e2009-05-22 14:51:39 -04009724 }
9725
James Smart1351e692018-02-22 08:18:43 -08009726 if (if_type == LPFC_SLI_INTF_IF_TYPE_6 &&
9727 pci_resource_start(pdev, PCI_64BIT_BAR4)) {
9728 /*
9729 * Map SLI4 if type 6 HBA DPP Register base to a kernel
9730 * virtual address and setup the registers.
9731 */
9732 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
9733 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
9734 phba->sli4_hba.dpp_regs_memmap_p =
9735 ioremap(phba->pci_bar2_map, bar2map_len);
9736 if (!phba->sli4_hba.dpp_regs_memmap_p) {
9737 dev_err(&pdev->dev,
9738 "ioremap failed for SLI4 HBA dpp registers.\n");
9739 goto out_iounmap_ctrl;
9740 }
9741 phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
9742 }
9743
James Smartb71413d2018-02-22 08:18:40 -08009744 /* Set up the EQ/CQ register handeling functions now */
James Smart27d6ac02018-02-22 08:18:42 -08009745 switch (if_type) {
9746 case LPFC_SLI_INTF_IF_TYPE_0:
9747 case LPFC_SLI_INTF_IF_TYPE_2:
James Smartb71413d2018-02-22 08:18:40 -08009748 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr;
9749 phba->sli4_hba.sli4_eq_release = lpfc_sli4_eq_release;
9750 phba->sli4_hba.sli4_cq_release = lpfc_sli4_cq_release;
James Smart27d6ac02018-02-22 08:18:42 -08009751 break;
9752 case LPFC_SLI_INTF_IF_TYPE_6:
9753 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_if6_eq_clr_intr;
9754 phba->sli4_hba.sli4_eq_release = lpfc_sli4_if6_eq_release;
9755 phba->sli4_hba.sli4_cq_release = lpfc_sli4_if6_cq_release;
9756 break;
9757 default:
9758 break;
James Smartb71413d2018-02-22 08:18:40 -08009759 }
9760
James Smartda0436e2009-05-22 14:51:39 -04009761 return 0;
9762
9763out_iounmap_all:
9764 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9765out_iounmap_ctrl:
9766 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9767out_iounmap_conf:
9768 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9769out:
9770 return error;
9771}
9772
9773/**
9774 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
9775 * @phba: pointer to lpfc hba data structure.
9776 *
9777 * This routine is invoked to unset the PCI device memory space for device
9778 * with SLI-4 interface spec.
9779 **/
9780static void
9781lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
9782{
James Smart2e90f4b2011-12-13 13:22:37 -05009783 uint32_t if_type;
9784 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -04009785
James Smart2e90f4b2011-12-13 13:22:37 -05009786 switch (if_type) {
9787 case LPFC_SLI_INTF_IF_TYPE_0:
9788 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9789 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9790 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9791 break;
9792 case LPFC_SLI_INTF_IF_TYPE_2:
9793 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9794 break;
James Smart27d6ac02018-02-22 08:18:42 -08009795 case LPFC_SLI_INTF_IF_TYPE_6:
9796 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9797 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9798 break;
James Smart2e90f4b2011-12-13 13:22:37 -05009799 case LPFC_SLI_INTF_IF_TYPE_1:
9800 default:
9801 dev_printk(KERN_ERR, &phba->pcidev->dev,
9802 "FATAL - unsupported SLI4 interface type - %d\n",
9803 if_type);
9804 break;
9805 }
James Smartda0436e2009-05-22 14:51:39 -04009806}
9807
9808/**
James Smart3772a992009-05-22 14:50:54 -04009809 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
9810 * @phba: pointer to lpfc hba data structure.
9811 *
9812 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009813 * with SLI-3 interface specs.
James Smart3772a992009-05-22 14:50:54 -04009814 *
9815 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009816 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009817 * other values - error
9818 **/
9819static int
9820lpfc_sli_enable_msix(struct lpfc_hba *phba)
9821{
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009822 int rc;
James Smart3772a992009-05-22 14:50:54 -04009823 LPFC_MBOXQ_t *pmb;
9824
9825 /* Set up MSI-X multi-message vectors */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009826 rc = pci_alloc_irq_vectors(phba->pcidev,
9827 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
9828 if (rc < 0) {
James Smart3772a992009-05-22 14:50:54 -04009829 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9830 "0420 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009831 goto vec_fail_out;
James Smart3772a992009-05-22 14:50:54 -04009832 }
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009833
James Smart3772a992009-05-22 14:50:54 -04009834 /*
9835 * Assign MSI-X vectors to interrupt handlers
9836 */
9837
9838 /* vector-0 is associated to slow-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009839 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
James Smarted243d32015-05-21 13:55:25 -04009840 &lpfc_sli_sp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04009841 LPFC_SP_DRIVER_HANDLER_NAME, phba);
9842 if (rc) {
9843 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9844 "0421 MSI-X slow-path request_irq failed "
9845 "(%d)\n", rc);
9846 goto msi_fail_out;
9847 }
9848
9849 /* vector-1 is associated to fast-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009850 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
James Smarted243d32015-05-21 13:55:25 -04009851 &lpfc_sli_fp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04009852 LPFC_FP_DRIVER_HANDLER_NAME, phba);
9853
9854 if (rc) {
9855 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9856 "0429 MSI-X fast-path request_irq failed "
9857 "(%d)\n", rc);
9858 goto irq_fail_out;
9859 }
9860
9861 /*
9862 * Configure HBA MSI-X attention conditions to messages
9863 */
9864 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9865
9866 if (!pmb) {
9867 rc = -ENOMEM;
9868 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9869 "0474 Unable to allocate memory for issuing "
9870 "MBOX_CONFIG_MSI command\n");
9871 goto mem_fail_out;
9872 }
9873 rc = lpfc_config_msi(phba, pmb);
9874 if (rc)
9875 goto mbx_fail_out;
9876 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
9877 if (rc != MBX_SUCCESS) {
9878 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
9879 "0351 Config MSI mailbox command failed, "
9880 "mbxCmd x%x, mbxStatus x%x\n",
9881 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
9882 goto mbx_fail_out;
9883 }
9884
9885 /* Free memory allocated for mailbox command */
9886 mempool_free(pmb, phba->mbox_mem_pool);
9887 return rc;
9888
9889mbx_fail_out:
9890 /* Free memory allocated for mailbox command */
9891 mempool_free(pmb, phba->mbox_mem_pool);
9892
9893mem_fail_out:
9894 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009895 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
James Smart3772a992009-05-22 14:50:54 -04009896
9897irq_fail_out:
9898 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009899 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
James Smart3772a992009-05-22 14:50:54 -04009900
9901msi_fail_out:
9902 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009903 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009904
9905vec_fail_out:
James Smart3772a992009-05-22 14:50:54 -04009906 return rc;
9907}
9908
9909/**
James Smart3772a992009-05-22 14:50:54 -04009910 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
9911 * @phba: pointer to lpfc hba data structure.
9912 *
9913 * This routine is invoked to enable the MSI interrupt mode to device with
9914 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
9915 * enable the MSI vector. The device driver is responsible for calling the
9916 * request_irq() to register MSI vector with a interrupt the handler, which
9917 * is done in this function.
9918 *
9919 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009920 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009921 * other values - error
9922 */
9923static int
9924lpfc_sli_enable_msi(struct lpfc_hba *phba)
9925{
9926 int rc;
9927
9928 rc = pci_enable_msi(phba->pcidev);
9929 if (!rc)
9930 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9931 "0462 PCI enable MSI mode success.\n");
9932 else {
9933 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9934 "0471 PCI enable MSI mode failed (%d)\n", rc);
9935 return rc;
9936 }
9937
9938 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04009939 0, LPFC_DRIVER_NAME, phba);
James Smart3772a992009-05-22 14:50:54 -04009940 if (rc) {
9941 pci_disable_msi(phba->pcidev);
9942 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9943 "0478 MSI request_irq failed (%d)\n", rc);
9944 }
9945 return rc;
9946}
9947
9948/**
James Smart3772a992009-05-22 14:50:54 -04009949 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
9950 * @phba: pointer to lpfc hba data structure.
9951 *
9952 * This routine is invoked to enable device interrupt and associate driver's
9953 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
9954 * spec. Depends on the interrupt mode configured to the driver, the driver
9955 * will try to fallback from the configured interrupt mode to an interrupt
9956 * mode which is supported by the platform, kernel, and device in the order
9957 * of:
9958 * MSI-X -> MSI -> IRQ.
9959 *
9960 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009961 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009962 * other values - error
9963 **/
9964static uint32_t
9965lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9966{
9967 uint32_t intr_mode = LPFC_INTR_ERROR;
9968 int retval;
9969
9970 if (cfg_mode == 2) {
9971 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
9972 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
9973 if (!retval) {
9974 /* Now, try to enable MSI-X interrupt mode */
9975 retval = lpfc_sli_enable_msix(phba);
9976 if (!retval) {
9977 /* Indicate initialization to MSI-X mode */
9978 phba->intr_type = MSIX;
9979 intr_mode = 2;
9980 }
9981 }
9982 }
9983
9984 /* Fallback to MSI if MSI-X initialization failed */
9985 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9986 retval = lpfc_sli_enable_msi(phba);
9987 if (!retval) {
9988 /* Indicate initialization to MSI mode */
9989 phba->intr_type = MSI;
9990 intr_mode = 1;
9991 }
9992 }
9993
9994 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9995 if (phba->intr_type == NONE) {
9996 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
9997 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9998 if (!retval) {
9999 /* Indicate initialization to INTx mode */
10000 phba->intr_type = INTx;
10001 intr_mode = 0;
10002 }
10003 }
10004 return intr_mode;
10005}
10006
10007/**
10008 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
10009 * @phba: pointer to lpfc hba data structure.
10010 *
10011 * This routine is invoked to disable device interrupt and disassociate the
10012 * driver's interrupt handler(s) from interrupt vector(s) to device with
10013 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
10014 * release the interrupt vector(s) for the message signaled interrupt.
10015 **/
10016static void
10017lpfc_sli_disable_intr(struct lpfc_hba *phba)
10018{
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010019 int nr_irqs, i;
10020
James Smart3772a992009-05-22 14:50:54 -040010021 if (phba->intr_type == MSIX)
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010022 nr_irqs = LPFC_MSIX_VECTORS;
10023 else
10024 nr_irqs = 1;
10025
10026 for (i = 0; i < nr_irqs; i++)
10027 free_irq(pci_irq_vector(phba->pcidev, i), phba);
10028 pci_free_irq_vectors(phba->pcidev);
James Smart3772a992009-05-22 14:50:54 -040010029
10030 /* Reset interrupt management states */
10031 phba->intr_type = NONE;
10032 phba->sli.slistat.sli_intr = 0;
James Smart3772a992009-05-22 14:50:54 -040010033}
10034
10035/**
James Smart895427b2017-02-12 13:52:30 -080010036 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
James Smart7bb03bb2013-04-17 20:19:16 -040010037 * @phba: pointer to lpfc hba data structure.
James Smart895427b2017-02-12 13:52:30 -080010038 * @vectors: number of msix vectors allocated.
James Smart7bb03bb2013-04-17 20:19:16 -040010039 *
James Smart895427b2017-02-12 13:52:30 -080010040 * The routine will figure out the CPU affinity assignment for every
10041 * MSI-X vector allocated for the HBA. The hba_eq_hdl will be updated
10042 * with a pointer to the CPU mask that defines ALL the CPUs this vector
10043 * can be associated with. If the vector can be unquely associated with
10044 * a single CPU, that CPU will be recorded in hba_eq_hdl[index].cpu.
10045 * In addition, the CPU to IO channel mapping will be calculated
10046 * and the phba->sli4_hba.cpu_map array will reflect this.
James Smart7bb03bb2013-04-17 20:19:16 -040010047 */
James Smart895427b2017-02-12 13:52:30 -080010048static void
10049lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
James Smart7bb03bb2013-04-17 20:19:16 -040010050{
10051 struct lpfc_vector_map_info *cpup;
James Smart895427b2017-02-12 13:52:30 -080010052 int index = 0;
10053 int vec = 0;
James Smart7bb03bb2013-04-17 20:19:16 -040010054 int cpu;
James Smart7bb03bb2013-04-17 20:19:16 -040010055#ifdef CONFIG_X86
10056 struct cpuinfo_x86 *cpuinfo;
10057#endif
James Smart7bb03bb2013-04-17 20:19:16 -040010058
10059 /* Init cpu_map array */
10060 memset(phba->sli4_hba.cpu_map, 0xff,
10061 (sizeof(struct lpfc_vector_map_info) *
James Smart895427b2017-02-12 13:52:30 -080010062 phba->sli4_hba.num_present_cpu));
James Smart7bb03bb2013-04-17 20:19:16 -040010063
10064 /* Update CPU map with physical id and core id of each CPU */
10065 cpup = phba->sli4_hba.cpu_map;
10066 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
10067#ifdef CONFIG_X86
10068 cpuinfo = &cpu_data(cpu);
10069 cpup->phys_id = cpuinfo->phys_proc_id;
10070 cpup->core_id = cpuinfo->cpu_core_id;
10071#else
10072 /* No distinction between CPUs for other platforms */
10073 cpup->phys_id = 0;
10074 cpup->core_id = 0;
10075#endif
James Smart895427b2017-02-12 13:52:30 -080010076 cpup->channel_id = index; /* For now round robin */
10077 cpup->irq = pci_irq_vector(phba->pcidev, vec);
10078 vec++;
10079 if (vec >= vectors)
10080 vec = 0;
10081 index++;
10082 if (index >= phba->cfg_fcp_io_channel)
10083 index = 0;
James Smart7bb03bb2013-04-17 20:19:16 -040010084 cpup++;
10085 }
James Smart7bb03bb2013-04-17 20:19:16 -040010086}
10087
10088
10089/**
James Smartda0436e2009-05-22 14:51:39 -040010090 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
10091 * @phba: pointer to lpfc hba data structure.
10092 *
10093 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010094 * with SLI-4 interface spec.
James Smartda0436e2009-05-22 14:51:39 -040010095 *
10096 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010097 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040010098 * other values - error
10099 **/
10100static int
10101lpfc_sli4_enable_msix(struct lpfc_hba *phba)
10102{
James Smart75baf692010-06-08 18:31:21 -040010103 int vectors, rc, index;
James Smartb83d0052017-06-01 21:07:05 -070010104 char *name;
James Smartda0436e2009-05-22 14:51:39 -040010105
10106 /* Set up MSI-X multi-message vectors */
James Smart895427b2017-02-12 13:52:30 -080010107 vectors = phba->io_channel_irqs;
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010108 if (phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -050010109 vectors++;
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010110
James Smartf358dd02017-02-12 13:52:34 -080010111 rc = pci_alloc_irq_vectors(phba->pcidev,
10112 (phba->nvmet_support) ? 1 : 2,
10113 vectors, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY);
Alexander Gordeev4f871e12014-09-03 12:56:29 -040010114 if (rc < 0) {
James Smartda0436e2009-05-22 14:51:39 -040010115 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10116 "0484 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +020010117 goto vec_fail_out;
James Smartda0436e2009-05-22 14:51:39 -040010118 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -040010119 vectors = rc;
James Smart75baf692010-06-08 18:31:21 -040010120
James Smart7bb03bb2013-04-17 20:19:16 -040010121 /* Assign MSI-X vectors to interrupt handlers */
James Smart67d12732012-08-03 12:36:13 -040010122 for (index = 0; index < vectors; index++) {
James Smartb83d0052017-06-01 21:07:05 -070010123 name = phba->sli4_hba.hba_eq_hdl[index].handler_name;
10124 memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ);
10125 snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ,
James Smart4305f182012-08-03 12:36:33 -040010126 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -040010127
James Smart895427b2017-02-12 13:52:30 -080010128 phba->sli4_hba.hba_eq_hdl[index].idx = index;
10129 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
10130 atomic_set(&phba->sli4_hba.hba_eq_hdl[index].hba_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -050010131 if (phba->cfg_fof && (index == (vectors - 1)))
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010132 rc = request_irq(pci_irq_vector(phba->pcidev, index),
James Smarted243d32015-05-21 13:55:25 -040010133 &lpfc_sli4_fof_intr_handler, 0,
James Smartb83d0052017-06-01 21:07:05 -070010134 name,
James Smart895427b2017-02-12 13:52:30 -080010135 &phba->sli4_hba.hba_eq_hdl[index]);
James Smart1ba981f2014-02-20 09:56:45 -050010136 else
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010137 rc = request_irq(pci_irq_vector(phba->pcidev, index),
James Smarted243d32015-05-21 13:55:25 -040010138 &lpfc_sli4_hba_intr_handler, 0,
James Smartb83d0052017-06-01 21:07:05 -070010139 name,
James Smart895427b2017-02-12 13:52:30 -080010140 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -040010141 if (rc) {
10142 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10143 "0486 MSI-X fast-path (%d) "
10144 "request_irq failed (%d)\n", index, rc);
10145 goto cfg_fail_out;
10146 }
10147 }
10148
James Smart1ba981f2014-02-20 09:56:45 -050010149 if (phba->cfg_fof)
10150 vectors--;
10151
James Smart895427b2017-02-12 13:52:30 -080010152 if (vectors != phba->io_channel_irqs) {
James Smart82c3e9b2012-09-29 11:29:50 -040010153 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10154 "3238 Reducing IO channels to match number of "
10155 "MSI-X vectors, requested %d got %d\n",
James Smart895427b2017-02-12 13:52:30 -080010156 phba->io_channel_irqs, vectors);
10157 if (phba->cfg_fcp_io_channel > vectors)
10158 phba->cfg_fcp_io_channel = vectors;
10159 if (phba->cfg_nvme_io_channel > vectors)
10160 phba->cfg_nvme_io_channel = vectors;
10161 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
10162 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
10163 else
10164 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
James Smart82c3e9b2012-09-29 11:29:50 -040010165 }
James Smart895427b2017-02-12 13:52:30 -080010166 lpfc_cpu_affinity_check(phba, vectors);
James Smart7bb03bb2013-04-17 20:19:16 -040010167
James Smartda0436e2009-05-22 14:51:39 -040010168 return rc;
10169
10170cfg_fail_out:
10171 /* free the irq already requested */
James Smart895427b2017-02-12 13:52:30 -080010172 for (--index; index >= 0; index--)
10173 free_irq(pci_irq_vector(phba->pcidev, index),
10174 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -040010175
James Smartda0436e2009-05-22 14:51:39 -040010176 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010177 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +020010178
10179vec_fail_out:
James Smartda0436e2009-05-22 14:51:39 -040010180 return rc;
10181}
10182
10183/**
James Smartda0436e2009-05-22 14:51:39 -040010184 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
10185 * @phba: pointer to lpfc hba data structure.
10186 *
10187 * This routine is invoked to enable the MSI interrupt mode to device with
10188 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
10189 * to enable the MSI vector. The device driver is responsible for calling
10190 * the request_irq() to register MSI vector with a interrupt the handler,
10191 * which is done in this function.
10192 *
10193 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010194 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040010195 * other values - error
10196 **/
10197static int
10198lpfc_sli4_enable_msi(struct lpfc_hba *phba)
10199{
10200 int rc, index;
10201
10202 rc = pci_enable_msi(phba->pcidev);
10203 if (!rc)
10204 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10205 "0487 PCI enable MSI mode success.\n");
10206 else {
10207 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10208 "0488 PCI enable MSI mode failed (%d)\n", rc);
10209 return rc;
10210 }
10211
10212 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
James Smarted243d32015-05-21 13:55:25 -040010213 0, LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -040010214 if (rc) {
10215 pci_disable_msi(phba->pcidev);
10216 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10217 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -040010218 return rc;
James Smartda0436e2009-05-22 14:51:39 -040010219 }
10220
James Smart895427b2017-02-12 13:52:30 -080010221 for (index = 0; index < phba->io_channel_irqs; index++) {
10222 phba->sli4_hba.hba_eq_hdl[index].idx = index;
10223 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smartda0436e2009-05-22 14:51:39 -040010224 }
10225
James Smart1ba981f2014-02-20 09:56:45 -050010226 if (phba->cfg_fof) {
James Smart895427b2017-02-12 13:52:30 -080010227 phba->sli4_hba.hba_eq_hdl[index].idx = index;
10228 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smart1ba981f2014-02-20 09:56:45 -050010229 }
James Smart75baf692010-06-08 18:31:21 -040010230 return 0;
James Smartda0436e2009-05-22 14:51:39 -040010231}
10232
10233/**
James Smartda0436e2009-05-22 14:51:39 -040010234 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
10235 * @phba: pointer to lpfc hba data structure.
10236 *
10237 * This routine is invoked to enable device interrupt and associate driver's
10238 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
10239 * interface spec. Depends on the interrupt mode configured to the driver,
10240 * the driver will try to fallback from the configured interrupt mode to an
10241 * interrupt mode which is supported by the platform, kernel, and device in
10242 * the order of:
10243 * MSI-X -> MSI -> IRQ.
10244 *
10245 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010246 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040010247 * other values - error
10248 **/
10249static uint32_t
10250lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
10251{
10252 uint32_t intr_mode = LPFC_INTR_ERROR;
James Smart895427b2017-02-12 13:52:30 -080010253 int retval, idx;
James Smartda0436e2009-05-22 14:51:39 -040010254
10255 if (cfg_mode == 2) {
10256 /* Preparation before conf_msi mbox cmd */
10257 retval = 0;
10258 if (!retval) {
10259 /* Now, try to enable MSI-X interrupt mode */
10260 retval = lpfc_sli4_enable_msix(phba);
10261 if (!retval) {
10262 /* Indicate initialization to MSI-X mode */
10263 phba->intr_type = MSIX;
10264 intr_mode = 2;
10265 }
10266 }
10267 }
10268
10269 /* Fallback to MSI if MSI-X initialization failed */
10270 if (cfg_mode >= 1 && phba->intr_type == NONE) {
10271 retval = lpfc_sli4_enable_msi(phba);
10272 if (!retval) {
10273 /* Indicate initialization to MSI mode */
10274 phba->intr_type = MSI;
10275 intr_mode = 1;
10276 }
10277 }
10278
10279 /* Fallback to INTx if both MSI-X/MSI initalization failed */
10280 if (phba->intr_type == NONE) {
10281 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
10282 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
10283 if (!retval) {
James Smart895427b2017-02-12 13:52:30 -080010284 struct lpfc_hba_eq_hdl *eqhdl;
10285
James Smartda0436e2009-05-22 14:51:39 -040010286 /* Indicate initialization to INTx mode */
10287 phba->intr_type = INTx;
10288 intr_mode = 0;
James Smart895427b2017-02-12 13:52:30 -080010289
10290 for (idx = 0; idx < phba->io_channel_irqs; idx++) {
10291 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
10292 eqhdl->idx = idx;
10293 eqhdl->phba = phba;
10294 atomic_set(&eqhdl->hba_eq_in_use, 1);
James Smartda0436e2009-05-22 14:51:39 -040010295 }
James Smart1ba981f2014-02-20 09:56:45 -050010296 if (phba->cfg_fof) {
James Smart895427b2017-02-12 13:52:30 -080010297 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
10298 eqhdl->idx = idx;
10299 eqhdl->phba = phba;
10300 atomic_set(&eqhdl->hba_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -050010301 }
James Smartda0436e2009-05-22 14:51:39 -040010302 }
10303 }
10304 return intr_mode;
10305}
10306
10307/**
10308 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
10309 * @phba: pointer to lpfc hba data structure.
10310 *
10311 * This routine is invoked to disable device interrupt and disassociate
10312 * the driver's interrupt handler(s) from interrupt vector(s) to device
10313 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
10314 * will release the interrupt vector(s) for the message signaled interrupt.
10315 **/
10316static void
10317lpfc_sli4_disable_intr(struct lpfc_hba *phba)
10318{
10319 /* Disable the currently initialized interrupt mode */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010320 if (phba->intr_type == MSIX) {
10321 int index;
10322
10323 /* Free up MSI-X multi-message vectors */
James Smart895427b2017-02-12 13:52:30 -080010324 for (index = 0; index < phba->io_channel_irqs; index++)
10325 free_irq(pci_irq_vector(phba->pcidev, index),
10326 &phba->sli4_hba.hba_eq_hdl[index]);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010327
10328 if (phba->cfg_fof)
James Smart895427b2017-02-12 13:52:30 -080010329 free_irq(pci_irq_vector(phba->pcidev, index),
10330 &phba->sli4_hba.hba_eq_hdl[index]);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010331 } else {
James Smartda0436e2009-05-22 14:51:39 -040010332 free_irq(phba->pcidev->irq, phba);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010333 }
10334
10335 pci_free_irq_vectors(phba->pcidev);
James Smartda0436e2009-05-22 14:51:39 -040010336
10337 /* Reset interrupt management states */
10338 phba->intr_type = NONE;
10339 phba->sli.slistat.sli_intr = 0;
James Smartda0436e2009-05-22 14:51:39 -040010340}
10341
10342/**
James Smart3772a992009-05-22 14:50:54 -040010343 * lpfc_unset_hba - Unset SLI3 hba device initialization
10344 * @phba: pointer to lpfc hba data structure.
10345 *
10346 * This routine is invoked to unset the HBA device initialization steps to
10347 * a device with SLI-3 interface spec.
10348 **/
10349static void
10350lpfc_unset_hba(struct lpfc_hba *phba)
10351{
10352 struct lpfc_vport *vport = phba->pport;
10353 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
10354
10355 spin_lock_irq(shost->host_lock);
10356 vport->load_flag |= FC_UNLOADING;
10357 spin_unlock_irq(shost->host_lock);
10358
James Smart72859902012-01-18 16:25:38 -050010359 kfree(phba->vpi_bmask);
10360 kfree(phba->vpi_ids);
10361
James Smart3772a992009-05-22 14:50:54 -040010362 lpfc_stop_hba_timers(phba);
10363
10364 phba->pport->work_port_events = 0;
10365
10366 lpfc_sli_hba_down(phba);
10367
10368 lpfc_sli_brdrestart(phba);
10369
10370 lpfc_sli_disable_intr(phba);
10371
10372 return;
10373}
10374
10375/**
James Smart5af5eee2010-10-22 11:06:38 -040010376 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
10377 * @phba: Pointer to HBA context object.
10378 *
10379 * This function is called in the SLI4 code path to wait for completion
10380 * of device's XRIs exchange busy. It will check the XRI exchange busy
10381 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
10382 * that, it will check the XRI exchange busy on outstanding FCP and ELS
10383 * I/Os every 30 seconds, log error message, and wait forever. Only when
10384 * all XRI exchange busy complete, the driver unload shall proceed with
10385 * invoking the function reset ioctl mailbox command to the CNA and the
10386 * the rest of the driver unload resource release.
10387 **/
10388static void
10389lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
10390{
10391 int wait_time = 0;
James Smart895427b2017-02-12 13:52:30 -080010392 int nvme_xri_cmpl = 1;
James Smart86c67372017-04-21 16:05:04 -070010393 int nvmet_xri_cmpl = 1;
James Smart895427b2017-02-12 13:52:30 -080010394 int fcp_xri_cmpl = 1;
James Smart5af5eee2010-10-22 11:06:38 -040010395 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
10396
James Smartc3725bd2017-11-20 16:00:42 -080010397 /* Driver just aborted IOs during the hba_unset process. Pause
10398 * here to give the HBA time to complete the IO and get entries
10399 * into the abts lists.
10400 */
10401 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5);
10402
10403 /* Wait for NVME pending IO to flush back to transport. */
10404 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
10405 lpfc_nvme_wait_for_io_drain(phba);
10406
James Smart895427b2017-02-12 13:52:30 -080010407 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
10408 fcp_xri_cmpl =
10409 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
James Smart86c67372017-04-21 16:05:04 -070010410 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -080010411 nvme_xri_cmpl =
10412 list_empty(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
James Smart86c67372017-04-21 16:05:04 -070010413 nvmet_xri_cmpl =
10414 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
10415 }
James Smart895427b2017-02-12 13:52:30 -080010416
James Smartf358dd02017-02-12 13:52:34 -080010417 while (!fcp_xri_cmpl || !els_xri_cmpl || !nvme_xri_cmpl ||
10418 !nvmet_xri_cmpl) {
James Smart5af5eee2010-10-22 11:06:38 -040010419 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
James Smart68c9b552018-06-26 08:24:25 -070010420 if (!nvmet_xri_cmpl)
10421 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10422 "6424 NVMET XRI exchange busy "
10423 "wait time: %d seconds.\n",
10424 wait_time/1000);
James Smart895427b2017-02-12 13:52:30 -080010425 if (!nvme_xri_cmpl)
10426 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10427 "6100 NVME XRI exchange busy "
10428 "wait time: %d seconds.\n",
10429 wait_time/1000);
James Smart5af5eee2010-10-22 11:06:38 -040010430 if (!fcp_xri_cmpl)
10431 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10432 "2877 FCP XRI exchange busy "
10433 "wait time: %d seconds.\n",
10434 wait_time/1000);
10435 if (!els_xri_cmpl)
10436 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10437 "2878 ELS XRI exchange busy "
10438 "wait time: %d seconds.\n",
10439 wait_time/1000);
10440 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
10441 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
10442 } else {
10443 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
10444 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
10445 }
James Smart86c67372017-04-21 16:05:04 -070010446 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -080010447 nvme_xri_cmpl = list_empty(
10448 &phba->sli4_hba.lpfc_abts_nvme_buf_list);
James Smart86c67372017-04-21 16:05:04 -070010449 nvmet_xri_cmpl = list_empty(
10450 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
10451 }
James Smart895427b2017-02-12 13:52:30 -080010452
10453 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
10454 fcp_xri_cmpl = list_empty(
10455 &phba->sli4_hba.lpfc_abts_scsi_buf_list);
10456
James Smart5af5eee2010-10-22 11:06:38 -040010457 els_xri_cmpl =
10458 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -080010459
James Smart5af5eee2010-10-22 11:06:38 -040010460 }
10461}
10462
10463/**
James Smartda0436e2009-05-22 14:51:39 -040010464 * lpfc_sli4_hba_unset - Unset the fcoe hba
10465 * @phba: Pointer to HBA context object.
10466 *
10467 * This function is called in the SLI4 code path to reset the HBA's FCoE
10468 * function. The caller is not required to hold any lock. This routine
10469 * issues PCI function reset mailbox command to reset the FCoE function.
10470 * At the end of the function, it calls lpfc_hba_down_post function to
10471 * free any pending commands.
10472 **/
10473static void
10474lpfc_sli4_hba_unset(struct lpfc_hba *phba)
10475{
10476 int wait_cnt = 0;
10477 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -040010478 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -040010479
10480 lpfc_stop_hba_timers(phba);
10481 phba->sli4_hba.intr_enable = 0;
10482
10483 /*
10484 * Gracefully wait out the potential current outstanding asynchronous
10485 * mailbox command.
10486 */
10487
10488 /* First, block any pending async mailbox command from posted */
10489 spin_lock_irq(&phba->hbalock);
10490 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
10491 spin_unlock_irq(&phba->hbalock);
10492 /* Now, trying to wait it out if we can */
10493 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
10494 msleep(10);
10495 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
10496 break;
10497 }
10498 /* Forcefully release the outstanding mailbox command if timed out */
10499 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
10500 spin_lock_irq(&phba->hbalock);
10501 mboxq = phba->sli.mbox_active;
10502 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
10503 __lpfc_mbox_cmpl_put(phba, mboxq);
10504 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
10505 phba->sli.mbox_active = NULL;
10506 spin_unlock_irq(&phba->hbalock);
10507 }
10508
James Smart5af5eee2010-10-22 11:06:38 -040010509 /* Abort all iocbs associated with the hba */
10510 lpfc_sli_hba_iocb_abort(phba);
10511
10512 /* Wait for completion of device XRI exchange busy */
10513 lpfc_sli4_xri_exchange_busy_wait(phba);
10514
James Smartda0436e2009-05-22 14:51:39 -040010515 /* Disable PCI subsystem interrupt */
10516 lpfc_sli4_disable_intr(phba);
10517
James Smart912e3ac2011-05-24 11:42:11 -040010518 /* Disable SR-IOV if enabled */
10519 if (phba->cfg_sriov_nr_virtfn)
10520 pci_disable_sriov(pdev);
10521
James Smartda0436e2009-05-22 14:51:39 -040010522 /* Stop kthread signal shall trigger work_done one more time */
10523 kthread_stop(phba->worker_thread);
10524
James Smartd2cc9bc2018-09-10 10:30:50 -070010525 /* Disable FW logging to host memory */
10526 writel(LPFC_CTL_PDEV_CTL_DDL_RAS,
10527 phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
10528
10529 /* Free RAS DMA memory */
10530 if (phba->ras_fwlog.ras_enabled == true)
10531 lpfc_sli4_ras_dma_free(phba);
10532
James Smartd1f525a2017-04-21 16:04:55 -070010533 /* Unset the queues shared with the hardware then release all
10534 * allocated resources.
10535 */
10536 lpfc_sli4_queue_unset(phba);
10537 lpfc_sli4_queue_destroy(phba);
10538
James Smart3677a3a2010-09-29 11:19:14 -040010539 /* Reset SLI4 HBA FCoE function */
10540 lpfc_pci_function_reset(phba);
10541
James Smartda0436e2009-05-22 14:51:39 -040010542 /* Stop the SLI4 device port */
10543 phba->pport->work_port_events = 0;
10544}
10545
James Smart28baac72010-02-12 14:42:03 -050010546 /**
10547 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
10548 * @phba: Pointer to HBA context object.
10549 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10550 *
10551 * This function is called in the SLI4 code path to read the port's
10552 * sli4 capabilities.
10553 *
10554 * This function may be be called from any context that can block-wait
10555 * for the completion. The expectation is that this routine is called
10556 * typically from probe_one or from the online routine.
10557 **/
10558int
10559lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10560{
10561 int rc;
10562 struct lpfc_mqe *mqe;
10563 struct lpfc_pc_sli4_params *sli4_params;
10564 uint32_t mbox_tmo;
10565
10566 rc = 0;
10567 mqe = &mboxq->u.mqe;
10568
10569 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -050010570 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -050010571 if (!phba->sli4_hba.intr_enable)
10572 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10573 else {
James Smarta183a152011-10-10 21:32:43 -040010574 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -050010575 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10576 }
10577
10578 if (unlikely(rc))
10579 return 1;
10580
10581 sli4_params = &phba->sli4_hba.pc_sli4_params;
10582 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
10583 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
10584 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
10585 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
10586 &mqe->un.sli4_params);
10587 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
10588 &mqe->un.sli4_params);
10589 sli4_params->proto_types = mqe->un.sli4_params.word3;
10590 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
10591 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
10592 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
10593 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
10594 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
10595 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
10596 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
10597 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
10598 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
10599 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
10600 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
10601 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
10602 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
10603 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
10604 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
10605 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
10606 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
10607 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
10608 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
10609 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -040010610
10611 /* Make sure that sge_supp_len can be handled by the driver */
10612 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10613 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10614
James Smart28baac72010-02-12 14:42:03 -050010615 return rc;
10616}
10617
James Smartda0436e2009-05-22 14:51:39 -040010618/**
James Smartfedd3b72011-02-16 12:39:24 -050010619 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
10620 * @phba: Pointer to HBA context object.
10621 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10622 *
10623 * This function is called in the SLI4 code path to read the port's
10624 * sli4 capabilities.
10625 *
10626 * This function may be be called from any context that can block-wait
10627 * for the completion. The expectation is that this routine is called
10628 * typically from probe_one or from the online routine.
10629 **/
10630int
10631lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10632{
10633 int rc;
10634 struct lpfc_mqe *mqe = &mboxq->u.mqe;
10635 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -040010636 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -050010637 int length;
James Smartbf316c72018-04-09 14:24:28 -070010638 bool exp_wqcq_pages = true;
James Smartfedd3b72011-02-16 12:39:24 -050010639 struct lpfc_sli4_parameters *mbx_sli4_parameters;
10640
James Smart6d368e52011-05-24 11:44:12 -040010641 /*
10642 * By default, the driver assumes the SLI4 port requires RPI
10643 * header postings. The SLI4_PARAM response will correct this
10644 * assumption.
10645 */
10646 phba->sli4_hba.rpi_hdrs_in_use = 1;
10647
James Smartfedd3b72011-02-16 12:39:24 -050010648 /* Read the port's SLI4 Config Parameters */
10649 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
10650 sizeof(struct lpfc_sli4_cfg_mhdr));
10651 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
10652 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
10653 length, LPFC_SLI4_MBX_EMBED);
10654 if (!phba->sli4_hba.intr_enable)
10655 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -040010656 else {
10657 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
10658 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10659 }
James Smartfedd3b72011-02-16 12:39:24 -050010660 if (unlikely(rc))
10661 return rc;
10662 sli4_params = &phba->sli4_hba.pc_sli4_params;
10663 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
10664 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
10665 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
10666 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
10667 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
10668 mbx_sli4_parameters);
10669 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
10670 mbx_sli4_parameters);
10671 if (bf_get(cfg_phwq, mbx_sli4_parameters))
10672 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
10673 else
10674 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
10675 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
10676 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
James Smart1ba981f2014-02-20 09:56:45 -050010677 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010678 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
10679 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
10680 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
10681 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
James Smart7365f6f2018-02-22 08:18:46 -080010682 sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters);
10683 sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters);
James Smart0c651872013-07-15 18:33:23 -040010684 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
James Smart66e9e6b2018-06-26 08:24:27 -070010685 sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010686 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
10687 mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080010688 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010689 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
10690 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -040010691 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
10692 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080010693 phba->nvme_support = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
10694 bf_get(cfg_xib, mbx_sli4_parameters));
10695
10696 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) ||
10697 !phba->nvme_support) {
10698 phba->nvme_support = 0;
10699 phba->nvmet_support = 0;
James Smartbcb24f62017-11-20 16:00:36 -080010700 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_OFF;
James Smart895427b2017-02-12 13:52:30 -080010701 phba->cfg_nvme_io_channel = 0;
10702 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
10703 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
10704 "6101 Disabling NVME support: "
10705 "Not supported by firmware: %d %d\n",
10706 bf_get(cfg_nvme, mbx_sli4_parameters),
10707 bf_get(cfg_xib, mbx_sli4_parameters));
10708
10709 /* If firmware doesn't support NVME, just use SCSI support */
10710 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
10711 return -ENODEV;
10712 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
10713 }
James Smart05580562011-05-24 11:40:48 -040010714
James Smart414abe02018-06-26 08:24:26 -070010715 /* Only embed PBDE for if_type 6, PBDE support requires xib be set */
10716 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
10717 LPFC_SLI_INTF_IF_TYPE_6) || (!bf_get(cfg_xib, mbx_sli4_parameters)))
10718 phba->cfg_enable_pbde = 0;
James Smart0bc2b7c2018-02-22 08:18:48 -080010719
James Smart20aefac2018-01-30 15:58:58 -080010720 /*
10721 * To support Suppress Response feature we must satisfy 3 conditions.
10722 * lpfc_suppress_rsp module parameter must be set (default).
10723 * In SLI4-Parameters Descriptor:
10724 * Extended Inline Buffers (XIB) must be supported.
10725 * Suppress Response IU Not Supported (SRIUNS) must NOT be supported
10726 * (double negative).
10727 */
10728 if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) &&
10729 !(bf_get(cfg_nosr, mbx_sli4_parameters)))
James Smartf358dd02017-02-12 13:52:34 -080010730 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
James Smart20aefac2018-01-30 15:58:58 -080010731 else
10732 phba->cfg_suppress_rsp = 0;
James Smartf358dd02017-02-12 13:52:34 -080010733
James Smart0cf07f842017-06-01 21:07:10 -070010734 if (bf_get(cfg_eqdr, mbx_sli4_parameters))
10735 phba->sli.sli_flag |= LPFC_SLI_USE_EQDR;
10736
James Smart05580562011-05-24 11:40:48 -040010737 /* Make sure that sge_supp_len can be handled by the driver */
10738 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10739 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10740
James Smartb5c53952016-03-31 14:12:30 -070010741 /*
James Smartc176ffa2018-01-30 15:58:46 -080010742 * Check whether the adapter supports an embedded copy of the
10743 * FCP CMD IU within the WQE for FCP_Ixxx commands. In order
10744 * to use this option, 128-byte WQEs must be used.
James Smartb5c53952016-03-31 14:12:30 -070010745 */
10746 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
10747 phba->fcp_embed_io = 1;
10748 else
10749 phba->fcp_embed_io = 0;
James Smart7bdedb32016-07-06 12:36:00 -070010750
James Smart0bc2b7c2018-02-22 08:18:48 -080010751 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
James Smart414abe02018-06-26 08:24:26 -070010752 "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n",
James Smart0bc2b7c2018-02-22 08:18:48 -080010753 bf_get(cfg_xib, mbx_sli4_parameters),
James Smart414abe02018-06-26 08:24:26 -070010754 phba->cfg_enable_pbde,
10755 phba->fcp_embed_io, phba->nvme_support,
James Smart4e565cf2018-02-22 08:18:50 -080010756 phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp);
James Smart0bc2b7c2018-02-22 08:18:48 -080010757
James Smartbf316c72018-04-09 14:24:28 -070010758 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
10759 LPFC_SLI_INTF_IF_TYPE_2) &&
10760 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
James Smartc2217682018-05-24 21:09:00 -070010761 LPFC_SLI_INTF_FAMILY_LNCR_A0))
James Smartbf316c72018-04-09 14:24:28 -070010762 exp_wqcq_pages = false;
10763
James Smartc176ffa2018-01-30 15:58:46 -080010764 if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) &&
10765 (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) &&
James Smartbf316c72018-04-09 14:24:28 -070010766 exp_wqcq_pages &&
James Smartc176ffa2018-01-30 15:58:46 -080010767 (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT))
10768 phba->enab_exp_wqcq_pages = 1;
10769 else
10770 phba->enab_exp_wqcq_pages = 0;
James Smart7bdedb32016-07-06 12:36:00 -070010771 /*
10772 * Check if the SLI port supports MDS Diagnostics
10773 */
10774 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
10775 phba->mds_diags_support = 1;
10776 else
10777 phba->mds_diags_support = 0;
James Smartd2cc9bc2018-09-10 10:30:50 -070010778
James Smartfedd3b72011-02-16 12:39:24 -050010779 return 0;
10780}
10781
10782/**
James Smart3772a992009-05-22 14:50:54 -040010783 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
10784 * @pdev: pointer to PCI device
10785 * @pid: pointer to PCI device identifier
10786 *
10787 * This routine is to be called to attach a device with SLI-3 interface spec
10788 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10789 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10790 * information of the device and driver to see if the driver state that it can
10791 * support this kind of device. If the match is successful, the driver core
10792 * invokes this routine. If this routine determines it can claim the HBA, it
10793 * does all the initialization that it needs to do to handle the HBA properly.
10794 *
10795 * Return code
10796 * 0 - driver can claim the device
10797 * negative value - driver can not claim the device
10798 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010799static int
James Smart3772a992009-05-22 14:50:54 -040010800lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
10801{
10802 struct lpfc_hba *phba;
10803 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040010804 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -040010805 int error;
10806 uint32_t cfg_mode, intr_mode;
10807
10808 /* Allocate memory for HBA structure */
10809 phba = lpfc_hba_alloc(pdev);
10810 if (!phba)
10811 return -ENOMEM;
10812
10813 /* Perform generic PCI device enabling operation */
10814 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040010815 if (error)
James Smart3772a992009-05-22 14:50:54 -040010816 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -040010817
10818 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
10819 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
10820 if (error)
10821 goto out_disable_pci_dev;
10822
10823 /* Set up SLI-3 specific device PCI memory space */
10824 error = lpfc_sli_pci_mem_setup(phba);
10825 if (error) {
10826 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10827 "1402 Failed to set up pci memory space.\n");
10828 goto out_disable_pci_dev;
10829 }
10830
James Smart3772a992009-05-22 14:50:54 -040010831 /* Set up SLI-3 specific device driver resources */
10832 error = lpfc_sli_driver_resource_setup(phba);
10833 if (error) {
10834 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10835 "1404 Failed to set up driver resource.\n");
10836 goto out_unset_pci_mem_s3;
10837 }
10838
10839 /* Initialize and populate the iocb list per host */
James Smartd1f525a2017-04-21 16:04:55 -070010840
James Smart3772a992009-05-22 14:50:54 -040010841 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
10842 if (error) {
10843 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10844 "1405 Failed to initialize iocb list.\n");
10845 goto out_unset_driver_resource_s3;
10846 }
10847
10848 /* Set up common device driver resources */
10849 error = lpfc_setup_driver_resource_phase2(phba);
10850 if (error) {
10851 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10852 "1406 Failed to set up driver resource.\n");
10853 goto out_free_iocb_list;
10854 }
10855
James Smart079b5c92011-08-21 21:48:49 -040010856 /* Get the default values for Model Name and Description */
10857 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
10858
James Smart3772a992009-05-22 14:50:54 -040010859 /* Create SCSI host to the physical port */
10860 error = lpfc_create_shost(phba);
10861 if (error) {
10862 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10863 "1407 Failed to create scsi host.\n");
10864 goto out_unset_driver_resource;
10865 }
10866
10867 /* Configure sysfs attributes */
10868 vport = phba->pport;
10869 error = lpfc_alloc_sysfs_attr(vport);
10870 if (error) {
10871 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10872 "1476 Failed to allocate sysfs attr\n");
10873 goto out_destroy_shost;
10874 }
10875
James Smart6669f9b2009-10-02 15:16:45 -040010876 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -040010877 /* Now, trying to enable interrupt and bring up the device */
10878 cfg_mode = phba->cfg_use_msi;
10879 while (true) {
10880 /* Put device to a known state before enabling interrupt */
10881 lpfc_stop_port(phba);
10882 /* Configure and enable interrupt */
10883 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
10884 if (intr_mode == LPFC_INTR_ERROR) {
10885 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10886 "0431 Failed to enable interrupt.\n");
10887 error = -ENODEV;
10888 goto out_free_sysfs_attr;
10889 }
10890 /* SLI-3 HBA setup */
10891 if (lpfc_sli_hba_setup(phba)) {
10892 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10893 "1477 Failed to set up hba\n");
10894 error = -ENODEV;
10895 goto out_remove_device;
10896 }
10897
10898 /* Wait 50ms for the interrupts of previous mailbox commands */
10899 msleep(50);
10900 /* Check active interrupts on message signaled interrupts */
10901 if (intr_mode == 0 ||
10902 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
10903 /* Log the current active interrupt mode */
10904 phba->intr_mode = intr_mode;
10905 lpfc_log_intr_mode(phba, intr_mode);
10906 break;
10907 } else {
10908 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10909 "0447 Configure interrupt mode (%d) "
10910 "failed active interrupt test.\n",
10911 intr_mode);
10912 /* Disable the current interrupt mode */
10913 lpfc_sli_disable_intr(phba);
10914 /* Try next level of interrupt mode */
10915 cfg_mode = --intr_mode;
10916 }
10917 }
10918
10919 /* Perform post initialization setup */
10920 lpfc_post_init_setup(phba);
10921
10922 /* Check if there are static vports to be created. */
10923 lpfc_create_static_vport(phba);
10924
10925 return 0;
10926
10927out_remove_device:
10928 lpfc_unset_hba(phba);
10929out_free_sysfs_attr:
10930 lpfc_free_sysfs_attr(vport);
10931out_destroy_shost:
10932 lpfc_destroy_shost(phba);
10933out_unset_driver_resource:
10934 lpfc_unset_driver_resource_phase2(phba);
10935out_free_iocb_list:
10936 lpfc_free_iocb_list(phba);
10937out_unset_driver_resource_s3:
10938 lpfc_sli_driver_resource_unset(phba);
10939out_unset_pci_mem_s3:
10940 lpfc_sli_pci_mem_unset(phba);
10941out_disable_pci_dev:
10942 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040010943 if (shost)
10944 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -040010945out_free_phba:
10946 lpfc_hba_free(phba);
10947 return error;
10948}
10949
10950/**
10951 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -040010952 * @pdev: pointer to PCI device
10953 *
James Smart3772a992009-05-22 14:50:54 -040010954 * This routine is to be called to disattach a device with SLI-3 interface
10955 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10956 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10957 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -040010958 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010959static void
James Smart3772a992009-05-22 14:50:54 -040010960lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -050010961{
James Smart2e0fef82007-06-17 19:56:36 -050010962 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10963 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -050010964 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -050010965 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -050010966 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -050010967
James Smart549e55c2007-08-02 11:09:51 -040010968 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -040010969 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -040010970 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -050010971
James Smart858c9f62007-06-17 19:56:39 -050010972 lpfc_free_sysfs_attr(vport);
10973
James Smarteada2722008-12-04 22:39:13 -050010974 /* Release all the vports against this physical port */
10975 vports = lpfc_create_vport_work_array(phba);
10976 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040010977 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10978 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
10979 continue;
James Smarteada2722008-12-04 22:39:13 -050010980 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040010981 }
James Smarteada2722008-12-04 22:39:13 -050010982 lpfc_destroy_vport_work_array(phba, vports);
10983
10984 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -050010985 fc_remove_host(shost);
10986 scsi_remove_host(shost);
James Smartd613b6a2017-02-12 13:52:37 -080010987
James Smart87af33f2007-10-27 13:37:43 -040010988 lpfc_cleanup(vport);
10989
James Smart2e0fef82007-06-17 19:56:36 -050010990 /*
10991 * Bring down the SLI Layer. This step disable all interrupts,
10992 * clears the rings, discards all mailbox commands, and resets
10993 * the HBA.
10994 */
James Smarta257bf92009-04-06 18:48:10 -040010995
Justin P. Mattock48e34d02010-12-30 15:07:58 -080010996 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -050010997 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -040010998 /* Stop kthread signal shall trigger work_done one more time */
10999 kthread_stop(phba->worker_thread);
11000 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -050011001 lpfc_sli_brdrestart(phba);
11002
James Smart72859902012-01-18 16:25:38 -050011003 kfree(phba->vpi_bmask);
11004 kfree(phba->vpi_ids);
11005
James Smart3772a992009-05-22 14:50:54 -040011006 lpfc_stop_hba_timers(phba);
James Smart523128e2018-09-10 10:30:46 -070011007 spin_lock_irq(&phba->port_list_lock);
James Smart858c9f62007-06-17 19:56:39 -050011008 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -070011009 spin_unlock_irq(&phba->port_list_lock);
James Smart858c9f62007-06-17 19:56:39 -050011010
James Smart858c9f62007-06-17 19:56:39 -050011011 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -050011012
James Smart912e3ac2011-05-24 11:42:11 -040011013 /* Disable SR-IOV if enabled */
11014 if (phba->cfg_sriov_nr_virtfn)
11015 pci_disable_sriov(pdev);
11016
James Smart5b75da22008-12-04 22:39:35 -050011017 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -040011018 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -050011019
James Smart858c9f62007-06-17 19:56:39 -050011020 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -050011021
11022 /*
11023 * Call scsi_free before mem_free since scsi bufs are released to their
11024 * corresponding pools here.
11025 */
11026 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -040011027 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -050011028
James Smart34b02dc2008-08-24 21:49:55 -040011029 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
11030 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -050011031
James Smart2e0fef82007-06-17 19:56:36 -050011032 /* Free resources associated with SLI2 interface */
11033 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -040011034 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -050011035
11036 /* unmap adapter SLIM and Control Registers */
11037 iounmap(phba->ctrl_regs_memmap_p);
11038 iounmap(phba->slim_memmap_p);
11039
James Smart3772a992009-05-22 14:50:54 -040011040 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -050011041
Johannes Thumshirne0c04832016-06-07 09:44:03 +020011042 pci_release_mem_regions(pdev);
James Smart2e0fef82007-06-17 19:56:36 -050011043 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -050011044}
11045
Linas Vepstas8d63f372007-02-14 14:28:36 -060011046/**
James Smart3772a992009-05-22 14:50:54 -040011047 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050011048 * @pdev: pointer to PCI device
11049 * @msg: power management message
11050 *
James Smart3772a992009-05-22 14:50:54 -040011051 * This routine is to be called from the kernel's PCI subsystem to support
11052 * system Power Management (PM) to device with SLI-3 interface spec. When
11053 * PM invokes this method, it quiesces the device by stopping the driver's
11054 * worker thread for the device, turning off device's interrupt and DMA,
11055 * and bring the device offline. Note that as the driver implements the
11056 * minimum PM requirements to a power-aware driver's PM support for the
11057 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
11058 * to the suspend() method call will be treated as SUSPEND and the driver will
11059 * fully reinitialize its device during resume() method call, the driver will
11060 * set device to PCI_D3hot state in PCI config space instead of setting it
11061 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -050011062 *
11063 * Return code
James Smart3772a992009-05-22 14:50:54 -040011064 * 0 - driver suspended the device
11065 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050011066 **/
11067static int
James Smart3772a992009-05-22 14:50:54 -040011068lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -050011069{
11070 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11071 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11072
11073 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11074 "0473 PCI device Power Management suspend.\n");
11075
11076 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040011077 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -050011078 lpfc_offline(phba);
11079 kthread_stop(phba->worker_thread);
11080
11081 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -040011082 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -050011083
11084 /* Save device state to PCI config space */
11085 pci_save_state(pdev);
11086 pci_set_power_state(pdev, PCI_D3hot);
11087
11088 return 0;
11089}
11090
11091/**
James Smart3772a992009-05-22 14:50:54 -040011092 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050011093 * @pdev: pointer to PCI device
11094 *
James Smart3772a992009-05-22 14:50:54 -040011095 * This routine is to be called from the kernel's PCI subsystem to support
11096 * system Power Management (PM) to device with SLI-3 interface spec. When PM
11097 * invokes this method, it restores the device's PCI config space state and
11098 * fully reinitializes the device and brings it online. Note that as the
11099 * driver implements the minimum PM requirements to a power-aware driver's
11100 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
11101 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
11102 * driver will fully reinitialize its device during resume() method call,
11103 * the device will be set to PCI_D0 directly in PCI config space before
11104 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -050011105 *
11106 * Return code
James Smart3772a992009-05-22 14:50:54 -040011107 * 0 - driver suspended the device
11108 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050011109 **/
11110static int
James Smart3772a992009-05-22 14:50:54 -040011111lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -050011112{
11113 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11114 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -050011115 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050011116 int error;
11117
11118 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11119 "0452 PCI device Power Management resume.\n");
11120
11121 /* Restore device state from PCI config space */
11122 pci_set_power_state(pdev, PCI_D0);
11123 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -040011124
James Smart1dfb5a42010-02-12 14:40:50 -050011125 /*
11126 * As the new kernel behavior of pci_restore_state() API call clears
11127 * device saved_state flag, need to save the restored state again.
11128 */
11129 pci_save_state(pdev);
11130
James Smart3a55b532008-12-04 22:38:54 -050011131 if (pdev->is_busmaster)
11132 pci_set_master(pdev);
11133
11134 /* Startup the kernel thread for this host adapter. */
11135 phba->worker_thread = kthread_run(lpfc_do_work, phba,
11136 "lpfc_worker_%d", phba->brd_no);
11137 if (IS_ERR(phba->worker_thread)) {
11138 error = PTR_ERR(phba->worker_thread);
11139 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11140 "0434 PM resume failed to start worker "
11141 "thread: error=x%x.\n", error);
11142 return error;
11143 }
11144
James Smart5b75da22008-12-04 22:39:35 -050011145 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040011146 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050011147 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -050011148 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -050011149 "0430 PM resume Failed to enable interrupt\n");
11150 return -EIO;
11151 } else
11152 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050011153
11154 /* Restart HBA and bring it online */
11155 lpfc_sli_brdrestart(phba);
11156 lpfc_online(phba);
11157
James Smart5b75da22008-12-04 22:39:35 -050011158 /* Log the current active interrupt mode */
11159 lpfc_log_intr_mode(phba, phba->intr_mode);
11160
James Smart3a55b532008-12-04 22:38:54 -050011161 return 0;
11162}
11163
11164/**
James Smart891478a2009-11-18 15:40:23 -050011165 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
11166 * @phba: pointer to lpfc hba data structure.
11167 *
11168 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -040011169 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -050011170 **/
11171static void
11172lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
11173{
11174 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11175 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -040011176
11177 /*
11178 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
11179 * and let the SCSI mid-layer to retry them to recover.
11180 */
James Smartdb55fba2014-04-04 13:52:02 -040011181 lpfc_sli_abort_fcp_rings(phba);
James Smart891478a2009-11-18 15:40:23 -050011182}
11183
11184/**
James Smart0d878412009-10-02 15:16:56 -040011185 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
11186 * @phba: pointer to lpfc hba data structure.
11187 *
11188 * This routine is called to prepare the SLI3 device for PCI slot reset. It
11189 * disables the device interrupt and pci device, and aborts the internal FCP
11190 * pending I/Os.
11191 **/
11192static void
11193lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
11194{
James Smart0d878412009-10-02 15:16:56 -040011195 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050011196 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -040011197
James Smart75baf692010-06-08 18:31:21 -040011198 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040011199 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040011200
James Smarte2af0d22010-03-15 11:25:32 -040011201 /* Block all SCSI devices' I/Os on the host */
11202 lpfc_scsi_dev_block(phba);
11203
James Smartea714f32013-04-17 20:18:47 -040011204 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
11205 lpfc_sli_flush_fcp_rings(phba);
11206
James Smarte2af0d22010-03-15 11:25:32 -040011207 /* stop all timers */
11208 lpfc_stop_hba_timers(phba);
11209
James Smart0d878412009-10-02 15:16:56 -040011210 /* Disable interrupt and pci device */
11211 lpfc_sli_disable_intr(phba);
11212 pci_disable_device(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -040011213}
11214
11215/**
11216 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
11217 * @phba: pointer to lpfc hba data structure.
11218 *
11219 * This routine is called to prepare the SLI3 device for PCI slot permanently
11220 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
11221 * pending I/Os.
11222 **/
11223static void
James Smart75baf692010-06-08 18:31:21 -040011224lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -040011225{
11226 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050011227 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -040011228 /* Block all SCSI devices' I/Os on the host */
11229 lpfc_scsi_dev_block(phba);
11230
11231 /* stop all timers */
11232 lpfc_stop_hba_timers(phba);
11233
James Smart0d878412009-10-02 15:16:56 -040011234 /* Clean up all driver's outstanding SCSI I/Os */
11235 lpfc_sli_flush_fcp_rings(phba);
11236}
11237
11238/**
James Smart3772a992009-05-22 14:50:54 -040011239 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -040011240 * @pdev: pointer to PCI device.
11241 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -060011242 *
James Smart3772a992009-05-22 14:50:54 -040011243 * This routine is called from the PCI subsystem for I/O error handling to
11244 * device with SLI-3 interface spec. This function is called by the PCI
11245 * subsystem after a PCI bus error affecting this device has been detected.
11246 * When this function is invoked, it will need to stop all the I/Os and
11247 * interrupt(s) to the device. Once that is done, it will return
11248 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
11249 * as desired.
James Smarte59058c2008-08-24 21:49:00 -040011250 *
11251 * Return codes
James Smart0d878412009-10-02 15:16:56 -040011252 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -040011253 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11254 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -040011255 **/
James Smart3772a992009-05-22 14:50:54 -040011256static pci_ers_result_t
11257lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -060011258{
James Smart51ef4c22007-08-02 11:10:31 -040011259 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11260 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011261
James Smart0d878412009-10-02 15:16:56 -040011262 switch (state) {
11263 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -050011264 /* Non-fatal error, prepare for recovery */
11265 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -040011266 return PCI_ERS_RESULT_CAN_RECOVER;
11267 case pci_channel_io_frozen:
11268 /* Fatal error, prepare for slot reset */
11269 lpfc_sli_prep_dev_for_reset(phba);
11270 return PCI_ERS_RESULT_NEED_RESET;
11271 case pci_channel_io_perm_failure:
11272 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -040011273 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011274 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -040011275 default:
11276 /* Unknown state, prepare and request slot reset */
11277 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11278 "0472 Unknown PCI error state: x%x\n", state);
11279 lpfc_sli_prep_dev_for_reset(phba);
11280 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -040011281 }
Linas Vepstas8d63f372007-02-14 14:28:36 -060011282}
11283
11284/**
James Smart3772a992009-05-22 14:50:54 -040011285 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -040011286 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -060011287 *
James Smart3772a992009-05-22 14:50:54 -040011288 * This routine is called from the PCI subsystem for error handling to
11289 * device with SLI-3 interface spec. This is called after PCI bus has been
11290 * reset to restart the PCI card from scratch, as if from a cold-boot.
11291 * During the PCI subsystem error recovery, after driver returns
11292 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
11293 * recovery and then call this routine before calling the .resume method
11294 * to recover the device. This function will initialize the HBA device,
11295 * enable the interrupt, but it will just put the HBA to offline state
11296 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -040011297 *
11298 * Return codes
James Smart3772a992009-05-22 14:50:54 -040011299 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11300 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -060011301 */
James Smart3772a992009-05-22 14:50:54 -040011302static pci_ers_result_t
11303lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060011304{
James Smart51ef4c22007-08-02 11:10:31 -040011305 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11306 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011307 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -050011308 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011309
11310 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +110011311 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -060011312 printk(KERN_ERR "lpfc: Cannot re-enable "
11313 "PCI device after reset.\n");
11314 return PCI_ERS_RESULT_DISCONNECT;
11315 }
11316
James Smart97207482008-12-04 22:39:19 -050011317 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050011318
11319 /*
11320 * As the new kernel behavior of pci_restore_state() API call clears
11321 * device saved_state flag, need to save the restored state again.
11322 */
11323 pci_save_state(pdev);
11324
James Smart97207482008-12-04 22:39:19 -050011325 if (pdev->is_busmaster)
11326 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011327
James Smart92d7f7b2007-06-17 19:56:38 -050011328 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040011329 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -050011330 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011331
James Smart5b75da22008-12-04 22:39:35 -050011332 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040011333 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050011334 if (intr_mode == LPFC_INTR_ERROR) {
11335 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11336 "0427 Cannot re-enable interrupt after "
11337 "slot reset.\n");
11338 return PCI_ERS_RESULT_DISCONNECT;
11339 } else
11340 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011341
James Smart75baf692010-06-08 18:31:21 -040011342 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -040011343 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011344 lpfc_offline(phba);
11345 lpfc_sli_brdrestart(phba);
11346
James Smart5b75da22008-12-04 22:39:35 -050011347 /* Log the current active interrupt mode */
11348 lpfc_log_intr_mode(phba, phba->intr_mode);
11349
Linas Vepstas8d63f372007-02-14 14:28:36 -060011350 return PCI_ERS_RESULT_RECOVERED;
11351}
11352
11353/**
James Smart3772a992009-05-22 14:50:54 -040011354 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -040011355 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -060011356 *
James Smart3772a992009-05-22 14:50:54 -040011357 * This routine is called from the PCI subsystem for error handling to device
11358 * with SLI-3 interface spec. It is called when kernel error recovery tells
11359 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
11360 * error recovery. After this call, traffic can start to flow from this device
11361 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -060011362 */
James Smart3772a992009-05-22 14:50:54 -040011363static void
11364lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060011365{
James Smart51ef4c22007-08-02 11:10:31 -040011366 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11367 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011368
James Smarte2af0d22010-03-15 11:25:32 -040011369 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -040011370 lpfc_online(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011371}
11372
James Smart3772a992009-05-22 14:50:54 -040011373/**
James Smartda0436e2009-05-22 14:51:39 -040011374 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
11375 * @phba: pointer to lpfc hba data structure.
11376 *
11377 * returns the number of ELS/CT IOCBs to reserve
11378 **/
11379int
11380lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
11381{
11382 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
11383
James Smartf1126682009-06-10 17:22:44 -040011384 if (phba->sli_rev == LPFC_SLI_REV4) {
11385 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -040011386 return 10;
James Smartf1126682009-06-10 17:22:44 -040011387 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -040011388 return 25;
James Smartf1126682009-06-10 17:22:44 -040011389 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -040011390 return 50;
James Smartf1126682009-06-10 17:22:44 -040011391 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -040011392 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -040011393 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -040011394 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -040011395 else if (max_xri <= 2048)
11396 return 200;
11397 else
11398 return 250;
James Smartf1126682009-06-10 17:22:44 -040011399 } else
11400 return 0;
James Smartda0436e2009-05-22 14:51:39 -040011401}
11402
11403/**
James Smart895427b2017-02-12 13:52:30 -080011404 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
11405 * @phba: pointer to lpfc hba data structure.
11406 *
James Smartf358dd02017-02-12 13:52:34 -080011407 * returns the number of ELS/CT + NVMET IOCBs to reserve
James Smart895427b2017-02-12 13:52:30 -080011408 **/
11409int
11410lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
11411{
11412 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
11413
James Smartf358dd02017-02-12 13:52:34 -080011414 if (phba->nvmet_support)
11415 max_xri += LPFC_NVMET_BUF_POST;
James Smart895427b2017-02-12 13:52:30 -080011416 return max_xri;
11417}
11418
11419
James Smart1feb8202018-02-22 08:18:47 -080011420static void
11421lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset,
11422 uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize,
11423 const struct firmware *fw)
11424{
James Smarta72d56b2018-05-04 20:37:52 -070011425 if ((offset == ADD_STATUS_FW_NOT_SUPPORTED) ||
11426 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
11427 magic_number != MAGIC_NUMER_G6) ||
11428 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC &&
11429 magic_number != MAGIC_NUMER_G7))
James Smart1feb8202018-02-22 08:18:47 -080011430 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11431 "3030 This firmware version is not supported on "
11432 "this HBA model. Device:%x Magic:%x Type:%x "
11433 "ID:%x Size %d %zd\n",
11434 phba->pcidev->device, magic_number, ftype, fid,
11435 fsize, fw->size);
11436 else
11437 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11438 "3022 FW Download failed. Device:%x Magic:%x Type:%x "
11439 "ID:%x Size %d %zd\n",
11440 phba->pcidev->device, magic_number, ftype, fid,
11441 fsize, fw->size);
11442}
11443
11444
James Smart895427b2017-02-12 13:52:30 -080011445/**
James Smart52d52442011-05-24 11:42:45 -040011446 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -040011447 * @fw: pointer to firmware image returned from request_firmware.
James Smartce396282012-09-29 11:30:56 -040011448 * @phba: pointer to lpfc hba data structure.
James Smart52d52442011-05-24 11:42:45 -040011449 *
James Smart52d52442011-05-24 11:42:45 -040011450 **/
James Smartce396282012-09-29 11:30:56 -040011451static void
11452lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -040011453{
James Smartce396282012-09-29 11:30:56 -040011454 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -050011455 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -040011456 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -040011457 struct list_head dma_buffer_list;
11458 int i, rc = 0;
11459 struct lpfc_dmabuf *dmabuf, *next;
11460 uint32_t offset = 0, temp_offset = 0;
James Smart6b6ef5d2016-10-13 15:06:17 -070011461 uint32_t magic_number, ftype, fid, fsize;
James Smart52d52442011-05-24 11:42:45 -040011462
James Smartc71ab862012-10-31 14:44:33 -040011463 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -040011464 if (!fw) {
11465 rc = -ENXIO;
11466 goto out;
11467 }
11468 image = (struct lpfc_grp_hdr *)fw->data;
11469
James Smart6b6ef5d2016-10-13 15:06:17 -070011470 magic_number = be32_to_cpu(image->magic_number);
11471 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
James Smart1feb8202018-02-22 08:18:47 -080011472 fid = bf_get_be32(lpfc_grp_hdr_id, image);
James Smart6b6ef5d2016-10-13 15:06:17 -070011473 fsize = be32_to_cpu(image->size);
11474
James Smart52d52442011-05-24 11:42:45 -040011475 INIT_LIST_HEAD(&dma_buffer_list);
James Smart52d52442011-05-24 11:42:45 -040011476 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -040011477 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -040011478 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartce396282012-09-29 11:30:56 -040011479 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -040011480 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -040011481 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -040011482 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
11483 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
11484 GFP_KERNEL);
11485 if (!dmabuf) {
11486 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040011487 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040011488 }
11489 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
11490 SLI4_PAGE_SIZE,
11491 &dmabuf->phys,
11492 GFP_KERNEL);
11493 if (!dmabuf->virt) {
11494 kfree(dmabuf);
11495 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040011496 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040011497 }
11498 list_add_tail(&dmabuf->list, &dma_buffer_list);
11499 }
11500 while (offset < fw->size) {
11501 temp_offset = offset;
11502 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -040011503 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -040011504 memcpy(dmabuf->virt,
11505 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -040011506 fw->size - temp_offset);
11507 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -040011508 break;
11509 }
James Smart52d52442011-05-24 11:42:45 -040011510 memcpy(dmabuf->virt, fw->data + temp_offset,
11511 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -040011512 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -040011513 }
11514 rc = lpfc_wr_object(phba, &dma_buffer_list,
11515 (fw->size - offset), &offset);
James Smart1feb8202018-02-22 08:18:47 -080011516 if (rc) {
11517 lpfc_log_write_firmware_error(phba, offset,
11518 magic_number, ftype, fid, fsize, fw);
James Smartce396282012-09-29 11:30:56 -040011519 goto release_out;
James Smart1feb8202018-02-22 08:18:47 -080011520 }
James Smart52d52442011-05-24 11:42:45 -040011521 }
11522 rc = offset;
James Smart1feb8202018-02-22 08:18:47 -080011523 } else
11524 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11525 "3029 Skipped Firmware update, Current "
11526 "Version:%s New Version:%s\n",
11527 fwrev, image->revision);
James Smartce396282012-09-29 11:30:56 -040011528
11529release_out:
James Smart52d52442011-05-24 11:42:45 -040011530 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
11531 list_del(&dmabuf->list);
11532 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
11533 dmabuf->virt, dmabuf->phys);
11534 kfree(dmabuf);
11535 }
James Smartce396282012-09-29 11:30:56 -040011536 release_firmware(fw);
11537out:
11538 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc71ab862012-10-31 14:44:33 -040011539 "3024 Firmware update done: %d.\n", rc);
James Smartce396282012-09-29 11:30:56 -040011540 return;
James Smart52d52442011-05-24 11:42:45 -040011541}
11542
11543/**
James Smartc71ab862012-10-31 14:44:33 -040011544 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
11545 * @phba: pointer to lpfc hba data structure.
11546 *
11547 * This routine is called to perform Linux generic firmware upgrade on device
11548 * that supports such feature.
11549 **/
11550int
11551lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
11552{
11553 uint8_t file_name[ELX_MODEL_NAME_SIZE];
11554 int ret;
11555 const struct firmware *fw;
11556
11557 /* Only supported on SLI4 interface type 2 for now */
James Smart27d6ac02018-02-22 08:18:42 -080011558 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smartc71ab862012-10-31 14:44:33 -040011559 LPFC_SLI_INTF_IF_TYPE_2)
11560 return -EPERM;
11561
11562 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
11563
11564 if (fw_upgrade == INT_FW_UPGRADE) {
11565 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
11566 file_name, &phba->pcidev->dev,
11567 GFP_KERNEL, (void *)phba,
11568 lpfc_write_firmware);
11569 } else if (fw_upgrade == RUN_FW_UPGRADE) {
11570 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
11571 if (!ret)
11572 lpfc_write_firmware(fw, (void *)phba);
11573 } else {
11574 ret = -EINVAL;
11575 }
11576
11577 return ret;
11578}
11579
11580/**
James Smartda0436e2009-05-22 14:51:39 -040011581 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
11582 * @pdev: pointer to PCI device
11583 * @pid: pointer to PCI device identifier
11584 *
11585 * This routine is called from the kernel's PCI subsystem to device with
11586 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11587 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
11588 * information of the device and driver to see if the driver state that it
11589 * can support this kind of device. If the match is successful, the driver
11590 * core invokes this routine. If this routine determines it can claim the HBA,
11591 * it does all the initialization that it needs to do to handle the HBA
11592 * properly.
11593 *
11594 * Return code
11595 * 0 - driver can claim the device
11596 * negative value - driver can not claim the device
11597 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011598static int
James Smartda0436e2009-05-22 14:51:39 -040011599lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
11600{
11601 struct lpfc_hba *phba;
11602 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040011603 struct Scsi_Host *shost = NULL;
James Smart6c621a22017-05-15 15:20:45 -070011604 int error;
James Smartda0436e2009-05-22 14:51:39 -040011605 uint32_t cfg_mode, intr_mode;
James Smartda0436e2009-05-22 14:51:39 -040011606
11607 /* Allocate memory for HBA structure */
11608 phba = lpfc_hba_alloc(pdev);
11609 if (!phba)
11610 return -ENOMEM;
11611
11612 /* Perform generic PCI device enabling operation */
11613 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040011614 if (error)
James Smartda0436e2009-05-22 14:51:39 -040011615 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -040011616
11617 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
11618 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
11619 if (error)
11620 goto out_disable_pci_dev;
11621
11622 /* Set up SLI-4 specific device PCI memory space */
11623 error = lpfc_sli4_pci_mem_setup(phba);
11624 if (error) {
11625 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11626 "1410 Failed to set up pci memory space.\n");
11627 goto out_disable_pci_dev;
11628 }
11629
James Smartda0436e2009-05-22 14:51:39 -040011630 /* Set up SLI-4 Specific device driver resources */
11631 error = lpfc_sli4_driver_resource_setup(phba);
11632 if (error) {
11633 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11634 "1412 Failed to set up driver resource.\n");
11635 goto out_unset_pci_mem_s4;
11636 }
11637
James Smart19ca7602010-11-20 23:11:55 -050011638 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -040011639 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -050011640
James Smartda0436e2009-05-22 14:51:39 -040011641 /* Set up common device driver resources */
11642 error = lpfc_setup_driver_resource_phase2(phba);
11643 if (error) {
11644 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11645 "1414 Failed to set up driver resource.\n");
James Smart6c621a22017-05-15 15:20:45 -070011646 goto out_unset_driver_resource_s4;
James Smartda0436e2009-05-22 14:51:39 -040011647 }
11648
James Smart079b5c92011-08-21 21:48:49 -040011649 /* Get the default values for Model Name and Description */
11650 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
11651
James Smartda0436e2009-05-22 14:51:39 -040011652 /* Create SCSI host to the physical port */
11653 error = lpfc_create_shost(phba);
11654 if (error) {
11655 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11656 "1415 Failed to create scsi host.\n");
11657 goto out_unset_driver_resource;
11658 }
11659
11660 /* Configure sysfs attributes */
11661 vport = phba->pport;
11662 error = lpfc_alloc_sysfs_attr(vport);
11663 if (error) {
11664 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11665 "1416 Failed to allocate sysfs attr\n");
11666 goto out_destroy_shost;
11667 }
11668
James Smart6669f9b2009-10-02 15:16:45 -040011669 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -040011670 /* Now, trying to enable interrupt and bring up the device */
11671 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -040011672
James Smart7b15db32013-01-03 15:43:29 -050011673 /* Put device to a known state before enabling interrupt */
11674 lpfc_stop_port(phba);
James Smart895427b2017-02-12 13:52:30 -080011675
James Smart7b15db32013-01-03 15:43:29 -050011676 /* Configure and enable interrupt */
11677 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
11678 if (intr_mode == LPFC_INTR_ERROR) {
11679 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11680 "0426 Failed to enable interrupt.\n");
11681 error = -ENODEV;
11682 goto out_free_sysfs_attr;
James Smartda0436e2009-05-22 14:51:39 -040011683 }
James Smart7b15db32013-01-03 15:43:29 -050011684 /* Default to single EQ for non-MSI-X */
James Smart895427b2017-02-12 13:52:30 -080011685 if (phba->intr_type != MSIX) {
11686 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
11687 phba->cfg_fcp_io_channel = 1;
James Smart2d7dbc42017-02-12 13:52:35 -080011688 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -080011689 phba->cfg_nvme_io_channel = 1;
James Smart2d7dbc42017-02-12 13:52:35 -080011690 if (phba->nvmet_support)
11691 phba->cfg_nvmet_mrq = 1;
11692 }
James Smart895427b2017-02-12 13:52:30 -080011693 phba->io_channel_irqs = 1;
11694 }
11695
James Smart7b15db32013-01-03 15:43:29 -050011696 /* Set up SLI-4 HBA */
11697 if (lpfc_sli4_hba_setup(phba)) {
11698 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11699 "1421 Failed to set up hba\n");
11700 error = -ENODEV;
11701 goto out_disable_intr;
11702 }
11703
11704 /* Log the current active interrupt mode */
11705 phba->intr_mode = intr_mode;
11706 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -040011707
11708 /* Perform post initialization setup */
11709 lpfc_post_init_setup(phba);
11710
James Smart01649562017-02-12 13:52:32 -080011711 /* NVME support in FW earlier in the driver load corrects the
11712 * FC4 type making a check for nvme_support unnecessary.
11713 */
11714 if ((phba->nvmet_support == 0) &&
11715 (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
11716 /* Create NVME binding with nvme_fc_transport. This
James Smartd1f525a2017-04-21 16:04:55 -070011717 * ensures the vport is initialized. If the localport
11718 * create fails, it should not unload the driver to
11719 * support field issues.
James Smart01649562017-02-12 13:52:32 -080011720 */
11721 error = lpfc_nvme_create_localport(vport);
11722 if (error) {
11723 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11724 "6004 NVME registration failed, "
11725 "error x%x\n",
11726 error);
James Smart01649562017-02-12 13:52:32 -080011727 }
11728 }
James Smart895427b2017-02-12 13:52:30 -080011729
James Smartc71ab862012-10-31 14:44:33 -040011730 /* check for firmware upgrade or downgrade */
11731 if (phba->cfg_request_firmware_upgrade)
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040011732 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -040011733
James Smart1c6834a2009-07-19 10:01:26 -040011734 /* Check if there are static vports to be created. */
11735 lpfc_create_static_vport(phba);
James Smartd2cc9bc2018-09-10 10:30:50 -070011736
11737 /* Enable RAS FW log support */
11738 lpfc_sli4_ras_setup(phba);
11739
James Smartda0436e2009-05-22 14:51:39 -040011740 return 0;
11741
11742out_disable_intr:
11743 lpfc_sli4_disable_intr(phba);
11744out_free_sysfs_attr:
11745 lpfc_free_sysfs_attr(vport);
11746out_destroy_shost:
11747 lpfc_destroy_shost(phba);
11748out_unset_driver_resource:
11749 lpfc_unset_driver_resource_phase2(phba);
James Smartda0436e2009-05-22 14:51:39 -040011750out_unset_driver_resource_s4:
11751 lpfc_sli4_driver_resource_unset(phba);
11752out_unset_pci_mem_s4:
11753 lpfc_sli4_pci_mem_unset(phba);
11754out_disable_pci_dev:
11755 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040011756 if (shost)
11757 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -040011758out_free_phba:
11759 lpfc_hba_free(phba);
11760 return error;
11761}
11762
11763/**
11764 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
11765 * @pdev: pointer to PCI device
11766 *
11767 * This routine is called from the kernel's PCI subsystem to device with
11768 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11769 * removed from PCI bus, it performs all the necessary cleanup for the HBA
11770 * device to be removed from the PCI subsystem properly.
11771 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011772static void
James Smartda0436e2009-05-22 14:51:39 -040011773lpfc_pci_remove_one_s4(struct pci_dev *pdev)
11774{
11775 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11776 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
11777 struct lpfc_vport **vports;
11778 struct lpfc_hba *phba = vport->phba;
11779 int i;
11780
11781 /* Mark the device unloading flag */
11782 spin_lock_irq(&phba->hbalock);
11783 vport->load_flag |= FC_UNLOADING;
11784 spin_unlock_irq(&phba->hbalock);
11785
11786 /* Free the HBA sysfs attributes */
11787 lpfc_free_sysfs_attr(vport);
11788
11789 /* Release all the vports against this physical port */
11790 vports = lpfc_create_vport_work_array(phba);
11791 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040011792 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
11793 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
11794 continue;
James Smartda0436e2009-05-22 14:51:39 -040011795 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040011796 }
James Smartda0436e2009-05-22 14:51:39 -040011797 lpfc_destroy_vport_work_array(phba, vports);
11798
11799 /* Remove FC host and then SCSI host with the physical port */
11800 fc_remove_host(shost);
11801 scsi_remove_host(shost);
James Smartda0436e2009-05-22 14:51:39 -040011802
James Smartda0436e2009-05-22 14:51:39 -040011803 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
11804 * localports are destroyed after to cleanup all transport memory.
11805 */
11806 lpfc_cleanup(vport);
11807 lpfc_nvmet_destroy_targetport(phba);
11808 lpfc_nvme_destroy_localport(vport);
11809
James Smart281d6192018-01-30 15:58:47 -080011810 /*
11811 * Bring down the SLI Layer. This step disables all interrupts,
11812 * clears the rings, discards all mailbox commands, and resets
11813 * the HBA FCoE function.
11814 */
11815 lpfc_debugfs_terminate(vport);
11816 lpfc_sli4_hba_unset(phba);
James Smartda0436e2009-05-22 14:51:39 -040011817
Dick Kennedy19017622017-09-29 17:34:27 -070011818 lpfc_stop_hba_timers(phba);
James Smart523128e2018-09-10 10:30:46 -070011819 spin_lock_irq(&phba->port_list_lock);
James Smartda0436e2009-05-22 14:51:39 -040011820 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -070011821 spin_unlock_irq(&phba->port_list_lock);
James Smartda0436e2009-05-22 14:51:39 -040011822
James Smart3677a3a2010-09-29 11:19:14 -040011823 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -040011824 * buffers are released to their corresponding pools here.
11825 */
11826 lpfc_scsi_free(phba);
James Smart895427b2017-02-12 13:52:30 -080011827 lpfc_nvme_free(phba);
James Smart01649562017-02-12 13:52:32 -080011828 lpfc_free_iocb_list(phba);
James Smart67d12732012-08-03 12:36:13 -040011829
James Smart0cdb84e2018-04-09 14:24:26 -070011830 lpfc_unset_driver_resource_phase2(phba);
James Smartda0436e2009-05-22 14:51:39 -040011831 lpfc_sli4_driver_resource_unset(phba);
11832
11833 /* Unmap adapter Control and Doorbell registers */
11834 lpfc_sli4_pci_mem_unset(phba);
11835
11836 /* Release PCI resources and disable device's PCI function */
11837 scsi_host_put(shost);
11838 lpfc_disable_pci_dev(phba);
11839
11840 /* Finally, free the driver's device data structure */
11841 lpfc_hba_free(phba);
11842
11843 return;
11844}
11845
11846/**
11847 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
11848 * @pdev: pointer to PCI device
11849 * @msg: power management message
11850 *
11851 * This routine is called from the kernel's PCI subsystem to support system
11852 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
11853 * this method, it quiesces the device by stopping the driver's worker
11854 * thread for the device, turning off device's interrupt and DMA, and bring
11855 * the device offline. Note that as the driver implements the minimum PM
11856 * requirements to a power-aware driver's PM support for suspend/resume -- all
11857 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
11858 * method call will be treated as SUSPEND and the driver will fully
11859 * reinitialize its device during resume() method call, the driver will set
11860 * device to PCI_D3hot state in PCI config space instead of setting it
11861 * according to the @msg provided by the PM.
11862 *
11863 * Return code
11864 * 0 - driver suspended the device
11865 * Error otherwise
11866 **/
11867static int
11868lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
11869{
11870 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11871 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11872
11873 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -040011874 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -040011875
11876 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040011877 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -040011878 lpfc_offline(phba);
11879 kthread_stop(phba->worker_thread);
11880
11881 /* Disable interrupt from device */
11882 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040011883 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040011884
11885 /* Save device state to PCI config space */
11886 pci_save_state(pdev);
11887 pci_set_power_state(pdev, PCI_D3hot);
11888
11889 return 0;
11890}
11891
11892/**
11893 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
11894 * @pdev: pointer to PCI device
11895 *
11896 * This routine is called from the kernel's PCI subsystem to support system
11897 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
11898 * this method, it restores the device's PCI config space state and fully
11899 * reinitializes the device and brings it online. Note that as the driver
11900 * implements the minimum PM requirements to a power-aware driver's PM for
11901 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
11902 * to the suspend() method call will be treated as SUSPEND and the driver
11903 * will fully reinitialize its device during resume() method call, the device
11904 * will be set to PCI_D0 directly in PCI config space before restoring the
11905 * state.
11906 *
11907 * Return code
11908 * 0 - driver suspended the device
11909 * Error otherwise
11910 **/
11911static int
11912lpfc_pci_resume_one_s4(struct pci_dev *pdev)
11913{
11914 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11915 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11916 uint32_t intr_mode;
11917 int error;
11918
11919 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11920 "0292 PCI device Power Management resume.\n");
11921
11922 /* Restore device state from PCI config space */
11923 pci_set_power_state(pdev, PCI_D0);
11924 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050011925
11926 /*
11927 * As the new kernel behavior of pci_restore_state() API call clears
11928 * device saved_state flag, need to save the restored state again.
11929 */
11930 pci_save_state(pdev);
11931
James Smartda0436e2009-05-22 14:51:39 -040011932 if (pdev->is_busmaster)
11933 pci_set_master(pdev);
11934
11935 /* Startup the kernel thread for this host adapter. */
11936 phba->worker_thread = kthread_run(lpfc_do_work, phba,
11937 "lpfc_worker_%d", phba->brd_no);
11938 if (IS_ERR(phba->worker_thread)) {
11939 error = PTR_ERR(phba->worker_thread);
11940 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11941 "0293 PM resume failed to start worker "
11942 "thread: error=x%x.\n", error);
11943 return error;
11944 }
11945
11946 /* Configure and enable interrupt */
11947 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
11948 if (intr_mode == LPFC_INTR_ERROR) {
11949 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11950 "0294 PM resume Failed to enable interrupt\n");
11951 return -EIO;
11952 } else
11953 phba->intr_mode = intr_mode;
11954
11955 /* Restart HBA and bring it online */
11956 lpfc_sli_brdrestart(phba);
11957 lpfc_online(phba);
11958
11959 /* Log the current active interrupt mode */
11960 lpfc_log_intr_mode(phba, phba->intr_mode);
11961
11962 return 0;
11963}
11964
11965/**
James Smart75baf692010-06-08 18:31:21 -040011966 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
11967 * @phba: pointer to lpfc hba data structure.
11968 *
11969 * This routine is called to prepare the SLI4 device for PCI slot recover. It
11970 * aborts all the outstanding SCSI I/Os to the pci device.
11971 **/
11972static void
11973lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
11974{
James Smart75baf692010-06-08 18:31:21 -040011975 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11976 "2828 PCI channel I/O abort preparing for recovery\n");
11977 /*
11978 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
11979 * and let the SCSI mid-layer to retry them to recover.
11980 */
James Smartdb55fba2014-04-04 13:52:02 -040011981 lpfc_sli_abort_fcp_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040011982}
11983
11984/**
11985 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
11986 * @phba: pointer to lpfc hba data structure.
11987 *
11988 * This routine is called to prepare the SLI4 device for PCI slot reset. It
11989 * disables the device interrupt and pci device, and aborts the internal FCP
11990 * pending I/Os.
11991 **/
11992static void
11993lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
11994{
11995 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11996 "2826 PCI channel disable preparing for reset\n");
11997
11998 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040011999 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -040012000
12001 /* Block all SCSI devices' I/Os on the host */
12002 lpfc_scsi_dev_block(phba);
12003
James Smartea714f32013-04-17 20:18:47 -040012004 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
12005 lpfc_sli_flush_fcp_rings(phba);
12006
James Smartc3725bd2017-11-20 16:00:42 -080012007 /* Flush the outstanding NVME IOs if fc4 type enabled. */
12008 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
12009 lpfc_sli_flush_nvme_rings(phba);
12010
James Smart75baf692010-06-08 18:31:21 -040012011 /* stop all timers */
12012 lpfc_stop_hba_timers(phba);
12013
12014 /* Disable interrupt and pci device */
12015 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040012016 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -040012017 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -040012018}
12019
12020/**
12021 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
12022 * @phba: pointer to lpfc hba data structure.
12023 *
12024 * This routine is called to prepare the SLI4 device for PCI slot permanently
12025 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
12026 * pending I/Os.
12027 **/
12028static void
12029lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
12030{
12031 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12032 "2827 PCI channel permanent disable for failure\n");
12033
12034 /* Block all SCSI devices' I/Os on the host */
12035 lpfc_scsi_dev_block(phba);
12036
12037 /* stop all timers */
12038 lpfc_stop_hba_timers(phba);
12039
12040 /* Clean up all driver's outstanding SCSI I/Os */
12041 lpfc_sli_flush_fcp_rings(phba);
James Smartc3725bd2017-11-20 16:00:42 -080012042
12043 /* Flush the outstanding NVME IOs if fc4 type enabled. */
12044 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
12045 lpfc_sli_flush_nvme_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040012046}
12047
12048/**
James Smartda0436e2009-05-22 14:51:39 -040012049 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
12050 * @pdev: pointer to PCI device.
12051 * @state: the current PCI connection state.
12052 *
12053 * This routine is called from the PCI subsystem for error handling to device
12054 * with SLI-4 interface spec. This function is called by the PCI subsystem
12055 * after a PCI bus error affecting this device has been detected. When this
12056 * function is invoked, it will need to stop all the I/Os and interrupt(s)
12057 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
12058 * for the PCI subsystem to perform proper recovery as desired.
12059 *
12060 * Return codes
12061 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
12062 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12063 **/
12064static pci_ers_result_t
12065lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
12066{
James Smart75baf692010-06-08 18:31:21 -040012067 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12068 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12069
12070 switch (state) {
12071 case pci_channel_io_normal:
12072 /* Non-fatal error, prepare for recovery */
12073 lpfc_sli4_prep_dev_for_recover(phba);
12074 return PCI_ERS_RESULT_CAN_RECOVER;
12075 case pci_channel_io_frozen:
12076 /* Fatal error, prepare for slot reset */
12077 lpfc_sli4_prep_dev_for_reset(phba);
12078 return PCI_ERS_RESULT_NEED_RESET;
12079 case pci_channel_io_perm_failure:
12080 /* Permanent failure, prepare for device down */
12081 lpfc_sli4_prep_dev_for_perm_failure(phba);
12082 return PCI_ERS_RESULT_DISCONNECT;
12083 default:
12084 /* Unknown state, prepare and request slot reset */
12085 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12086 "2825 Unknown PCI error state: x%x\n", state);
12087 lpfc_sli4_prep_dev_for_reset(phba);
12088 return PCI_ERS_RESULT_NEED_RESET;
12089 }
James Smartda0436e2009-05-22 14:51:39 -040012090}
12091
12092/**
12093 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
12094 * @pdev: pointer to PCI device.
12095 *
12096 * This routine is called from the PCI subsystem for error handling to device
12097 * with SLI-4 interface spec. It is called after PCI bus has been reset to
12098 * restart the PCI card from scratch, as if from a cold-boot. During the
12099 * PCI subsystem error recovery, after the driver returns
12100 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
12101 * recovery and then call this routine before calling the .resume method to
12102 * recover the device. This function will initialize the HBA device, enable
12103 * the interrupt, but it will just put the HBA to offline state without
12104 * passing any I/O traffic.
12105 *
12106 * Return codes
12107 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
12108 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12109 */
12110static pci_ers_result_t
12111lpfc_io_slot_reset_s4(struct pci_dev *pdev)
12112{
James Smart75baf692010-06-08 18:31:21 -040012113 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12114 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12115 struct lpfc_sli *psli = &phba->sli;
12116 uint32_t intr_mode;
12117
12118 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
12119 if (pci_enable_device_mem(pdev)) {
12120 printk(KERN_ERR "lpfc: Cannot re-enable "
12121 "PCI device after reset.\n");
12122 return PCI_ERS_RESULT_DISCONNECT;
12123 }
12124
12125 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040012126
12127 /*
12128 * As the new kernel behavior of pci_restore_state() API call clears
12129 * device saved_state flag, need to save the restored state again.
12130 */
12131 pci_save_state(pdev);
12132
James Smart75baf692010-06-08 18:31:21 -040012133 if (pdev->is_busmaster)
12134 pci_set_master(pdev);
12135
12136 spin_lock_irq(&phba->hbalock);
12137 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
12138 spin_unlock_irq(&phba->hbalock);
12139
12140 /* Configure and enable interrupt */
12141 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
12142 if (intr_mode == LPFC_INTR_ERROR) {
12143 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12144 "2824 Cannot re-enable interrupt after "
12145 "slot reset.\n");
12146 return PCI_ERS_RESULT_DISCONNECT;
12147 } else
12148 phba->intr_mode = intr_mode;
12149
12150 /* Log the current active interrupt mode */
12151 lpfc_log_intr_mode(phba, phba->intr_mode);
12152
James Smartda0436e2009-05-22 14:51:39 -040012153 return PCI_ERS_RESULT_RECOVERED;
12154}
12155
12156/**
12157 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
12158 * @pdev: pointer to PCI device
12159 *
12160 * This routine is called from the PCI subsystem for error handling to device
12161 * with SLI-4 interface spec. It is called when kernel error recovery tells
12162 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
12163 * error recovery. After this call, traffic can start to flow from this device
12164 * again.
12165 **/
12166static void
12167lpfc_io_resume_s4(struct pci_dev *pdev)
12168{
James Smart75baf692010-06-08 18:31:21 -040012169 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12170 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12171
12172 /*
12173 * In case of slot reset, as function reset is performed through
12174 * mailbox command which needs DMA to be enabled, this operation
12175 * has to be moved to the io resume phase. Taking device offline
12176 * will perform the necessary cleanup.
12177 */
12178 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
12179 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040012180 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040012181 lpfc_offline(phba);
12182 lpfc_sli_brdrestart(phba);
12183 /* Bring the device back online */
12184 lpfc_online(phba);
12185 }
James Smartda0436e2009-05-22 14:51:39 -040012186}
12187
12188/**
James Smart3772a992009-05-22 14:50:54 -040012189 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
12190 * @pdev: pointer to PCI device
12191 * @pid: pointer to PCI device identifier
12192 *
12193 * This routine is to be registered to the kernel's PCI subsystem. When an
12194 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
12195 * at PCI device-specific information of the device and driver to see if the
12196 * driver state that it can support this kind of device. If the match is
12197 * successful, the driver core invokes this routine. This routine dispatches
12198 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
12199 * do all the initialization that it needs to do to handle the HBA device
12200 * properly.
12201 *
12202 * Return code
12203 * 0 - driver can claim the device
12204 * negative value - driver can not claim the device
12205 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012206static int
James Smart3772a992009-05-22 14:50:54 -040012207lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
12208{
12209 int rc;
James Smart8fa38512009-07-19 10:01:03 -040012210 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040012211
James Smart28baac72010-02-12 14:42:03 -050012212 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040012213 return -ENODEV;
12214
James Smart8fa38512009-07-19 10:01:03 -040012215 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050012216 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040012217 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040012218 else
James Smart3772a992009-05-22 14:50:54 -040012219 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040012220
James Smart3772a992009-05-22 14:50:54 -040012221 return rc;
12222}
12223
12224/**
12225 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
12226 * @pdev: pointer to PCI device
12227 *
12228 * This routine is to be registered to the kernel's PCI subsystem. When an
12229 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
12230 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
12231 * remove routine, which will perform all the necessary cleanup for the
12232 * device to be removed from the PCI subsystem properly.
12233 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012234static void
James Smart3772a992009-05-22 14:50:54 -040012235lpfc_pci_remove_one(struct pci_dev *pdev)
12236{
12237 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12238 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12239
12240 switch (phba->pci_dev_grp) {
12241 case LPFC_PCI_DEV_LP:
12242 lpfc_pci_remove_one_s3(pdev);
12243 break;
James Smartda0436e2009-05-22 14:51:39 -040012244 case LPFC_PCI_DEV_OC:
12245 lpfc_pci_remove_one_s4(pdev);
12246 break;
James Smart3772a992009-05-22 14:50:54 -040012247 default:
12248 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12249 "1424 Invalid PCI device group: 0x%x\n",
12250 phba->pci_dev_grp);
12251 break;
12252 }
12253 return;
12254}
12255
12256/**
12257 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
12258 * @pdev: pointer to PCI device
12259 * @msg: power management message
12260 *
12261 * This routine is to be registered to the kernel's PCI subsystem to support
12262 * system Power Management (PM). When PM invokes this method, it dispatches
12263 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
12264 * suspend the device.
12265 *
12266 * Return code
12267 * 0 - driver suspended the device
12268 * Error otherwise
12269 **/
12270static int
12271lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
12272{
12273 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12274 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12275 int rc = -ENODEV;
12276
12277 switch (phba->pci_dev_grp) {
12278 case LPFC_PCI_DEV_LP:
12279 rc = lpfc_pci_suspend_one_s3(pdev, msg);
12280 break;
James Smartda0436e2009-05-22 14:51:39 -040012281 case LPFC_PCI_DEV_OC:
12282 rc = lpfc_pci_suspend_one_s4(pdev, msg);
12283 break;
James Smart3772a992009-05-22 14:50:54 -040012284 default:
12285 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12286 "1425 Invalid PCI device group: 0x%x\n",
12287 phba->pci_dev_grp);
12288 break;
12289 }
12290 return rc;
12291}
12292
12293/**
12294 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
12295 * @pdev: pointer to PCI device
12296 *
12297 * This routine is to be registered to the kernel's PCI subsystem to support
12298 * system Power Management (PM). When PM invokes this method, it dispatches
12299 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
12300 * resume the device.
12301 *
12302 * Return code
12303 * 0 - driver suspended the device
12304 * Error otherwise
12305 **/
12306static int
12307lpfc_pci_resume_one(struct pci_dev *pdev)
12308{
12309 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12310 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12311 int rc = -ENODEV;
12312
12313 switch (phba->pci_dev_grp) {
12314 case LPFC_PCI_DEV_LP:
12315 rc = lpfc_pci_resume_one_s3(pdev);
12316 break;
James Smartda0436e2009-05-22 14:51:39 -040012317 case LPFC_PCI_DEV_OC:
12318 rc = lpfc_pci_resume_one_s4(pdev);
12319 break;
James Smart3772a992009-05-22 14:50:54 -040012320 default:
12321 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12322 "1426 Invalid PCI device group: 0x%x\n",
12323 phba->pci_dev_grp);
12324 break;
12325 }
12326 return rc;
12327}
12328
12329/**
12330 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
12331 * @pdev: pointer to PCI device.
12332 * @state: the current PCI connection state.
12333 *
12334 * This routine is registered to the PCI subsystem for error handling. This
12335 * function is called by the PCI subsystem after a PCI bus error affecting
12336 * this device has been detected. When this routine is invoked, it dispatches
12337 * the action to the proper SLI-3 or SLI-4 device error detected handling
12338 * routine, which will perform the proper error detected operation.
12339 *
12340 * Return codes
12341 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
12342 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12343 **/
12344static pci_ers_result_t
12345lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
12346{
12347 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12348 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12349 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
12350
12351 switch (phba->pci_dev_grp) {
12352 case LPFC_PCI_DEV_LP:
12353 rc = lpfc_io_error_detected_s3(pdev, state);
12354 break;
James Smartda0436e2009-05-22 14:51:39 -040012355 case LPFC_PCI_DEV_OC:
12356 rc = lpfc_io_error_detected_s4(pdev, state);
12357 break;
James Smart3772a992009-05-22 14:50:54 -040012358 default:
12359 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12360 "1427 Invalid PCI device group: 0x%x\n",
12361 phba->pci_dev_grp);
12362 break;
12363 }
12364 return rc;
12365}
12366
12367/**
12368 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
12369 * @pdev: pointer to PCI device.
12370 *
12371 * This routine is registered to the PCI subsystem for error handling. This
12372 * function is called after PCI bus has been reset to restart the PCI card
12373 * from scratch, as if from a cold-boot. When this routine is invoked, it
12374 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
12375 * routine, which will perform the proper device reset.
12376 *
12377 * Return codes
12378 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
12379 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12380 **/
12381static pci_ers_result_t
12382lpfc_io_slot_reset(struct pci_dev *pdev)
12383{
12384 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12385 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12386 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
12387
12388 switch (phba->pci_dev_grp) {
12389 case LPFC_PCI_DEV_LP:
12390 rc = lpfc_io_slot_reset_s3(pdev);
12391 break;
James Smartda0436e2009-05-22 14:51:39 -040012392 case LPFC_PCI_DEV_OC:
12393 rc = lpfc_io_slot_reset_s4(pdev);
12394 break;
James Smart3772a992009-05-22 14:50:54 -040012395 default:
12396 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12397 "1428 Invalid PCI device group: 0x%x\n",
12398 phba->pci_dev_grp);
12399 break;
12400 }
12401 return rc;
12402}
12403
12404/**
12405 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
12406 * @pdev: pointer to PCI device
12407 *
12408 * This routine is registered to the PCI subsystem for error handling. It
12409 * is called when kernel error recovery tells the lpfc driver that it is
12410 * OK to resume normal PCI operation after PCI bus error recovery. When
12411 * this routine is invoked, it dispatches the action to the proper SLI-3
12412 * or SLI-4 device io_resume routine, which will resume the device operation.
12413 **/
12414static void
12415lpfc_io_resume(struct pci_dev *pdev)
12416{
12417 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12418 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12419
12420 switch (phba->pci_dev_grp) {
12421 case LPFC_PCI_DEV_LP:
12422 lpfc_io_resume_s3(pdev);
12423 break;
James Smartda0436e2009-05-22 14:51:39 -040012424 case LPFC_PCI_DEV_OC:
12425 lpfc_io_resume_s4(pdev);
12426 break;
James Smart3772a992009-05-22 14:50:54 -040012427 default:
12428 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12429 "1429 Invalid PCI device group: 0x%x\n",
12430 phba->pci_dev_grp);
12431 break;
12432 }
12433 return;
12434}
12435
James Smart1ba981f2014-02-20 09:56:45 -050012436/**
12437 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
12438 * @phba: pointer to lpfc hba data structure.
12439 *
12440 * This routine checks to see if OAS is supported for this adapter. If
12441 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
12442 * the enable oas flag is cleared and the pool created for OAS device data
12443 * is destroyed.
12444 *
12445 **/
12446void
12447lpfc_sli4_oas_verify(struct lpfc_hba *phba)
12448{
12449
12450 if (!phba->cfg_EnableXLane)
12451 return;
12452
12453 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
12454 phba->cfg_fof = 1;
12455 } else {
James Smartf38fa0b2014-04-04 13:52:21 -040012456 phba->cfg_fof = 0;
James Smart1ba981f2014-02-20 09:56:45 -050012457 if (phba->device_data_mem_pool)
12458 mempool_destroy(phba->device_data_mem_pool);
12459 phba->device_data_mem_pool = NULL;
12460 }
12461
12462 return;
12463}
12464
12465/**
James Smartd2cc9bc2018-09-10 10:30:50 -070012466 * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter
12467 * @phba: pointer to lpfc hba data structure.
12468 *
12469 * This routine checks to see if RAS is supported by the adapter. Check the
12470 * function through which RAS support enablement is to be done.
12471 **/
12472void
12473lpfc_sli4_ras_init(struct lpfc_hba *phba)
12474{
12475 switch (phba->pcidev->device) {
12476 case PCI_DEVICE_ID_LANCER_G6_FC:
12477 case PCI_DEVICE_ID_LANCER_G7_FC:
12478 phba->ras_fwlog.ras_hwsupport = true;
12479 if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn))
12480 phba->ras_fwlog.ras_enabled = true;
12481 else
12482 phba->ras_fwlog.ras_enabled = false;
12483 break;
12484 default:
12485 phba->ras_fwlog.ras_hwsupport = false;
12486 }
12487}
12488
12489/**
James Smart1ba981f2014-02-20 09:56:45 -050012490 * lpfc_fof_queue_setup - Set up all the fof queues
12491 * @phba: pointer to lpfc hba data structure.
12492 *
12493 * This routine is invoked to set up all the fof queues for the FC HBA
12494 * operation.
12495 *
12496 * Return codes
12497 * 0 - successful
12498 * -ENOMEM - No available memory
12499 **/
12500int
12501lpfc_fof_queue_setup(struct lpfc_hba *phba)
12502{
James Smart895427b2017-02-12 13:52:30 -080012503 struct lpfc_sli_ring *pring;
James Smart1ba981f2014-02-20 09:56:45 -050012504 int rc;
12505
12506 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
12507 if (rc)
12508 return -ENOMEM;
12509
James Smartf38fa0b2014-04-04 13:52:21 -040012510 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050012511
12512 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
12513 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
12514 if (rc)
12515 goto out_oas_cq;
12516
12517 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
12518 phba->sli4_hba.oas_cq, LPFC_FCP);
12519 if (rc)
12520 goto out_oas_wq;
12521
James Smart895427b2017-02-12 13:52:30 -080012522 /* Bind this CQ/WQ to the NVME ring */
12523 pring = phba->sli4_hba.oas_wq->pring;
12524 pring->sli.sli4.wqp =
12525 (void *)phba->sli4_hba.oas_wq;
12526 phba->sli4_hba.oas_cq->pring = pring;
James Smart1ba981f2014-02-20 09:56:45 -050012527 }
12528
12529 return 0;
12530
12531out_oas_wq:
James Smartf38fa0b2014-04-04 13:52:21 -040012532 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
James Smart1ba981f2014-02-20 09:56:45 -050012533out_oas_cq:
12534 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
12535 return rc;
12536
12537}
12538
12539/**
12540 * lpfc_fof_queue_create - Create all the fof queues
12541 * @phba: pointer to lpfc hba data structure.
12542 *
12543 * This routine is invoked to allocate all the fof queues for the FC HBA
12544 * operation. For each SLI4 queue type, the parameters such as queue entry
12545 * count (queue depth) shall be taken from the module parameter. For now,
12546 * we just use some constant number as place holder.
12547 *
12548 * Return codes
12549 * 0 - successful
12550 * -ENOMEM - No availble memory
12551 * -EIO - The mailbox failed to complete successfully.
12552 **/
12553int
12554lpfc_fof_queue_create(struct lpfc_hba *phba)
12555{
12556 struct lpfc_queue *qdesc;
James Smartc176ffa2018-01-30 15:58:46 -080012557 uint32_t wqesize;
James Smart1ba981f2014-02-20 09:56:45 -050012558
12559 /* Create FOF EQ */
James Smart81b96ed2017-11-20 16:00:29 -080012560 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
12561 phba->sli4_hba.eq_esize,
James Smart1ba981f2014-02-20 09:56:45 -050012562 phba->sli4_hba.eq_ecount);
12563 if (!qdesc)
12564 goto out_error;
12565
James Smart7365f6f2018-02-22 08:18:46 -080012566 qdesc->qe_valid = 1;
James Smart1ba981f2014-02-20 09:56:45 -050012567 phba->sli4_hba.fof_eq = qdesc;
12568
James Smartf38fa0b2014-04-04 13:52:21 -040012569 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050012570
12571 /* Create OAS CQ */
James Smartc176ffa2018-01-30 15:58:46 -080012572 if (phba->enab_exp_wqcq_pages)
James Smarta51e41b2017-12-08 17:18:06 -080012573 qdesc = lpfc_sli4_queue_alloc(phba,
12574 LPFC_EXPANDED_PAGE_SIZE,
12575 phba->sli4_hba.cq_esize,
12576 LPFC_CQE_EXP_COUNT);
12577 else
12578 qdesc = lpfc_sli4_queue_alloc(phba,
12579 LPFC_DEFAULT_PAGE_SIZE,
12580 phba->sli4_hba.cq_esize,
12581 phba->sli4_hba.cq_ecount);
James Smart1ba981f2014-02-20 09:56:45 -050012582 if (!qdesc)
12583 goto out_error;
12584
James Smart7365f6f2018-02-22 08:18:46 -080012585 qdesc->qe_valid = 1;
James Smart1ba981f2014-02-20 09:56:45 -050012586 phba->sli4_hba.oas_cq = qdesc;
12587
12588 /* Create OAS WQ */
James Smartc176ffa2018-01-30 15:58:46 -080012589 if (phba->enab_exp_wqcq_pages) {
12590 wqesize = (phba->fcp_embed_io) ?
12591 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
James Smarta51e41b2017-12-08 17:18:06 -080012592 qdesc = lpfc_sli4_queue_alloc(phba,
12593 LPFC_EXPANDED_PAGE_SIZE,
James Smartc176ffa2018-01-30 15:58:46 -080012594 wqesize,
James Smarta51e41b2017-12-08 17:18:06 -080012595 LPFC_WQE_EXP_COUNT);
James Smartc176ffa2018-01-30 15:58:46 -080012596 } else
James Smarta51e41b2017-12-08 17:18:06 -080012597 qdesc = lpfc_sli4_queue_alloc(phba,
12598 LPFC_DEFAULT_PAGE_SIZE,
12599 phba->sli4_hba.wq_esize,
12600 phba->sli4_hba.wq_ecount);
James Smartc176ffa2018-01-30 15:58:46 -080012601
James Smart1ba981f2014-02-20 09:56:45 -050012602 if (!qdesc)
12603 goto out_error;
12604
12605 phba->sli4_hba.oas_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -080012606 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
James Smart1ba981f2014-02-20 09:56:45 -050012607
12608 }
12609 return 0;
12610
12611out_error:
12612 lpfc_fof_queue_destroy(phba);
12613 return -ENOMEM;
12614}
12615
12616/**
12617 * lpfc_fof_queue_destroy - Destroy all the fof queues
12618 * @phba: pointer to lpfc hba data structure.
12619 *
12620 * This routine is invoked to release all the SLI4 queues with the FC HBA
12621 * operation.
12622 *
12623 * Return codes
12624 * 0 - successful
12625 **/
12626int
12627lpfc_fof_queue_destroy(struct lpfc_hba *phba)
12628{
12629 /* Release FOF Event queue */
12630 if (phba->sli4_hba.fof_eq != NULL) {
12631 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
12632 phba->sli4_hba.fof_eq = NULL;
12633 }
12634
12635 /* Release OAS Completion queue */
12636 if (phba->sli4_hba.oas_cq != NULL) {
12637 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
12638 phba->sli4_hba.oas_cq = NULL;
12639 }
12640
12641 /* Release OAS Work queue */
12642 if (phba->sli4_hba.oas_wq != NULL) {
12643 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
12644 phba->sli4_hba.oas_wq = NULL;
12645 }
12646 return 0;
12647}
12648
dea31012005-04-17 16:05:31 -050012649MODULE_DEVICE_TABLE(pci, lpfc_id_table);
12650
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070012651static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060012652 .error_detected = lpfc_io_error_detected,
12653 .slot_reset = lpfc_io_slot_reset,
12654 .resume = lpfc_io_resume,
12655};
12656
dea31012005-04-17 16:05:31 -050012657static struct pci_driver lpfc_driver = {
12658 .name = LPFC_DRIVER_NAME,
12659 .id_table = lpfc_id_table,
12660 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012661 .remove = lpfc_pci_remove_one,
Anton Blanchard85e8a232017-02-13 08:49:20 +110012662 .shutdown = lpfc_pci_remove_one,
James Smart3a55b532008-12-04 22:38:54 -050012663 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040012664 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050012665 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050012666};
12667
James Smart3ef6d242012-01-18 16:23:48 -050012668static const struct file_operations lpfc_mgmt_fop = {
Al Viro858feac2013-04-14 22:39:37 -040012669 .owner = THIS_MODULE,
James Smart3ef6d242012-01-18 16:23:48 -050012670};
12671
12672static struct miscdevice lpfc_mgmt_dev = {
12673 .minor = MISC_DYNAMIC_MINOR,
12674 .name = "lpfcmgmt",
12675 .fops = &lpfc_mgmt_fop,
12676};
12677
James Smarte59058c2008-08-24 21:49:00 -040012678/**
James Smart3621a712009-04-06 18:47:14 -040012679 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040012680 *
12681 * This routine is to be invoked when the lpfc module is loaded into the
12682 * kernel. The special kernel macro module_init() is used to indicate the
12683 * role of this routine to the kernel as lpfc module entry point.
12684 *
12685 * Return codes
12686 * 0 - successful
12687 * -ENOMEM - FC attach transport failed
12688 * all others - failed
12689 */
dea31012005-04-17 16:05:31 -050012690static int __init
12691lpfc_init(void)
12692{
12693 int error = 0;
12694
12695 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012696 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050012697
James Smart3ef6d242012-01-18 16:23:48 -050012698 error = misc_register(&lpfc_mgmt_dev);
12699 if (error)
12700 printk(KERN_ERR "Could not register lpfcmgmt device, "
12701 "misc_register returned with status %d", error);
12702
James Smart458c0832016-07-06 12:36:07 -070012703 lpfc_transport_functions.vport_create = lpfc_vport_create;
12704 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
dea31012005-04-17 16:05:31 -050012705 lpfc_transport_template =
12706 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040012707 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050012708 return -ENOMEM;
James Smart458c0832016-07-06 12:36:07 -070012709 lpfc_vport_transport_template =
12710 fc_attach_transport(&lpfc_vport_transport_functions);
12711 if (lpfc_vport_transport_template == NULL) {
12712 fc_release_transport(lpfc_transport_template);
12713 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040012714 }
James Smart5fd11082018-03-05 12:04:04 -080012715 lpfc_nvme_cmd_template();
James Smartbd3061b2018-03-05 12:04:05 -080012716 lpfc_nvmet_cmd_template();
James Smart7bb03bb2013-04-17 20:19:16 -040012717
12718 /* Initialize in case vector mapping is needed */
James Smartb246de12013-05-31 17:03:07 -040012719 lpfc_used_cpu = NULL;
James Smart2ea259e2017-02-12 13:52:27 -080012720 lpfc_present_cpu = num_present_cpus();
James Smart7bb03bb2013-04-17 20:19:16 -040012721
dea31012005-04-17 16:05:31 -050012722 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050012723 if (error) {
dea31012005-04-17 16:05:31 -050012724 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070012725 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050012726 }
dea31012005-04-17 16:05:31 -050012727
12728 return error;
12729}
12730
James Smarte59058c2008-08-24 21:49:00 -040012731/**
James Smart3621a712009-04-06 18:47:14 -040012732 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040012733 *
12734 * This routine is invoked when the lpfc module is removed from the kernel.
12735 * The special kernel macro module_exit() is used to indicate the role of
12736 * this routine to the kernel as lpfc module exit point.
12737 */
dea31012005-04-17 16:05:31 -050012738static void __exit
12739lpfc_exit(void)
12740{
James Smart3ef6d242012-01-18 16:23:48 -050012741 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050012742 pci_unregister_driver(&lpfc_driver);
12743 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070012744 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050012745 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040012746 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
12747 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050012748 (1L << _dump_buf_data_order), _dump_buf_data);
12749 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
12750 }
12751
12752 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040012753 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
12754 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050012755 (1L << _dump_buf_dif_order), _dump_buf_dif);
12756 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
12757 }
James Smartb246de12013-05-31 17:03:07 -040012758 kfree(lpfc_used_cpu);
Johannes Thumshirn79739672015-08-31 16:48:11 -040012759 idr_destroy(&lpfc_hba_index);
dea31012005-04-17 16:05:31 -050012760}
12761
12762module_init(lpfc_init);
12763module_exit(lpfc_exit);
12764MODULE_LICENSE("GPL");
12765MODULE_DESCRIPTION(LPFC_MODULE_DESC);
James Smartd080abe2017-02-12 13:52:39 -080012766MODULE_AUTHOR("Broadcom");
dea31012005-04-17 16:05:31 -050012767MODULE_VERSION("0:" LPFC_DRIVER_VERSION);