blob: f539c554588cc751642fc81715e1ec3e9b363221 [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 Smartd080abe2017-02-12 13:52:39 -08004 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
James Smart50611572016-03-31 14:12:34 -07006 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * EMULEX and SLI are trademarks of Emulex. *
James Smartd080abe2017-02-12 13:52:39 -08008 * www.broadcom.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04009 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -050010 * *
11 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
dea31012005-04-17 16:05:31 -050022 *******************************************************************/
23
dea31012005-04-17 16:05:31 -050024#include <linux/blkdev.h>
25#include <linux/delay.h>
26#include <linux/dma-mapping.h>
27#include <linux/idr.h>
28#include <linux/interrupt.h>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040029#include <linux/module.h>
dea31012005-04-17 16:05:31 -050030#include <linux/kthread.h>
31#include <linux/pci.h>
32#include <linux/spinlock.h>
James Smart92d7f7b2007-06-17 19:56:38 -050033#include <linux/ctype.h>
James Smart0d878412009-10-02 15:16:56 -040034#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
James Smart52d52442011-05-24 11:42:45 -040036#include <linux/firmware.h>
James Smart3ef6d242012-01-18 16:23:48 -050037#include <linux/miscdevice.h>
James Smart7bb03bb2013-04-17 20:19:16 -040038#include <linux/percpu.h>
James Smart895427b2017-02-12 13:52:30 -080039#include <linux/msi.h>
Maurizio Lombardi286871a2017-08-23 16:55:48 -070040#include <linux/bitops.h>
dea31012005-04-17 16:05:31 -050041
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040042#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050043#include <scsi/scsi_device.h>
44#include <scsi/scsi_host.h>
45#include <scsi/scsi_transport_fc.h>
James Smart86c67372017-04-21 16:05:04 -070046#include <scsi/scsi_tcq.h>
47#include <scsi/fc/fc_fs.h>
48
49#include <linux/nvme-fc-driver.h>
dea31012005-04-17 16:05:31 -050050
James Smartda0436e2009-05-22 14:51:39 -040051#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050052#include "lpfc_hw.h"
53#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040054#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040055#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050056#include "lpfc_disc.h"
dea31012005-04-17 16:05:31 -050057#include "lpfc.h"
James Smart895427b2017-02-12 13:52:30 -080058#include "lpfc_scsi.h"
59#include "lpfc_nvme.h"
James Smart86c67372017-04-21 16:05:04 -070060#include "lpfc_nvmet.h"
dea31012005-04-17 16:05:31 -050061#include "lpfc_logmsg.h"
62#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050063#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050064#include "lpfc_version.h"
James Smart12f44452016-07-06 12:36:03 -070065#include "lpfc_ids.h"
dea31012005-04-17 16:05:31 -050066
James Smart81301a92008-12-04 22:39:46 -050067char *_dump_buf_data;
68unsigned long _dump_buf_data_order;
69char *_dump_buf_dif;
70unsigned long _dump_buf_dif_order;
71spinlock_t _dump_buf_lock;
72
James Smart7bb03bb2013-04-17 20:19:16 -040073/* Used when mapping IRQ vectors in a driver centric manner */
James Smartb246de12013-05-31 17:03:07 -040074uint16_t *lpfc_used_cpu;
75uint32_t lpfc_present_cpu;
James Smart7bb03bb2013-04-17 20:19:16 -040076
dea31012005-04-17 16:05:31 -050077static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
78static int lpfc_post_rcv_buf(struct lpfc_hba *);
James Smart5350d872011-10-10 21:33:49 -040079static int lpfc_sli4_queue_verify(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040080static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
81static int lpfc_setup_endian_order(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040082static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040083static void lpfc_free_els_sgl_list(struct lpfc_hba *);
James Smartf358dd02017-02-12 13:52:34 -080084static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040085static void lpfc_init_sgl_list(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040086static int lpfc_init_active_sgl_array(struct lpfc_hba *);
87static void lpfc_free_active_sgl(struct lpfc_hba *);
88static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
89static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
90static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
91static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
92static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
James Smart618a5232012-06-12 13:54:36 -040093static void lpfc_sli4_disable_intr(struct lpfc_hba *);
94static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
James Smart1ba981f2014-02-20 09:56:45 -050095static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
dea31012005-04-17 16:05:31 -050096
97static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050098static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -050099static DEFINE_IDR(lpfc_hba_index);
James Smartf358dd02017-02-12 13:52:34 -0800100#define LPFC_NVMET_BUF_POST 254
dea31012005-04-17 16:05:31 -0500101
James Smarte59058c2008-08-24 21:49:00 -0400102/**
James Smart3621a712009-04-06 18:47:14 -0400103 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
James Smarte59058c2008-08-24 21:49:00 -0400104 * @phba: pointer to lpfc hba data structure.
105 *
106 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
107 * mailbox command. It retrieves the revision information from the HBA and
108 * collects the Vital Product Data (VPD) about the HBA for preparing the
109 * configuration of the HBA.
110 *
111 * Return codes:
112 * 0 - success.
113 * -ERESTART - requests the SLI layer to reset the HBA and try again.
114 * Any other value - indicates an error.
115 **/
dea31012005-04-17 16:05:31 -0500116int
James Smart2e0fef82007-06-17 19:56:36 -0500117lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500118{
119 lpfc_vpd_t *vp = &phba->vpd;
120 int i = 0, rc;
121 LPFC_MBOXQ_t *pmb;
122 MAILBOX_t *mb;
123 char *lpfc_vpd_data = NULL;
124 uint16_t offset = 0;
125 static char licensed[56] =
126 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -0400127 static int init_key = 1;
dea31012005-04-17 16:05:31 -0500128
129 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
130 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500131 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500132 return -ENOMEM;
133 }
134
James Smart04c68492009-05-22 14:52:52 -0400135 mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -0500136 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -0500137
138 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -0400139 if (init_key) {
140 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -0500141
James Smart65a29c12006-07-06 15:50:50 -0400142 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
143 *ptext = cpu_to_be32(*ptext);
144 init_key = 0;
145 }
dea31012005-04-17 16:05:31 -0500146
147 lpfc_read_nv(phba, pmb);
148 memset((char*)mb->un.varRDnvp.rsvd3, 0,
149 sizeof (mb->un.varRDnvp.rsvd3));
150 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
151 sizeof (licensed));
152
153 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
154
155 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500156 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400157 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500158 "error, mbxCmd x%x READ_NVPARM, "
159 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500160 mb->mbxCommand, mb->mbxStatus);
161 mempool_free(pmb, phba->mbox_mem_pool);
162 return -ERESTART;
163 }
164 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500165 sizeof(phba->wwnn));
166 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
167 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500168 }
169
James Smart92d7f7b2007-06-17 19:56:38 -0500170 phba->sli3_options = 0x0;
171
dea31012005-04-17 16:05:31 -0500172 /* Setup and issue mailbox READ REV command */
173 lpfc_read_rev(phba, pmb);
174 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
175 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500176 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400177 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500178 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500179 mb->mbxCommand, mb->mbxStatus);
180 mempool_free( pmb, phba->mbox_mem_pool);
181 return -ERESTART;
182 }
183
James Smart92d7f7b2007-06-17 19:56:38 -0500184
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500185 /*
186 * The value of rr must be 1 since the driver set the cv field to 1.
187 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500188 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500189 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500190 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500191 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400192 "0440 Adapter failed to init, READ_REV has "
193 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500194 mempool_free(pmb, phba->mbox_mem_pool);
195 return -ERESTART;
dea31012005-04-17 16:05:31 -0500196 }
197
James Smart495a7142008-06-14 22:52:59 -0400198 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
199 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500200 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400201 }
James Smarted957682007-06-17 19:56:37 -0500202
dea31012005-04-17 16:05:31 -0500203 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500204 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500205 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500206 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
207 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
208 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
209 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500210 vp->rev.biuRev = mb->un.varRdRev.biuRev;
211 vp->rev.smRev = mb->un.varRdRev.smRev;
212 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
213 vp->rev.endecRev = mb->un.varRdRev.endecRev;
214 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
215 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
216 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
217 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
218 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
219 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
220
James Smart92d7f7b2007-06-17 19:56:38 -0500221 /* If the sli feature level is less then 9, we must
222 * tear down all RPIs and VPIs on link down if NPIV
223 * is enabled.
224 */
225 if (vp->rev.feaLevelHigh < 9)
226 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
227
dea31012005-04-17 16:05:31 -0500228 if (lpfc_is_LC_HBA(phba->pcidev->device))
229 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
230 sizeof (phba->RandomData));
231
dea31012005-04-17 16:05:31 -0500232 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500233 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
234 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400235 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500236 do {
James Smarta0c87cb2009-07-19 10:01:10 -0400237 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
dea31012005-04-17 16:05:31 -0500238 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
239
240 if (rc != MBX_SUCCESS) {
241 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400242 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500243 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500244 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500245 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500246 }
James Smart04c68492009-05-22 14:52:52 -0400247 /* dump mem may return a zero when finished or we got a
248 * mailbox error, either way we are done.
249 */
250 if (mb->un.varDmp.word_cnt == 0)
251 break;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500252 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
253 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400254 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
255 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500256 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500257 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500258 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
259 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500260
261 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500262out_free_mbox:
263 mempool_free(pmb, phba->mbox_mem_pool);
264 return 0;
265}
266
James Smarte59058c2008-08-24 21:49:00 -0400267/**
James Smart3621a712009-04-06 18:47:14 -0400268 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
James Smarte59058c2008-08-24 21:49:00 -0400269 * @phba: pointer to lpfc hba data structure.
270 * @pmboxq: pointer to the driver internal queue element for mailbox command.
271 *
272 * This is the completion handler for driver's configuring asynchronous event
273 * mailbox command to the device. If the mailbox command returns successfully,
274 * it will set internal async event support flag to 1; otherwise, it will
275 * set internal async event support flag to 0.
276 **/
James Smart57127f12007-10-27 13:37:05 -0400277static void
278lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
279{
James Smart04c68492009-05-22 14:52:52 -0400280 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
James Smart57127f12007-10-27 13:37:05 -0400281 phba->temp_sensor_support = 1;
282 else
283 phba->temp_sensor_support = 0;
284 mempool_free(pmboxq, phba->mbox_mem_pool);
285 return;
286}
287
James Smarte59058c2008-08-24 21:49:00 -0400288/**
James Smart3621a712009-04-06 18:47:14 -0400289 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
James Smart97207482008-12-04 22:39:19 -0500290 * @phba: pointer to lpfc hba data structure.
291 * @pmboxq: pointer to the driver internal queue element for mailbox command.
292 *
293 * This is the completion handler for dump mailbox command for getting
294 * wake up parameters. When this command complete, the response contain
295 * Option rom version of the HBA. This function translate the version number
296 * into a human readable string and store it in OptionROMVersion.
297 **/
298static void
299lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
300{
301 struct prog_id *prg;
302 uint32_t prog_id_word;
303 char dist = ' ';
304 /* character array used for decoding dist type. */
305 char dist_char[] = "nabx";
306
James Smart04c68492009-05-22 14:52:52 -0400307 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
James Smart9f1e1b52008-12-04 22:39:40 -0500308 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500309 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500310 }
James Smart97207482008-12-04 22:39:19 -0500311
312 prg = (struct prog_id *) &prog_id_word;
313
314 /* word 7 contain option rom version */
James Smart04c68492009-05-22 14:52:52 -0400315 prog_id_word = pmboxq->u.mb.un.varWords[7];
James Smart97207482008-12-04 22:39:19 -0500316
317 /* Decode the Option rom version word to a readable string */
318 if (prg->dist < 4)
319 dist = dist_char[prg->dist];
320
321 if ((prg->dist == 3) && (prg->num == 0))
James Smarta2fc4aef2014-09-03 12:57:55 -0400322 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
James Smart97207482008-12-04 22:39:19 -0500323 prg->ver, prg->rev, prg->lev);
324 else
James Smarta2fc4aef2014-09-03 12:57:55 -0400325 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
James Smart97207482008-12-04 22:39:19 -0500326 prg->ver, prg->rev, prg->lev,
327 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500328 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500329 return;
330}
331
332/**
James Smart05580562011-05-24 11:40:48 -0400333 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
334 * cfg_soft_wwnn, cfg_soft_wwpn
335 * @vport: pointer to lpfc vport data structure.
336 *
337 *
338 * Return codes
339 * None.
340 **/
341void
342lpfc_update_vport_wwn(struct lpfc_vport *vport)
343{
James Smartaeb3c812017-04-21 16:05:02 -0700344 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
345 u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0];
346
James Smart05580562011-05-24 11:40:48 -0400347 /* If the soft name exists then update it using the service params */
348 if (vport->phba->cfg_soft_wwnn)
349 u64_to_wwn(vport->phba->cfg_soft_wwnn,
350 vport->fc_sparam.nodeName.u.wwn);
351 if (vport->phba->cfg_soft_wwpn)
352 u64_to_wwn(vport->phba->cfg_soft_wwpn,
353 vport->fc_sparam.portName.u.wwn);
354
355 /*
356 * If the name is empty or there exists a soft name
357 * then copy the service params name, otherwise use the fc name
358 */
359 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
360 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
361 sizeof(struct lpfc_name));
362 else
363 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
364 sizeof(struct lpfc_name));
365
James Smartaeb3c812017-04-21 16:05:02 -0700366 /*
367 * If the port name has changed, then set the Param changes flag
368 * to unreg the login
369 */
370 if (vport->fc_portname.u.wwn[0] != 0 &&
371 memcmp(&vport->fc_portname, &vport->fc_sparam.portName,
372 sizeof(struct lpfc_name)))
373 vport->vport_flag |= FAWWPN_PARAM_CHG;
374
375 if (vport->fc_portname.u.wwn[0] == 0 ||
376 vport->phba->cfg_soft_wwpn ||
377 (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) ||
378 vport->vport_flag & FAWWPN_SET) {
James Smart05580562011-05-24 11:40:48 -0400379 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
380 sizeof(struct lpfc_name));
James Smartaeb3c812017-04-21 16:05:02 -0700381 vport->vport_flag &= ~FAWWPN_SET;
382 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR)
383 vport->vport_flag |= FAWWPN_SET;
384 }
James Smart05580562011-05-24 11:40:48 -0400385 else
386 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
387 sizeof(struct lpfc_name));
388}
389
390/**
James Smart3621a712009-04-06 18:47:14 -0400391 * lpfc_config_port_post - Perform lpfc initialization after config port
James Smarte59058c2008-08-24 21:49:00 -0400392 * @phba: pointer to lpfc hba data structure.
393 *
394 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
395 * command call. It performs all internal resource and state setups on the
396 * port: post IOCB buffers, enable appropriate host interrupt attentions,
397 * ELS ring timers, etc.
398 *
399 * Return codes
400 * 0 - success.
401 * Any other value - error.
402 **/
dea31012005-04-17 16:05:31 -0500403int
James Smart2e0fef82007-06-17 19:56:36 -0500404lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500405{
James Smart2e0fef82007-06-17 19:56:36 -0500406 struct lpfc_vport *vport = phba->pport;
James Smarta257bf92009-04-06 18:48:10 -0400407 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500408 LPFC_MBOXQ_t *pmb;
409 MAILBOX_t *mb;
410 struct lpfc_dmabuf *mp;
411 struct lpfc_sli *psli = &phba->sli;
412 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500413 int i, j;
414 int rc;
dea31012005-04-17 16:05:31 -0500415
James Smart7af67052007-10-27 13:38:11 -0400416 spin_lock_irq(&phba->hbalock);
417 /*
418 * If the Config port completed correctly the HBA is not
419 * over heated any more.
420 */
421 if (phba->over_temp_state == HBA_OVER_TEMP)
422 phba->over_temp_state = HBA_NORMAL_TEMP;
423 spin_unlock_irq(&phba->hbalock);
424
dea31012005-04-17 16:05:31 -0500425 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
426 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500427 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500428 return -ENOMEM;
429 }
James Smart04c68492009-05-22 14:52:52 -0400430 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500431
dea31012005-04-17 16:05:31 -0500432 /* Get login parameters for NID. */
James Smart9f1177a2010-02-26 14:12:57 -0500433 rc = lpfc_read_sparam(phba, pmb, 0);
434 if (rc) {
435 mempool_free(pmb, phba->mbox_mem_pool);
436 return -ENOMEM;
437 }
438
James Smarted957682007-06-17 19:56:37 -0500439 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500440 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500441 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400442 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500443 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500444 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500445 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500446 mp = (struct lpfc_dmabuf *) pmb->context1;
James Smart9f1177a2010-02-26 14:12:57 -0500447 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500448 lpfc_mbuf_free(phba, mp->virt, mp->phys);
449 kfree(mp);
450 return -EIO;
451 }
452
453 mp = (struct lpfc_dmabuf *) pmb->context1;
454
James Smart2e0fef82007-06-17 19:56:36 -0500455 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500456 lpfc_mbuf_free(phba, mp->virt, mp->phys);
457 kfree(mp);
458 pmb->context1 = NULL;
James Smart05580562011-05-24 11:40:48 -0400459 lpfc_update_vport_wwn(vport);
James Smarta257bf92009-04-06 18:48:10 -0400460
461 /* Update the fc_host data structures with new wwn. */
462 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
463 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart21e9a0a2009-05-22 14:53:21 -0400464 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smarta257bf92009-04-06 18:48:10 -0400465
dea31012005-04-17 16:05:31 -0500466 /* If no serial number in VPD data, use low 6 bytes of WWNN */
467 /* This should be consolidated into parse_vpd ? - mr */
468 if (phba->SerialNumber[0] == 0) {
469 uint8_t *outptr;
470
James Smart2e0fef82007-06-17 19:56:36 -0500471 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500472 for (i = 0; i < 12; i++) {
473 status = *outptr++;
474 j = ((status & 0xf0) >> 4);
475 if (j <= 9)
476 phba->SerialNumber[i] =
477 (char)((uint8_t) 0x30 + (uint8_t) j);
478 else
479 phba->SerialNumber[i] =
480 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
481 i++;
482 j = (status & 0xf);
483 if (j <= 9)
484 phba->SerialNumber[i] =
485 (char)((uint8_t) 0x30 + (uint8_t) j);
486 else
487 phba->SerialNumber[i] =
488 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
489 }
490 }
491
dea31012005-04-17 16:05:31 -0500492 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500493 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500494 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500495 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400496 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500497 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500498 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500499 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500500 mempool_free( pmb, phba->mbox_mem_pool);
501 return -EIO;
502 }
503
James Smarta0c87cb2009-07-19 10:01:10 -0400504 /* Check if the port is disabled */
505 lpfc_sli_read_link_ste(phba);
506
dea31012005-04-17 16:05:31 -0500507 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -0400508 i = (mb->un.varRdConfig.max_xri + 1);
509 if (phba->cfg_hba_queue_depth > i) {
510 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
511 "3359 HBA queue depth changed from %d to %d\n",
512 phba->cfg_hba_queue_depth, i);
513 phba->cfg_hba_queue_depth = i;
514 }
515
516 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
517 i = (mb->un.varRdConfig.max_xri >> 3);
518 if (phba->pport->cfg_lun_queue_depth > i) {
519 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
520 "3360 LUN queue depth changed from %d to %d\n",
521 phba->pport->cfg_lun_queue_depth, i);
522 phba->pport->cfg_lun_queue_depth = i;
523 }
dea31012005-04-17 16:05:31 -0500524
525 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500526
527 /* Get the default values for Model Name and Description */
528 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
529
James Smart2e0fef82007-06-17 19:56:36 -0500530 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500531
James Smart0b727fe2007-10-27 13:37:25 -0400532 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smart895427b2017-02-12 13:52:30 -0800533 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
534 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
535 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
536 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500537
538 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500539 if (phba->sli_rev != 3)
540 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500541
James Smart93996272008-08-24 21:50:30 -0400542 /*
543 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
544 */
545 if (phba->intr_type == MSIX) {
546 rc = lpfc_config_msi(phba, pmb);
547 if (rc) {
548 mempool_free(pmb, phba->mbox_mem_pool);
549 return -EIO;
550 }
551 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
552 if (rc != MBX_SUCCESS) {
553 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
554 "0352 Config MSI mailbox command "
555 "failed, mbxCmd x%x, mbxStatus x%x\n",
James Smart04c68492009-05-22 14:52:52 -0400556 pmb->u.mb.mbxCommand,
557 pmb->u.mb.mbxStatus);
James Smart93996272008-08-24 21:50:30 -0400558 mempool_free(pmb, phba->mbox_mem_pool);
559 return -EIO;
560 }
561 }
562
James Smart04c68492009-05-22 14:52:52 -0400563 spin_lock_irq(&phba->hbalock);
James Smart93996272008-08-24 21:50:30 -0400564 /* Initialize ERATT handling flag */
565 phba->hba_flag &= ~HBA_ERATT_HANDLED;
566
dea31012005-04-17 16:05:31 -0500567 /* Enable appropriate host interrupts */
James Smart9940b972011-03-11 16:06:12 -0500568 if (lpfc_readl(phba->HCregaddr, &status)) {
569 spin_unlock_irq(&phba->hbalock);
570 return -EIO;
571 }
dea31012005-04-17 16:05:31 -0500572 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
573 if (psli->num_rings > 0)
574 status |= HC_R0INT_ENA;
575 if (psli->num_rings > 1)
576 status |= HC_R1INT_ENA;
577 if (psli->num_rings > 2)
578 status |= HC_R2INT_ENA;
579 if (psli->num_rings > 3)
580 status |= HC_R3INT_ENA;
581
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500582 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
583 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400584 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500585
dea31012005-04-17 16:05:31 -0500586 writel(status, phba->HCregaddr);
587 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500588 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500589
James Smart93996272008-08-24 21:50:30 -0400590 /* Set up ring-0 (ELS) timer */
591 timeout = phba->fc_ratov * 2;
James Smart256ec0d2013-04-17 20:14:58 -0400592 mod_timer(&vport->els_tmofunc,
593 jiffies + msecs_to_jiffies(1000 * timeout));
James Smart93996272008-08-24 21:50:30 -0400594 /* Set up heart beat (HB) timer */
James Smart256ec0d2013-04-17 20:14:58 -0400595 mod_timer(&phba->hb_tmofunc,
596 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -0500597 phba->hb_outstanding = 0;
598 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400599 /* Set up error attention (ERATT) polling timer */
James Smart256ec0d2013-04-17 20:14:58 -0400600 mod_timer(&phba->eratt_poll,
James Smart65791f12016-07-06 12:35:56 -0700601 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
dea31012005-04-17 16:05:31 -0500602
James Smarta0c87cb2009-07-19 10:01:10 -0400603 if (phba->hba_flag & LINK_DISABLED) {
604 lpfc_printf_log(phba,
605 KERN_ERR, LOG_INIT,
606 "2598 Adapter Link is disabled.\n");
607 lpfc_down_link(phba, pmb);
608 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
609 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
610 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
611 lpfc_printf_log(phba,
612 KERN_ERR, LOG_INIT,
613 "2599 Adapter failed to issue DOWN_LINK"
614 " mbox command rc 0x%x\n", rc);
615
616 mempool_free(pmb, phba->mbox_mem_pool);
617 return -EIO;
618 }
James Smarte40a02c2010-02-26 14:13:54 -0500619 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
James Smart026abb82011-12-13 13:20:45 -0500620 mempool_free(pmb, phba->mbox_mem_pool);
621 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
622 if (rc)
623 return rc;
dea31012005-04-17 16:05:31 -0500624 }
625 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400626 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500627 if (!pmb) {
628 phba->link_state = LPFC_HBA_ERROR;
629 return -ENOMEM;
630 }
631
James Smart57127f12007-10-27 13:37:05 -0400632 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
633 pmb->mbox_cmpl = lpfc_config_async_cmpl;
634 pmb->vport = phba->pport;
635 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500636
James Smart57127f12007-10-27 13:37:05 -0400637 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
638 lpfc_printf_log(phba,
639 KERN_ERR,
640 LOG_INIT,
641 "0456 Adapter failed to issue "
James Smarte4e74272009-07-19 10:01:38 -0400642 "ASYNCEVT_ENABLE mbox status x%x\n",
James Smart57127f12007-10-27 13:37:05 -0400643 rc);
644 mempool_free(pmb, phba->mbox_mem_pool);
645 }
James Smart97207482008-12-04 22:39:19 -0500646
647 /* Get Option rom version */
648 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500649 if (!pmb) {
650 phba->link_state = LPFC_HBA_ERROR;
651 return -ENOMEM;
652 }
653
James Smart97207482008-12-04 22:39:19 -0500654 lpfc_dump_wakeup_param(phba, pmb);
655 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
656 pmb->vport = phba->pport;
657 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
658
659 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
660 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
James Smarte4e74272009-07-19 10:01:38 -0400661 "to get Option ROM version status x%x\n", rc);
James Smart97207482008-12-04 22:39:19 -0500662 mempool_free(pmb, phba->mbox_mem_pool);
663 }
664
James Smartd7c255b2008-08-24 21:50:00 -0400665 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400666}
667
James Smarte59058c2008-08-24 21:49:00 -0400668/**
James Smart84d1b002010-02-12 14:42:33 -0500669 * lpfc_hba_init_link - Initialize the FC link
670 * @phba: pointer to lpfc hba data structure.
James Smart6e7288d2010-06-07 15:23:35 -0400671 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500672 *
673 * This routine will issue the INIT_LINK mailbox command call.
674 * It is available to other drivers through the lpfc_hba data
675 * structure for use as a delayed link up mechanism with the
676 * module parameter lpfc_suppress_link_up.
677 *
678 * Return code
679 * 0 - success
680 * Any other value - error
681 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400682static int
James Smart6e7288d2010-06-07 15:23:35 -0400683lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500684{
James Smart1b511972011-12-13 13:23:09 -0500685 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
686}
687
688/**
689 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
690 * @phba: pointer to lpfc hba data structure.
691 * @fc_topology: desired fc topology.
692 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
693 *
694 * This routine will issue the INIT_LINK mailbox command call.
695 * It is available to other drivers through the lpfc_hba data
696 * structure for use as a delayed link up mechanism with the
697 * module parameter lpfc_suppress_link_up.
698 *
699 * Return code
700 * 0 - success
701 * Any other value - error
702 **/
703int
704lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
705 uint32_t flag)
706{
James Smart84d1b002010-02-12 14:42:33 -0500707 struct lpfc_vport *vport = phba->pport;
708 LPFC_MBOXQ_t *pmb;
709 MAILBOX_t *mb;
710 int rc;
711
712 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
713 if (!pmb) {
714 phba->link_state = LPFC_HBA_ERROR;
715 return -ENOMEM;
716 }
717 mb = &pmb->u.mb;
718 pmb->vport = vport;
719
James Smart026abb82011-12-13 13:20:45 -0500720 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
721 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
722 !(phba->lmt & LMT_1Gb)) ||
723 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
724 !(phba->lmt & LMT_2Gb)) ||
725 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
726 !(phba->lmt & LMT_4Gb)) ||
727 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
728 !(phba->lmt & LMT_8Gb)) ||
729 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
730 !(phba->lmt & LMT_10Gb)) ||
731 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
James Smartd38dd522015-08-31 16:48:17 -0400732 !(phba->lmt & LMT_16Gb)) ||
733 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
734 !(phba->lmt & LMT_32Gb))) {
James Smart026abb82011-12-13 13:20:45 -0500735 /* Reset link speed to auto */
736 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
737 "1302 Invalid speed for this board:%d "
738 "Reset link speed to auto.\n",
739 phba->cfg_link_speed);
740 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
741 }
James Smart1b511972011-12-13 13:23:09 -0500742 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
James Smart84d1b002010-02-12 14:42:33 -0500743 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart1b511972011-12-13 13:23:09 -0500744 if (phba->sli_rev < LPFC_SLI_REV4)
745 lpfc_set_loopback_flag(phba);
James Smart6e7288d2010-06-07 15:23:35 -0400746 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart76a95d72010-11-20 23:11:48 -0500747 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
James Smart84d1b002010-02-12 14:42:33 -0500748 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
749 "0498 Adapter failed to init, mbxCmd x%x "
750 "INIT_LINK, mbxStatus x%x\n",
751 mb->mbxCommand, mb->mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -0500752 if (phba->sli_rev <= LPFC_SLI_REV3) {
753 /* Clear all interrupt enable conditions */
754 writel(0, phba->HCregaddr);
755 readl(phba->HCregaddr); /* flush */
756 /* Clear all pending interrupts */
757 writel(0xffffffff, phba->HAregaddr);
758 readl(phba->HAregaddr); /* flush */
759 }
James Smart84d1b002010-02-12 14:42:33 -0500760 phba->link_state = LPFC_HBA_ERROR;
James Smart6e7288d2010-06-07 15:23:35 -0400761 if (rc != MBX_BUSY || flag == MBX_POLL)
James Smart84d1b002010-02-12 14:42:33 -0500762 mempool_free(pmb, phba->mbox_mem_pool);
763 return -EIO;
764 }
James Smarte40a02c2010-02-26 14:13:54 -0500765 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
James Smart6e7288d2010-06-07 15:23:35 -0400766 if (flag == MBX_POLL)
767 mempool_free(pmb, phba->mbox_mem_pool);
James Smart84d1b002010-02-12 14:42:33 -0500768
769 return 0;
770}
771
772/**
773 * lpfc_hba_down_link - this routine downs the FC link
James Smart6e7288d2010-06-07 15:23:35 -0400774 * @phba: pointer to lpfc hba data structure.
775 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500776 *
777 * This routine will issue the DOWN_LINK mailbox command call.
778 * It is available to other drivers through the lpfc_hba data
779 * structure for use to stop the link.
780 *
781 * Return code
782 * 0 - success
783 * Any other value - error
784 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400785static int
James Smart6e7288d2010-06-07 15:23:35 -0400786lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500787{
788 LPFC_MBOXQ_t *pmb;
789 int rc;
790
791 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
792 if (!pmb) {
793 phba->link_state = LPFC_HBA_ERROR;
794 return -ENOMEM;
795 }
796
797 lpfc_printf_log(phba,
798 KERN_ERR, LOG_INIT,
799 "0491 Adapter Link is disabled.\n");
800 lpfc_down_link(phba, pmb);
801 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart6e7288d2010-06-07 15:23:35 -0400802 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart84d1b002010-02-12 14:42:33 -0500803 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
804 lpfc_printf_log(phba,
805 KERN_ERR, LOG_INIT,
806 "2522 Adapter failed to issue DOWN_LINK"
807 " mbox command rc 0x%x\n", rc);
808
809 mempool_free(pmb, phba->mbox_mem_pool);
810 return -EIO;
811 }
James Smart6e7288d2010-06-07 15:23:35 -0400812 if (flag == MBX_POLL)
813 mempool_free(pmb, phba->mbox_mem_pool);
814
James Smart84d1b002010-02-12 14:42:33 -0500815 return 0;
816}
817
818/**
James Smart3621a712009-04-06 18:47:14 -0400819 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400820 * @phba: pointer to lpfc HBA data structure.
821 *
822 * This routine will do LPFC uninitialization before the HBA is reset when
823 * bringing down the SLI Layer.
824 *
825 * Return codes
826 * 0 - success.
827 * Any other value - error.
828 **/
dea31012005-04-17 16:05:31 -0500829int
James Smart2e0fef82007-06-17 19:56:36 -0500830lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500831{
James Smart1b32f6a2008-02-08 18:49:39 -0500832 struct lpfc_vport **vports;
833 int i;
James Smart3772a992009-05-22 14:50:54 -0400834
835 if (phba->sli_rev <= LPFC_SLI_REV3) {
836 /* Disable interrupts */
837 writel(0, phba->HCregaddr);
838 readl(phba->HCregaddr); /* flush */
839 }
dea31012005-04-17 16:05:31 -0500840
James Smart1b32f6a2008-02-08 18:49:39 -0500841 if (phba->pport->load_flag & FC_UNLOADING)
842 lpfc_cleanup_discovery_resources(phba->pport);
843 else {
844 vports = lpfc_create_vport_work_array(phba);
845 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -0400846 for (i = 0; i <= phba->max_vports &&
847 vports[i] != NULL; i++)
James Smart1b32f6a2008-02-08 18:49:39 -0500848 lpfc_cleanup_discovery_resources(vports[i]);
849 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500850 }
851 return 0;
dea31012005-04-17 16:05:31 -0500852}
853
James Smarte59058c2008-08-24 21:49:00 -0400854/**
James Smart68e814f2014-05-21 08:04:59 -0400855 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
856 * rspiocb which got deferred
857 *
858 * @phba: pointer to lpfc HBA data structure.
859 *
860 * This routine will cleanup completed slow path events after HBA is reset
861 * when bringing down the SLI Layer.
862 *
863 *
864 * Return codes
865 * void.
866 **/
867static void
868lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
869{
870 struct lpfc_iocbq *rspiocbq;
871 struct hbq_dmabuf *dmabuf;
872 struct lpfc_cq_event *cq_event;
873
874 spin_lock_irq(&phba->hbalock);
875 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
876 spin_unlock_irq(&phba->hbalock);
877
878 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
879 /* Get the response iocb from the head of work queue */
880 spin_lock_irq(&phba->hbalock);
881 list_remove_head(&phba->sli4_hba.sp_queue_event,
882 cq_event, struct lpfc_cq_event, list);
883 spin_unlock_irq(&phba->hbalock);
884
885 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
886 case CQE_CODE_COMPL_WQE:
887 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
888 cq_event);
889 lpfc_sli_release_iocbq(phba, rspiocbq);
890 break;
891 case CQE_CODE_RECEIVE:
892 case CQE_CODE_RECEIVE_V1:
893 dmabuf = container_of(cq_event, struct hbq_dmabuf,
894 cq_event);
895 lpfc_in_buf_free(phba, &dmabuf->dbuf);
896 }
897 }
898}
899
900/**
James Smartbcece5f2014-04-04 13:51:34 -0400901 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
902 * @phba: pointer to lpfc HBA data structure.
903 *
904 * This routine will cleanup posted ELS buffers after the HBA is reset
905 * when bringing down the SLI Layer.
906 *
907 *
908 * Return codes
909 * void.
910 **/
911static void
912lpfc_hba_free_post_buf(struct lpfc_hba *phba)
913{
914 struct lpfc_sli *psli = &phba->sli;
915 struct lpfc_sli_ring *pring;
916 struct lpfc_dmabuf *mp, *next_mp;
James Smart07eab622014-04-04 13:51:44 -0400917 LIST_HEAD(buflist);
918 int count;
James Smartbcece5f2014-04-04 13:51:34 -0400919
920 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
921 lpfc_sli_hbqbuf_free_all(phba);
922 else {
923 /* Cleanup preposted buffers on the ELS ring */
James Smart895427b2017-02-12 13:52:30 -0800924 pring = &psli->sli3_ring[LPFC_ELS_RING];
James Smart07eab622014-04-04 13:51:44 -0400925 spin_lock_irq(&phba->hbalock);
926 list_splice_init(&pring->postbufq, &buflist);
927 spin_unlock_irq(&phba->hbalock);
928
929 count = 0;
930 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
James Smartbcece5f2014-04-04 13:51:34 -0400931 list_del(&mp->list);
James Smart07eab622014-04-04 13:51:44 -0400932 count++;
James Smartbcece5f2014-04-04 13:51:34 -0400933 lpfc_mbuf_free(phba, mp->virt, mp->phys);
934 kfree(mp);
935 }
James Smart07eab622014-04-04 13:51:44 -0400936
937 spin_lock_irq(&phba->hbalock);
938 pring->postbufq_cnt -= count;
James Smartbcece5f2014-04-04 13:51:34 -0400939 spin_unlock_irq(&phba->hbalock);
940 }
941}
942
943/**
944 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
945 * @phba: pointer to lpfc HBA data structure.
946 *
947 * This routine will cleanup the txcmplq after the HBA is reset when bringing
948 * down the SLI Layer.
949 *
950 * Return codes
951 * void
952 **/
953static void
954lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
955{
956 struct lpfc_sli *psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -0800957 struct lpfc_queue *qp = NULL;
James Smartbcece5f2014-04-04 13:51:34 -0400958 struct lpfc_sli_ring *pring;
959 LIST_HEAD(completions);
960 int i;
961
James Smart895427b2017-02-12 13:52:30 -0800962 if (phba->sli_rev != LPFC_SLI_REV4) {
963 for (i = 0; i < psli->num_rings; i++) {
964 pring = &psli->sli3_ring[i];
James Smartbcece5f2014-04-04 13:51:34 -0400965 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -0800966 /* At this point in time the HBA is either reset or DOA
967 * Nothing should be on txcmplq as it will
968 * NEVER complete.
969 */
970 list_splice_init(&pring->txcmplq, &completions);
971 pring->txcmplq_cnt = 0;
James Smartbcece5f2014-04-04 13:51:34 -0400972 spin_unlock_irq(&phba->hbalock);
973
James Smart895427b2017-02-12 13:52:30 -0800974 lpfc_sli_abort_iocb_ring(phba, pring);
975 }
James Smartbcece5f2014-04-04 13:51:34 -0400976 /* Cancel all the IOCBs from the completions list */
James Smart895427b2017-02-12 13:52:30 -0800977 lpfc_sli_cancel_iocbs(phba, &completions,
978 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
979 return;
980 }
981 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
982 pring = qp->pring;
983 if (!pring)
984 continue;
985 spin_lock_irq(&pring->ring_lock);
986 list_splice_init(&pring->txcmplq, &completions);
987 pring->txcmplq_cnt = 0;
988 spin_unlock_irq(&pring->ring_lock);
James Smartbcece5f2014-04-04 13:51:34 -0400989 lpfc_sli_abort_iocb_ring(phba, pring);
990 }
James Smart895427b2017-02-12 13:52:30 -0800991 /* Cancel all the IOCBs from the completions list */
992 lpfc_sli_cancel_iocbs(phba, &completions,
993 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smartbcece5f2014-04-04 13:51:34 -0400994}
995
996/**
James Smart3772a992009-05-22 14:50:54 -0400997 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smartbcece5f2014-04-04 13:51:34 -0400998 int i;
James Smarte59058c2008-08-24 21:49:00 -0400999 * @phba: pointer to lpfc HBA data structure.
1000 *
1001 * This routine will do uninitialization after the HBA is reset when bring
1002 * down the SLI Layer.
1003 *
1004 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001005 * 0 - success.
James Smarte59058c2008-08-24 21:49:00 -04001006 * Any other value - error.
1007 **/
James Smart3772a992009-05-22 14:50:54 -04001008static int
1009lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001010{
James Smartbcece5f2014-04-04 13:51:34 -04001011 lpfc_hba_free_post_buf(phba);
1012 lpfc_hba_clean_txcmplq(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001013 return 0;
1014}
James Smart5af5eee2010-10-22 11:06:38 -04001015
James Smartda0436e2009-05-22 14:51:39 -04001016/**
1017 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
1018 * @phba: pointer to lpfc HBA data structure.
1019 *
1020 * This routine will do uninitialization after the HBA is reset when bring
1021 * down the SLI Layer.
1022 *
1023 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001024 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001025 * Any other value - error.
1026 **/
1027static int
1028lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1029{
1030 struct lpfc_scsi_buf *psb, *psb_next;
James Smart86c67372017-04-21 16:05:04 -07001031 struct lpfc_nvmet_rcv_ctx *ctxp, *ctxp_next;
James Smartda0436e2009-05-22 14:51:39 -04001032 LIST_HEAD(aborts);
James Smart895427b2017-02-12 13:52:30 -08001033 LIST_HEAD(nvme_aborts);
James Smart86c67372017-04-21 16:05:04 -07001034 LIST_HEAD(nvmet_aborts);
James Smartda0436e2009-05-22 14:51:39 -04001035 unsigned long iflag = 0;
James Smart0f65ff62010-02-26 14:14:23 -05001036 struct lpfc_sglq *sglq_entry = NULL;
James Smartcf1a1d32017-12-08 17:18:03 -08001037 int cnt;
James Smart0f65ff62010-02-26 14:14:23 -05001038
James Smart895427b2017-02-12 13:52:30 -08001039
1040 lpfc_sli_hbqbuf_free_all(phba);
James Smartbcece5f2014-04-04 13:51:34 -04001041 lpfc_hba_clean_txcmplq(phba);
1042
James Smartda0436e2009-05-22 14:51:39 -04001043 /* At this point in time the HBA is either reset or DOA. Either
1044 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
James Smart895427b2017-02-12 13:52:30 -08001045 * on the lpfc_els_sgl_list so that it can either be freed if the
James Smartda0436e2009-05-22 14:51:39 -04001046 * driver is unloading or reposted if the driver is restarting
1047 * the port.
1048 */
James Smart895427b2017-02-12 13:52:30 -08001049 spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */
James Smartda0436e2009-05-22 14:51:39 -04001050 /* scsl_buf_list */
James Smart895427b2017-02-12 13:52:30 -08001051 /* sgl_list_lock required because worker thread uses this
James Smartda0436e2009-05-22 14:51:39 -04001052 * list.
1053 */
James Smart895427b2017-02-12 13:52:30 -08001054 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05001055 list_for_each_entry(sglq_entry,
1056 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1057 sglq_entry->state = SGL_FREED;
1058
James Smartda0436e2009-05-22 14:51:39 -04001059 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
James Smart895427b2017-02-12 13:52:30 -08001060 &phba->sli4_hba.lpfc_els_sgl_list);
1061
James Smartf358dd02017-02-12 13:52:34 -08001062
James Smart895427b2017-02-12 13:52:30 -08001063 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04001064 /* abts_scsi_buf_list_lock required because worker thread uses this
1065 * list.
1066 */
James Smart895427b2017-02-12 13:52:30 -08001067 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
1068 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1069 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
1070 &aborts);
1071 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1072 }
1073
1074 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1075 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1076 list_splice_init(&phba->sli4_hba.lpfc_abts_nvme_buf_list,
1077 &nvme_aborts);
James Smart86c67372017-04-21 16:05:04 -07001078 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1079 &nvmet_aborts);
James Smart895427b2017-02-12 13:52:30 -08001080 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1081 }
1082
James Smartda0436e2009-05-22 14:51:39 -04001083 spin_unlock_irq(&phba->hbalock);
1084
1085 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1086 psb->pCmd = NULL;
1087 psb->status = IOSTAT_SUCCESS;
1088 }
James Smarta40fc5f2013-04-17 20:17:40 -04001089 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1090 list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
1091 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
James Smart68e814f2014-05-21 08:04:59 -04001092
James Smart86c67372017-04-21 16:05:04 -07001093 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smartcf1a1d32017-12-08 17:18:03 -08001094 cnt = 0;
James Smart86c67372017-04-21 16:05:04 -07001095 list_for_each_entry_safe(psb, psb_next, &nvme_aborts, list) {
1096 psb->pCmd = NULL;
1097 psb->status = IOSTAT_SUCCESS;
James Smartcf1a1d32017-12-08 17:18:03 -08001098 cnt++;
James Smart86c67372017-04-21 16:05:04 -07001099 }
1100 spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag);
James Smartcf1a1d32017-12-08 17:18:03 -08001101 phba->put_nvme_bufs += cnt;
James Smart86c67372017-04-21 16:05:04 -07001102 list_splice(&nvme_aborts, &phba->lpfc_nvme_buf_list_put);
1103 spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag);
1104
1105 list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) {
1106 ctxp->flag &= ~(LPFC_NVMET_XBUSY | LPFC_NVMET_ABORT_OP);
James Smart6c621a22017-05-15 15:20:45 -07001107 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
James Smart86c67372017-04-21 16:05:04 -07001108 }
James Smart895427b2017-02-12 13:52:30 -08001109 }
James Smart895427b2017-02-12 13:52:30 -08001110
James Smart68e814f2014-05-21 08:04:59 -04001111 lpfc_sli4_free_sp_events(phba);
James Smartda0436e2009-05-22 14:51:39 -04001112 return 0;
1113}
1114
1115/**
1116 * lpfc_hba_down_post - Wrapper func for hba down post routine
1117 * @phba: pointer to lpfc HBA data structure.
1118 *
1119 * This routine wraps the actual SLI3 or SLI4 routine for performing
1120 * uninitialization after the HBA is reset when bring down the SLI Layer.
1121 *
1122 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001123 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001124 * Any other value - error.
1125 **/
1126int
1127lpfc_hba_down_post(struct lpfc_hba *phba)
1128{
1129 return (*phba->lpfc_hba_down_post)(phba);
1130}
Jamie Wellnitz41415862006-02-28 19:25:27 -05001131
James Smarte59058c2008-08-24 21:49:00 -04001132/**
James Smart3621a712009-04-06 18:47:14 -04001133 * lpfc_hb_timeout - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001134 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1135 *
1136 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1137 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1138 * work-port-events bitmap and the worker thread is notified. This timeout
1139 * event will be used by the worker thread to invoke the actual timeout
1140 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1141 * be performed in the timeout handler and the HBA timeout event bit shall
1142 * be cleared by the worker thread after it has taken the event bitmap out.
1143 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001144static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07001145lpfc_hb_timeout(struct timer_list *t)
James Smart858c9f62007-06-17 19:56:39 -05001146{
1147 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001148 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -05001149 unsigned long iflag;
1150
Kees Cookf22eb4d2017-09-06 20:24:26 -07001151 phba = from_timer(phba, t, hb_tmofunc);
James Smart93996272008-08-24 21:50:30 -04001152
1153 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -05001154 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001155 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1156 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -05001157 phba->pport->work_port_events |= WORKER_HB_TMO;
1158 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1159
James Smart93996272008-08-24 21:50:30 -04001160 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -04001161 if (!tmo_posted)
1162 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -05001163 return;
1164}
1165
James Smarte59058c2008-08-24 21:49:00 -04001166/**
James Smart19ca7602010-11-20 23:11:55 -05001167 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1168 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1169 *
1170 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1171 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1172 * work-port-events bitmap and the worker thread is notified. This timeout
1173 * event will be used by the worker thread to invoke the actual timeout
1174 * handler routine, lpfc_rrq_handler. Any periodical operations will
1175 * be performed in the timeout handler and the RRQ timeout event bit shall
1176 * be cleared by the worker thread after it has taken the event bitmap out.
1177 **/
1178static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07001179lpfc_rrq_timeout(struct timer_list *t)
James Smart19ca7602010-11-20 23:11:55 -05001180{
1181 struct lpfc_hba *phba;
James Smart19ca7602010-11-20 23:11:55 -05001182 unsigned long iflag;
1183
Kees Cookf22eb4d2017-09-06 20:24:26 -07001184 phba = from_timer(phba, t, rrq_tmr);
James Smart19ca7602010-11-20 23:11:55 -05001185 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001186 if (!(phba->pport->load_flag & FC_UNLOADING))
1187 phba->hba_flag |= HBA_RRQ_ACTIVE;
1188 else
1189 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
James Smart19ca7602010-11-20 23:11:55 -05001190 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001191
1192 if (!(phba->pport->load_flag & FC_UNLOADING))
1193 lpfc_worker_wake_up(phba);
James Smart19ca7602010-11-20 23:11:55 -05001194}
1195
1196/**
James Smart3621a712009-04-06 18:47:14 -04001197 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -04001198 * @phba: pointer to lpfc hba data structure.
1199 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1200 *
1201 * This is the callback function to the lpfc heart-beat mailbox command.
1202 * If configured, the lpfc driver issues the heart-beat mailbox command to
1203 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1204 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1205 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1206 * heart-beat outstanding state. Once the mailbox command comes back and
1207 * no error conditions detected, the heart-beat mailbox command timer is
1208 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1209 * state is cleared for the next heart-beat. If the timer expired with the
1210 * heart-beat outstanding state set, the driver will put the HBA offline.
1211 **/
James Smart858c9f62007-06-17 19:56:39 -05001212static void
1213lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1214{
1215 unsigned long drvr_flag;
1216
1217 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1218 phba->hb_outstanding = 0;
1219 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1220
James Smart93996272008-08-24 21:50:30 -04001221 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -05001222 mempool_free(pmboxq, phba->mbox_mem_pool);
1223 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1224 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -04001225 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -05001226 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001227 jiffies +
1228 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001229 return;
1230}
1231
James Smarte59058c2008-08-24 21:49:00 -04001232/**
James Smart3621a712009-04-06 18:47:14 -04001233 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001234 * @phba: pointer to lpfc hba data structure.
1235 *
1236 * This is the actual HBA-timer timeout handler to be invoked by the worker
1237 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1238 * handler performs any periodic operations needed for the device. If such
1239 * periodic event has already been attended to either in the interrupt handler
1240 * or by processing slow-ring or fast-ring events within the HBA-timer
1241 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1242 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1243 * is configured and there is no heart-beat mailbox command outstanding, a
1244 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1245 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1246 * to offline.
1247 **/
James Smart858c9f62007-06-17 19:56:39 -05001248void
1249lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1250{
James Smart45ed1192009-10-02 15:17:02 -04001251 struct lpfc_vport **vports;
James Smart858c9f62007-06-17 19:56:39 -05001252 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -05001253 struct lpfc_dmabuf *buf_ptr;
James Smart45ed1192009-10-02 15:17:02 -04001254 int retval, i;
James Smart858c9f62007-06-17 19:56:39 -05001255 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -05001256 LIST_HEAD(completions);
James Smart0cf07f842017-06-01 21:07:10 -07001257 struct lpfc_queue *qp;
1258 unsigned long time_elapsed;
1259 uint32_t tick_cqe, max_cqe, val;
1260 uint64_t tot, data1, data2, data3;
Dick Kennedy66d7ce92017-08-23 16:55:42 -07001261 struct lpfc_nvmet_tgtport *tgtp;
James Smart0cf07f842017-06-01 21:07:10 -07001262 struct lpfc_register reg_data;
1263 void __iomem *eqdreg = phba->sli4_hba.u.if_type2.EQDregaddr;
James Smart858c9f62007-06-17 19:56:39 -05001264
James Smart45ed1192009-10-02 15:17:02 -04001265 vports = lpfc_create_vport_work_array(phba);
1266 if (vports != NULL)
James Smart4258e982015-12-16 18:11:58 -05001267 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart45ed1192009-10-02 15:17:02 -04001268 lpfc_rcv_seq_check_edtov(vports[i]);
James Smart4258e982015-12-16 18:11:58 -05001269 lpfc_fdmi_num_disc_check(vports[i]);
1270 }
James Smart45ed1192009-10-02 15:17:02 -04001271 lpfc_destroy_vport_work_array(phba, vports);
1272
James Smart858c9f62007-06-17 19:56:39 -05001273 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -04001274 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -05001275 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1276 return;
1277
James Smart0cf07f842017-06-01 21:07:10 -07001278 if (phba->cfg_auto_imax) {
1279 if (!phba->last_eqdelay_time) {
1280 phba->last_eqdelay_time = jiffies;
1281 goto skip_eqdelay;
1282 }
1283 time_elapsed = jiffies - phba->last_eqdelay_time;
1284 phba->last_eqdelay_time = jiffies;
1285
1286 tot = 0xffff;
1287 /* Check outstanding IO count */
1288 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1289 if (phba->nvmet_support) {
Dick Kennedy66d7ce92017-08-23 16:55:42 -07001290 tgtp = phba->targetport->private;
1291 /* Calculate outstanding IOs */
1292 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
1293 tot += atomic_read(&tgtp->xmt_fcp_release);
1294 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
James Smart0cf07f842017-06-01 21:07:10 -07001295 } else {
1296 tot = atomic_read(&phba->fc4NvmeIoCmpls);
1297 data1 = atomic_read(
1298 &phba->fc4NvmeInputRequests);
1299 data2 = atomic_read(
1300 &phba->fc4NvmeOutputRequests);
1301 data3 = atomic_read(
1302 &phba->fc4NvmeControlRequests);
1303 tot = (data1 + data2 + data3) - tot;
1304 }
1305 }
1306
1307 /* Interrupts per sec per EQ */
1308 val = phba->cfg_fcp_imax / phba->io_channel_irqs;
1309 tick_cqe = val / CONFIG_HZ; /* Per tick per EQ */
1310
1311 /* Assume 1 CQE/ISR, calc max CQEs allowed for time duration */
1312 max_cqe = time_elapsed * tick_cqe;
1313
1314 for (i = 0; i < phba->io_channel_irqs; i++) {
1315 /* Fast-path EQ */
1316 qp = phba->sli4_hba.hba_eq[i];
1317 if (!qp)
1318 continue;
1319
1320 /* Use no EQ delay if we don't have many outstanding
1321 * IOs, or if we are only processing 1 CQE/ISR or less.
1322 * Otherwise, assume we can process up to lpfc_fcp_imax
1323 * interrupts per HBA.
1324 */
1325 if (tot < LPFC_NODELAY_MAX_IO ||
1326 qp->EQ_cqe_cnt <= max_cqe)
1327 val = 0;
1328 else
1329 val = phba->cfg_fcp_imax;
1330
1331 if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) {
1332 /* Use EQ Delay Register method */
1333
1334 /* Convert for EQ Delay register */
1335 if (val) {
1336 /* First, interrupts per sec per EQ */
1337 val = phba->cfg_fcp_imax /
1338 phba->io_channel_irqs;
1339
1340 /* us delay between each interrupt */
1341 val = LPFC_SEC_TO_USEC / val;
1342 }
1343 if (val != qp->q_mode) {
1344 reg_data.word0 = 0;
1345 bf_set(lpfc_sliport_eqdelay_id,
1346 &reg_data, qp->queue_id);
1347 bf_set(lpfc_sliport_eqdelay_delay,
1348 &reg_data, val);
1349 writel(reg_data.word0, eqdreg);
1350 }
1351 } else {
1352 /* Use mbox command method */
1353 if (val != qp->q_mode)
1354 lpfc_modify_hba_eq_delay(phba, i,
1355 1, val);
1356 }
1357
1358 /*
1359 * val is cfg_fcp_imax or 0 for mbox delay or us delay
1360 * between interrupts for EQDR.
1361 */
1362 qp->q_mode = val;
1363 qp->EQ_cqe_cnt = 0;
1364 }
1365 }
1366
1367skip_eqdelay:
James Smart858c9f62007-06-17 19:56:39 -05001368 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -05001369
James Smart256ec0d2013-04-17 20:14:58 -04001370 if (time_after(phba->last_completion_time +
1371 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1372 jiffies)) {
James Smart858c9f62007-06-17 19:56:39 -05001373 spin_unlock_irq(&phba->pport->work_port_lock);
1374 if (!phba->hb_outstanding)
1375 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001376 jiffies +
1377 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001378 else
1379 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001380 jiffies +
1381 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001382 return;
1383 }
1384 spin_unlock_irq(&phba->pport->work_port_lock);
1385
James Smart0ff10d42008-01-11 01:52:36 -05001386 if (phba->elsbuf_cnt &&
1387 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1388 spin_lock_irq(&phba->hbalock);
1389 list_splice_init(&phba->elsbuf, &completions);
1390 phba->elsbuf_cnt = 0;
1391 phba->elsbuf_prev_cnt = 0;
1392 spin_unlock_irq(&phba->hbalock);
1393
1394 while (!list_empty(&completions)) {
1395 list_remove_head(&completions, buf_ptr,
1396 struct lpfc_dmabuf, list);
1397 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1398 kfree(buf_ptr);
1399 }
1400 }
1401 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1402
James Smart858c9f62007-06-17 19:56:39 -05001403 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -05001404 if (phba->cfg_enable_hba_heartbeat) {
1405 if (!phba->hb_outstanding) {
James Smartbc739052010-08-04 16:11:18 -04001406 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1407 (list_empty(&psli->mboxq))) {
1408 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1409 GFP_KERNEL);
1410 if (!pmboxq) {
1411 mod_timer(&phba->hb_tmofunc,
1412 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001413 msecs_to_jiffies(1000 *
1414 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001415 return;
1416 }
James Smart13815c82008-01-11 01:52:48 -05001417
James Smartbc739052010-08-04 16:11:18 -04001418 lpfc_heart_beat(phba, pmboxq);
1419 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1420 pmboxq->vport = phba->pport;
1421 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1422 MBX_NOWAIT);
James Smart13815c82008-01-11 01:52:48 -05001423
James Smartbc739052010-08-04 16:11:18 -04001424 if (retval != MBX_BUSY &&
1425 retval != MBX_SUCCESS) {
1426 mempool_free(pmboxq,
1427 phba->mbox_mem_pool);
1428 mod_timer(&phba->hb_tmofunc,
1429 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001430 msecs_to_jiffies(1000 *
1431 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001432 return;
1433 }
1434 phba->skipped_hb = 0;
1435 phba->hb_outstanding = 1;
1436 } else if (time_before_eq(phba->last_completion_time,
1437 phba->skipped_hb)) {
1438 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1439 "2857 Last completion time not "
1440 " updated in %d ms\n",
1441 jiffies_to_msecs(jiffies
1442 - phba->last_completion_time));
1443 } else
1444 phba->skipped_hb = jiffies;
1445
James Smart858c9f62007-06-17 19:56:39 -05001446 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001447 jiffies +
1448 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001449 return;
James Smart13815c82008-01-11 01:52:48 -05001450 } else {
1451 /*
1452 * If heart beat timeout called with hb_outstanding set
James Smartdcf2a4e2010-09-29 11:18:53 -04001453 * we need to give the hb mailbox cmd a chance to
1454 * complete or TMO.
James Smart13815c82008-01-11 01:52:48 -05001455 */
James Smartdcf2a4e2010-09-29 11:18:53 -04001456 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1457 "0459 Adapter heartbeat still out"
1458 "standing:last compl time was %d ms.\n",
1459 jiffies_to_msecs(jiffies
1460 - phba->last_completion_time));
1461 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001462 jiffies +
1463 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001464 }
James Smart4258e982015-12-16 18:11:58 -05001465 } else {
1466 mod_timer(&phba->hb_tmofunc,
1467 jiffies +
1468 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001469 }
1470}
1471
James Smarte59058c2008-08-24 21:49:00 -04001472/**
James Smart3621a712009-04-06 18:47:14 -04001473 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -04001474 * @phba: pointer to lpfc hba data structure.
1475 *
1476 * This routine is called to bring the HBA offline when HBA hardware error
1477 * other than Port Error 6 has been detected.
1478 **/
James Smart09372822008-01-11 01:52:54 -05001479static void
1480lpfc_offline_eratt(struct lpfc_hba *phba)
1481{
1482 struct lpfc_sli *psli = &phba->sli;
1483
1484 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001485 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -05001486 spin_unlock_irq(&phba->hbalock);
James Smart618a5232012-06-12 13:54:36 -04001487 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart09372822008-01-11 01:52:54 -05001488
1489 lpfc_offline(phba);
1490 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001491 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001492 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001493 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001494 lpfc_hba_down_post(phba);
1495 lpfc_sli_brdready(phba, HS_MBRDY);
1496 lpfc_unblock_mgmt_io(phba);
1497 phba->link_state = LPFC_HBA_ERROR;
1498 return;
1499}
1500
James Smarte59058c2008-08-24 21:49:00 -04001501/**
James Smartda0436e2009-05-22 14:51:39 -04001502 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1503 * @phba: pointer to lpfc hba data structure.
1504 *
1505 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1506 * other than Port Error 6 has been detected.
1507 **/
James Smarta88dbb62013-04-17 20:18:39 -04001508void
James Smartda0436e2009-05-22 14:51:39 -04001509lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1510{
James Smart946727d2015-04-07 15:07:09 -04001511 spin_lock_irq(&phba->hbalock);
1512 phba->link_state = LPFC_HBA_ERROR;
1513 spin_unlock_irq(&phba->hbalock);
1514
James Smart618a5232012-06-12 13:54:36 -04001515 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smartda0436e2009-05-22 14:51:39 -04001516 lpfc_offline(phba);
James Smartda0436e2009-05-22 14:51:39 -04001517 lpfc_hba_down_post(phba);
James Smartda0436e2009-05-22 14:51:39 -04001518 lpfc_unblock_mgmt_io(phba);
James Smartda0436e2009-05-22 14:51:39 -04001519}
1520
1521/**
James Smarta257bf92009-04-06 18:48:10 -04001522 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1523 * @phba: pointer to lpfc hba data structure.
1524 *
1525 * This routine is invoked to handle the deferred HBA hardware error
1526 * conditions. This type of error is indicated by HBA by setting ER1
1527 * and another ER bit in the host status register. The driver will
1528 * wait until the ER1 bit clears before handling the error condition.
1529 **/
1530static void
1531lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1532{
1533 uint32_t old_host_status = phba->work_hs;
James Smarta257bf92009-04-06 18:48:10 -04001534 struct lpfc_sli *psli = &phba->sli;
1535
James Smartf4b4c682009-05-22 14:53:12 -04001536 /* If the pci channel is offline, ignore possible errors,
1537 * since we cannot communicate with the pci card anyway.
1538 */
1539 if (pci_channel_offline(phba->pcidev)) {
1540 spin_lock_irq(&phba->hbalock);
1541 phba->hba_flag &= ~DEFER_ERATT;
1542 spin_unlock_irq(&phba->hbalock);
1543 return;
1544 }
1545
James Smarta257bf92009-04-06 18:48:10 -04001546 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1547 "0479 Deferred Adapter Hardware Error "
1548 "Data: x%x x%x x%x\n",
1549 phba->work_hs,
1550 phba->work_status[0], phba->work_status[1]);
1551
1552 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001553 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001554 spin_unlock_irq(&phba->hbalock);
1555
1556
1557 /*
1558 * Firmware stops when it triggred erratt. That could cause the I/Os
1559 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1560 * SCSI layer retry it after re-establishing link.
1561 */
James Smartdb55fba2014-04-04 13:52:02 -04001562 lpfc_sli_abort_fcp_rings(phba);
James Smarta257bf92009-04-06 18:48:10 -04001563
1564 /*
1565 * There was a firmware error. Take the hba offline and then
1566 * attempt to restart it.
1567 */
James Smart618a5232012-06-12 13:54:36 -04001568 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smarta257bf92009-04-06 18:48:10 -04001569 lpfc_offline(phba);
1570
1571 /* Wait for the ER1 bit to clear.*/
1572 while (phba->work_hs & HS_FFER1) {
1573 msleep(100);
James Smart9940b972011-03-11 16:06:12 -05001574 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1575 phba->work_hs = UNPLUG_ERR ;
1576 break;
1577 }
James Smarta257bf92009-04-06 18:48:10 -04001578 /* If driver is unloading let the worker thread continue */
1579 if (phba->pport->load_flag & FC_UNLOADING) {
1580 phba->work_hs = 0;
1581 break;
1582 }
1583 }
1584
1585 /*
1586 * This is to ptrotect against a race condition in which
1587 * first write to the host attention register clear the
1588 * host status register.
1589 */
1590 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1591 phba->work_hs = old_host_status & ~HS_FFER1;
1592
James Smart3772a992009-05-22 14:50:54 -04001593 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001594 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001595 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001596 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1597 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1598}
1599
James Smart3772a992009-05-22 14:50:54 -04001600static void
1601lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1602{
1603 struct lpfc_board_event_header board_event;
1604 struct Scsi_Host *shost;
1605
1606 board_event.event_type = FC_REG_BOARD_EVENT;
1607 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1608 shost = lpfc_shost_from_vport(phba->pport);
1609 fc_host_post_vendor_event(shost, fc_get_event_number(),
1610 sizeof(board_event),
1611 (char *) &board_event,
1612 LPFC_NL_VENDOR_ID);
1613}
1614
James Smarta257bf92009-04-06 18:48:10 -04001615/**
James Smart3772a992009-05-22 14:50:54 -04001616 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001617 * @phba: pointer to lpfc hba data structure.
1618 *
1619 * This routine is invoked to handle the following HBA hardware error
1620 * conditions:
1621 * 1 - HBA error attention interrupt
1622 * 2 - DMA ring index out of range
1623 * 3 - Mailbox command came back as unknown
1624 **/
James Smart3772a992009-05-22 14:50:54 -04001625static void
1626lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001627{
James Smart2e0fef82007-06-17 19:56:36 -05001628 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001629 struct lpfc_sli *psli = &phba->sli;
James Smartd2873e42006-08-18 17:46:43 -04001630 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001631 unsigned long temperature;
1632 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001633 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001634
Linas Vepstas8d63f372007-02-14 14:28:36 -06001635 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001636 * since we cannot communicate with the pci card anyway.
1637 */
1638 if (pci_channel_offline(phba->pcidev)) {
1639 spin_lock_irq(&phba->hbalock);
1640 phba->hba_flag &= ~DEFER_ERATT;
1641 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001642 return;
James Smart3772a992009-05-22 14:50:54 -04001643 }
1644
James Smart13815c82008-01-11 01:52:48 -05001645 /* If resets are disabled then leave the HBA alone and return */
1646 if (!phba->cfg_enable_hba_reset)
1647 return;
dea31012005-04-17 16:05:31 -05001648
James Smartea2151b2008-09-07 11:52:10 -04001649 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001650 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001651
James Smarta257bf92009-04-06 18:48:10 -04001652 if (phba->hba_flag & DEFER_ERATT)
1653 lpfc_handle_deferred_eratt(phba);
1654
James Smartdcf2a4e2010-09-29 11:18:53 -04001655 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1656 if (phba->work_hs & HS_FFER6)
1657 /* Re-establishing Link */
1658 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1659 "1301 Re-establishing Link "
1660 "Data: x%x x%x x%x\n",
1661 phba->work_hs, phba->work_status[0],
1662 phba->work_status[1]);
1663 if (phba->work_hs & HS_FFER8)
1664 /* Device Zeroization */
1665 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1666 "2861 Host Authentication device "
1667 "zeroization Data:x%x x%x x%x\n",
1668 phba->work_hs, phba->work_status[0],
1669 phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001670
James Smart92d7f7b2007-06-17 19:56:38 -05001671 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001672 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001673 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001674
1675 /*
1676 * Firmware stops when it triggled erratt with HS_FFER6.
1677 * That could cause the I/Os dropped by the firmware.
1678 * Error iocb (I/O) on txcmplq and let the SCSI layer
1679 * retry it after re-establishing link.
1680 */
James Smartdb55fba2014-04-04 13:52:02 -04001681 lpfc_sli_abort_fcp_rings(phba);
dea31012005-04-17 16:05:31 -05001682
dea31012005-04-17 16:05:31 -05001683 /*
1684 * There was a firmware error. Take the hba offline and then
1685 * attempt to restart it.
1686 */
James Smart618a5232012-06-12 13:54:36 -04001687 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
dea31012005-04-17 16:05:31 -05001688 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001689 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001690 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001691 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001692 return;
1693 }
James Smart46fa3112007-04-25 09:51:45 -04001694 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001695 } else if (phba->work_hs & HS_CRIT_TEMP) {
1696 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1697 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1698 temp_event_data.event_code = LPFC_CRIT_TEMP;
1699 temp_event_data.data = (uint32_t)temperature;
1700
1701 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001702 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001703 "(%ld), taking this port offline "
1704 "Data: x%x x%x x%x\n",
1705 temperature, phba->work_hs,
1706 phba->work_status[0], phba->work_status[1]);
1707
1708 shost = lpfc_shost_from_vport(phba->pport);
1709 fc_host_post_vendor_event(shost, fc_get_event_number(),
1710 sizeof(temp_event_data),
1711 (char *) &temp_event_data,
1712 SCSI_NL_VID_TYPE_PCI
1713 | PCI_VENDOR_ID_EMULEX);
1714
James Smart7af67052007-10-27 13:38:11 -04001715 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001716 phba->over_temp_state = HBA_OVER_TEMP;
1717 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001718 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001719
dea31012005-04-17 16:05:31 -05001720 } else {
1721 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001722 * failure is a value other than FFER6. Do not call the offline
1723 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001724 */
1725 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001726 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001727 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001728 phba->work_hs,
dea31012005-04-17 16:05:31 -05001729 phba->work_status[0], phba->work_status[1]);
1730
James Smartd2873e42006-08-18 17:46:43 -04001731 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001732 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001733 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001734 sizeof(event_data), (char *) &event_data,
1735 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1736
James Smart09372822008-01-11 01:52:54 -05001737 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001738 }
James Smart93996272008-08-24 21:50:30 -04001739 return;
dea31012005-04-17 16:05:31 -05001740}
1741
James Smarte59058c2008-08-24 21:49:00 -04001742/**
James Smart618a5232012-06-12 13:54:36 -04001743 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1744 * @phba: pointer to lpfc hba data structure.
1745 * @mbx_action: flag for mailbox shutdown action.
1746 *
1747 * This routine is invoked to perform an SLI4 port PCI function reset in
1748 * response to port status register polling attention. It waits for port
1749 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1750 * During this process, interrupt vectors are freed and later requested
1751 * for handling possible port resource change.
1752 **/
1753static int
James Smarte10b2022014-02-20 09:57:43 -05001754lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1755 bool en_rn_msg)
James Smart618a5232012-06-12 13:54:36 -04001756{
1757 int rc;
1758 uint32_t intr_mode;
1759
James Smart65791f12016-07-06 12:35:56 -07001760 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1761 LPFC_SLI_INTF_IF_TYPE_2) {
1762 /*
1763 * On error status condition, driver need to wait for port
1764 * ready before performing reset.
1765 */
1766 rc = lpfc_sli4_pdev_status_reg_wait(phba);
James Smart0e916ee2016-07-06 12:36:06 -07001767 if (rc)
James Smart65791f12016-07-06 12:35:56 -07001768 return rc;
James Smart618a5232012-06-12 13:54:36 -04001769 }
James Smart0e916ee2016-07-06 12:36:06 -07001770
James Smart65791f12016-07-06 12:35:56 -07001771 /* need reset: attempt for port recovery */
1772 if (en_rn_msg)
1773 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1774 "2887 Reset Needed: Attempting Port "
1775 "Recovery...\n");
1776 lpfc_offline_prep(phba, mbx_action);
1777 lpfc_offline(phba);
1778 /* release interrupt for possible resource change */
1779 lpfc_sli4_disable_intr(phba);
1780 lpfc_sli_brdrestart(phba);
1781 /* request and enable interrupt */
1782 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1783 if (intr_mode == LPFC_INTR_ERROR) {
1784 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1785 "3175 Failed to enable interrupt\n");
1786 return -EIO;
1787 }
1788 phba->intr_mode = intr_mode;
1789 rc = lpfc_online(phba);
1790 if (rc == 0)
1791 lpfc_unblock_mgmt_io(phba);
1792
James Smart618a5232012-06-12 13:54:36 -04001793 return rc;
1794}
1795
1796/**
James Smartda0436e2009-05-22 14:51:39 -04001797 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1798 * @phba: pointer to lpfc hba data structure.
1799 *
1800 * This routine is invoked to handle the SLI4 HBA hardware error attention
1801 * conditions.
1802 **/
1803static void
1804lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1805{
1806 struct lpfc_vport *vport = phba->pport;
1807 uint32_t event_data;
1808 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001809 uint32_t if_type;
James Smart2e90f4b2011-12-13 13:22:37 -05001810 struct lpfc_register portstat_reg = {0};
1811 uint32_t reg_err1, reg_err2;
1812 uint32_t uerrlo_reg, uemasklo_reg;
James Smart65791f12016-07-06 12:35:56 -07001813 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
James Smarte10b2022014-02-20 09:57:43 -05001814 bool en_rn_msg = true;
James Smart946727d2015-04-07 15:07:09 -04001815 struct temp_event temp_event_data;
James Smart65791f12016-07-06 12:35:56 -07001816 struct lpfc_register portsmphr_reg;
1817 int rc, i;
James Smartda0436e2009-05-22 14:51:39 -04001818
1819 /* If the pci channel is offline, ignore possible errors, since
1820 * we cannot communicate with the pci card anyway.
1821 */
1822 if (pci_channel_offline(phba->pcidev))
1823 return;
James Smartda0436e2009-05-22 14:51:39 -04001824
James Smart65791f12016-07-06 12:35:56 -07001825 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
James Smart2fcee4b2010-12-15 17:57:46 -05001826 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1827 switch (if_type) {
1828 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart2e90f4b2011-12-13 13:22:37 -05001829 pci_rd_rc1 = lpfc_readl(
1830 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1831 &uerrlo_reg);
1832 pci_rd_rc2 = lpfc_readl(
1833 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1834 &uemasklo_reg);
1835 /* consider PCI bus read error as pci_channel_offline */
1836 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1837 return;
James Smart65791f12016-07-06 12:35:56 -07001838 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
1839 lpfc_sli4_offline_eratt(phba);
1840 return;
1841 }
1842 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1843 "7623 Checking UE recoverable");
1844
1845 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
1846 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1847 &portsmphr_reg.word0))
1848 continue;
1849
1850 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
1851 &portsmphr_reg);
1852 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1853 LPFC_PORT_SEM_UE_RECOVERABLE)
1854 break;
1855 /*Sleep for 1Sec, before checking SEMAPHORE */
1856 msleep(1000);
1857 }
1858
1859 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1860 "4827 smphr_port_status x%x : Waited %dSec",
1861 smphr_port_status, i);
1862
1863 /* Recoverable UE, reset the HBA device */
1864 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1865 LPFC_PORT_SEM_UE_RECOVERABLE) {
1866 for (i = 0; i < 20; i++) {
1867 msleep(1000);
1868 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1869 &portsmphr_reg.word0) &&
1870 (LPFC_POST_STAGE_PORT_READY ==
1871 bf_get(lpfc_port_smphr_port_status,
1872 &portsmphr_reg))) {
1873 rc = lpfc_sli4_port_sta_fn_reset(phba,
1874 LPFC_MBX_NO_WAIT, en_rn_msg);
1875 if (rc == 0)
1876 return;
1877 lpfc_printf_log(phba,
1878 KERN_ERR, LOG_INIT,
1879 "4215 Failed to recover UE");
1880 break;
1881 }
1882 }
1883 }
1884 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1885 "7624 Firmware not ready: Failing UE recovery,"
1886 " waited %dSec", i);
James Smart2fcee4b2010-12-15 17:57:46 -05001887 lpfc_sli4_offline_eratt(phba);
1888 break;
James Smart946727d2015-04-07 15:07:09 -04001889
James Smart2fcee4b2010-12-15 17:57:46 -05001890 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2e90f4b2011-12-13 13:22:37 -05001891 pci_rd_rc1 = lpfc_readl(
1892 phba->sli4_hba.u.if_type2.STATUSregaddr,
1893 &portstat_reg.word0);
1894 /* consider PCI bus read error as pci_channel_offline */
James Smart6b5151f2012-01-18 16:24:06 -05001895 if (pci_rd_rc1 == -EIO) {
1896 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1897 "3151 PCI bus read access failure: x%x\n",
1898 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
James Smart2e90f4b2011-12-13 13:22:37 -05001899 return;
James Smart6b5151f2012-01-18 16:24:06 -05001900 }
James Smart2e90f4b2011-12-13 13:22:37 -05001901 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1902 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
James Smart2fcee4b2010-12-15 17:57:46 -05001903 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
James Smart2fcee4b2010-12-15 17:57:46 -05001904 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1905 "2889 Port Overtemperature event, "
James Smart946727d2015-04-07 15:07:09 -04001906 "taking port offline Data: x%x x%x\n",
1907 reg_err1, reg_err2);
1908
James Smart310429e2016-07-06 12:35:54 -07001909 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04001910 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1911 temp_event_data.event_code = LPFC_CRIT_TEMP;
1912 temp_event_data.data = 0xFFFFFFFF;
1913
1914 shost = lpfc_shost_from_vport(phba->pport);
1915 fc_host_post_vendor_event(shost, fc_get_event_number(),
1916 sizeof(temp_event_data),
1917 (char *)&temp_event_data,
1918 SCSI_NL_VID_TYPE_PCI
1919 | PCI_VENDOR_ID_EMULEX);
1920
James Smart2fcee4b2010-12-15 17:57:46 -05001921 spin_lock_irq(&phba->hbalock);
1922 phba->over_temp_state = HBA_OVER_TEMP;
1923 spin_unlock_irq(&phba->hbalock);
1924 lpfc_sli4_offline_eratt(phba);
James Smart946727d2015-04-07 15:07:09 -04001925 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001926 }
James Smart2e90f4b2011-12-13 13:22:37 -05001927 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smarte10b2022014-02-20 09:57:43 -05001928 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
James Smart2e90f4b2011-12-13 13:22:37 -05001929 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte10b2022014-02-20 09:57:43 -05001930 "3143 Port Down: Firmware Update "
1931 "Detected\n");
1932 en_rn_msg = false;
1933 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smart2e90f4b2011-12-13 13:22:37 -05001934 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1935 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1936 "3144 Port Down: Debug Dump\n");
1937 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1938 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1939 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1940 "3145 Port Down: Provisioning\n");
James Smart618a5232012-06-12 13:54:36 -04001941
James Smart946727d2015-04-07 15:07:09 -04001942 /* If resets are disabled then leave the HBA alone and return */
1943 if (!phba->cfg_enable_hba_reset)
1944 return;
1945
James Smart618a5232012-06-12 13:54:36 -04001946 /* Check port status register for function reset */
James Smarte10b2022014-02-20 09:57:43 -05001947 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1948 en_rn_msg);
James Smart618a5232012-06-12 13:54:36 -04001949 if (rc == 0) {
1950 /* don't report event on forced debug dump */
1951 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1952 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1953 return;
1954 else
1955 break;
James Smart2fcee4b2010-12-15 17:57:46 -05001956 }
James Smart618a5232012-06-12 13:54:36 -04001957 /* fall through for not able to recover */
James Smart6b5151f2012-01-18 16:24:06 -05001958 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1959 "3152 Unrecoverable error, bring the port "
1960 "offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05001961 lpfc_sli4_offline_eratt(phba);
1962 break;
1963 case LPFC_SLI_INTF_IF_TYPE_1:
1964 default:
1965 break;
1966 }
James Smart2e90f4b2011-12-13 13:22:37 -05001967 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1968 "3123 Report dump event to upper layer\n");
1969 /* Send an internal error event to mgmt application */
1970 lpfc_board_errevt_to_mgmt(phba);
1971
1972 event_data = FC_REG_DUMP_EVENT;
1973 shost = lpfc_shost_from_vport(vport);
1974 fc_host_post_vendor_event(shost, fc_get_event_number(),
1975 sizeof(event_data), (char *) &event_data,
1976 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
James Smartda0436e2009-05-22 14:51:39 -04001977}
1978
1979/**
1980 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1981 * @phba: pointer to lpfc HBA data structure.
1982 *
1983 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1984 * routine from the API jump table function pointer from the lpfc_hba struct.
1985 *
1986 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001987 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001988 * Any other value - error.
1989 **/
1990void
1991lpfc_handle_eratt(struct lpfc_hba *phba)
1992{
1993 (*phba->lpfc_handle_eratt)(phba);
1994}
1995
1996/**
James Smart3621a712009-04-06 18:47:14 -04001997 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04001998 * @phba: pointer to lpfc hba data structure.
1999 *
2000 * This routine is invoked from the worker thread to handle a HBA host
James Smart895427b2017-02-12 13:52:30 -08002001 * attention link event. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002002 **/
dea31012005-04-17 16:05:31 -05002003void
James Smart2e0fef82007-06-17 19:56:36 -05002004lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002005{
James Smart2e0fef82007-06-17 19:56:36 -05002006 struct lpfc_vport *vport = phba->pport;
2007 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05002008 LPFC_MBOXQ_t *pmb;
2009 volatile uint32_t control;
2010 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05002011 int rc = 0;
dea31012005-04-17 16:05:31 -05002012
2013 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05002014 if (!pmb) {
2015 rc = 1;
dea31012005-04-17 16:05:31 -05002016 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05002017 }
dea31012005-04-17 16:05:31 -05002018
2019 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05002020 if (!mp) {
2021 rc = 2;
dea31012005-04-17 16:05:31 -05002022 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05002023 }
dea31012005-04-17 16:05:31 -05002024
2025 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05002026 if (!mp->virt) {
2027 rc = 3;
dea31012005-04-17 16:05:31 -05002028 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05002029 }
dea31012005-04-17 16:05:31 -05002030
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05002031 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04002032 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05002033
2034 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05002035 lpfc_read_topology(phba, pmb, mp);
2036 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05002037 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04002038 /* Block ELS IOCBs until we have processed this mbox command */
James Smart895427b2017-02-12 13:52:30 -08002039 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04002040 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05002041 if (rc == MBX_NOT_FINISHED) {
2042 rc = 4;
James Smart14691152006-12-02 13:34:28 -05002043 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05002044 }
dea31012005-04-17 16:05:31 -05002045
2046 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05002047 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002048 writel(HA_LATT, phba->HAregaddr);
2049 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05002050 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002051
2052 return;
2053
James Smart14691152006-12-02 13:34:28 -05002054lpfc_handle_latt_free_mbuf:
James Smart895427b2017-02-12 13:52:30 -08002055 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05002056 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05002057lpfc_handle_latt_free_mp:
2058 kfree(mp);
2059lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04002060 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002061lpfc_handle_latt_err_exit:
2062 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05002063 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002064 psli->sli_flag |= LPFC_PROCESS_LA;
2065 control = readl(phba->HCregaddr);
2066 control |= HC_LAINT_ENA;
2067 writel(control, phba->HCregaddr);
2068 readl(phba->HCregaddr); /* flush */
2069
2070 /* Clear Link Attention in HA REG */
2071 writel(HA_LATT, phba->HAregaddr);
2072 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05002073 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002074 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002075 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002076
James Smart09372822008-01-11 01:52:54 -05002077 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
2078 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05002079
2080 return;
2081}
2082
James Smarte59058c2008-08-24 21:49:00 -04002083/**
James Smart3621a712009-04-06 18:47:14 -04002084 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04002085 * @phba: pointer to lpfc hba data structure.
2086 * @vpd: pointer to the vital product data.
2087 * @len: length of the vital product data in bytes.
2088 *
2089 * This routine parses the Vital Product Data (VPD). The VPD is treated as
2090 * an array of characters. In this routine, the ModelName, ProgramType, and
2091 * ModelDesc, etc. fields of the phba data structure will be populated.
2092 *
2093 * Return codes
2094 * 0 - pointer to the VPD passed in is NULL
2095 * 1 - success
2096 **/
James Smart3772a992009-05-22 14:50:54 -04002097int
James Smart2e0fef82007-06-17 19:56:36 -05002098lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05002099{
2100 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05002101 int Length;
dea31012005-04-17 16:05:31 -05002102 int i, j;
2103 int finished = 0;
2104 int index = 0;
2105
2106 if (!vpd)
2107 return 0;
2108
2109 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05002110 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002111 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05002112 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
2113 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002114 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05002115 switch (vpd[index]) {
2116 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002117 case 0x91:
dea31012005-04-17 16:05:31 -05002118 index += 1;
2119 lenlo = vpd[index];
2120 index += 1;
2121 lenhi = vpd[index];
2122 index += 1;
2123 i = ((((unsigned short)lenhi) << 8) + lenlo);
2124 index += i;
2125 break;
2126 case 0x90:
2127 index += 1;
2128 lenlo = vpd[index];
2129 index += 1;
2130 lenhi = vpd[index];
2131 index += 1;
2132 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002133 if (Length > len - index)
2134 Length = len - index;
dea31012005-04-17 16:05:31 -05002135 while (Length > 0) {
2136 /* Look for Serial Number */
2137 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
2138 index += 2;
2139 i = vpd[index];
2140 index += 1;
2141 j = 0;
2142 Length -= (3+i);
2143 while(i--) {
2144 phba->SerialNumber[j++] = vpd[index++];
2145 if (j == 31)
2146 break;
2147 }
2148 phba->SerialNumber[j] = 0;
2149 continue;
2150 }
2151 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
2152 phba->vpd_flag |= VPD_MODEL_DESC;
2153 index += 2;
2154 i = vpd[index];
2155 index += 1;
2156 j = 0;
2157 Length -= (3+i);
2158 while(i--) {
2159 phba->ModelDesc[j++] = vpd[index++];
2160 if (j == 255)
2161 break;
2162 }
2163 phba->ModelDesc[j] = 0;
2164 continue;
2165 }
2166 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
2167 phba->vpd_flag |= VPD_MODEL_NAME;
2168 index += 2;
2169 i = vpd[index];
2170 index += 1;
2171 j = 0;
2172 Length -= (3+i);
2173 while(i--) {
2174 phba->ModelName[j++] = vpd[index++];
2175 if (j == 79)
2176 break;
2177 }
2178 phba->ModelName[j] = 0;
2179 continue;
2180 }
2181 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2182 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2183 index += 2;
2184 i = vpd[index];
2185 index += 1;
2186 j = 0;
2187 Length -= (3+i);
2188 while(i--) {
2189 phba->ProgramType[j++] = vpd[index++];
2190 if (j == 255)
2191 break;
2192 }
2193 phba->ProgramType[j] = 0;
2194 continue;
2195 }
2196 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2197 phba->vpd_flag |= VPD_PORT;
2198 index += 2;
2199 i = vpd[index];
2200 index += 1;
2201 j = 0;
2202 Length -= (3+i);
2203 while(i--) {
James Smartcd1c8302011-10-10 21:33:25 -04002204 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2205 (phba->sli4_hba.pport_name_sta ==
2206 LPFC_SLI4_PPNAME_GET)) {
2207 j++;
2208 index++;
2209 } else
2210 phba->Port[j++] = vpd[index++];
2211 if (j == 19)
2212 break;
dea31012005-04-17 16:05:31 -05002213 }
James Smartcd1c8302011-10-10 21:33:25 -04002214 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2215 (phba->sli4_hba.pport_name_sta ==
2216 LPFC_SLI4_PPNAME_NON))
2217 phba->Port[j] = 0;
dea31012005-04-17 16:05:31 -05002218 continue;
2219 }
2220 else {
2221 index += 2;
2222 i = vpd[index];
2223 index += 1;
2224 index += i;
2225 Length -= (3 + i);
2226 }
2227 }
2228 finished = 0;
2229 break;
2230 case 0x78:
2231 finished = 1;
2232 break;
2233 default:
2234 index ++;
2235 break;
2236 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002237 }
dea31012005-04-17 16:05:31 -05002238
2239 return(1);
2240}
2241
James Smarte59058c2008-08-24 21:49:00 -04002242/**
James Smart3621a712009-04-06 18:47:14 -04002243 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04002244 * @phba: pointer to lpfc hba data structure.
2245 * @mdp: pointer to the data structure to hold the derived model name.
2246 * @descp: pointer to the data structure to hold the derived description.
2247 *
2248 * This routine retrieves HBA's description based on its registered PCI device
2249 * ID. The @descp passed into this function points to an array of 256 chars. It
2250 * shall be returned with the model name, maximum speed, and the host bus type.
2251 * The @mdp passed into this function points to an array of 80 chars. When the
2252 * function returns, the @mdp will be filled with the model name.
2253 **/
dea31012005-04-17 16:05:31 -05002254static void
James Smart2e0fef82007-06-17 19:56:36 -05002255lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05002256{
2257 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05002258 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002259 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04002260 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04002261 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002262 struct {
James Smarta747c9c2009-11-18 15:41:10 -05002263 char *name;
2264 char *bus;
2265 char *function;
2266 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002267
2268 if (mdp && mdp[0] != '\0'
2269 && descp && descp[0] != '\0')
2270 return;
2271
James Smartd38dd522015-08-31 16:48:17 -04002272 if (phba->lmt & LMT_32Gb)
2273 max_speed = 32;
2274 else if (phba->lmt & LMT_16Gb)
James Smartc0c11512011-05-24 11:41:34 -04002275 max_speed = 16;
2276 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002277 max_speed = 10;
2278 else if (phba->lmt & LMT_8Gb)
2279 max_speed = 8;
2280 else if (phba->lmt & LMT_4Gb)
2281 max_speed = 4;
2282 else if (phba->lmt & LMT_2Gb)
2283 max_speed = 2;
James Smart4169d862012-09-29 11:32:09 -04002284 else if (phba->lmt & LMT_1Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002285 max_speed = 1;
James Smart4169d862012-09-29 11:32:09 -04002286 else
2287 max_speed = 0;
dea31012005-04-17 16:05:31 -05002288
2289 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05002290
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002291 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002292 case PCI_DEVICE_ID_FIREFLY:
James Smart12222f42014-05-21 08:05:19 -04002293 m = (typeof(m)){"LP6000", "PCI",
2294 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002295 break;
dea31012005-04-17 16:05:31 -05002296 case PCI_DEVICE_ID_SUPERFLY:
2297 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart12222f42014-05-21 08:05:19 -04002298 m = (typeof(m)){"LP7000", "PCI", ""};
dea31012005-04-17 16:05:31 -05002299 else
James Smart12222f42014-05-21 08:05:19 -04002300 m = (typeof(m)){"LP7000E", "PCI", ""};
2301 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002302 break;
2303 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002304 m = (typeof(m)){"LP8000", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002305 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002306 break;
2307 case PCI_DEVICE_ID_CENTAUR:
2308 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart12222f42014-05-21 08:05:19 -04002309 m = (typeof(m)){"LP9002", "PCI", ""};
dea31012005-04-17 16:05:31 -05002310 else
James Smart12222f42014-05-21 08:05:19 -04002311 m = (typeof(m)){"LP9000", "PCI", ""};
2312 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002313 break;
2314 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002315 m = (typeof(m)){"LP952", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002316 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002317 break;
2318 case PCI_DEVICE_ID_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05002319 m = (typeof(m)){"LP9802", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002320 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002321 break;
2322 case PCI_DEVICE_ID_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05002323 m = (typeof(m)){"LP10000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002324 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002325 break;
2326 case PCI_DEVICE_ID_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05002327 m = (typeof(m)){"LPX1000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002328 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002329 break;
2330 case PCI_DEVICE_ID_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002331 m = (typeof(m)){"LP982", "PCI-X",
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_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002335 m = (typeof(m)){"LP1050", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002336 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002337 break;
2338 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05002339 m = (typeof(m)){"LP11000", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002340 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002341 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002342 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002343 m = (typeof(m)){"LP11000-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002344 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002345 break;
2346 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002347 m = (typeof(m)){"LP11002-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002348 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002349 break;
2350 case PCI_DEVICE_ID_NEPTUNE:
James Smart12222f42014-05-21 08:05:19 -04002351 m = (typeof(m)){"LPe1000", "PCIe",
2352 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002353 break;
2354 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart12222f42014-05-21 08:05:19 -04002355 m = (typeof(m)){"LPe1000-SP", "PCIe",
2356 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002357 break;
2358 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart12222f42014-05-21 08:05:19 -04002359 m = (typeof(m)){"LPe1002-SP", "PCIe",
2360 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002361 break;
dea31012005-04-17 16:05:31 -05002362 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05002363 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002364 break;
2365 case PCI_DEVICE_ID_BSMB:
James Smart12222f42014-05-21 08:05:19 -04002366 m = (typeof(m)){"LP111", "PCI-X2",
2367 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002368 break;
2369 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05002370 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002371 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002372 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002373 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002374 break;
2375 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002376 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04002377 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002378 break;
dea31012005-04-17 16:05:31 -05002379 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05002380 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002381 break;
2382 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05002383 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002384 break;
2385 case PCI_DEVICE_ID_LP101:
James Smart12222f42014-05-21 08:05:19 -04002386 m = (typeof(m)){"LP101", "PCI-X",
2387 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002388 break;
2389 case PCI_DEVICE_ID_LP10000S:
James Smart12222f42014-05-21 08:05:19 -04002390 m = (typeof(m)){"LP10000-S", "PCI",
2391 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002392 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002393 case PCI_DEVICE_ID_LP11000S:
James Smart12222f42014-05-21 08:05:19 -04002394 m = (typeof(m)){"LP11000-S", "PCI-X2",
2395 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05002396 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002397 case PCI_DEVICE_ID_LPE11000S:
James Smart12222f42014-05-21 08:05:19 -04002398 m = (typeof(m)){"LPe11000-S", "PCIe",
2399 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002400 break;
James Smartb87eab32007-04-25 09:53:28 -04002401 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05002402 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002403 break;
2404 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05002405 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002406 break;
2407 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05002408 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002409 break;
2410 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002411 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002412 break;
2413 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002414 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002415 break;
2416 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05002417 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002418 break;
James Smart84774a42008-08-24 21:50:06 -04002419 case PCI_DEVICE_ID_HORNET:
James Smart12222f42014-05-21 08:05:19 -04002420 m = (typeof(m)){"LP21000", "PCIe",
2421 "Obsolete, Unsupported FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002422 GE = 1;
2423 break;
2424 case PCI_DEVICE_ID_PROTEUS_VF:
James Smarta747c9c2009-11-18 15:41:10 -05002425 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002426 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002427 break;
2428 case PCI_DEVICE_ID_PROTEUS_PF:
James Smarta747c9c2009-11-18 15:41:10 -05002429 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002430 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002431 break;
2432 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05002433 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002434 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002435 break;
James Smartda0436e2009-05-22 14:51:39 -04002436 case PCI_DEVICE_ID_TIGERSHARK:
2437 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002438 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04002439 break;
James Smarta747c9c2009-11-18 15:41:10 -05002440 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04002441 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002442 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2443 break;
2444 case PCI_DEVICE_ID_FALCON:
2445 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2446 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04002447 break;
James Smart98fc5dd2010-06-07 15:24:29 -04002448 case PCI_DEVICE_ID_BALIUS:
2449 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
James Smart12222f42014-05-21 08:05:19 -04002450 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart98fc5dd2010-06-07 15:24:29 -04002451 break;
James Smart085c6472010-11-20 23:11:37 -05002452 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04002453 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05002454 break;
James Smart12222f42014-05-21 08:05:19 -04002455 case PCI_DEVICE_ID_LANCER_FC_VF:
2456 m = (typeof(m)){"LPe16000", "PCIe",
2457 "Obsolete, Unsupported Fibre Channel Adapter"};
2458 break;
James Smart085c6472010-11-20 23:11:37 -05002459 case PCI_DEVICE_ID_LANCER_FCOE:
2460 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04002461 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05002462 break;
James Smart12222f42014-05-21 08:05:19 -04002463 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2464 oneConnect = 1;
2465 m = (typeof(m)){"OCe15100", "PCIe",
2466 "Obsolete, Unsupported FCoE"};
2467 break;
James Smartd38dd522015-08-31 16:48:17 -04002468 case PCI_DEVICE_ID_LANCER_G6_FC:
2469 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2470 break;
James Smartf8cafd32012-08-03 12:42:51 -04002471 case PCI_DEVICE_ID_SKYHAWK:
2472 case PCI_DEVICE_ID_SKYHAWK_VF:
2473 oneConnect = 1;
2474 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2475 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002476 default:
James Smarta747c9c2009-11-18 15:41:10 -05002477 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002478 break;
dea31012005-04-17 16:05:31 -05002479 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002480
2481 if (mdp && mdp[0] == '\0')
2482 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04002483 /*
2484 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04002485 * and we put the port number on the end
2486 */
2487 if (descp && descp[0] == '\0') {
2488 if (oneConnect)
2489 snprintf(descp, 255,
James Smart4169d862012-09-29 11:32:09 -04002490 "Emulex OneConnect %s, %s Initiator %s",
James Smarta747c9c2009-11-18 15:41:10 -05002491 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04002492 phba->Port);
James Smart4169d862012-09-29 11:32:09 -04002493 else if (max_speed == 0)
2494 snprintf(descp, 255,
Sebastian Herbszt290237d2015-08-31 16:48:08 -04002495 "Emulex %s %s %s",
James Smart4169d862012-09-29 11:32:09 -04002496 m.name, m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002497 else
2498 snprintf(descp, 255,
2499 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05002500 m.name, max_speed, (GE) ? "GE" : "Gb",
2501 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002502 }
dea31012005-04-17 16:05:31 -05002503}
2504
James Smarte59058c2008-08-24 21:49:00 -04002505/**
James Smart3621a712009-04-06 18:47:14 -04002506 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04002507 * @phba: pointer to lpfc hba data structure.
2508 * @pring: pointer to a IOCB ring.
2509 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2510 *
2511 * This routine posts a given number of IOCBs with the associated DMA buffer
2512 * descriptors specified by the cnt argument to the given IOCB ring.
2513 *
2514 * Return codes
2515 * The number of IOCBs NOT able to be posted to the IOCB ring.
2516 **/
dea31012005-04-17 16:05:31 -05002517int
James Smart495a7142008-06-14 22:52:59 -04002518lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002519{
2520 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002521 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002522 struct lpfc_dmabuf *mp1, *mp2;
2523
2524 cnt += pring->missbufcnt;
2525
2526 /* While there are buffers to post */
2527 while (cnt > 0) {
2528 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002529 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002530 if (iocb == NULL) {
2531 pring->missbufcnt = cnt;
2532 return cnt;
2533 }
dea31012005-04-17 16:05:31 -05002534 icmd = &iocb->iocb;
2535
2536 /* 2 buffers can be posted per command */
2537 /* Allocate buffer to post */
2538 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2539 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002540 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2541 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002542 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002543 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002544 pring->missbufcnt = cnt;
2545 return cnt;
2546 }
2547
2548 INIT_LIST_HEAD(&mp1->list);
2549 /* Allocate buffer to post */
2550 if (cnt > 1) {
2551 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2552 if (mp2)
2553 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2554 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002555 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002556 kfree(mp2);
dea31012005-04-17 16:05:31 -05002557 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2558 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002559 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002560 pring->missbufcnt = cnt;
2561 return cnt;
2562 }
2563
2564 INIT_LIST_HEAD(&mp2->list);
2565 } else {
2566 mp2 = NULL;
2567 }
2568
2569 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2570 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2571 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2572 icmd->ulpBdeCount = 1;
2573 cnt--;
2574 if (mp2) {
2575 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2576 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2577 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2578 cnt--;
2579 icmd->ulpBdeCount = 2;
2580 }
2581
2582 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2583 icmd->ulpLe = 1;
2584
James Smart3772a992009-05-22 14:50:54 -04002585 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2586 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002587 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2588 kfree(mp1);
2589 cnt++;
2590 if (mp2) {
2591 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2592 kfree(mp2);
2593 cnt++;
2594 }
James Bottomley604a3e32005-10-29 10:28:33 -05002595 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002596 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002597 return cnt;
2598 }
dea31012005-04-17 16:05:31 -05002599 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002600 if (mp2)
dea31012005-04-17 16:05:31 -05002601 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002602 }
2603 pring->missbufcnt = 0;
2604 return 0;
2605}
2606
James Smarte59058c2008-08-24 21:49:00 -04002607/**
James Smart3621a712009-04-06 18:47:14 -04002608 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002609 * @phba: pointer to lpfc hba data structure.
2610 *
2611 * This routine posts initial receive IOCB buffers to the ELS ring. The
2612 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
James Smart895427b2017-02-12 13:52:30 -08002613 * set to 64 IOCBs. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002614 *
2615 * Return codes
2616 * 0 - success (currently always success)
2617 **/
dea31012005-04-17 16:05:31 -05002618static int
James Smart2e0fef82007-06-17 19:56:36 -05002619lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002620{
2621 struct lpfc_sli *psli = &phba->sli;
2622
2623 /* Ring 0, ELS / CT buffers */
James Smart895427b2017-02-12 13:52:30 -08002624 lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002625 /* Ring 2 - FCP no buffers needed */
2626
2627 return 0;
2628}
2629
2630#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2631
James Smarte59058c2008-08-24 21:49:00 -04002632/**
James Smart3621a712009-04-06 18:47:14 -04002633 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002634 * @HashResultPointer: pointer to an array as hash table.
2635 *
2636 * This routine sets up the initial values to the array of hash table entries
2637 * for the LC HBAs.
2638 **/
dea31012005-04-17 16:05:31 -05002639static void
2640lpfc_sha_init(uint32_t * HashResultPointer)
2641{
2642 HashResultPointer[0] = 0x67452301;
2643 HashResultPointer[1] = 0xEFCDAB89;
2644 HashResultPointer[2] = 0x98BADCFE;
2645 HashResultPointer[3] = 0x10325476;
2646 HashResultPointer[4] = 0xC3D2E1F0;
2647}
2648
James Smarte59058c2008-08-24 21:49:00 -04002649/**
James Smart3621a712009-04-06 18:47:14 -04002650 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002651 * @HashResultPointer: pointer to an initial/result hash table.
2652 * @HashWorkingPointer: pointer to an working hash table.
2653 *
2654 * This routine iterates an initial hash table pointed by @HashResultPointer
2655 * with the values from the working hash table pointeed by @HashWorkingPointer.
2656 * The results are putting back to the initial hash table, returned through
2657 * the @HashResultPointer as the result hash table.
2658 **/
dea31012005-04-17 16:05:31 -05002659static void
2660lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2661{
2662 int t;
2663 uint32_t TEMP;
2664 uint32_t A, B, C, D, E;
2665 t = 16;
2666 do {
2667 HashWorkingPointer[t] =
2668 S(1,
2669 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2670 8] ^
2671 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2672 } while (++t <= 79);
2673 t = 0;
2674 A = HashResultPointer[0];
2675 B = HashResultPointer[1];
2676 C = HashResultPointer[2];
2677 D = HashResultPointer[3];
2678 E = HashResultPointer[4];
2679
2680 do {
2681 if (t < 20) {
2682 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2683 } else if (t < 40) {
2684 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2685 } else if (t < 60) {
2686 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2687 } else {
2688 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2689 }
2690 TEMP += S(5, A) + E + HashWorkingPointer[t];
2691 E = D;
2692 D = C;
2693 C = S(30, B);
2694 B = A;
2695 A = TEMP;
2696 } while (++t <= 79);
2697
2698 HashResultPointer[0] += A;
2699 HashResultPointer[1] += B;
2700 HashResultPointer[2] += C;
2701 HashResultPointer[3] += D;
2702 HashResultPointer[4] += E;
2703
2704}
2705
James Smarte59058c2008-08-24 21:49:00 -04002706/**
James Smart3621a712009-04-06 18:47:14 -04002707 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002708 * @RandomChallenge: pointer to the entry of host challenge random number array.
2709 * @HashWorking: pointer to the entry of the working hash array.
2710 *
2711 * This routine calculates the working hash array referred by @HashWorking
2712 * from the challenge random numbers associated with the host, referred by
2713 * @RandomChallenge. The result is put into the entry of the working hash
2714 * array and returned by reference through @HashWorking.
2715 **/
dea31012005-04-17 16:05:31 -05002716static void
2717lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2718{
2719 *HashWorking = (*RandomChallenge ^ *HashWorking);
2720}
2721
James Smarte59058c2008-08-24 21:49:00 -04002722/**
James Smart3621a712009-04-06 18:47:14 -04002723 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002724 * @phba: pointer to lpfc hba data structure.
2725 * @hbainit: pointer to an array of unsigned 32-bit integers.
2726 *
2727 * This routine performs the special handling for LC HBA initialization.
2728 **/
dea31012005-04-17 16:05:31 -05002729void
2730lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2731{
2732 int t;
2733 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002734 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002735
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002736 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002737 if (!HashWorking)
2738 return;
2739
dea31012005-04-17 16:05:31 -05002740 HashWorking[0] = HashWorking[78] = *pwwnn++;
2741 HashWorking[1] = HashWorking[79] = *pwwnn;
2742
2743 for (t = 0; t < 7; t++)
2744 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2745
2746 lpfc_sha_init(hbainit);
2747 lpfc_sha_iterate(hbainit, HashWorking);
2748 kfree(HashWorking);
2749}
2750
James Smarte59058c2008-08-24 21:49:00 -04002751/**
James Smart3621a712009-04-06 18:47:14 -04002752 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002753 * @vport: pointer to a virtual N_Port data structure.
2754 *
2755 * This routine performs the necessary cleanups before deleting the @vport.
2756 * It invokes the discovery state machine to perform necessary state
2757 * transitions and to release the ndlps associated with the @vport. Note,
2758 * the physical port is treated as @vport 0.
2759 **/
James Smart87af33f2007-10-27 13:37:43 -04002760void
James Smart2e0fef82007-06-17 19:56:36 -05002761lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002762{
James Smart87af33f2007-10-27 13:37:43 -04002763 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002764 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002765 int i = 0;
dea31012005-04-17 16:05:31 -05002766
James Smart87af33f2007-10-27 13:37:43 -04002767 if (phba->link_state > LPFC_LINK_DOWN)
2768 lpfc_port_link_failure(vport);
2769
2770 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002771 if (!NLP_CHK_NODE_ACT(ndlp)) {
2772 ndlp = lpfc_enable_node(vport, ndlp,
2773 NLP_STE_UNUSED_NODE);
2774 if (!ndlp)
2775 continue;
2776 spin_lock_irq(&phba->ndlp_lock);
2777 NLP_SET_FREE_REQ(ndlp);
2778 spin_unlock_irq(&phba->ndlp_lock);
2779 /* Trigger the release of the ndlp memory */
2780 lpfc_nlp_put(ndlp);
2781 continue;
2782 }
2783 spin_lock_irq(&phba->ndlp_lock);
2784 if (NLP_CHK_FREE_REQ(ndlp)) {
2785 /* The ndlp should not be in memory free mode already */
2786 spin_unlock_irq(&phba->ndlp_lock);
2787 continue;
2788 } else
2789 /* Indicate request for freeing ndlp memory */
2790 NLP_SET_FREE_REQ(ndlp);
2791 spin_unlock_irq(&phba->ndlp_lock);
2792
James Smart58da1ff2008-04-07 10:15:56 -04002793 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2794 ndlp->nlp_DID == Fabric_DID) {
2795 /* Just free up ndlp with Fabric_DID for vports */
2796 lpfc_nlp_put(ndlp);
2797 continue;
2798 }
2799
James Smarteff4a012012-01-18 16:25:25 -05002800 /* take care of nodes in unused state before the state
2801 * machine taking action.
2802 */
2803 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2804 lpfc_nlp_put(ndlp);
2805 continue;
2806 }
2807
James Smart87af33f2007-10-27 13:37:43 -04002808 if (ndlp->nlp_type & NLP_FABRIC)
2809 lpfc_disc_state_machine(vport, ndlp, NULL,
2810 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002811
James Smart87af33f2007-10-27 13:37:43 -04002812 lpfc_disc_state_machine(vport, ndlp, NULL,
2813 NLP_EVT_DEVICE_RM);
2814 }
2815
James Smarta8adb832007-10-27 13:37:53 -04002816 /* At this point, ALL ndlp's should be gone
2817 * because of the previous NLP_EVT_DEVICE_RM.
2818 * Lets wait for this to happen, if needed.
2819 */
James Smart87af33f2007-10-27 13:37:43 -04002820 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002821 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04002822 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04002823 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002824 list_for_each_entry_safe(ndlp, next_ndlp,
2825 &vport->fc_nodes, nlp_listp) {
2826 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2827 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04002828 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05002829 "usgmap:x%x refcnt:%d\n",
2830 ndlp->nlp_DID, (void *)ndlp,
2831 ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01002832 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05002833 }
James Smarta8adb832007-10-27 13:37:53 -04002834 break;
James Smart87af33f2007-10-27 13:37:43 -04002835 }
James Smarta8adb832007-10-27 13:37:53 -04002836
2837 /* Wait for any activity on ndlps to settle */
2838 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002839 }
James Smart1151e3e2011-02-16 12:39:35 -05002840 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002841}
2842
James Smarte59058c2008-08-24 21:49:00 -04002843/**
James Smart3621a712009-04-06 18:47:14 -04002844 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002845 * @vport: pointer to a virtual N_Port data structure.
2846 *
2847 * This routine stops all the timers associated with a @vport. This function
2848 * is invoked before disabling or deleting a @vport. Note that the physical
2849 * port is treated as @vport 0.
2850 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002851void
2852lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002853{
James Smart92d7f7b2007-06-17 19:56:38 -05002854 del_timer_sync(&vport->els_tmofunc);
James Smart92494142011-02-16 12:39:44 -05002855 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002856 lpfc_can_disctmo(vport);
2857 return;
dea31012005-04-17 16:05:31 -05002858}
2859
James Smarte59058c2008-08-24 21:49:00 -04002860/**
James Smartecfd03c2010-02-12 14:41:27 -05002861 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2862 * @phba: pointer to lpfc hba data structure.
2863 *
2864 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2865 * caller of this routine should already hold the host lock.
2866 **/
2867void
2868__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2869{
James Smart5ac6b302010-10-22 11:05:36 -04002870 /* Clear pending FCF rediscovery wait flag */
2871 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2872
James Smartecfd03c2010-02-12 14:41:27 -05002873 /* Now, try to stop the timer */
2874 del_timer(&phba->fcf.redisc_wait);
2875}
2876
2877/**
2878 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2879 * @phba: pointer to lpfc hba data structure.
2880 *
2881 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2882 * checks whether the FCF rediscovery wait timer is pending with the host
2883 * lock held before proceeding with disabling the timer and clearing the
2884 * wait timer pendig flag.
2885 **/
2886void
2887lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2888{
2889 spin_lock_irq(&phba->hbalock);
2890 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2891 /* FCF rediscovery timer already fired or stopped */
2892 spin_unlock_irq(&phba->hbalock);
2893 return;
2894 }
2895 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002896 /* Clear failover in progress flags */
2897 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002898 spin_unlock_irq(&phba->hbalock);
2899}
2900
2901/**
James Smart3772a992009-05-22 14:50:54 -04002902 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002903 * @phba: pointer to lpfc hba data structure.
2904 *
2905 * This routine stops all the timers associated with a HBA. This function is
2906 * invoked before either putting a HBA offline or unloading the driver.
2907 **/
James Smart3772a992009-05-22 14:50:54 -04002908void
2909lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002910{
James Smart51ef4c22007-08-02 11:10:31 -04002911 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05002912 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002913 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002914 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002915 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002916 if (phba->sli_rev == LPFC_SLI_REV4) {
2917 del_timer_sync(&phba->rrq_tmr);
2918 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2919 }
James Smart3772a992009-05-22 14:50:54 -04002920 phba->hb_outstanding = 0;
2921
2922 switch (phba->pci_dev_grp) {
2923 case LPFC_PCI_DEV_LP:
2924 /* Stop any LightPulse device specific driver timers */
2925 del_timer_sync(&phba->fcp_poll_timer);
2926 break;
2927 case LPFC_PCI_DEV_OC:
2928 /* Stop any OneConnect device sepcific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002929 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002930 break;
2931 default:
2932 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2933 "0297 Invalid device group (x%x)\n",
2934 phba->pci_dev_grp);
2935 break;
2936 }
James Smart2e0fef82007-06-17 19:56:36 -05002937 return;
dea31012005-04-17 16:05:31 -05002938}
2939
James Smarte59058c2008-08-24 21:49:00 -04002940/**
James Smart3621a712009-04-06 18:47:14 -04002941 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002942 * @phba: pointer to lpfc hba data structure.
2943 *
2944 * This routine marks a HBA's management interface as blocked. Once the HBA's
2945 * management interface is marked as blocked, all the user space access to
2946 * the HBA, whether they are from sysfs interface or libdfc interface will
2947 * all be blocked. The HBA is set to block the management interface when the
2948 * driver prepares the HBA interface for online or offline.
2949 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01002950static void
James Smart618a5232012-06-12 13:54:36 -04002951lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
Adrian Bunka6ababd2007-11-05 18:07:33 +01002952{
2953 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04002954 uint8_t actcmd = MBX_HEARTBEAT;
2955 unsigned long timeout;
2956
Adrian Bunka6ababd2007-11-05 18:07:33 +01002957 spin_lock_irqsave(&phba->hbalock, iflag);
2958 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart618a5232012-06-12 13:54:36 -04002959 spin_unlock_irqrestore(&phba->hbalock, iflag);
2960 if (mbx_action == LPFC_MBX_NO_WAIT)
2961 return;
2962 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2963 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002964 if (phba->sli.mbox_active) {
James Smart6e7288d2010-06-07 15:23:35 -04002965 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
James Smarta183a152011-10-10 21:32:43 -04002966 /* Determine how long we might wait for the active mailbox
2967 * command to be gracefully completed by firmware.
2968 */
2969 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
2970 phba->sli.mbox_active) * 1000) + jiffies;
2971 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002972 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002973
James Smart6e7288d2010-06-07 15:23:35 -04002974 /* Wait for the outstnading mailbox command to complete */
2975 while (phba->sli.mbox_active) {
2976 /* Check active mailbox complete status every 2ms */
2977 msleep(2);
2978 if (time_after(jiffies, timeout)) {
2979 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2980 "2813 Mgmt IO is Blocked %x "
2981 "- mbox cmd %x still active\n",
2982 phba->sli.sli_flag, actcmd);
2983 break;
2984 }
2985 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002986}
2987
James Smarte59058c2008-08-24 21:49:00 -04002988/**
James Smart6b5151f2012-01-18 16:24:06 -05002989 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
2990 * @phba: pointer to lpfc hba data structure.
2991 *
2992 * Allocate RPIs for all active remote nodes. This is needed whenever
2993 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
2994 * is to fixup the temporary rpi assignments.
2995 **/
2996void
2997lpfc_sli4_node_prep(struct lpfc_hba *phba)
2998{
2999 struct lpfc_nodelist *ndlp, *next_ndlp;
3000 struct lpfc_vport **vports;
James Smart9d3d3402017-04-21 16:05:00 -07003001 int i, rpi;
3002 unsigned long flags;
James Smart6b5151f2012-01-18 16:24:06 -05003003
3004 if (phba->sli_rev != LPFC_SLI_REV4)
3005 return;
3006
3007 vports = lpfc_create_vport_work_array(phba);
James Smart9d3d3402017-04-21 16:05:00 -07003008 if (vports == NULL)
3009 return;
James Smart6b5151f2012-01-18 16:24:06 -05003010
James Smart9d3d3402017-04-21 16:05:00 -07003011 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3012 if (vports[i]->load_flag & FC_UNLOADING)
3013 continue;
3014
3015 list_for_each_entry_safe(ndlp, next_ndlp,
3016 &vports[i]->fc_nodes,
3017 nlp_listp) {
3018 if (!NLP_CHK_NODE_ACT(ndlp))
3019 continue;
3020 rpi = lpfc_sli4_alloc_rpi(phba);
3021 if (rpi == LPFC_RPI_ALLOC_ERROR) {
3022 spin_lock_irqsave(&phba->ndlp_lock, flags);
3023 NLP_CLR_NODE_ACT(ndlp);
3024 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3025 continue;
James Smart6b5151f2012-01-18 16:24:06 -05003026 }
James Smart9d3d3402017-04-21 16:05:00 -07003027 ndlp->nlp_rpi = rpi;
3028 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3029 "0009 rpi:%x DID:%x "
3030 "flg:%x map:%x %p\n", ndlp->nlp_rpi,
3031 ndlp->nlp_DID, ndlp->nlp_flag,
3032 ndlp->nlp_usg_map, ndlp);
James Smart6b5151f2012-01-18 16:24:06 -05003033 }
3034 }
3035 lpfc_destroy_vport_work_array(phba, vports);
3036}
3037
3038/**
James Smart3621a712009-04-06 18:47:14 -04003039 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04003040 * @phba: pointer to lpfc hba data structure.
3041 *
3042 * This routine initializes the HBA and brings a HBA online. During this
3043 * process, the management interface is blocked to prevent user space access
3044 * to the HBA interfering with the driver initialization.
3045 *
3046 * Return codes
3047 * 0 - successful
3048 * 1 - failed
3049 **/
dea31012005-04-17 16:05:31 -05003050int
James Smart2e0fef82007-06-17 19:56:36 -05003051lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003052{
Julia Lawall372bd282008-12-16 16:15:08 +01003053 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04003054 struct lpfc_vport **vports;
Dick Kennedya145fda2017-08-23 16:55:44 -07003055 int i, error = 0;
James Smart16a3a202013-04-17 20:14:38 -04003056 bool vpis_cleared = false;
James Smart2e0fef82007-06-17 19:56:36 -05003057
dea31012005-04-17 16:05:31 -05003058 if (!phba)
3059 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01003060 vport = phba->pport;
dea31012005-04-17 16:05:31 -05003061
James Smart2e0fef82007-06-17 19:56:36 -05003062 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05003063 return 0;
3064
James Smarted957682007-06-17 19:56:37 -05003065 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003066 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05003067
James Smart618a5232012-06-12 13:54:36 -04003068 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05003069
James Smartda0436e2009-05-22 14:51:39 -04003070 if (phba->sli_rev == LPFC_SLI_REV4) {
3071 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
3072 lpfc_unblock_mgmt_io(phba);
3073 return 1;
3074 }
James Smart16a3a202013-04-17 20:14:38 -04003075 spin_lock_irq(&phba->hbalock);
3076 if (!phba->sli4_hba.max_cfg_param.vpi_used)
3077 vpis_cleared = true;
3078 spin_unlock_irq(&phba->hbalock);
Dick Kennedya145fda2017-08-23 16:55:44 -07003079
3080 /* Reestablish the local initiator port.
3081 * The offline process destroyed the previous lport.
3082 */
3083 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
3084 !phba->nvmet_support) {
3085 error = lpfc_nvme_create_localport(phba->pport);
3086 if (error)
3087 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3088 "6132 NVME restore reg failed "
3089 "on nvmei error x%x\n", error);
3090 }
James Smartda0436e2009-05-22 14:51:39 -04003091 } else {
James Smart895427b2017-02-12 13:52:30 -08003092 lpfc_sli_queue_init(phba);
James Smartda0436e2009-05-22 14:51:39 -04003093 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
3094 lpfc_unblock_mgmt_io(phba);
3095 return 1;
3096 }
James Smart46fa3112007-04-25 09:51:45 -04003097 }
dea31012005-04-17 16:05:31 -05003098
James Smart549e55c2007-08-02 11:09:51 -04003099 vports = lpfc_create_vport_work_array(phba);
Arnd Bergmannaeb66412016-03-14 15:29:44 +01003100 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003101 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003102 struct Scsi_Host *shost;
3103 shost = lpfc_shost_from_vport(vports[i]);
3104 spin_lock_irq(shost->host_lock);
3105 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
3106 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
3107 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart16a3a202013-04-17 20:14:38 -04003108 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart1c6834a2009-07-19 10:01:26 -04003109 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart16a3a202013-04-17 20:14:38 -04003110 if ((vpis_cleared) &&
3111 (vports[i]->port_type !=
3112 LPFC_PHYSICAL_PORT))
3113 vports[i]->vpi = 0;
3114 }
James Smart549e55c2007-08-02 11:09:51 -04003115 spin_unlock_irq(shost->host_lock);
3116 }
Arnd Bergmannaeb66412016-03-14 15:29:44 +01003117 }
3118 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003119
James Smart46fa3112007-04-25 09:51:45 -04003120 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05003121 return 0;
3122}
3123
James Smarte59058c2008-08-24 21:49:00 -04003124/**
James Smart3621a712009-04-06 18:47:14 -04003125 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04003126 * @phba: pointer to lpfc hba data structure.
3127 *
3128 * This routine marks a HBA's management interface as not blocked. Once the
3129 * HBA's management interface is marked as not blocked, all the user space
3130 * access to the HBA, whether they are from sysfs interface or libdfc
3131 * interface will be allowed. The HBA is set to block the management interface
3132 * when the driver prepares the HBA interface for online or offline and then
3133 * set to unblock the management interface afterwards.
3134 **/
James Smart46fa3112007-04-25 09:51:45 -04003135void
James Smart46fa3112007-04-25 09:51:45 -04003136lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
3137{
3138 unsigned long iflag;
3139
James Smart2e0fef82007-06-17 19:56:36 -05003140 spin_lock_irqsave(&phba->hbalock, iflag);
3141 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3142 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04003143}
3144
James Smarte59058c2008-08-24 21:49:00 -04003145/**
James Smart3621a712009-04-06 18:47:14 -04003146 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04003147 * @phba: pointer to lpfc hba data structure.
3148 *
3149 * This routine is invoked to prepare a HBA to be brought offline. It performs
3150 * unregistration login to all the nodes on all vports and flushes the mailbox
3151 * queue to make it ready to be brought offline.
3152 **/
James Smart46fa3112007-04-25 09:51:45 -04003153void
James Smart618a5232012-06-12 13:54:36 -04003154lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04003155{
James Smart2e0fef82007-06-17 19:56:36 -05003156 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04003157 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04003158 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05003159 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04003160 int i;
dea31012005-04-17 16:05:31 -05003161
James Smart2e0fef82007-06-17 19:56:36 -05003162 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003163 return;
dea31012005-04-17 16:05:31 -05003164
James Smart618a5232012-06-12 13:54:36 -04003165 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05003166
3167 lpfc_linkdown(phba);
3168
James Smart87af33f2007-10-27 13:37:43 -04003169 /* Issue an unreg_login to all nodes on all vports */
3170 vports = lpfc_create_vport_work_array(phba);
3171 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003172 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04003173 if (vports[i]->load_flag & FC_UNLOADING)
3174 continue;
James Smart72100cc2010-02-12 14:43:01 -05003175 shost = lpfc_shost_from_vport(vports[i]);
3176 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003177 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003178 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3179 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05003180 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05003181
James Smart87af33f2007-10-27 13:37:43 -04003182 shost = lpfc_shost_from_vport(vports[i]);
3183 list_for_each_entry_safe(ndlp, next_ndlp,
3184 &vports[i]->fc_nodes,
3185 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003186 if (!NLP_CHK_NODE_ACT(ndlp))
3187 continue;
James Smart87af33f2007-10-27 13:37:43 -04003188 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3189 continue;
3190 if (ndlp->nlp_type & NLP_FABRIC) {
3191 lpfc_disc_state_machine(vports[i], ndlp,
3192 NULL, NLP_EVT_DEVICE_RECOVERY);
3193 lpfc_disc_state_machine(vports[i], ndlp,
3194 NULL, NLP_EVT_DEVICE_RM);
3195 }
3196 spin_lock_irq(shost->host_lock);
3197 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart401ee0c2012-03-01 22:35:34 -05003198 spin_unlock_irq(shost->host_lock);
James Smart6b5151f2012-01-18 16:24:06 -05003199 /*
3200 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05003201 * RPI. Get a new RPI when the adapter port
3202 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05003203 */
James Smartbe6bb942015-04-07 15:07:22 -04003204 if (phba->sli_rev == LPFC_SLI_REV4) {
3205 lpfc_printf_vlog(ndlp->vport,
3206 KERN_INFO, LOG_NODE,
3207 "0011 lpfc_offline: "
3208 "ndlp:x%p did %x "
3209 "usgmap:x%x rpi:%x\n",
3210 ndlp, ndlp->nlp_DID,
3211 ndlp->nlp_usg_map,
3212 ndlp->nlp_rpi);
3213
James Smart6b5151f2012-01-18 16:24:06 -05003214 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smartbe6bb942015-04-07 15:07:22 -04003215 }
James Smart87af33f2007-10-27 13:37:43 -04003216 lpfc_unreg_rpi(vports[i], ndlp);
3217 }
3218 }
3219 }
James Smart09372822008-01-11 01:52:54 -05003220 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003221
James Smart618a5232012-06-12 13:54:36 -04003222 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
Dick Kennedyf485c182017-09-29 17:34:34 -07003223
3224 if (phba->wq)
3225 flush_workqueue(phba->wq);
James Smart46fa3112007-04-25 09:51:45 -04003226}
3227
James Smarte59058c2008-08-24 21:49:00 -04003228/**
James Smart3621a712009-04-06 18:47:14 -04003229 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04003230 * @phba: pointer to lpfc hba data structure.
3231 *
3232 * This routine actually brings a HBA offline. It stops all the timers
3233 * associated with the HBA, brings down the SLI layer, and eventually
3234 * marks the HBA as in offline state for the upper layer protocol.
3235 **/
James Smart46fa3112007-04-25 09:51:45 -04003236void
James Smart2e0fef82007-06-17 19:56:36 -05003237lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04003238{
James Smart549e55c2007-08-02 11:09:51 -04003239 struct Scsi_Host *shost;
3240 struct lpfc_vport **vports;
3241 int i;
James Smart46fa3112007-04-25 09:51:45 -04003242
James Smart549e55c2007-08-02 11:09:51 -04003243 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003244 return;
James Smart688a8862006-07-06 15:49:56 -04003245
James Smartda0436e2009-05-22 14:51:39 -04003246 /* stop port and all timers associated with this hba */
3247 lpfc_stop_port(phba);
Dick Kennedy4b40d022017-08-23 16:55:38 -07003248
3249 /* Tear down the local and target port registrations. The
3250 * nvme transports need to cleanup.
3251 */
3252 lpfc_nvmet_destroy_targetport(phba);
3253 lpfc_nvme_destroy_localport(phba->pport);
3254
James Smart51ef4c22007-08-02 11:10:31 -04003255 vports = lpfc_create_vport_work_array(phba);
3256 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003257 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04003258 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05003259 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05003260 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003261 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05003262 /* Bring down the SLI Layer and cleanup. The HBA is offline
3263 now. */
3264 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003265 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04003266 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003267 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04003268 vports = lpfc_create_vport_work_array(phba);
3269 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003270 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003271 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04003272 spin_lock_irq(shost->host_lock);
3273 vports[i]->work_port_events = 0;
3274 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3275 spin_unlock_irq(shost->host_lock);
3276 }
James Smart09372822008-01-11 01:52:54 -05003277 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003278}
3279
James Smarte59058c2008-08-24 21:49:00 -04003280/**
James Smart3621a712009-04-06 18:47:14 -04003281 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04003282 * @phba: pointer to lpfc hba data structure.
3283 *
3284 * This routine is to free all the SCSI buffers and IOCBs from the driver
3285 * list back to kernel. It is called from lpfc_pci_remove_one to free
3286 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04003287 **/
James Smart8a9d2e82012-05-09 21:16:12 -04003288static void
James Smart2e0fef82007-06-17 19:56:36 -05003289lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003290{
3291 struct lpfc_scsi_buf *sb, *sb_next;
dea31012005-04-17 16:05:31 -05003292
James Smart895427b2017-02-12 13:52:30 -08003293 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3294 return;
3295
James Smart2e0fef82007-06-17 19:56:36 -05003296 spin_lock_irq(&phba->hbalock);
James Smarta40fc5f2013-04-17 20:17:40 -04003297
dea31012005-04-17 16:05:31 -05003298 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smarta40fc5f2013-04-17 20:17:40 -04003299
3300 spin_lock(&phba->scsi_buf_list_put_lock);
3301 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3302 list) {
dea31012005-04-17 16:05:31 -05003303 list_del(&sb->list);
Romain Perier771db5c2017-07-06 10:13:05 +02003304 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05003305 sb->dma_handle);
dea31012005-04-17 16:05:31 -05003306 kfree(sb);
3307 phba->total_scsi_bufs--;
3308 }
James Smarta40fc5f2013-04-17 20:17:40 -04003309 spin_unlock(&phba->scsi_buf_list_put_lock);
3310
3311 spin_lock(&phba->scsi_buf_list_get_lock);
3312 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3313 list) {
3314 list_del(&sb->list);
Romain Perier771db5c2017-07-06 10:13:05 +02003315 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smarta40fc5f2013-04-17 20:17:40 -04003316 sb->dma_handle);
3317 kfree(sb);
3318 phba->total_scsi_bufs--;
3319 }
3320 spin_unlock(&phba->scsi_buf_list_get_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003321 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003322}
James Smart8a9d2e82012-05-09 21:16:12 -04003323/**
James Smart895427b2017-02-12 13:52:30 -08003324 * lpfc_nvme_free - Free all the NVME buffers and IOCBs from driver lists
3325 * @phba: pointer to lpfc hba data structure.
3326 *
3327 * This routine is to free all the NVME buffers and IOCBs from the driver
3328 * list back to kernel. It is called from lpfc_pci_remove_one to free
3329 * the internal resources before the device is removed from the system.
3330 **/
3331static void
3332lpfc_nvme_free(struct lpfc_hba *phba)
3333{
3334 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
James Smart895427b2017-02-12 13:52:30 -08003335
3336 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3337 return;
3338
3339 spin_lock_irq(&phba->hbalock);
3340
3341 /* Release all the lpfc_nvme_bufs maintained by this host. */
3342 spin_lock(&phba->nvme_buf_list_put_lock);
3343 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3344 &phba->lpfc_nvme_buf_list_put, list) {
3345 list_del(&lpfc_ncmd->list);
James Smartcf1a1d32017-12-08 17:18:03 -08003346 phba->put_nvme_bufs--;
Romain Perier771db5c2017-07-06 10:13:05 +02003347 dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
James Smart895427b2017-02-12 13:52:30 -08003348 lpfc_ncmd->dma_handle);
3349 kfree(lpfc_ncmd);
3350 phba->total_nvme_bufs--;
3351 }
3352 spin_unlock(&phba->nvme_buf_list_put_lock);
3353
3354 spin_lock(&phba->nvme_buf_list_get_lock);
3355 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3356 &phba->lpfc_nvme_buf_list_get, list) {
3357 list_del(&lpfc_ncmd->list);
James Smartcf1a1d32017-12-08 17:18:03 -08003358 phba->get_nvme_bufs--;
Romain Perier771db5c2017-07-06 10:13:05 +02003359 dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
James Smart895427b2017-02-12 13:52:30 -08003360 lpfc_ncmd->dma_handle);
3361 kfree(lpfc_ncmd);
3362 phba->total_nvme_bufs--;
3363 }
3364 spin_unlock(&phba->nvme_buf_list_get_lock);
James Smart895427b2017-02-12 13:52:30 -08003365 spin_unlock_irq(&phba->hbalock);
3366}
3367/**
3368 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
James Smart8a9d2e82012-05-09 21:16:12 -04003369 * @phba: pointer to lpfc hba data structure.
3370 *
3371 * This routine first calculates the sizes of the current els and allocated
3372 * scsi sgl lists, and then goes through all sgls to updates the physical
3373 * XRIs assigned due to port function reset. During port initialization, the
3374 * current els and allocated scsi sgl lists are 0s.
3375 *
3376 * Return codes
3377 * 0 - successful (for now, it always returns 0)
3378 **/
3379int
James Smart895427b2017-02-12 13:52:30 -08003380lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
James Smart8a9d2e82012-05-09 21:16:12 -04003381{
3382 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
James Smart895427b2017-02-12 13:52:30 -08003383 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart8a9d2e82012-05-09 21:16:12 -04003384 LIST_HEAD(els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003385 int rc;
3386
3387 /*
3388 * update on pci function's els xri-sgl list
3389 */
3390 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart895427b2017-02-12 13:52:30 -08003391
James Smart8a9d2e82012-05-09 21:16:12 -04003392 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3393 /* els xri-sgl expanded */
3394 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3395 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3396 "3157 ELS xri-sgl count increased from "
3397 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3398 els_xri_cnt);
3399 /* allocate the additional els sgls */
3400 for (i = 0; i < xri_cnt; i++) {
3401 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3402 GFP_KERNEL);
3403 if (sglq_entry == NULL) {
3404 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3405 "2562 Failure to allocate an "
3406 "ELS sgl entry:%d\n", i);
3407 rc = -ENOMEM;
3408 goto out_free_mem;
3409 }
3410 sglq_entry->buff_type = GEN_BUFF_TYPE;
3411 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3412 &sglq_entry->phys);
3413 if (sglq_entry->virt == NULL) {
3414 kfree(sglq_entry);
3415 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3416 "2563 Failure to allocate an "
3417 "ELS mbuf:%d\n", i);
3418 rc = -ENOMEM;
3419 goto out_free_mem;
3420 }
3421 sglq_entry->sgl = sglq_entry->virt;
3422 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3423 sglq_entry->state = SGL_FREED;
3424 list_add_tail(&sglq_entry->list, &els_sgl_list);
3425 }
James Smart38c20672013-03-01 16:37:44 -05003426 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003427 spin_lock(&phba->sli4_hba.sgl_list_lock);
3428 list_splice_init(&els_sgl_list,
3429 &phba->sli4_hba.lpfc_els_sgl_list);
3430 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart38c20672013-03-01 16:37:44 -05003431 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003432 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3433 /* els xri-sgl shrinked */
3434 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3435 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3436 "3158 ELS xri-sgl count decreased from "
3437 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3438 els_xri_cnt);
3439 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003440 spin_lock(&phba->sli4_hba.sgl_list_lock);
3441 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
3442 &els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003443 /* release extra els sgls from list */
3444 for (i = 0; i < xri_cnt; i++) {
3445 list_remove_head(&els_sgl_list,
3446 sglq_entry, struct lpfc_sglq, list);
3447 if (sglq_entry) {
James Smart895427b2017-02-12 13:52:30 -08003448 __lpfc_mbuf_free(phba, sglq_entry->virt,
3449 sglq_entry->phys);
James Smart8a9d2e82012-05-09 21:16:12 -04003450 kfree(sglq_entry);
3451 }
3452 }
James Smart895427b2017-02-12 13:52:30 -08003453 list_splice_init(&els_sgl_list,
3454 &phba->sli4_hba.lpfc_els_sgl_list);
3455 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003456 spin_unlock_irq(&phba->hbalock);
3457 } else
3458 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3459 "3163 ELS xri-sgl count unchanged: %d\n",
3460 els_xri_cnt);
3461 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3462
3463 /* update xris to els sgls on the list */
3464 sglq_entry = NULL;
3465 sglq_entry_next = NULL;
3466 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
James Smart895427b2017-02-12 13:52:30 -08003467 &phba->sli4_hba.lpfc_els_sgl_list, list) {
James Smart8a9d2e82012-05-09 21:16:12 -04003468 lxri = lpfc_sli4_next_xritag(phba);
3469 if (lxri == NO_XRI) {
3470 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3471 "2400 Failed to allocate xri for "
3472 "ELS sgl\n");
3473 rc = -ENOMEM;
3474 goto out_free_mem;
3475 }
3476 sglq_entry->sli4_lxritag = lxri;
3477 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3478 }
James Smart895427b2017-02-12 13:52:30 -08003479 return 0;
3480
3481out_free_mem:
3482 lpfc_free_els_sgl_list(phba);
3483 return rc;
3484}
3485
3486/**
James Smartf358dd02017-02-12 13:52:34 -08003487 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
3488 * @phba: pointer to lpfc hba data structure.
3489 *
3490 * This routine first calculates the sizes of the current els and allocated
3491 * scsi sgl lists, and then goes through all sgls to updates the physical
3492 * XRIs assigned due to port function reset. During port initialization, the
3493 * current els and allocated scsi sgl lists are 0s.
3494 *
3495 * Return codes
3496 * 0 - successful (for now, it always returns 0)
3497 **/
3498int
3499lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
3500{
3501 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3502 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart6c621a22017-05-15 15:20:45 -07003503 uint16_t nvmet_xri_cnt;
James Smartf358dd02017-02-12 13:52:34 -08003504 LIST_HEAD(nvmet_sgl_list);
3505 int rc;
3506
3507 /*
3508 * update on pci function's nvmet xri-sgl list
3509 */
3510 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart61f3d4b2017-05-15 15:20:41 -07003511
James Smart6c621a22017-05-15 15:20:45 -07003512 /* For NVMET, ALL remaining XRIs are dedicated for IO processing */
3513 nvmet_xri_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
James Smartf358dd02017-02-12 13:52:34 -08003514 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
3515 /* els xri-sgl expanded */
3516 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
3517 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3518 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
3519 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
3520 /* allocate the additional nvmet sgls */
3521 for (i = 0; i < xri_cnt; i++) {
3522 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3523 GFP_KERNEL);
3524 if (sglq_entry == NULL) {
3525 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3526 "6303 Failure to allocate an "
3527 "NVMET sgl entry:%d\n", i);
3528 rc = -ENOMEM;
3529 goto out_free_mem;
3530 }
3531 sglq_entry->buff_type = NVMET_BUFF_TYPE;
3532 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
3533 &sglq_entry->phys);
3534 if (sglq_entry->virt == NULL) {
3535 kfree(sglq_entry);
3536 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3537 "6304 Failure to allocate an "
3538 "NVMET buf:%d\n", i);
3539 rc = -ENOMEM;
3540 goto out_free_mem;
3541 }
3542 sglq_entry->sgl = sglq_entry->virt;
3543 memset(sglq_entry->sgl, 0,
3544 phba->cfg_sg_dma_buf_size);
3545 sglq_entry->state = SGL_FREED;
3546 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
3547 }
3548 spin_lock_irq(&phba->hbalock);
3549 spin_lock(&phba->sli4_hba.sgl_list_lock);
3550 list_splice_init(&nvmet_sgl_list,
3551 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3552 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3553 spin_unlock_irq(&phba->hbalock);
3554 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
3555 /* nvmet xri-sgl shrunk */
3556 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
3557 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3558 "6305 NVMET xri-sgl count decreased from "
3559 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
3560 nvmet_xri_cnt);
3561 spin_lock_irq(&phba->hbalock);
3562 spin_lock(&phba->sli4_hba.sgl_list_lock);
3563 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
3564 &nvmet_sgl_list);
3565 /* release extra nvmet sgls from list */
3566 for (i = 0; i < xri_cnt; i++) {
3567 list_remove_head(&nvmet_sgl_list,
3568 sglq_entry, struct lpfc_sglq, list);
3569 if (sglq_entry) {
3570 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
3571 sglq_entry->phys);
3572 kfree(sglq_entry);
3573 }
3574 }
3575 list_splice_init(&nvmet_sgl_list,
3576 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3577 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3578 spin_unlock_irq(&phba->hbalock);
3579 } else
3580 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3581 "6306 NVMET xri-sgl count unchanged: %d\n",
3582 nvmet_xri_cnt);
3583 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
3584
3585 /* update xris to nvmet sgls on the list */
3586 sglq_entry = NULL;
3587 sglq_entry_next = NULL;
3588 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3589 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
3590 lxri = lpfc_sli4_next_xritag(phba);
3591 if (lxri == NO_XRI) {
3592 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3593 "6307 Failed to allocate xri for "
3594 "NVMET sgl\n");
3595 rc = -ENOMEM;
3596 goto out_free_mem;
3597 }
3598 sglq_entry->sli4_lxritag = lxri;
3599 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3600 }
3601 return 0;
3602
3603out_free_mem:
3604 lpfc_free_nvmet_sgl_list(phba);
3605 return rc;
3606}
3607
3608/**
James Smart895427b2017-02-12 13:52:30 -08003609 * lpfc_sli4_scsi_sgl_update - update xri-sgl sizing and mapping
3610 * @phba: pointer to lpfc hba data structure.
3611 *
3612 * This routine first calculates the sizes of the current els and allocated
3613 * scsi sgl lists, and then goes through all sgls to updates the physical
3614 * XRIs assigned due to port function reset. During port initialization, the
3615 * current els and allocated scsi sgl lists are 0s.
3616 *
3617 * Return codes
3618 * 0 - successful (for now, it always returns 0)
3619 **/
3620int
3621lpfc_sli4_scsi_sgl_update(struct lpfc_hba *phba)
3622{
3623 struct lpfc_scsi_buf *psb, *psb_next;
3624 uint16_t i, lxri, els_xri_cnt, scsi_xri_cnt;
3625 LIST_HEAD(scsi_sgl_list);
3626 int rc;
3627
3628 /*
3629 * update on pci function's els xri-sgl list
3630 */
3631 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3632 phba->total_scsi_bufs = 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003633
3634 /*
3635 * update on pci function's allocated scsi xri-sgl list
3636 */
James Smart8a9d2e82012-05-09 21:16:12 -04003637 /* maximum number of xris available for scsi buffers */
3638 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3639 els_xri_cnt;
3640
James Smart895427b2017-02-12 13:52:30 -08003641 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3642 return 0;
3643
3644 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3645 phba->sli4_hba.scsi_xri_max = /* Split them up */
3646 (phba->sli4_hba.scsi_xri_max *
3647 phba->cfg_xri_split) / 100;
James Smart8a9d2e82012-05-09 21:16:12 -04003648
James Smarta40fc5f2013-04-17 20:17:40 -04003649 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003650 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003651 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3652 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
James Smart164cecd2013-09-06 12:22:38 -04003653 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003654 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003655
James Smarte8c0a772017-04-21 16:04:49 -07003656 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3657 "6060 Current allocated SCSI xri-sgl count:%d, "
3658 "maximum SCSI xri count:%d (split:%d)\n",
3659 phba->sli4_hba.scsi_xri_cnt,
3660 phba->sli4_hba.scsi_xri_max, phba->cfg_xri_split);
3661
James Smart8a9d2e82012-05-09 21:16:12 -04003662 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3663 /* max scsi xri shrinked below the allocated scsi buffers */
3664 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3665 phba->sli4_hba.scsi_xri_max;
3666 /* release the extra allocated scsi buffers */
3667 for (i = 0; i < scsi_xri_cnt; i++) {
3668 list_remove_head(&scsi_sgl_list, psb,
3669 struct lpfc_scsi_buf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04003670 if (psb) {
Romain Perier771db5c2017-07-06 10:13:05 +02003671 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
James Smarta2fc4aef2014-09-03 12:57:55 -04003672 psb->data, psb->dma_handle);
3673 kfree(psb);
3674 }
James Smart8a9d2e82012-05-09 21:16:12 -04003675 }
James Smarta40fc5f2013-04-17 20:17:40 -04003676 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003677 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
James Smarta40fc5f2013-04-17 20:17:40 -04003678 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003679 }
3680
3681 /* update xris associated to remaining allocated scsi buffers */
3682 psb = NULL;
3683 psb_next = NULL;
3684 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3685 lxri = lpfc_sli4_next_xritag(phba);
3686 if (lxri == NO_XRI) {
3687 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3688 "2560 Failed to allocate xri for "
3689 "scsi buffer\n");
3690 rc = -ENOMEM;
3691 goto out_free_mem;
3692 }
3693 psb->cur_iocbq.sli4_lxritag = lxri;
3694 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3695 }
James Smarta40fc5f2013-04-17 20:17:40 -04003696 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003697 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003698 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3699 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
James Smart164cecd2013-09-06 12:22:38 -04003700 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003701 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
dea31012005-04-17 16:05:31 -05003702 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003703
3704out_free_mem:
James Smart8a9d2e82012-05-09 21:16:12 -04003705 lpfc_scsi_free(phba);
3706 return rc;
dea31012005-04-17 16:05:31 -05003707}
3708
James Smart96418b52017-03-04 09:30:31 -08003709static uint64_t
3710lpfc_get_wwpn(struct lpfc_hba *phba)
3711{
3712 uint64_t wwn;
3713 int rc;
3714 LPFC_MBOXQ_t *mboxq;
3715 MAILBOX_t *mb;
3716
James Smart96418b52017-03-04 09:30:31 -08003717 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
3718 GFP_KERNEL);
3719 if (!mboxq)
3720 return (uint64_t)-1;
3721
3722 /* First get WWN of HBA instance */
3723 lpfc_read_nv(phba, mboxq);
3724 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
3725 if (rc != MBX_SUCCESS) {
3726 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3727 "6019 Mailbox failed , mbxCmd x%x "
3728 "READ_NV, mbxStatus x%x\n",
3729 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
3730 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
3731 mempool_free(mboxq, phba->mbox_mem_pool);
3732 return (uint64_t) -1;
3733 }
3734 mb = &mboxq->u.mb;
3735 memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
3736 /* wwn is WWPN of HBA instance */
3737 mempool_free(mboxq, phba->mbox_mem_pool);
3738 if (phba->sli_rev == LPFC_SLI_REV4)
3739 return be64_to_cpu(wwn);
3740 else
Maurizio Lombardi286871a2017-08-23 16:55:48 -07003741 return rol64(wwn, 32);
James Smart96418b52017-03-04 09:30:31 -08003742}
3743
James Smarte59058c2008-08-24 21:49:00 -04003744/**
James Smart895427b2017-02-12 13:52:30 -08003745 * lpfc_sli4_nvme_sgl_update - update xri-sgl sizing and mapping
3746 * @phba: pointer to lpfc hba data structure.
3747 *
3748 * This routine first calculates the sizes of the current els and allocated
3749 * scsi sgl lists, and then goes through all sgls to updates the physical
3750 * XRIs assigned due to port function reset. During port initialization, the
3751 * current els and allocated scsi sgl lists are 0s.
3752 *
3753 * Return codes
3754 * 0 - successful (for now, it always returns 0)
3755 **/
3756int
3757lpfc_sli4_nvme_sgl_update(struct lpfc_hba *phba)
3758{
3759 struct lpfc_nvme_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
3760 uint16_t i, lxri, els_xri_cnt;
3761 uint16_t nvme_xri_cnt, nvme_xri_max;
3762 LIST_HEAD(nvme_sgl_list);
James Smartcf1a1d32017-12-08 17:18:03 -08003763 int rc, cnt;
James Smart895427b2017-02-12 13:52:30 -08003764
3765 phba->total_nvme_bufs = 0;
James Smartcf1a1d32017-12-08 17:18:03 -08003766 phba->get_nvme_bufs = 0;
3767 phba->put_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08003768
3769 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3770 return 0;
3771 /*
3772 * update on pci function's allocated nvme xri-sgl list
3773 */
3774
3775 /* maximum number of xris available for nvme buffers */
3776 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3777 nvme_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3778 phba->sli4_hba.nvme_xri_max = nvme_xri_max;
3779 phba->sli4_hba.nvme_xri_max -= phba->sli4_hba.scsi_xri_max;
3780
3781 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3782 "6074 Current allocated NVME xri-sgl count:%d, "
3783 "maximum NVME xri count:%d\n",
3784 phba->sli4_hba.nvme_xri_cnt,
3785 phba->sli4_hba.nvme_xri_max);
3786
3787 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3788 spin_lock(&phba->nvme_buf_list_put_lock);
3789 list_splice_init(&phba->lpfc_nvme_buf_list_get, &nvme_sgl_list);
3790 list_splice(&phba->lpfc_nvme_buf_list_put, &nvme_sgl_list);
James Smartcf1a1d32017-12-08 17:18:03 -08003791 cnt = phba->get_nvme_bufs + phba->put_nvme_bufs;
3792 phba->get_nvme_bufs = 0;
3793 phba->put_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08003794 spin_unlock(&phba->nvme_buf_list_put_lock);
3795 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3796
3797 if (phba->sli4_hba.nvme_xri_cnt > phba->sli4_hba.nvme_xri_max) {
3798 /* max nvme xri shrunk below the allocated nvme buffers */
3799 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3800 nvme_xri_cnt = phba->sli4_hba.nvme_xri_cnt -
3801 phba->sli4_hba.nvme_xri_max;
3802 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3803 /* release the extra allocated nvme buffers */
3804 for (i = 0; i < nvme_xri_cnt; i++) {
3805 list_remove_head(&nvme_sgl_list, lpfc_ncmd,
3806 struct lpfc_nvme_buf, list);
3807 if (lpfc_ncmd) {
Romain Perier771db5c2017-07-06 10:13:05 +02003808 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
James Smart895427b2017-02-12 13:52:30 -08003809 lpfc_ncmd->data,
3810 lpfc_ncmd->dma_handle);
3811 kfree(lpfc_ncmd);
3812 }
3813 }
3814 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3815 phba->sli4_hba.nvme_xri_cnt -= nvme_xri_cnt;
3816 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3817 }
3818
3819 /* update xris associated to remaining allocated nvme buffers */
3820 lpfc_ncmd = NULL;
3821 lpfc_ncmd_next = NULL;
3822 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3823 &nvme_sgl_list, list) {
3824 lxri = lpfc_sli4_next_xritag(phba);
3825 if (lxri == NO_XRI) {
3826 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3827 "6075 Failed to allocate xri for "
3828 "nvme buffer\n");
3829 rc = -ENOMEM;
3830 goto out_free_mem;
3831 }
3832 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
3833 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3834 }
3835 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3836 spin_lock(&phba->nvme_buf_list_put_lock);
3837 list_splice_init(&nvme_sgl_list, &phba->lpfc_nvme_buf_list_get);
James Smartcf1a1d32017-12-08 17:18:03 -08003838 phba->get_nvme_bufs = cnt;
James Smart895427b2017-02-12 13:52:30 -08003839 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
3840 spin_unlock(&phba->nvme_buf_list_put_lock);
3841 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3842 return 0;
3843
3844out_free_mem:
3845 lpfc_nvme_free(phba);
3846 return rc;
3847}
3848
3849/**
James Smart3621a712009-04-06 18:47:14 -04003850 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04003851 * @phba: pointer to lpfc hba data structure.
3852 * @instance: a unique integer ID to this FC port.
3853 * @dev: pointer to the device data structure.
3854 *
3855 * This routine creates a FC port for the upper layer protocol. The FC port
3856 * can be created on top of either a physical port or a virtual port provided
3857 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3858 * and associates the FC port created before adding the shost into the SCSI
3859 * layer.
3860 *
3861 * Return codes
3862 * @vport - pointer to the virtual N_Port data structure.
3863 * NULL - port create failed.
3864 **/
James Smart2e0fef82007-06-17 19:56:36 -05003865struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04003866lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04003867{
James Smart2e0fef82007-06-17 19:56:36 -05003868 struct lpfc_vport *vport;
James Smart895427b2017-02-12 13:52:30 -08003869 struct Scsi_Host *shost = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003870 int error = 0;
James Smart96418b52017-03-04 09:30:31 -08003871 int i;
3872 uint64_t wwn;
3873 bool use_no_reset_hba = false;
James Smart56bc8022017-06-15 22:56:43 -07003874 int rc;
James Smart96418b52017-03-04 09:30:31 -08003875
James Smart56bc8022017-06-15 22:56:43 -07003876 if (lpfc_no_hba_reset_cnt) {
3877 if (phba->sli_rev < LPFC_SLI_REV4 &&
3878 dev == &phba->pcidev->dev) {
3879 /* Reset the port first */
3880 lpfc_sli_brdrestart(phba);
3881 rc = lpfc_sli_chipset_init(phba);
3882 if (rc)
3883 return NULL;
3884 }
3885 wwn = lpfc_get_wwpn(phba);
3886 }
James Smart96418b52017-03-04 09:30:31 -08003887
3888 for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
3889 if (wwn == lpfc_no_hba_reset[i]) {
3890 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3891 "6020 Setting use_no_reset port=%llx\n",
3892 wwn);
3893 use_no_reset_hba = true;
3894 break;
3895 }
3896 }
James Smart47a86172007-04-25 09:53:22 -04003897
James Smart895427b2017-02-12 13:52:30 -08003898 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
3899 if (dev != &phba->pcidev->dev) {
3900 shost = scsi_host_alloc(&lpfc_vport_template,
3901 sizeof(struct lpfc_vport));
3902 } else {
James Smart96418b52017-03-04 09:30:31 -08003903 if (!use_no_reset_hba)
James Smart895427b2017-02-12 13:52:30 -08003904 shost = scsi_host_alloc(&lpfc_template,
3905 sizeof(struct lpfc_vport));
3906 else
James Smart96418b52017-03-04 09:30:31 -08003907 shost = scsi_host_alloc(&lpfc_template_no_hr,
James Smart895427b2017-02-12 13:52:30 -08003908 sizeof(struct lpfc_vport));
3909 }
3910 } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
3911 shost = scsi_host_alloc(&lpfc_template_nvme,
James Smartea4142f2015-04-07 15:07:13 -04003912 sizeof(struct lpfc_vport));
3913 }
James Smart2e0fef82007-06-17 19:56:36 -05003914 if (!shost)
3915 goto out;
James Smart47a86172007-04-25 09:53:22 -04003916
James Smart2e0fef82007-06-17 19:56:36 -05003917 vport = (struct lpfc_vport *) shost->hostdata;
3918 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05003919 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05003920 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05003921 vport->fc_rscn_flush = 0;
James Smart3de2a652007-08-02 11:09:59 -04003922 lpfc_get_vport_cfgparam(vport);
James Smart895427b2017-02-12 13:52:30 -08003923
James Smart2e0fef82007-06-17 19:56:36 -05003924 shost->unique_id = instance;
3925 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04003926 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05003927 shost->this_id = -1;
3928 shost->max_cmd_len = 16;
James Smart8b0dff12015-05-22 10:42:38 -04003929 shost->nr_hw_queues = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04003930 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05003931 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04003932 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smartda0436e2009-05-22 14:51:39 -04003933 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
3934 }
James Smart81301a92008-12-04 22:39:46 -05003935
James Smart47a86172007-04-25 09:53:22 -04003936 /*
James Smart2e0fef82007-06-17 19:56:36 -05003937 * Set initial can_queue value since 0 is no longer supported and
3938 * scsi_add_host will fail. This will be adjusted later based on the
3939 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04003940 */
James Smart2e0fef82007-06-17 19:56:36 -05003941 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04003942 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05003943 shost->transportt = lpfc_vport_transport_template;
3944 vport->port_type = LPFC_NPIV_PORT;
3945 } else {
3946 shost->transportt = lpfc_transport_template;
3947 vport->port_type = LPFC_PHYSICAL_PORT;
3948 }
James Smart47a86172007-04-25 09:53:22 -04003949
James Smart2e0fef82007-06-17 19:56:36 -05003950 /* Initialize all internally managed lists. */
3951 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04003952 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05003953 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04003954
Kees Cookf22eb4d2017-09-06 20:24:26 -07003955 timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0);
James Smart47a86172007-04-25 09:53:22 -04003956
Kees Cookf22eb4d2017-09-06 20:24:26 -07003957 timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0);
James Smart92494142011-02-16 12:39:44 -05003958
Kees Cookf22eb4d2017-09-06 20:24:26 -07003959 timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0);
James Smart92494142011-02-16 12:39:44 -05003960
James Bottomleyd139b9b2009-11-05 13:33:12 -06003961 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05003962 if (error)
3963 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04003964
James Smart549e55c2007-08-02 11:09:51 -04003965 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003966 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04003967 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003968 return vport;
James Smart47a86172007-04-25 09:53:22 -04003969
James Smart2e0fef82007-06-17 19:56:36 -05003970out_put_shost:
3971 scsi_host_put(shost);
3972out:
3973 return NULL;
James Smart47a86172007-04-25 09:53:22 -04003974}
3975
James Smarte59058c2008-08-24 21:49:00 -04003976/**
James Smart3621a712009-04-06 18:47:14 -04003977 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04003978 * @vport: pointer to an lpfc virtual N_Port data structure.
3979 *
3980 * This routine destroys a FC port from the upper layer protocol. All the
3981 * resources associated with the port are released.
3982 **/
James Smart2e0fef82007-06-17 19:56:36 -05003983void
3984destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04003985{
James Smart92d7f7b2007-06-17 19:56:38 -05003986 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3987 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003988
James Smart858c9f62007-06-17 19:56:39 -05003989 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05003990 fc_remove_host(shost);
3991 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04003992
James Smart92d7f7b2007-06-17 19:56:38 -05003993 spin_lock_irq(&phba->hbalock);
3994 list_del_init(&vport->listentry);
3995 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04003996
James Smart92d7f7b2007-06-17 19:56:38 -05003997 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04003998 return;
James Smart47a86172007-04-25 09:53:22 -04003999}
4000
James Smarte59058c2008-08-24 21:49:00 -04004001/**
James Smart3621a712009-04-06 18:47:14 -04004002 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04004003 *
4004 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
4005 * uses the kernel idr facility to perform the task.
4006 *
4007 * Return codes:
4008 * instance - a unique integer ID allocated as the new instance.
4009 * -1 - lpfc get instance failed.
4010 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004011int
4012lpfc_get_instance(void)
4013{
Tejun Heoab516032013-02-27 17:04:44 -08004014 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05004015
Tejun Heoab516032013-02-27 17:04:44 -08004016 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
4017 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05004018}
4019
James Smarte59058c2008-08-24 21:49:00 -04004020/**
James Smart3621a712009-04-06 18:47:14 -04004021 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04004022 * @shost: pointer to SCSI host data structure.
4023 * @time: elapsed time of the scan in jiffies.
4024 *
4025 * This routine is called by the SCSI layer with a SCSI host to determine
4026 * whether the scan host is finished.
4027 *
4028 * Note: there is no scan_start function as adapter initialization will have
4029 * asynchronously kicked off the link initialization.
4030 *
4031 * Return codes
4032 * 0 - SCSI host scan is not over yet.
4033 * 1 - SCSI host scan is over.
4034 **/
James Smart47a86172007-04-25 09:53:22 -04004035int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
4036{
James Smart2e0fef82007-06-17 19:56:36 -05004037 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4038 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05004039 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04004040
James Smart858c9f62007-06-17 19:56:39 -05004041 spin_lock_irq(shost->host_lock);
4042
James Smart51ef4c22007-08-02 11:10:31 -04004043 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05004044 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004045 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05004046 }
James Smart256ec0d2013-04-17 20:14:58 -04004047 if (time >= msecs_to_jiffies(30 * 1000)) {
James Smart2e0fef82007-06-17 19:56:36 -05004048 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004049 "0461 Scanning longer than 30 "
4050 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05004051 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004052 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004053 }
James Smart256ec0d2013-04-17 20:14:58 -04004054 if (time >= msecs_to_jiffies(15 * 1000) &&
4055 phba->link_state <= LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05004056 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004057 "0465 Link down longer than 15 "
4058 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05004059 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05004060 goto finished;
James Smart47a86172007-04-25 09:53:22 -04004061 }
4062
James Smart2e0fef82007-06-17 19:56:36 -05004063 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05004064 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004065 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05004066 goto finished;
James Smart256ec0d2013-04-17 20:14:58 -04004067 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
James Smart858c9f62007-06-17 19:56:39 -05004068 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004069 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05004070 goto finished;
4071
4072 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004073
4074finished:
James Smart858c9f62007-06-17 19:56:39 -05004075 spin_unlock_irq(shost->host_lock);
4076 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05004077}
4078
James Smarte59058c2008-08-24 21:49:00 -04004079/**
James Smart3621a712009-04-06 18:47:14 -04004080 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04004081 * @shost: pointer to SCSI host data structure.
4082 *
4083 * This routine initializes a given SCSI host attributes on a FC port. The
4084 * SCSI host can be either on top of a physical port or a virtual port.
4085 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004086void lpfc_host_attrib_init(struct Scsi_Host *shost)
4087{
4088 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4089 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04004090 /*
James Smart2e0fef82007-06-17 19:56:36 -05004091 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04004092 */
4093
James Smart2e0fef82007-06-17 19:56:36 -05004094 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
4095 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04004096 fc_host_supported_classes(shost) = FC_COS_CLASS3;
4097
4098 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05004099 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04004100 fc_host_supported_fc4s(shost)[2] = 1;
4101 fc_host_supported_fc4s(shost)[7] = 1;
4102
James Smart92d7f7b2007-06-17 19:56:38 -05004103 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
4104 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04004105
4106 fc_host_supported_speeds(shost) = 0;
James Smartd38dd522015-08-31 16:48:17 -04004107 if (phba->lmt & LMT_32Gb)
4108 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
James Smart88a2cfb2011-07-22 18:36:33 -04004109 if (phba->lmt & LMT_16Gb)
4110 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
James Smart47a86172007-04-25 09:53:22 -04004111 if (phba->lmt & LMT_10Gb)
4112 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04004113 if (phba->lmt & LMT_8Gb)
4114 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04004115 if (phba->lmt & LMT_4Gb)
4116 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
4117 if (phba->lmt & LMT_2Gb)
4118 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
4119 if (phba->lmt & LMT_1Gb)
4120 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
4121
4122 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05004123 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
4124 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04004125
Mike Christie0af5d702010-09-15 16:52:31 -05004126 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
4127
James Smart47a86172007-04-25 09:53:22 -04004128 /* This value is also unchanging */
4129 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05004130 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04004131 fc_host_active_fc4s(shost)[2] = 1;
4132 fc_host_active_fc4s(shost)[7] = 1;
4133
James Smart92d7f7b2007-06-17 19:56:38 -05004134 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04004135 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04004136 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04004137 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04004138}
dea31012005-04-17 16:05:31 -05004139
James Smarte59058c2008-08-24 21:49:00 -04004140/**
James Smartda0436e2009-05-22 14:51:39 -04004141 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04004142 * @phba: pointer to lpfc hba data structure.
4143 *
James Smartda0436e2009-05-22 14:51:39 -04004144 * This routine is invoked to stop an SLI3 device port, it stops the device
4145 * from generating interrupts and stops the device driver's timers for the
4146 * device.
James Smarte59058c2008-08-24 21:49:00 -04004147 **/
James Smartdb2378e2008-02-08 18:49:51 -05004148static void
James Smartda0436e2009-05-22 14:51:39 -04004149lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05004150{
James Smartda0436e2009-05-22 14:51:39 -04004151 /* Clear all interrupt enable conditions */
4152 writel(0, phba->HCregaddr);
4153 readl(phba->HCregaddr); /* flush */
4154 /* Clear all pending interrupts */
4155 writel(0xffffffff, phba->HAregaddr);
4156 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04004157
James Smartda0436e2009-05-22 14:51:39 -04004158 /* Reset some HBA SLI setup states */
4159 lpfc_stop_hba_timers(phba);
4160 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05004161}
4162
James Smarte59058c2008-08-24 21:49:00 -04004163/**
James Smartda0436e2009-05-22 14:51:39 -04004164 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05004165 * @phba: pointer to lpfc hba data structure.
4166 *
James Smartda0436e2009-05-22 14:51:39 -04004167 * This routine is invoked to stop an SLI4 device port, it stops the device
4168 * from generating interrupts and stops the device driver's timers for the
4169 * device.
4170 **/
4171static void
4172lpfc_stop_port_s4(struct lpfc_hba *phba)
4173{
4174 /* Reset some HBA SLI4 setup states */
4175 lpfc_stop_hba_timers(phba);
4176 phba->pport->work_port_events = 0;
4177 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04004178}
4179
4180/**
4181 * lpfc_stop_port - Wrapper function for stopping hba port
4182 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05004183 *
James Smartda0436e2009-05-22 14:51:39 -04004184 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
4185 * the API jump table function pointer from the lpfc_hba struct.
4186 **/
4187void
4188lpfc_stop_port(struct lpfc_hba *phba)
4189{
4190 phba->lpfc_stop_port(phba);
Dick Kennedyf485c182017-09-29 17:34:34 -07004191
4192 if (phba->wq)
4193 flush_workqueue(phba->wq);
James Smartda0436e2009-05-22 14:51:39 -04004194}
4195
4196/**
James Smartecfd03c2010-02-12 14:41:27 -05004197 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
4198 * @phba: Pointer to hba for which this call is being executed.
4199 *
4200 * This routine starts the timer waiting for the FCF rediscovery to complete.
4201 **/
4202void
4203lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
4204{
4205 unsigned long fcf_redisc_wait_tmo =
4206 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
4207 /* Start fcf rediscovery wait period timer */
4208 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
4209 spin_lock_irq(&phba->hbalock);
4210 /* Allow action to new fcf asynchronous event */
4211 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
4212 /* Mark the FCF rediscovery pending state */
4213 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
4214 spin_unlock_irq(&phba->hbalock);
4215}
4216
4217/**
4218 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
4219 * @ptr: Map to lpfc_hba data structure pointer.
4220 *
4221 * This routine is invoked when waiting for FCF table rediscover has been
4222 * timed out. If new FCF record(s) has (have) been discovered during the
4223 * wait period, a new FCF event shall be added to the FCOE async event
4224 * list, and then worker thread shall be waked up for processing from the
4225 * worker thread context.
4226 **/
Rashika Kheriae399b222014-09-03 12:55:28 -04004227static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07004228lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t)
James Smartecfd03c2010-02-12 14:41:27 -05004229{
Kees Cookf22eb4d2017-09-06 20:24:26 -07004230 struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait);
James Smartecfd03c2010-02-12 14:41:27 -05004231
4232 /* Don't send FCF rediscovery event if timer cancelled */
4233 spin_lock_irq(&phba->hbalock);
4234 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
4235 spin_unlock_irq(&phba->hbalock);
4236 return;
4237 }
4238 /* Clear FCF rediscovery timer pending flag */
4239 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
4240 /* FCF rediscovery event to worker thread */
4241 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
4242 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004243 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04004244 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05004245 /* wake up worker thread */
4246 lpfc_worker_wake_up(phba);
4247}
4248
4249/**
James Smartda0436e2009-05-22 14:51:39 -04004250 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
4251 * @phba: pointer to lpfc hba data structure.
4252 * @acqe_link: pointer to the async link completion queue entry.
4253 *
4254 * This routine is to parse the SLI4 link-attention link fault code and
4255 * translate it into the base driver's read link attention mailbox command
4256 * status.
4257 *
4258 * Return: Link-attention status in terms of base driver's coding.
4259 **/
4260static uint16_t
4261lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
4262 struct lpfc_acqe_link *acqe_link)
4263{
4264 uint16_t latt_fault;
4265
4266 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
4267 case LPFC_ASYNC_LINK_FAULT_NONE:
4268 case LPFC_ASYNC_LINK_FAULT_LOCAL:
4269 case LPFC_ASYNC_LINK_FAULT_REMOTE:
4270 latt_fault = 0;
4271 break;
4272 default:
4273 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4274 "0398 Invalid link fault code: x%x\n",
4275 bf_get(lpfc_acqe_link_fault, acqe_link));
4276 latt_fault = MBXERR_ERROR;
4277 break;
4278 }
4279 return latt_fault;
4280}
4281
4282/**
4283 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
4284 * @phba: pointer to lpfc hba data structure.
4285 * @acqe_link: pointer to the async link completion queue entry.
4286 *
4287 * This routine is to parse the SLI4 link attention type and translate it
4288 * into the base driver's link attention type coding.
4289 *
4290 * Return: Link attention type in terms of base driver's coding.
4291 **/
4292static uint8_t
4293lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
4294 struct lpfc_acqe_link *acqe_link)
4295{
4296 uint8_t att_type;
4297
4298 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
4299 case LPFC_ASYNC_LINK_STATUS_DOWN:
4300 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05004301 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04004302 break;
4303 case LPFC_ASYNC_LINK_STATUS_UP:
4304 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05004305 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004306 break;
4307 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05004308 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04004309 break;
4310 default:
4311 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4312 "0399 Invalid link attention type: x%x\n",
4313 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05004314 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004315 break;
4316 }
4317 return att_type;
4318}
4319
4320/**
James Smart8b68cd52012-09-29 11:32:37 -04004321 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
4322 * @phba: pointer to lpfc hba data structure.
4323 *
4324 * This routine is to get an SLI3 FC port's link speed in Mbps.
4325 *
4326 * Return: link speed in terms of Mbps.
4327 **/
4328uint32_t
4329lpfc_sli_port_speed_get(struct lpfc_hba *phba)
4330{
4331 uint32_t link_speed;
4332
4333 if (!lpfc_is_link_up(phba))
4334 return 0;
4335
James Smarta085e872015-12-16 18:12:02 -05004336 if (phba->sli_rev <= LPFC_SLI_REV3) {
4337 switch (phba->fc_linkspeed) {
4338 case LPFC_LINK_SPEED_1GHZ:
4339 link_speed = 1000;
4340 break;
4341 case LPFC_LINK_SPEED_2GHZ:
4342 link_speed = 2000;
4343 break;
4344 case LPFC_LINK_SPEED_4GHZ:
4345 link_speed = 4000;
4346 break;
4347 case LPFC_LINK_SPEED_8GHZ:
4348 link_speed = 8000;
4349 break;
4350 case LPFC_LINK_SPEED_10GHZ:
4351 link_speed = 10000;
4352 break;
4353 case LPFC_LINK_SPEED_16GHZ:
4354 link_speed = 16000;
4355 break;
4356 default:
4357 link_speed = 0;
4358 }
4359 } else {
4360 if (phba->sli4_hba.link_state.logical_speed)
4361 link_speed =
4362 phba->sli4_hba.link_state.logical_speed;
4363 else
4364 link_speed = phba->sli4_hba.link_state.speed;
James Smart8b68cd52012-09-29 11:32:37 -04004365 }
4366 return link_speed;
4367}
4368
4369/**
4370 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
4371 * @phba: pointer to lpfc hba data structure.
4372 * @evt_code: asynchronous event code.
4373 * @speed_code: asynchronous event link speed code.
4374 *
4375 * This routine is to parse the giving SLI4 async event link speed code into
4376 * value of Mbps for the link speed.
4377 *
4378 * Return: link speed in terms of Mbps.
4379 **/
4380static uint32_t
4381lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
4382 uint8_t speed_code)
4383{
4384 uint32_t port_speed;
4385
4386 switch (evt_code) {
4387 case LPFC_TRAILER_CODE_LINK:
4388 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004389 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smart8b68cd52012-09-29 11:32:37 -04004390 port_speed = 0;
4391 break;
James Smart26d830e2015-04-07 15:07:17 -04004392 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004393 port_speed = 10;
4394 break;
James Smart26d830e2015-04-07 15:07:17 -04004395 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004396 port_speed = 100;
4397 break;
James Smart26d830e2015-04-07 15:07:17 -04004398 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004399 port_speed = 1000;
4400 break;
James Smart26d830e2015-04-07 15:07:17 -04004401 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004402 port_speed = 10000;
4403 break;
James Smart26d830e2015-04-07 15:07:17 -04004404 case LPFC_ASYNC_LINK_SPEED_20GBPS:
4405 port_speed = 20000;
4406 break;
4407 case LPFC_ASYNC_LINK_SPEED_25GBPS:
4408 port_speed = 25000;
4409 break;
4410 case LPFC_ASYNC_LINK_SPEED_40GBPS:
4411 port_speed = 40000;
4412 break;
James Smart8b68cd52012-09-29 11:32:37 -04004413 default:
4414 port_speed = 0;
4415 }
4416 break;
4417 case LPFC_TRAILER_CODE_FC:
4418 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004419 case LPFC_FC_LA_SPEED_UNKNOWN:
James Smart8b68cd52012-09-29 11:32:37 -04004420 port_speed = 0;
4421 break;
James Smart26d830e2015-04-07 15:07:17 -04004422 case LPFC_FC_LA_SPEED_1G:
James Smart8b68cd52012-09-29 11:32:37 -04004423 port_speed = 1000;
4424 break;
James Smart26d830e2015-04-07 15:07:17 -04004425 case LPFC_FC_LA_SPEED_2G:
James Smart8b68cd52012-09-29 11:32:37 -04004426 port_speed = 2000;
4427 break;
James Smart26d830e2015-04-07 15:07:17 -04004428 case LPFC_FC_LA_SPEED_4G:
James Smart8b68cd52012-09-29 11:32:37 -04004429 port_speed = 4000;
4430 break;
James Smart26d830e2015-04-07 15:07:17 -04004431 case LPFC_FC_LA_SPEED_8G:
James Smart8b68cd52012-09-29 11:32:37 -04004432 port_speed = 8000;
4433 break;
James Smart26d830e2015-04-07 15:07:17 -04004434 case LPFC_FC_LA_SPEED_10G:
James Smart8b68cd52012-09-29 11:32:37 -04004435 port_speed = 10000;
4436 break;
James Smart26d830e2015-04-07 15:07:17 -04004437 case LPFC_FC_LA_SPEED_16G:
James Smart8b68cd52012-09-29 11:32:37 -04004438 port_speed = 16000;
4439 break;
James Smartd38dd522015-08-31 16:48:17 -04004440 case LPFC_FC_LA_SPEED_32G:
4441 port_speed = 32000;
4442 break;
James Smart8b68cd52012-09-29 11:32:37 -04004443 default:
4444 port_speed = 0;
4445 }
4446 break;
4447 default:
4448 port_speed = 0;
4449 }
4450 return port_speed;
4451}
4452
4453/**
James Smart70f3c072010-12-15 17:57:33 -05004454 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04004455 * @phba: pointer to lpfc hba data structure.
4456 * @acqe_link: pointer to the async link completion queue entry.
4457 *
James Smart70f3c072010-12-15 17:57:33 -05004458 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04004459 **/
4460static void
4461lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
4462 struct lpfc_acqe_link *acqe_link)
4463{
4464 struct lpfc_dmabuf *mp;
4465 LPFC_MBOXQ_t *pmb;
4466 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05004467 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04004468 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05004469 int rc;
James Smartda0436e2009-05-22 14:51:39 -04004470
4471 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05004472 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04004473 return;
James Smart32b97932009-07-19 10:01:21 -04004474 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004475 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4476 if (!pmb) {
4477 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4478 "0395 The mboxq allocation failed\n");
4479 return;
4480 }
4481 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4482 if (!mp) {
4483 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4484 "0396 The lpfc_dmabuf allocation failed\n");
4485 goto out_free_pmb;
4486 }
4487 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4488 if (!mp->virt) {
4489 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4490 "0397 The mbuf allocation failed\n");
4491 goto out_free_dmabuf;
4492 }
4493
4494 /* Cleanup any outstanding ELS commands */
4495 lpfc_els_flush_all_cmd(phba);
4496
4497 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004498 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smartda0436e2009-05-22 14:51:39 -04004499
4500 /* Update link event statistics */
4501 phba->sli.slistat.link_event++;
4502
James Smart76a95d72010-11-20 23:11:48 -05004503 /* Create lpfc_handle_latt mailbox command from link ACQE */
4504 lpfc_read_topology(phba, pmb, mp);
4505 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04004506 pmb->vport = phba->pport;
4507
James Smartda0436e2009-05-22 14:51:39 -04004508 /* Keep the link status for extra SLI4 state machine reference */
4509 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004510 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
4511 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04004512 phba->sli4_hba.link_state.duplex =
4513 bf_get(lpfc_acqe_link_duplex, acqe_link);
4514 phba->sli4_hba.link_state.status =
4515 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05004516 phba->sli4_hba.link_state.type =
4517 bf_get(lpfc_acqe_link_type, acqe_link);
4518 phba->sli4_hba.link_state.number =
4519 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04004520 phba->sli4_hba.link_state.fault =
4521 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05004522 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004523 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
4524
James Smart70f3c072010-12-15 17:57:33 -05004525 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04004526 "2900 Async FC/FCoE Link event - Speed:%dGBit "
4527 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
4528 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05004529 phba->sli4_hba.link_state.speed,
4530 phba->sli4_hba.link_state.topology,
4531 phba->sli4_hba.link_state.status,
4532 phba->sli4_hba.link_state.type,
4533 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004534 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004535 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05004536 /*
4537 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
4538 * topology info. Note: Optional for non FC-AL ports.
4539 */
4540 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
4541 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4542 if (rc == MBX_NOT_FINISHED)
4543 goto out_free_dmabuf;
4544 return;
4545 }
4546 /*
4547 * For FCoE Mode: fill in all the topology information we need and call
4548 * the READ_TOPOLOGY completion routine to continue without actually
4549 * sending the READ_TOPOLOGY mailbox command to the port.
4550 */
4551 /* Parse and translate status field */
4552 mb = &pmb->u.mb;
4553 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
4554
4555 /* Parse and translate link attention fields */
4556 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
4557 la->eventTag = acqe_link->event_tag;
4558 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
4559 bf_set(lpfc_mbx_read_top_link_spd, la,
James Smarta085e872015-12-16 18:12:02 -05004560 (bf_get(lpfc_acqe_link_speed, acqe_link)));
James Smart76a95d72010-11-20 23:11:48 -05004561
4562 /* Fake the the following irrelvant fields */
4563 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
4564 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
4565 bf_set(lpfc_mbx_read_top_il, la, 0);
4566 bf_set(lpfc_mbx_read_top_pb, la, 0);
4567 bf_set(lpfc_mbx_read_top_fa, la, 0);
4568 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04004569
4570 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05004571 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04004572
4573 return;
4574
4575out_free_dmabuf:
4576 kfree(mp);
4577out_free_pmb:
4578 mempool_free(pmb, phba->mbox_mem_pool);
4579}
4580
4581/**
James Smart70f3c072010-12-15 17:57:33 -05004582 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
4583 * @phba: pointer to lpfc hba data structure.
4584 * @acqe_fc: pointer to the async fc completion queue entry.
4585 *
4586 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
4587 * that the event was received and then issue a read_topology mailbox command so
4588 * that the rest of the driver will treat it the same as SLI3.
4589 **/
4590static void
4591lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
4592{
4593 struct lpfc_dmabuf *mp;
4594 LPFC_MBOXQ_t *pmb;
James Smart7bdedb32016-07-06 12:36:00 -07004595 MAILBOX_t *mb;
4596 struct lpfc_mbx_read_top *la;
James Smart70f3c072010-12-15 17:57:33 -05004597 int rc;
4598
4599 if (bf_get(lpfc_trailer_type, acqe_fc) !=
4600 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
4601 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4602 "2895 Non FC link Event detected.(%d)\n",
4603 bf_get(lpfc_trailer_type, acqe_fc));
4604 return;
4605 }
4606 /* Keep the link status for extra SLI4 state machine reference */
4607 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004608 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
4609 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05004610 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
4611 phba->sli4_hba.link_state.topology =
4612 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
4613 phba->sli4_hba.link_state.status =
4614 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
4615 phba->sli4_hba.link_state.type =
4616 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
4617 phba->sli4_hba.link_state.number =
4618 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
4619 phba->sli4_hba.link_state.fault =
4620 bf_get(lpfc_acqe_link_fault, acqe_fc);
4621 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004622 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart70f3c072010-12-15 17:57:33 -05004623 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4624 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4625 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4626 "%dMbps Fault:%d\n",
4627 phba->sli4_hba.link_state.speed,
4628 phba->sli4_hba.link_state.topology,
4629 phba->sli4_hba.link_state.status,
4630 phba->sli4_hba.link_state.type,
4631 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004632 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004633 phba->sli4_hba.link_state.fault);
4634 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4635 if (!pmb) {
4636 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4637 "2897 The mboxq allocation failed\n");
4638 return;
4639 }
4640 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4641 if (!mp) {
4642 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4643 "2898 The lpfc_dmabuf allocation failed\n");
4644 goto out_free_pmb;
4645 }
4646 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4647 if (!mp->virt) {
4648 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4649 "2899 The mbuf allocation failed\n");
4650 goto out_free_dmabuf;
4651 }
4652
4653 /* Cleanup any outstanding ELS commands */
4654 lpfc_els_flush_all_cmd(phba);
4655
4656 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004657 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smart70f3c072010-12-15 17:57:33 -05004658
4659 /* Update link event statistics */
4660 phba->sli.slistat.link_event++;
4661
4662 /* Create lpfc_handle_latt mailbox command from link ACQE */
4663 lpfc_read_topology(phba, pmb, mp);
4664 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4665 pmb->vport = phba->pport;
4666
James Smart7bdedb32016-07-06 12:36:00 -07004667 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
James Smartae9e28f2017-05-15 15:20:51 -07004668 phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK);
4669
4670 switch (phba->sli4_hba.link_state.status) {
4671 case LPFC_FC_LA_TYPE_MDS_LINK_DOWN:
4672 phba->link_flag |= LS_MDS_LINK_DOWN;
4673 break;
4674 case LPFC_FC_LA_TYPE_MDS_LOOPBACK:
4675 phba->link_flag |= LS_MDS_LOOPBACK;
4676 break;
4677 default:
4678 break;
4679 }
4680
James Smart7bdedb32016-07-06 12:36:00 -07004681 /* Parse and translate status field */
4682 mb = &pmb->u.mb;
4683 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba,
4684 (void *)acqe_fc);
4685
4686 /* Parse and translate link attention fields */
4687 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
4688 la->eventTag = acqe_fc->event_tag;
James Smart7bdedb32016-07-06 12:36:00 -07004689
James Smartaeb3c812017-04-21 16:05:02 -07004690 if (phba->sli4_hba.link_state.status ==
4691 LPFC_FC_LA_TYPE_UNEXP_WWPN) {
4692 bf_set(lpfc_mbx_read_top_att_type, la,
4693 LPFC_FC_LA_TYPE_UNEXP_WWPN);
4694 } else {
4695 bf_set(lpfc_mbx_read_top_att_type, la,
4696 LPFC_FC_LA_TYPE_LINK_DOWN);
4697 }
James Smart7bdedb32016-07-06 12:36:00 -07004698 /* Invoke the mailbox command callback function */
4699 lpfc_mbx_cmpl_read_topology(phba, pmb);
4700
4701 return;
4702 }
4703
James Smart70f3c072010-12-15 17:57:33 -05004704 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4705 if (rc == MBX_NOT_FINISHED)
4706 goto out_free_dmabuf;
4707 return;
4708
4709out_free_dmabuf:
4710 kfree(mp);
4711out_free_pmb:
4712 mempool_free(pmb, phba->mbox_mem_pool);
4713}
4714
4715/**
4716 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4717 * @phba: pointer to lpfc hba data structure.
4718 * @acqe_fc: pointer to the async SLI completion queue entry.
4719 *
4720 * This routine is to handle the SLI4 asynchronous SLI events.
4721 **/
4722static void
4723lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
4724{
James Smart4b8bae02012-06-12 13:55:07 -04004725 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04004726 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04004727 uint8_t status;
James Smart946727d2015-04-07 15:07:09 -04004728 uint8_t evt_type;
James Smart448193b2015-12-16 18:12:05 -05004729 uint8_t operational = 0;
James Smart946727d2015-04-07 15:07:09 -04004730 struct temp_event temp_event_data;
James Smart4b8bae02012-06-12 13:55:07 -04004731 struct lpfc_acqe_misconfigured_event *misconfigured;
James Smart946727d2015-04-07 15:07:09 -04004732 struct Scsi_Host *shost;
James Smart4b8bae02012-06-12 13:55:07 -04004733
James Smart946727d2015-04-07 15:07:09 -04004734 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
4735
James Smart448193b2015-12-16 18:12:05 -05004736 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4737 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4738 "x%08x SLI Event Type:%d\n",
4739 acqe_sli->event_data1, acqe_sli->event_data2,
4740 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004741
4742 port_name = phba->Port[0];
4743 if (port_name == 0x00)
4744 port_name = '?'; /* get port name is empty */
4745
James Smart946727d2015-04-07 15:07:09 -04004746 switch (evt_type) {
4747 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
4748 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4749 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
4750 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4751
4752 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4753 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4754 acqe_sli->event_data1, port_name);
4755
James Smart310429e2016-07-06 12:35:54 -07004756 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04004757 shost = lpfc_shost_from_vport(phba->pport);
4758 fc_host_post_vendor_event(shost, fc_get_event_number(),
4759 sizeof(temp_event_data),
4760 (char *)&temp_event_data,
4761 SCSI_NL_VID_TYPE_PCI
4762 | PCI_VENDOR_ID_EMULEX);
4763 break;
4764 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
4765 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4766 temp_event_data.event_code = LPFC_NORMAL_TEMP;
4767 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4768
4769 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4770 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4771 acqe_sli->event_data1, port_name);
4772
4773 shost = lpfc_shost_from_vport(phba->pport);
4774 fc_host_post_vendor_event(shost, fc_get_event_number(),
4775 sizeof(temp_event_data),
4776 (char *)&temp_event_data,
4777 SCSI_NL_VID_TYPE_PCI
4778 | PCI_VENDOR_ID_EMULEX);
4779 break;
4780 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
4781 misconfigured = (struct lpfc_acqe_misconfigured_event *)
James Smart4b8bae02012-06-12 13:55:07 -04004782 &acqe_sli->event_data1;
4783
James Smart946727d2015-04-07 15:07:09 -04004784 /* fetch the status for this port */
4785 switch (phba->sli4_hba.lnk_info.lnk_no) {
4786 case LPFC_LINK_NUMBER_0:
James Smart448193b2015-12-16 18:12:05 -05004787 status = bf_get(lpfc_sli_misconfigured_port0_state,
4788 &misconfigured->theEvent);
4789 operational = bf_get(lpfc_sli_misconfigured_port0_op,
James Smart4b8bae02012-06-12 13:55:07 -04004790 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004791 break;
4792 case LPFC_LINK_NUMBER_1:
James Smart448193b2015-12-16 18:12:05 -05004793 status = bf_get(lpfc_sli_misconfigured_port1_state,
4794 &misconfigured->theEvent);
4795 operational = bf_get(lpfc_sli_misconfigured_port1_op,
James Smart4b8bae02012-06-12 13:55:07 -04004796 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004797 break;
4798 case LPFC_LINK_NUMBER_2:
James Smart448193b2015-12-16 18:12:05 -05004799 status = bf_get(lpfc_sli_misconfigured_port2_state,
4800 &misconfigured->theEvent);
4801 operational = bf_get(lpfc_sli_misconfigured_port2_op,
James Smart4b8bae02012-06-12 13:55:07 -04004802 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004803 break;
4804 case LPFC_LINK_NUMBER_3:
James Smart448193b2015-12-16 18:12:05 -05004805 status = bf_get(lpfc_sli_misconfigured_port3_state,
4806 &misconfigured->theEvent);
4807 operational = bf_get(lpfc_sli_misconfigured_port3_op,
James Smart4b8bae02012-06-12 13:55:07 -04004808 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004809 break;
4810 default:
James Smart448193b2015-12-16 18:12:05 -05004811 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4812 "3296 "
4813 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
4814 "event: Invalid link %d",
4815 phba->sli4_hba.lnk_info.lnk_no);
4816 return;
James Smart946727d2015-04-07 15:07:09 -04004817 }
James Smart4b8bae02012-06-12 13:55:07 -04004818
James Smart448193b2015-12-16 18:12:05 -05004819 /* Skip if optic state unchanged */
4820 if (phba->sli4_hba.lnk_info.optic_state == status)
4821 return;
4822
James Smart946727d2015-04-07 15:07:09 -04004823 switch (status) {
4824 case LPFC_SLI_EVENT_STATUS_VALID:
James Smart448193b2015-12-16 18:12:05 -05004825 sprintf(message, "Physical Link is functional");
4826 break;
James Smart946727d2015-04-07 15:07:09 -04004827 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
4828 sprintf(message, "Optics faulted/incorrectly "
4829 "installed/not installed - Reseat optics, "
4830 "if issue not resolved, replace.");
4831 break;
4832 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
4833 sprintf(message,
4834 "Optics of two types installed - Remove one "
4835 "optic or install matching pair of optics.");
4836 break;
4837 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
4838 sprintf(message, "Incompatible optics - Replace with "
James Smart292098b2012-09-29 11:31:41 -04004839 "compatible optics for card to function.");
James Smart946727d2015-04-07 15:07:09 -04004840 break;
James Smart448193b2015-12-16 18:12:05 -05004841 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
4842 sprintf(message, "Unqualified optics - Replace with "
4843 "Avago optics for Warranty and Technical "
4844 "Support - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08004845 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05004846 break;
4847 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
4848 sprintf(message, "Uncertified optics - Replace with "
4849 "Avago-certified optics to enable link "
4850 "operation - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08004851 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05004852 break;
James Smart946727d2015-04-07 15:07:09 -04004853 default:
4854 /* firmware is reporting a status we don't know about */
4855 sprintf(message, "Unknown event status x%02x", status);
4856 break;
4857 }
James Smart448193b2015-12-16 18:12:05 -05004858 phba->sli4_hba.lnk_info.optic_state = status;
James Smart946727d2015-04-07 15:07:09 -04004859 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart448193b2015-12-16 18:12:05 -05004860 "3176 Port Name %c %s\n", port_name, message);
James Smart946727d2015-04-07 15:07:09 -04004861 break;
4862 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
4863 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4864 "3192 Remote DPort Test Initiated - "
4865 "Event Data1:x%08x Event Data2: x%08x\n",
4866 acqe_sli->event_data1, acqe_sli->event_data2);
James Smart4b8bae02012-06-12 13:55:07 -04004867 break;
4868 default:
James Smart946727d2015-04-07 15:07:09 -04004869 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4870 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
4871 "x%08x SLI Event Type:%d\n",
4872 acqe_sli->event_data1, acqe_sli->event_data2,
4873 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004874 break;
4875 }
James Smart70f3c072010-12-15 17:57:33 -05004876}
4877
4878/**
James Smartfc2b9892010-02-26 14:15:29 -05004879 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
4880 * @vport: pointer to vport data structure.
4881 *
4882 * This routine is to perform Clear Virtual Link (CVL) on a vport in
4883 * response to a CVL event.
4884 *
4885 * Return the pointer to the ndlp with the vport if successful, otherwise
4886 * return NULL.
4887 **/
4888static struct lpfc_nodelist *
4889lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
4890{
4891 struct lpfc_nodelist *ndlp;
4892 struct Scsi_Host *shost;
4893 struct lpfc_hba *phba;
4894
4895 if (!vport)
4896 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05004897 phba = vport->phba;
4898 if (!phba)
4899 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04004900 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4901 if (!ndlp) {
4902 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07004903 ndlp = lpfc_nlp_init(vport, Fabric_DID);
James Smart78730cf2010-04-06 15:06:30 -04004904 if (!ndlp)
4905 return 0;
James Smart78730cf2010-04-06 15:06:30 -04004906 /* Set the node type */
4907 ndlp->nlp_type |= NLP_FABRIC;
4908 /* Put ndlp onto node list */
4909 lpfc_enqueue_node(vport, ndlp);
4910 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4911 /* re-setup ndlp without removing from node list */
4912 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4913 if (!ndlp)
4914 return 0;
4915 }
James Smart63e801c2010-11-20 23:14:19 -05004916 if ((phba->pport->port_state < LPFC_FLOGI) &&
4917 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004918 return NULL;
4919 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05004920 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
4921 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004922 return NULL;
4923 shost = lpfc_shost_from_vport(vport);
4924 if (!shost)
4925 return NULL;
4926 lpfc_linkdown_port(vport);
4927 lpfc_cleanup_pending_mbox(vport);
4928 spin_lock_irq(shost->host_lock);
4929 vport->fc_flag |= FC_VPORT_CVL_RCVD;
4930 spin_unlock_irq(shost->host_lock);
4931
4932 return ndlp;
4933}
4934
4935/**
4936 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4937 * @vport: pointer to lpfc hba data structure.
4938 *
4939 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4940 * response to a FCF dead event.
4941 **/
4942static void
4943lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
4944{
4945 struct lpfc_vport **vports;
4946 int i;
4947
4948 vports = lpfc_create_vport_work_array(phba);
4949 if (vports)
4950 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4951 lpfc_sli4_perform_vport_cvl(vports[i]);
4952 lpfc_destroy_vport_work_array(phba, vports);
4953}
4954
4955/**
James Smart76a95d72010-11-20 23:11:48 -05004956 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04004957 * @phba: pointer to lpfc hba data structure.
4958 * @acqe_link: pointer to the async fcoe completion queue entry.
4959 *
4960 * This routine is to handle the SLI4 asynchronous fcoe event.
4961 **/
4962static void
James Smart76a95d72010-11-20 23:11:48 -05004963lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05004964 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04004965{
James Smart70f3c072010-12-15 17:57:33 -05004966 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004967 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04004968 struct lpfc_vport *vport;
4969 struct lpfc_nodelist *ndlp;
4970 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05004971 int active_vlink_present;
4972 struct lpfc_vport **vports;
4973 int i;
James Smartda0436e2009-05-22 14:51:39 -04004974
James Smart70f3c072010-12-15 17:57:33 -05004975 phba->fc_eventTag = acqe_fip->event_tag;
4976 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004977 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05004978 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
4979 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
4980 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04004981 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4982 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004983 "2546 New FCF event, evt_tag:x%x, "
4984 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004985 acqe_fip->event_tag,
4986 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04004987 else
4988 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
4989 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004990 "2788 FCF param modified event, "
4991 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004992 acqe_fip->event_tag,
4993 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04004994 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004995 /*
4996 * During period of FCF discovery, read the FCF
4997 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04004998 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05004999 */
5000 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5001 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005002 "2779 Read FCF (x%x) for updating "
5003 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05005004 acqe_fip->index);
5005 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05005006 }
James Smart38b92ef2010-08-04 16:11:39 -04005007
5008 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04005009 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04005010 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04005011 spin_unlock_irq(&phba->hbalock);
5012 break;
5013 }
5014 /* If fast FCF failover rescan event is pending, do nothing */
5015 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
5016 spin_unlock_irq(&phba->hbalock);
5017 break;
5018 }
5019
James Smartc2b97122013-05-31 17:05:36 -04005020 /* If the FCF has been in discovered state, do nothing. */
5021 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
James Smart3804dc82010-07-14 15:31:37 -04005022 spin_unlock_irq(&phba->hbalock);
5023 break;
5024 }
5025 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04005026
James Smart0c9ab6f2010-02-26 14:15:57 -05005027 /* Otherwise, scan the entire FCF table and re-discover SAN */
5028 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005029 "2770 Start FCF table scan per async FCF "
5030 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005031 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05005032 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
5033 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04005034 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05005035 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5036 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04005037 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04005038 break;
5039
James Smart70f3c072010-12-15 17:57:33 -05005040 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04005041 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04005042 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005043 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
5044 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04005045 break;
5046
James Smart70f3c072010-12-15 17:57:33 -05005047 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05005048 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05005049 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005050 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05005051 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04005052 /*
5053 * If we are in the middle of FCF failover process, clear
5054 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04005055 */
James Smartfc2b9892010-02-26 14:15:29 -05005056 spin_lock_irq(&phba->hbalock);
James Smarta1cadfe2016-07-06 12:36:02 -07005057 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
5058 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
James Smartfc2b9892010-02-26 14:15:29 -05005059 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005060 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05005061 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05005062 break;
5063 }
James Smart38b92ef2010-08-04 16:11:39 -04005064 spin_unlock_irq(&phba->hbalock);
5065
5066 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05005067 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04005068 break;
5069
5070 /*
5071 * Otherwise, request the port to rediscover the entire FCF
5072 * table for a fast recovery from case that the current FCF
5073 * is no longer valid as we are not in the middle of FCF
5074 * failover process already.
5075 */
James Smartc2b97122013-05-31 17:05:36 -04005076 spin_lock_irq(&phba->hbalock);
5077 /* Mark the fast failover process in progress */
5078 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
5079 spin_unlock_irq(&phba->hbalock);
5080
5081 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
5082 "2771 Start FCF fast failover process due to "
5083 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
5084 "\n", acqe_fip->event_tag, acqe_fip->index);
5085 rc = lpfc_sli4_redisc_fcf_table(phba);
5086 if (rc) {
5087 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5088 LOG_DISCOVERY,
5089 "2772 Issue FCF rediscover mabilbox "
5090 "command failed, fail through to FCF "
5091 "dead event\n");
5092 spin_lock_irq(&phba->hbalock);
5093 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
5094 spin_unlock_irq(&phba->hbalock);
5095 /*
5096 * Last resort will fail over by treating this
5097 * as a link down to FCF registration.
5098 */
5099 lpfc_sli4_fcf_dead_failthrough(phba);
5100 } else {
5101 /* Reset FCF roundrobin bmask for new discovery */
5102 lpfc_sli4_clear_fcf_rr_bmask(phba);
5103 /*
5104 * Handling fast FCF failover to a DEAD FCF event is
5105 * considered equalivant to receiving CVL to all vports.
5106 */
5107 lpfc_sli4_perform_all_vport_cvl(phba);
5108 }
James Smartda0436e2009-05-22 14:51:39 -04005109 break;
James Smart70f3c072010-12-15 17:57:33 -05005110 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05005111 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05005112 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04005113 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05005114 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04005115
James Smart6669f9b2009-10-02 15:16:45 -04005116 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04005117 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05005118 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04005119 if (!ndlp)
5120 break;
James Smart695a8142010-01-26 23:08:03 -05005121 active_vlink_present = 0;
5122
5123 vports = lpfc_create_vport_work_array(phba);
5124 if (vports) {
5125 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
5126 i++) {
5127 if ((!(vports[i]->fc_flag &
5128 FC_VPORT_CVL_RCVD)) &&
5129 (vports[i]->port_state > LPFC_FDISC)) {
5130 active_vlink_present = 1;
5131 break;
5132 }
5133 }
5134 lpfc_destroy_vport_work_array(phba, vports);
5135 }
5136
James Smartcc823552015-05-21 13:55:26 -04005137 /*
5138 * Don't re-instantiate if vport is marked for deletion.
5139 * If we are here first then vport_delete is going to wait
5140 * for discovery to complete.
5141 */
5142 if (!(vport->load_flag & FC_UNLOADING) &&
5143 active_vlink_present) {
James Smart695a8142010-01-26 23:08:03 -05005144 /*
5145 * If there are other active VLinks present,
5146 * re-instantiate the Vlink using FDISC.
5147 */
James Smart256ec0d2013-04-17 20:14:58 -04005148 mod_timer(&ndlp->nlp_delayfunc,
5149 jiffies + msecs_to_jiffies(1000));
James Smartfc2b9892010-02-26 14:15:29 -05005150 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04005151 spin_lock_irq(shost->host_lock);
5152 ndlp->nlp_flag |= NLP_DELAY_TMO;
5153 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05005154 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
5155 vport->port_state = LPFC_FDISC;
5156 } else {
James Smartecfd03c2010-02-12 14:41:27 -05005157 /*
5158 * Otherwise, we request port to rediscover
5159 * the entire FCF table for a fast recovery
5160 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05005161 * is no longer valid if we are not already
5162 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05005163 */
James Smartfc2b9892010-02-26 14:15:29 -05005164 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005165 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05005166 spin_unlock_irq(&phba->hbalock);
5167 break;
5168 }
5169 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05005170 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05005171 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005172 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5173 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005174 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05005175 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05005176 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05005177 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05005178 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5179 LOG_DISCOVERY,
5180 "2774 Issue FCF rediscover "
5181 "mabilbox command failed, "
5182 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05005183 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005184 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05005185 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05005186 /*
5187 * Last resort will be re-try on the
5188 * the current registered FCF entry.
5189 */
5190 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04005191 } else
5192 /*
5193 * Reset FCF roundrobin bmask for new
5194 * discovery.
5195 */
James Smart7d791df2011-07-22 18:37:52 -04005196 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04005197 }
5198 break;
James Smartda0436e2009-05-22 14:51:39 -04005199 default:
5200 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5201 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05005202 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04005203 break;
5204 }
5205}
5206
5207/**
5208 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
5209 * @phba: pointer to lpfc hba data structure.
5210 * @acqe_link: pointer to the async dcbx completion queue entry.
5211 *
5212 * This routine is to handle the SLI4 asynchronous dcbx event.
5213 **/
5214static void
5215lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
5216 struct lpfc_acqe_dcbx *acqe_dcbx)
5217{
James Smart4d9ab992009-10-02 15:16:39 -04005218 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04005219 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5220 "0290 The SLI4 DCBX asynchronous event is not "
5221 "handled yet\n");
5222}
5223
5224/**
James Smartb19a0612010-04-06 14:48:51 -04005225 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
5226 * @phba: pointer to lpfc hba data structure.
5227 * @acqe_link: pointer to the async grp5 completion queue entry.
5228 *
5229 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
5230 * is an asynchronous notified of a logical link speed change. The Port
5231 * reports the logical link speed in units of 10Mbps.
5232 **/
5233static void
5234lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
5235 struct lpfc_acqe_grp5 *acqe_grp5)
5236{
5237 uint16_t prev_ll_spd;
5238
5239 phba->fc_eventTag = acqe_grp5->event_tag;
5240 phba->fcoe_eventtag = acqe_grp5->event_tag;
5241 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
5242 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04005243 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04005244 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5245 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04005246 "from %dMbps to %dMbps\n", prev_ll_spd,
5247 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04005248}
5249
5250/**
James Smartda0436e2009-05-22 14:51:39 -04005251 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
5252 * @phba: pointer to lpfc hba data structure.
5253 *
5254 * This routine is invoked by the worker thread to process all the pending
5255 * SLI4 asynchronous events.
5256 **/
5257void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
5258{
5259 struct lpfc_cq_event *cq_event;
5260
5261 /* First, declare the async event has been handled */
5262 spin_lock_irq(&phba->hbalock);
5263 phba->hba_flag &= ~ASYNC_EVENT;
5264 spin_unlock_irq(&phba->hbalock);
5265 /* Now, handle all the async events */
5266 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
5267 /* Get the first event from the head of the event queue */
5268 spin_lock_irq(&phba->hbalock);
5269 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
5270 cq_event, struct lpfc_cq_event, list);
5271 spin_unlock_irq(&phba->hbalock);
5272 /* Process the asynchronous event */
5273 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
5274 case LPFC_TRAILER_CODE_LINK:
5275 lpfc_sli4_async_link_evt(phba,
5276 &cq_event->cqe.acqe_link);
5277 break;
5278 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05005279 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04005280 break;
5281 case LPFC_TRAILER_CODE_DCBX:
5282 lpfc_sli4_async_dcbx_evt(phba,
5283 &cq_event->cqe.acqe_dcbx);
5284 break;
James Smartb19a0612010-04-06 14:48:51 -04005285 case LPFC_TRAILER_CODE_GRP5:
5286 lpfc_sli4_async_grp5_evt(phba,
5287 &cq_event->cqe.acqe_grp5);
5288 break;
James Smart70f3c072010-12-15 17:57:33 -05005289 case LPFC_TRAILER_CODE_FC:
5290 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
5291 break;
5292 case LPFC_TRAILER_CODE_SLI:
5293 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
5294 break;
James Smartda0436e2009-05-22 14:51:39 -04005295 default:
5296 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5297 "1804 Invalid asynchrous event code: "
5298 "x%x\n", bf_get(lpfc_trailer_code,
5299 &cq_event->cqe.mcqe_cmpl));
5300 break;
5301 }
5302 /* Free the completion event processed to the free pool */
5303 lpfc_sli4_cq_event_release(phba, cq_event);
5304 }
5305}
5306
5307/**
James Smartecfd03c2010-02-12 14:41:27 -05005308 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
5309 * @phba: pointer to lpfc hba data structure.
5310 *
5311 * This routine is invoked by the worker thread to process FCF table
5312 * rediscovery pending completion event.
5313 **/
5314void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
5315{
5316 int rc;
5317
5318 spin_lock_irq(&phba->hbalock);
5319 /* Clear FCF rediscovery timeout event */
5320 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
5321 /* Clear driver fast failover FCF record flag */
5322 phba->fcf.failover_rec.flag = 0;
5323 /* Set state for FCF fast failover */
5324 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
5325 spin_unlock_irq(&phba->hbalock);
5326
5327 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05005328 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005329 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05005330 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05005331 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05005332 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5333 "2747 Issue FCF scan read FCF mailbox "
5334 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05005335}
5336
5337/**
James Smartda0436e2009-05-22 14:51:39 -04005338 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
5339 * @phba: pointer to lpfc hba data structure.
5340 * @dev_grp: The HBA PCI-Device group number.
5341 *
5342 * This routine is invoked to set up the per HBA PCI-Device group function
5343 * API jump table entries.
5344 *
5345 * Return: 0 if success, otherwise -ENODEV
5346 **/
5347int
5348lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05005349{
5350 int rc;
5351
James Smartda0436e2009-05-22 14:51:39 -04005352 /* Set up lpfc PCI-device group */
5353 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05005354
James Smartda0436e2009-05-22 14:51:39 -04005355 /* The LPFC_PCI_DEV_OC uses SLI4 */
5356 if (dev_grp == LPFC_PCI_DEV_OC)
5357 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05005358
James Smartda0436e2009-05-22 14:51:39 -04005359 /* Set up device INIT API function jump table */
5360 rc = lpfc_init_api_table_setup(phba, dev_grp);
5361 if (rc)
5362 return -ENODEV;
5363 /* Set up SCSI API function jump table */
5364 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
5365 if (rc)
5366 return -ENODEV;
5367 /* Set up SLI API function jump table */
5368 rc = lpfc_sli_api_table_setup(phba, dev_grp);
5369 if (rc)
5370 return -ENODEV;
5371 /* Set up MBOX API function jump table */
5372 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
5373 if (rc)
5374 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05005375
James Smartda0436e2009-05-22 14:51:39 -04005376 return 0;
James Smart5b75da22008-12-04 22:39:35 -05005377}
5378
5379/**
James Smart3621a712009-04-06 18:47:14 -04005380 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05005381 * @phba: pointer to lpfc hba data structure.
5382 * @intr_mode: active interrupt mode adopted.
5383 *
5384 * This routine it invoked to log the currently used active interrupt mode
5385 * to the device.
James Smart3772a992009-05-22 14:50:54 -04005386 **/
5387static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05005388{
5389 switch (intr_mode) {
5390 case 0:
5391 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5392 "0470 Enable INTx interrupt mode.\n");
5393 break;
5394 case 1:
5395 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5396 "0481 Enabled MSI interrupt mode.\n");
5397 break;
5398 case 2:
5399 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5400 "0480 Enabled MSI-X interrupt mode.\n");
5401 break;
5402 default:
5403 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5404 "0482 Illegal interrupt mode.\n");
5405 break;
5406 }
5407 return;
5408}
5409
James Smart5b75da22008-12-04 22:39:35 -05005410/**
James Smart3772a992009-05-22 14:50:54 -04005411 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05005412 * @phba: pointer to lpfc hba data structure.
5413 *
James Smart3772a992009-05-22 14:50:54 -04005414 * This routine is invoked to enable the PCI device that is common to all
5415 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05005416 *
5417 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005418 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005419 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05005420 **/
James Smart3772a992009-05-22 14:50:54 -04005421static int
5422lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05005423{
James Smart3772a992009-05-22 14:50:54 -04005424 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05005425
James Smart3772a992009-05-22 14:50:54 -04005426 /* Obtain PCI device reference */
5427 if (!phba->pcidev)
5428 goto out_error;
5429 else
5430 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04005431 /* Enable PCI device */
5432 if (pci_enable_device_mem(pdev))
5433 goto out_error;
5434 /* Request PCI resource for the device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005435 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
James Smart3772a992009-05-22 14:50:54 -04005436 goto out_disable_device;
5437 /* Set up device as PCI master and save state for EEH */
5438 pci_set_master(pdev);
5439 pci_try_set_mwi(pdev);
5440 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05005441
James Smart05580562011-05-24 11:40:48 -04005442 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
Jon Mason453193e2013-09-11 15:38:13 -07005443 if (pci_is_pcie(pdev))
James Smart05580562011-05-24 11:40:48 -04005444 pdev->needs_freset = 1;
5445
James Smart3772a992009-05-22 14:50:54 -04005446 return 0;
James Smart5b75da22008-12-04 22:39:35 -05005447
James Smart3772a992009-05-22 14:50:54 -04005448out_disable_device:
5449 pci_disable_device(pdev);
5450out_error:
James Smart079b5c92011-08-21 21:48:49 -04005451 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005452 "1401 Failed to enable pci device\n");
James Smart3772a992009-05-22 14:50:54 -04005453 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05005454}
5455
5456/**
James Smart3772a992009-05-22 14:50:54 -04005457 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05005458 * @phba: pointer to lpfc hba data structure.
5459 *
James Smart3772a992009-05-22 14:50:54 -04005460 * This routine is invoked to disable the PCI device that is common to all
5461 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05005462 **/
5463static void
James Smart3772a992009-05-22 14:50:54 -04005464lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05005465{
James Smart3772a992009-05-22 14:50:54 -04005466 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05005467
James Smart3772a992009-05-22 14:50:54 -04005468 /* Obtain PCI device reference */
5469 if (!phba->pcidev)
5470 return;
5471 else
5472 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04005473 /* Release PCI resource and disable PCI device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005474 pci_release_mem_regions(pdev);
James Smart3772a992009-05-22 14:50:54 -04005475 pci_disable_device(pdev);
James Smart5b75da22008-12-04 22:39:35 -05005476
5477 return;
5478}
5479
5480/**
James Smart3772a992009-05-22 14:50:54 -04005481 * lpfc_reset_hba - Reset a hba
5482 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04005483 *
James Smart3772a992009-05-22 14:50:54 -04005484 * This routine is invoked to reset a hba device. It brings the HBA
5485 * offline, performs a board restart, and then brings the board back
5486 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
5487 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04005488 **/
James Smart3772a992009-05-22 14:50:54 -04005489void
5490lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05005491{
James Smart3772a992009-05-22 14:50:54 -04005492 /* If resets are disabled then set error state and return. */
5493 if (!phba->cfg_enable_hba_reset) {
5494 phba->link_state = LPFC_HBA_ERROR;
5495 return;
5496 }
James Smartee620212014-04-04 13:51:53 -04005497 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
5498 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
5499 else
5500 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart3772a992009-05-22 14:50:54 -04005501 lpfc_offline(phba);
5502 lpfc_sli_brdrestart(phba);
5503 lpfc_online(phba);
5504 lpfc_unblock_mgmt_io(phba);
5505}
dea31012005-04-17 16:05:31 -05005506
James Smart3772a992009-05-22 14:50:54 -04005507/**
James Smart0a96e972011-07-22 18:37:28 -04005508 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
5509 * @phba: pointer to lpfc hba data structure.
5510 *
5511 * This function enables the PCI SR-IOV virtual functions to a physical
5512 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5513 * enable the number of virtual functions to the physical function. As
5514 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5515 * API call does not considered as an error condition for most of the device.
5516 **/
5517uint16_t
5518lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
5519{
5520 struct pci_dev *pdev = phba->pcidev;
5521 uint16_t nr_virtfn;
5522 int pos;
5523
James Smart0a96e972011-07-22 18:37:28 -04005524 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
5525 if (pos == 0)
5526 return 0;
5527
5528 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
5529 return nr_virtfn;
5530}
5531
5532/**
James Smart912e3ac2011-05-24 11:42:11 -04005533 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
5534 * @phba: pointer to lpfc hba data structure.
5535 * @nr_vfn: number of virtual functions to be enabled.
5536 *
5537 * This function enables the PCI SR-IOV virtual functions to a physical
5538 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5539 * enable the number of virtual functions to the physical function. As
5540 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5541 * API call does not considered as an error condition for most of the device.
5542 **/
5543int
5544lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
5545{
5546 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04005547 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04005548 int rc;
5549
James Smart0a96e972011-07-22 18:37:28 -04005550 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
5551 if (nr_vfn > max_nr_vfn) {
5552 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5553 "3057 Requested vfs (%d) greater than "
5554 "supported vfs (%d)", nr_vfn, max_nr_vfn);
5555 return -EINVAL;
5556 }
5557
James Smart912e3ac2011-05-24 11:42:11 -04005558 rc = pci_enable_sriov(pdev, nr_vfn);
5559 if (rc) {
5560 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5561 "2806 Failed to enable sriov on this device "
5562 "with vfn number nr_vf:%d, rc:%d\n",
5563 nr_vfn, rc);
5564 } else
5565 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5566 "2807 Successful enable sriov on this device "
5567 "with vfn number nr_vf:%d\n", nr_vfn);
5568 return rc;
5569}
5570
5571/**
James Smart895427b2017-02-12 13:52:30 -08005572 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
James Smart3772a992009-05-22 14:50:54 -04005573 * @phba: pointer to lpfc hba data structure.
5574 *
James Smart895427b2017-02-12 13:52:30 -08005575 * This routine is invoked to set up the driver internal resources before the
5576 * device specific resource setup to support the HBA device it attached to.
James Smart3772a992009-05-22 14:50:54 -04005577 *
5578 * Return codes
James Smart895427b2017-02-12 13:52:30 -08005579 * 0 - successful
5580 * other values - error
James Smart3772a992009-05-22 14:50:54 -04005581 **/
5582static int
James Smart895427b2017-02-12 13:52:30 -08005583lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
James Smart3772a992009-05-22 14:50:54 -04005584{
James Smart895427b2017-02-12 13:52:30 -08005585 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05005586
James Smart3772a992009-05-22 14:50:54 -04005587 /*
James Smart895427b2017-02-12 13:52:30 -08005588 * Driver resources common to all SLI revisions
James Smart3772a992009-05-22 14:50:54 -04005589 */
James Smart895427b2017-02-12 13:52:30 -08005590 atomic_set(&phba->fast_event_count, 0);
5591 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005592
James Smart895427b2017-02-12 13:52:30 -08005593 /* Initialize ndlp management spinlock */
5594 spin_lock_init(&phba->ndlp_lock);
James Smart3772a992009-05-22 14:50:54 -04005595
James Smart895427b2017-02-12 13:52:30 -08005596 INIT_LIST_HEAD(&phba->port_list);
5597 INIT_LIST_HEAD(&phba->work_list);
5598 init_waitqueue_head(&phba->wait_4_mlo_m_q);
5599
5600 /* Initialize the wait queue head for the kernel thread */
5601 init_waitqueue_head(&phba->work_waitq);
5602
5603 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartf358dd02017-02-12 13:52:34 -08005604 "1403 Protocols supported %s %s %s\n",
James Smart895427b2017-02-12 13:52:30 -08005605 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
5606 "SCSI" : " "),
5607 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
James Smartf358dd02017-02-12 13:52:34 -08005608 "NVME" : " "),
5609 (phba->nvmet_support ? "NVMET" : " "));
James Smart895427b2017-02-12 13:52:30 -08005610
5611 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5612 /* Initialize the scsi buffer list used by driver for scsi IO */
5613 spin_lock_init(&phba->scsi_buf_list_get_lock);
5614 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5615 spin_lock_init(&phba->scsi_buf_list_put_lock);
5616 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
5617 }
5618
5619 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
5620 (phba->nvmet_support == 0)) {
5621 /* Initialize the NVME buffer list used by driver for NVME IO */
5622 spin_lock_init(&phba->nvme_buf_list_get_lock);
5623 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_get);
James Smartcf1a1d32017-12-08 17:18:03 -08005624 phba->get_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08005625 spin_lock_init(&phba->nvme_buf_list_put_lock);
5626 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
James Smartcf1a1d32017-12-08 17:18:03 -08005627 phba->put_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08005628 }
5629
5630 /* Initialize the fabric iocb list */
5631 INIT_LIST_HEAD(&phba->fabric_iocb_list);
5632
5633 /* Initialize list to save ELS buffers */
5634 INIT_LIST_HEAD(&phba->elsbuf);
5635
5636 /* Initialize FCF connection rec list */
5637 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
5638
5639 /* Initialize OAS configuration list */
5640 spin_lock_init(&phba->devicelock);
5641 INIT_LIST_HEAD(&phba->luns);
5642
James Smart3772a992009-05-22 14:50:54 -04005643 /* MBOX heartbeat timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005644 timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04005645 /* Fabric block timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005646 timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04005647 /* EA polling mode timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005648 timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0);
James Smart895427b2017-02-12 13:52:30 -08005649 /* Heartbeat timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005650 timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0);
James Smart895427b2017-02-12 13:52:30 -08005651
5652 return 0;
5653}
5654
5655/**
5656 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
5657 * @phba: pointer to lpfc hba data structure.
5658 *
5659 * This routine is invoked to set up the driver internal resources specific to
5660 * support the SLI-3 HBA device it attached to.
5661 *
5662 * Return codes
5663 * 0 - successful
5664 * other values - error
5665 **/
5666static int
5667lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
5668{
5669 int rc;
5670
5671 /*
5672 * Initialize timers used by driver
5673 */
5674
5675 /* FCP polling mode timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005676 timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04005677
5678 /* Host attention work mask setup */
5679 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
5680 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
5681
5682 /* Get all the module params for configuring this host */
5683 lpfc_get_cfgparam(phba);
James Smart895427b2017-02-12 13:52:30 -08005684 /* Set up phase-1 common device driver resources */
5685
5686 rc = lpfc_setup_driver_resource_phase1(phba);
5687 if (rc)
5688 return -ENODEV;
5689
James Smart49198b32010-04-06 15:04:33 -04005690 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
5691 phba->menlo_flag |= HBA_MENLO_SUPPORT;
5692 /* check for menlo minimum sg count */
5693 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
5694 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
5695 }
5696
James Smart895427b2017-02-12 13:52:30 -08005697 if (!phba->sli.sli3_ring)
5698 phba->sli.sli3_ring = kzalloc(LPFC_SLI3_MAX_RING *
James Smart2a76a282012-08-03 12:35:54 -04005699 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
James Smart895427b2017-02-12 13:52:30 -08005700 if (!phba->sli.sli3_ring)
James Smart2a76a282012-08-03 12:35:54 -04005701 return -ENOMEM;
5702
James Smart3772a992009-05-22 14:50:54 -04005703 /*
James Smart96f70772013-04-17 20:16:15 -04005704 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smart3772a992009-05-22 14:50:54 -04005705 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart3772a992009-05-22 14:50:54 -04005706 */
James Smart3772a992009-05-22 14:50:54 -04005707
James Smart96f70772013-04-17 20:16:15 -04005708 /* Initialize the host templates the configured values. */
James Smart3772a992009-05-22 14:50:54 -04005709 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart96418b52017-03-04 09:30:31 -08005710 lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt;
5711 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart3772a992009-05-22 14:50:54 -04005712
James Smart96f70772013-04-17 20:16:15 -04005713 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
5714 if (phba->cfg_enable_bg) {
5715 /*
5716 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5717 * the FCP rsp, and a BDE for each. Sice we have no control
5718 * over how many protection data segments the SCSI Layer
5719 * will hand us (ie: there could be one for every block
5720 * in the IO), we just allocate enough BDEs to accomidate
5721 * our max amount and we need to limit lpfc_sg_seg_cnt to
5722 * minimize the risk of running out.
5723 */
5724 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5725 sizeof(struct fcp_rsp) +
5726 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
5727
5728 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
5729 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
5730
5731 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
5732 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
5733 } else {
5734 /*
5735 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5736 * the FCP rsp, a BDE for each, and a BDE for up to
5737 * cfg_sg_seg_cnt data segments.
5738 */
5739 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5740 sizeof(struct fcp_rsp) +
5741 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
5742
5743 /* Total BDEs in BPL for scsi_sg_list */
5744 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5745 }
5746
5747 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5748 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
5749 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5750 phba->cfg_total_seg_cnt);
5751
James Smart3772a992009-05-22 14:50:54 -04005752 phba->max_vpi = LPFC_MAX_VPI;
5753 /* This will be set to correct value after config_port mbox */
5754 phba->max_vports = 0;
5755
5756 /*
5757 * Initialize the SLI Layer to run with lpfc HBAs.
5758 */
5759 lpfc_sli_setup(phba);
James Smart895427b2017-02-12 13:52:30 -08005760 lpfc_sli_queue_init(phba);
James Smart3772a992009-05-22 14:50:54 -04005761
5762 /* Allocate device driver memory */
5763 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
5764 return -ENOMEM;
5765
James Smart912e3ac2011-05-24 11:42:11 -04005766 /*
5767 * Enable sr-iov virtual functions if supported and configured
5768 * through the module parameter.
5769 */
5770 if (phba->cfg_sriov_nr_virtfn > 0) {
5771 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5772 phba->cfg_sriov_nr_virtfn);
5773 if (rc) {
5774 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5775 "2808 Requested number of SR-IOV "
5776 "virtual functions (%d) is not "
5777 "supported\n",
5778 phba->cfg_sriov_nr_virtfn);
5779 phba->cfg_sriov_nr_virtfn = 0;
5780 }
5781 }
5782
James Smart3772a992009-05-22 14:50:54 -04005783 return 0;
5784}
5785
5786/**
5787 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
5788 * @phba: pointer to lpfc hba data structure.
5789 *
5790 * This routine is invoked to unset the driver internal resources set up
5791 * specific for supporting the SLI-3 HBA device it attached to.
5792 **/
5793static void
5794lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
5795{
5796 /* Free device driver memory allocated */
5797 lpfc_mem_free_all(phba);
5798
5799 return;
5800}
5801
5802/**
James Smartda0436e2009-05-22 14:51:39 -04005803 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
5804 * @phba: pointer to lpfc hba data structure.
5805 *
5806 * This routine is invoked to set up the driver internal resources specific to
5807 * support the SLI-4 HBA device it attached to.
5808 *
5809 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005810 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04005811 * other values - error
5812 **/
5813static int
5814lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5815{
James Smart28baac72010-02-12 14:42:03 -05005816 LPFC_MBOXQ_t *mboxq;
James Smartf358dd02017-02-12 13:52:34 -08005817 MAILBOX_t *mb;
James Smart895427b2017-02-12 13:52:30 -08005818 int rc, i, max_buf_size;
James Smart28baac72010-02-12 14:42:03 -05005819 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
5820 struct lpfc_mqe *mqe;
James Smart09294d42013-04-17 20:16:05 -04005821 int longs;
James Smart1ba981f2014-02-20 09:56:45 -05005822 int fof_vectors = 0;
James Smart81e6a632017-11-20 16:00:43 -08005823 int extra;
James Smartf358dd02017-02-12 13:52:34 -08005824 uint64_t wwn;
James Smartda0436e2009-05-22 14:51:39 -04005825
James Smart895427b2017-02-12 13:52:30 -08005826 phba->sli4_hba.num_online_cpu = num_online_cpus();
5827 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
5828 phba->sli4_hba.curr_disp_cpu = 0;
5829
James Smart716d3bc2013-09-06 12:18:28 -04005830 /* Get all the module params for configuring this host */
5831 lpfc_get_cfgparam(phba);
5832
James Smart895427b2017-02-12 13:52:30 -08005833 /* Set up phase-1 common device driver resources */
5834 rc = lpfc_setup_driver_resource_phase1(phba);
5835 if (rc)
5836 return -ENODEV;
5837
James Smartda0436e2009-05-22 14:51:39 -04005838 /* Before proceed, wait for POST done and device ready */
5839 rc = lpfc_sli4_post_status_check(phba);
5840 if (rc)
5841 return -ENODEV;
5842
5843 /*
5844 * Initialize timers used by driver
5845 */
5846
Kees Cookf22eb4d2017-09-06 20:24:26 -07005847 timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0);
James Smartda0436e2009-05-22 14:51:39 -04005848
James Smartecfd03c2010-02-12 14:41:27 -05005849 /* FCF rediscover timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005850 timer_setup(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo, 0);
James Smartecfd03c2010-02-12 14:41:27 -05005851
James Smartda0436e2009-05-22 14:51:39 -04005852 /*
James Smart7ad20aa2011-05-24 11:44:28 -04005853 * Control structure for handling external multi-buffer mailbox
5854 * command pass-through.
5855 */
5856 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
5857 sizeof(struct lpfc_mbox_ext_buf_ctx));
5858 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
5859
James Smartda0436e2009-05-22 14:51:39 -04005860 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04005861
James Smartda0436e2009-05-22 14:51:39 -04005862 /* This will be set to correct value after the read_config mbox */
5863 phba->max_vports = 0;
5864
5865 /* Program the default value of vlan_id and fc_map */
5866 phba->valid_vlan = 0;
5867 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5868 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5869 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5870
5871 /*
James Smart2a76a282012-08-03 12:35:54 -04005872 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
James Smart895427b2017-02-12 13:52:30 -08005873 * we will associate a new ring, for each EQ/CQ/WQ tuple.
5874 * The WQ create will allocate the ring.
James Smart2a76a282012-08-03 12:35:54 -04005875 */
James Smart085c6472010-11-20 23:11:37 -05005876
James Smart09294d42013-04-17 20:16:05 -04005877 /*
James Smart81e6a632017-11-20 16:00:43 -08005878 * 1 for cmd, 1 for rsp, NVME adds an extra one
5879 * for boundary conditions in its max_sgl_segment template.
5880 */
5881 extra = 2;
5882 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
5883 extra++;
5884
5885 /*
James Smart09294d42013-04-17 20:16:05 -04005886 * It doesn't matter what family our adapter is in, we are
5887 * limited to 2 Pages, 512 SGEs, for our SGL.
5888 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
5889 */
5890 max_buf_size = (2 * SLI4_PAGE_SIZE);
James Smart81e6a632017-11-20 16:00:43 -08005891 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - extra)
5892 phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - extra;
James Smart09294d42013-04-17 20:16:05 -04005893
James Smartda0436e2009-05-22 14:51:39 -04005894 /*
James Smart895427b2017-02-12 13:52:30 -08005895 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
5896 * used to create the sg_dma_buf_pool must be calculated.
James Smart28baac72010-02-12 14:42:03 -05005897 */
James Smart96f70772013-04-17 20:16:15 -04005898 if (phba->cfg_enable_bg) {
5899 /*
James Smart895427b2017-02-12 13:52:30 -08005900 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
5901 * the FCP rsp, and a SGE. Sice we have no control
5902 * over how many protection segments the SCSI Layer
James Smart96f70772013-04-17 20:16:15 -04005903 * will hand us (ie: there could be one for every block
James Smart895427b2017-02-12 13:52:30 -08005904 * in the IO), just allocate enough SGEs to accomidate
5905 * our max amount and we need to limit lpfc_sg_seg_cnt
5906 * to minimize the risk of running out.
James Smart96f70772013-04-17 20:16:15 -04005907 */
5908 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08005909 sizeof(struct fcp_rsp) + max_buf_size;
James Smart96f70772013-04-17 20:16:15 -04005910
5911 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
5912 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
5913
5914 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
James Smart895427b2017-02-12 13:52:30 -08005915 phba->cfg_sg_seg_cnt =
5916 LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
James Smart96f70772013-04-17 20:16:15 -04005917 } else {
5918 /*
James Smart895427b2017-02-12 13:52:30 -08005919 * The scsi_buf for a regular I/O holds the FCP cmnd,
James Smart96f70772013-04-17 20:16:15 -04005920 * the FCP rsp, a SGE for each, and a SGE for up to
5921 * cfg_sg_seg_cnt data segments.
5922 */
5923 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08005924 sizeof(struct fcp_rsp) +
James Smart81e6a632017-11-20 16:00:43 -08005925 ((phba->cfg_sg_seg_cnt + extra) *
James Smart895427b2017-02-12 13:52:30 -08005926 sizeof(struct sli4_sge));
James Smart96f70772013-04-17 20:16:15 -04005927
5928 /* Total SGEs for scsi_sg_list */
James Smart81e6a632017-11-20 16:00:43 -08005929 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra;
James Smart895427b2017-02-12 13:52:30 -08005930
James Smart96f70772013-04-17 20:16:15 -04005931 /*
James Smart81e6a632017-11-20 16:00:43 -08005932 * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only
James Smart895427b2017-02-12 13:52:30 -08005933 * need to post 1 page for the SGL.
James Smart96f70772013-04-17 20:16:15 -04005934 */
James Smart085c6472010-11-20 23:11:37 -05005935 }
James Smartacd68592012-01-18 16:25:09 -05005936
James Smart96f70772013-04-17 20:16:15 -04005937 /* Initialize the host templates with the updated values. */
5938 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5939 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart96418b52017-03-04 09:30:31 -08005940 lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart96f70772013-04-17 20:16:15 -04005941
5942 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
5943 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
5944 else
5945 phba->cfg_sg_dma_buf_size =
5946 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
5947
5948 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5949 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
5950 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5951 phba->cfg_total_seg_cnt);
James Smartda0436e2009-05-22 14:51:39 -04005952
5953 /* Initialize buffer queue management fields */
James Smart895427b2017-02-12 13:52:30 -08005954 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
James Smartda0436e2009-05-22 14:51:39 -04005955 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
5956 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
5957
5958 /*
5959 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
5960 */
James Smart895427b2017-02-12 13:52:30 -08005961 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5962 /* Initialize the Abort scsi buffer list used by driver */
5963 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
5964 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
5965 }
5966
5967 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
5968 /* Initialize the Abort nvme buffer list used by driver */
5969 spin_lock_init(&phba->sli4_hba.abts_nvme_buf_list_lock);
5970 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
James Smart86c67372017-04-21 16:05:04 -07005971 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
James Smarta8cf5df2017-05-15 15:20:46 -07005972 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list);
James Smart895427b2017-02-12 13:52:30 -08005973 }
5974
James Smartda0436e2009-05-22 14:51:39 -04005975 /* This abort list used by worker thread */
James Smart895427b2017-02-12 13:52:30 -08005976 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
James Smarta8cf5df2017-05-15 15:20:46 -07005977 spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock);
James Smartda0436e2009-05-22 14:51:39 -04005978
5979 /*
James Smart6d368e52011-05-24 11:44:12 -04005980 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04005981 */
5982
5983 /* Driver internel slow-path CQ Event pool */
5984 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
5985 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04005986 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04005987 /* Asynchronous event CQ Event work queue list */
5988 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
5989 /* Fast-path XRI aborted CQ Event work queue list */
5990 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
5991 /* Slow-path XRI aborted CQ Event work queue list */
5992 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
5993 /* Receive queue CQ Event work queue list */
5994 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
5995
James Smart6d368e52011-05-24 11:44:12 -04005996 /* Initialize extent block lists. */
5997 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
5998 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
5999 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
6000 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
6001
James Smartd1f525a2017-04-21 16:04:55 -07006002 /* Initialize mboxq lists. If the early init routines fail
6003 * these lists need to be correctly initialized.
6004 */
6005 INIT_LIST_HEAD(&phba->sli.mboxq);
6006 INIT_LIST_HEAD(&phba->sli.mboxq_cmpl);
6007
James Smart448193b2015-12-16 18:12:05 -05006008 /* initialize optic_state to 0xFF */
6009 phba->sli4_hba.lnk_info.optic_state = 0xff;
6010
James Smartda0436e2009-05-22 14:51:39 -04006011 /* Allocate device driver memory */
6012 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
6013 if (rc)
6014 return -ENOMEM;
6015
James Smart2fcee4b2010-12-15 17:57:46 -05006016 /* IF Type 2 ports get initialized now. */
6017 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
6018 LPFC_SLI_INTF_IF_TYPE_2) {
6019 rc = lpfc_pci_function_reset(phba);
James Smart895427b2017-02-12 13:52:30 -08006020 if (unlikely(rc)) {
6021 rc = -ENODEV;
6022 goto out_free_mem;
6023 }
James Smart946727d2015-04-07 15:07:09 -04006024 phba->temp_sensor_support = 1;
James Smart2fcee4b2010-12-15 17:57:46 -05006025 }
6026
James Smartda0436e2009-05-22 14:51:39 -04006027 /* Create the bootstrap mailbox command */
6028 rc = lpfc_create_bootstrap_mbox(phba);
6029 if (unlikely(rc))
6030 goto out_free_mem;
6031
6032 /* Set up the host's endian order with the device. */
6033 rc = lpfc_setup_endian_order(phba);
6034 if (unlikely(rc))
6035 goto out_free_bsmbx;
6036
6037 /* Set up the hba's configuration parameters. */
6038 rc = lpfc_sli4_read_config(phba);
6039 if (unlikely(rc))
6040 goto out_free_bsmbx;
James Smartcff261f2013-12-17 20:29:47 -05006041 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
6042 if (unlikely(rc))
6043 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04006044
James Smart2fcee4b2010-12-15 17:57:46 -05006045 /* IF Type 0 ports get initialized now. */
6046 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
6047 LPFC_SLI_INTF_IF_TYPE_0) {
6048 rc = lpfc_pci_function_reset(phba);
6049 if (unlikely(rc))
6050 goto out_free_bsmbx;
6051 }
James Smartda0436e2009-05-22 14:51:39 -04006052
James Smartcb5172e2010-03-15 11:25:07 -04006053 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
6054 GFP_KERNEL);
6055 if (!mboxq) {
6056 rc = -ENOMEM;
6057 goto out_free_bsmbx;
6058 }
6059
James Smartf358dd02017-02-12 13:52:34 -08006060 /* Check for NVMET being configured */
James Smart895427b2017-02-12 13:52:30 -08006061 phba->nvmet_support = 0;
James Smartf358dd02017-02-12 13:52:34 -08006062 if (lpfc_enable_nvmet_cnt) {
6063
6064 /* First get WWN of HBA instance */
6065 lpfc_read_nv(phba, mboxq);
6066 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6067 if (rc != MBX_SUCCESS) {
6068 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6069 "6016 Mailbox failed , mbxCmd x%x "
6070 "READ_NV, mbxStatus x%x\n",
6071 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
6072 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
James Smartd1f525a2017-04-21 16:04:55 -07006073 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartf358dd02017-02-12 13:52:34 -08006074 rc = -EIO;
6075 goto out_free_bsmbx;
6076 }
6077 mb = &mboxq->u.mb;
6078 memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
6079 sizeof(uint64_t));
6080 wwn = cpu_to_be64(wwn);
6081 phba->sli4_hba.wwnn.u.name = wwn;
6082 memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
6083 sizeof(uint64_t));
6084 /* wwn is WWPN of HBA instance */
6085 wwn = cpu_to_be64(wwn);
6086 phba->sli4_hba.wwpn.u.name = wwn;
6087
6088 /* Check to see if it matches any module parameter */
6089 for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
6090 if (wwn == lpfc_enable_nvmet[i]) {
James Smart7d708032017-03-08 14:36:01 -08006091#if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
James Smart3c603be2017-05-15 15:20:44 -07006092 if (lpfc_nvmet_mem_alloc(phba))
6093 break;
6094
6095 phba->nvmet_support = 1; /* a match */
6096
James Smartf358dd02017-02-12 13:52:34 -08006097 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6098 "6017 NVME Target %016llx\n",
6099 wwn);
James Smart7d708032017-03-08 14:36:01 -08006100#else
6101 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6102 "6021 Can't enable NVME Target."
6103 " NVME_TARGET_FC infrastructure"
6104 " is not in kernel\n");
6105#endif
James Smart3c603be2017-05-15 15:20:44 -07006106 break;
James Smartf358dd02017-02-12 13:52:34 -08006107 }
6108 }
6109 }
James Smart895427b2017-02-12 13:52:30 -08006110
6111 lpfc_nvme_mod_param_dep(phba);
6112
James Smartfedd3b72011-02-16 12:39:24 -05006113 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04006114 lpfc_supported_pages(mboxq);
6115 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05006116 if (!rc) {
6117 mqe = &mboxq->u.mqe;
6118 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
6119 LPFC_MAX_SUPPORTED_PAGES);
6120 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
6121 switch (pn_page[i]) {
6122 case LPFC_SLI4_PARAMETERS:
6123 phba->sli4_hba.pc_sli4_params.supported = 1;
6124 break;
6125 default:
6126 break;
6127 }
6128 }
6129 /* Read the port's SLI4 Parameters capabilities if supported. */
6130 if (phba->sli4_hba.pc_sli4_params.supported)
6131 rc = lpfc_pc_sli4_params_get(phba, mboxq);
6132 if (rc) {
6133 mempool_free(mboxq, phba->mbox_mem_pool);
6134 rc = -EIO;
6135 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04006136 }
6137 }
James Smart65791f12016-07-06 12:35:56 -07006138
James Smartfedd3b72011-02-16 12:39:24 -05006139 /*
6140 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04006141 * If this call fails, it isn't critical unless the SLI4 parameters come
6142 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05006143 */
James Smart6d368e52011-05-24 11:44:12 -04006144 rc = lpfc_get_sli4_parameters(phba, mboxq);
6145 if (rc) {
6146 if (phba->sli4_hba.extents_in_use &&
6147 phba->sli4_hba.rpi_hdrs_in_use) {
6148 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6149 "2999 Unsupported SLI4 Parameters "
6150 "Extents and RPI headers enabled.\n");
James Smart6d368e52011-05-24 11:44:12 -04006151 }
James Smart895427b2017-02-12 13:52:30 -08006152 mempool_free(mboxq, phba->mbox_mem_pool);
Stefano Brivio5c756062017-09-06 11:02:56 +02006153 rc = -EIO;
James Smart895427b2017-02-12 13:52:30 -08006154 goto out_free_bsmbx;
James Smart6d368e52011-05-24 11:44:12 -04006155 }
James Smart895427b2017-02-12 13:52:30 -08006156
James Smartcb5172e2010-03-15 11:25:07 -04006157 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -05006158
6159 /* Verify OAS is supported */
6160 lpfc_sli4_oas_verify(phba);
6161 if (phba->cfg_fof)
6162 fof_vectors = 1;
6163
James Smart5350d872011-10-10 21:33:49 -04006164 /* Verify all the SLI4 queues */
6165 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04006166 if (rc)
6167 goto out_free_bsmbx;
6168
6169 /* Create driver internal CQE event pool */
6170 rc = lpfc_sli4_cq_event_pool_create(phba);
6171 if (rc)
James Smart5350d872011-10-10 21:33:49 -04006172 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04006173
James Smart8a9d2e82012-05-09 21:16:12 -04006174 /* Initialize sgl lists per host */
6175 lpfc_init_sgl_list(phba);
6176
6177 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04006178 rc = lpfc_init_active_sgl_array(phba);
6179 if (rc) {
6180 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6181 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04006182 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04006183 }
James Smartda0436e2009-05-22 14:51:39 -04006184 rc = lpfc_sli4_init_rpi_hdrs(phba);
6185 if (rc) {
6186 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6187 "1432 Failed to initialize rpi headers.\n");
6188 goto out_free_active_sgl;
6189 }
6190
James Smarta93ff372010-10-22 11:06:08 -04006191 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05006192 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
6193 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
6194 GFP_KERNEL);
6195 if (!phba->fcf.fcf_rr_bmask) {
6196 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6197 "2759 Failed allocate memory for FCF round "
6198 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04006199 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05006200 goto out_remove_rpi_hdrs;
6201 }
6202
James Smart895427b2017-02-12 13:52:30 -08006203 phba->sli4_hba.hba_eq_hdl = kcalloc(fof_vectors + phba->io_channel_irqs,
6204 sizeof(struct lpfc_hba_eq_hdl),
6205 GFP_KERNEL);
6206 if (!phba->sli4_hba.hba_eq_hdl) {
James Smart67d12732012-08-03 12:36:13 -04006207 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6208 "2572 Failed allocate memory for "
6209 "fast-path per-EQ handle array\n");
6210 rc = -ENOMEM;
6211 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04006212 }
6213
James Smart895427b2017-02-12 13:52:30 -08006214 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_present_cpu,
6215 sizeof(struct lpfc_vector_map_info),
6216 GFP_KERNEL);
James Smart7bb03bb2013-04-17 20:19:16 -04006217 if (!phba->sli4_hba.cpu_map) {
6218 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6219 "3327 Failed allocate memory for msi-x "
6220 "interrupt vector mapping\n");
6221 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08006222 goto out_free_hba_eq_hdl;
James Smart7bb03bb2013-04-17 20:19:16 -04006223 }
James Smartb246de12013-05-31 17:03:07 -04006224 if (lpfc_used_cpu == NULL) {
James Smart895427b2017-02-12 13:52:30 -08006225 lpfc_used_cpu = kcalloc(lpfc_present_cpu, sizeof(uint16_t),
6226 GFP_KERNEL);
James Smartb246de12013-05-31 17:03:07 -04006227 if (!lpfc_used_cpu) {
6228 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6229 "3335 Failed allocate memory for msi-x "
6230 "interrupt vector mapping\n");
6231 kfree(phba->sli4_hba.cpu_map);
6232 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08006233 goto out_free_hba_eq_hdl;
James Smartb246de12013-05-31 17:03:07 -04006234 }
6235 for (i = 0; i < lpfc_present_cpu; i++)
6236 lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
6237 }
6238
James Smart912e3ac2011-05-24 11:42:11 -04006239 /*
6240 * Enable sr-iov virtual functions if supported and configured
6241 * through the module parameter.
6242 */
6243 if (phba->cfg_sriov_nr_virtfn > 0) {
6244 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
6245 phba->cfg_sriov_nr_virtfn);
6246 if (rc) {
6247 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6248 "3020 Requested number of SR-IOV "
6249 "virtual functions (%d) is not "
6250 "supported\n",
6251 phba->cfg_sriov_nr_virtfn);
6252 phba->cfg_sriov_nr_virtfn = 0;
6253 }
6254 }
6255
James Smart5248a742011-07-22 18:37:06 -04006256 return 0;
James Smartda0436e2009-05-22 14:51:39 -04006257
James Smart895427b2017-02-12 13:52:30 -08006258out_free_hba_eq_hdl:
6259 kfree(phba->sli4_hba.hba_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05006260out_free_fcf_rr_bmask:
6261 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04006262out_remove_rpi_hdrs:
6263 lpfc_sli4_remove_rpi_hdrs(phba);
6264out_free_active_sgl:
6265 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04006266out_destroy_cq_event_pool:
6267 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04006268out_free_bsmbx:
6269 lpfc_destroy_bootstrap_mbox(phba);
6270out_free_mem:
6271 lpfc_mem_free(phba);
6272 return rc;
6273}
6274
6275/**
6276 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
6277 * @phba: pointer to lpfc hba data structure.
6278 *
6279 * This routine is invoked to unset the driver internal resources set up
6280 * specific for supporting the SLI-4 HBA device it attached to.
6281 **/
6282static void
6283lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
6284{
6285 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6286
James Smart7bb03bb2013-04-17 20:19:16 -04006287 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
6288 kfree(phba->sli4_hba.cpu_map);
6289 phba->sli4_hba.num_present_cpu = 0;
6290 phba->sli4_hba.num_online_cpu = 0;
James Smart76fd07a2014-02-20 09:57:18 -05006291 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04006292
James Smartda0436e2009-05-22 14:51:39 -04006293 /* Free memory allocated for fast-path work queue handles */
James Smart895427b2017-02-12 13:52:30 -08006294 kfree(phba->sli4_hba.hba_eq_hdl);
James Smartda0436e2009-05-22 14:51:39 -04006295
6296 /* Free the allocated rpi headers. */
6297 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04006298 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04006299
James Smart0c9ab6f2010-02-26 14:15:57 -05006300 /* Free eligible FCF index bmask */
6301 kfree(phba->fcf.fcf_rr_bmask);
6302
James Smartda0436e2009-05-22 14:51:39 -04006303 /* Free the ELS sgl list */
6304 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04006305 lpfc_free_els_sgl_list(phba);
James Smartf358dd02017-02-12 13:52:34 -08006306 lpfc_free_nvmet_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04006307
James Smartda0436e2009-05-22 14:51:39 -04006308 /* Free the completion queue EQ event pool */
6309 lpfc_sli4_cq_event_release_all(phba);
6310 lpfc_sli4_cq_event_pool_destroy(phba);
6311
James Smart6d368e52011-05-24 11:44:12 -04006312 /* Release resource identifiers. */
6313 lpfc_sli4_dealloc_resource_identifiers(phba);
6314
James Smartda0436e2009-05-22 14:51:39 -04006315 /* Free the bsmbx region. */
6316 lpfc_destroy_bootstrap_mbox(phba);
6317
6318 /* Free the SLI Layer memory with SLI4 HBAs */
6319 lpfc_mem_free_all(phba);
6320
6321 /* Free the current connect table */
6322 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04006323 &phba->fcf_conn_rec_list, list) {
6324 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04006325 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04006326 }
James Smartda0436e2009-05-22 14:51:39 -04006327
6328 return;
6329}
6330
6331/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006332 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04006333 * @phba: The hba struct for which this call is being executed.
6334 * @dev_grp: The HBA PCI-Device group number.
6335 *
6336 * This routine sets up the device INIT interface API function jump table
6337 * in @phba struct.
6338 *
6339 * Returns: 0 - success, -ENODEV - failure.
6340 **/
6341int
6342lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
6343{
James Smart84d1b002010-02-12 14:42:33 -05006344 phba->lpfc_hba_init_link = lpfc_hba_init_link;
6345 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05006346 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04006347 switch (dev_grp) {
6348 case LPFC_PCI_DEV_LP:
6349 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
6350 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
6351 phba->lpfc_stop_port = lpfc_stop_port_s3;
6352 break;
James Smartda0436e2009-05-22 14:51:39 -04006353 case LPFC_PCI_DEV_OC:
6354 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
6355 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
6356 phba->lpfc_stop_port = lpfc_stop_port_s4;
6357 break;
James Smart3772a992009-05-22 14:50:54 -04006358 default:
6359 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6360 "1431 Invalid HBA PCI-device group: 0x%x\n",
6361 dev_grp);
6362 return -ENODEV;
6363 break;
6364 }
6365 return 0;
6366}
6367
6368/**
James Smart3772a992009-05-22 14:50:54 -04006369 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
6370 * @phba: pointer to lpfc hba data structure.
6371 *
6372 * This routine is invoked to set up the driver internal resources after the
6373 * device specific resource setup to support the HBA device it attached to.
6374 *
6375 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006376 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006377 * other values - error
6378 **/
6379static int
6380lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
6381{
6382 int error;
6383
6384 /* Startup the kernel thread for this host adapter. */
6385 phba->worker_thread = kthread_run(lpfc_do_work, phba,
6386 "lpfc_worker_%d", phba->brd_no);
6387 if (IS_ERR(phba->worker_thread)) {
6388 error = PTR_ERR(phba->worker_thread);
6389 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006390 }
6391
Dick Kennedyf485c182017-09-29 17:34:34 -07006392 /* workqueue for deferred irq use */
6393 phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0);
6394
James Smart3772a992009-05-22 14:50:54 -04006395 return 0;
6396}
6397
6398/**
6399 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
6400 * @phba: pointer to lpfc hba data structure.
6401 *
6402 * This routine is invoked to unset the driver internal resources set up after
6403 * the device specific resource setup for supporting the HBA device it
6404 * attached to.
6405 **/
6406static void
6407lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
6408{
Dick Kennedyf485c182017-09-29 17:34:34 -07006409 if (phba->wq) {
6410 flush_workqueue(phba->wq);
6411 destroy_workqueue(phba->wq);
6412 phba->wq = NULL;
6413 }
6414
James Smart3772a992009-05-22 14:50:54 -04006415 /* Stop kernel worker thread */
6416 kthread_stop(phba->worker_thread);
6417}
6418
6419/**
6420 * lpfc_free_iocb_list - Free iocb list.
6421 * @phba: pointer to lpfc hba data structure.
6422 *
6423 * This routine is invoked to free the driver's IOCB list and memory.
6424 **/
James Smart6c621a22017-05-15 15:20:45 -07006425void
James Smart3772a992009-05-22 14:50:54 -04006426lpfc_free_iocb_list(struct lpfc_hba *phba)
6427{
6428 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
6429
6430 spin_lock_irq(&phba->hbalock);
6431 list_for_each_entry_safe(iocbq_entry, iocbq_next,
6432 &phba->lpfc_iocb_list, list) {
6433 list_del(&iocbq_entry->list);
6434 kfree(iocbq_entry);
6435 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006436 }
James Smart3772a992009-05-22 14:50:54 -04006437 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006438
James Smart3772a992009-05-22 14:50:54 -04006439 return;
6440}
dea31012005-04-17 16:05:31 -05006441
James Smart3772a992009-05-22 14:50:54 -04006442/**
6443 * lpfc_init_iocb_list - Allocate and initialize iocb list.
6444 * @phba: pointer to lpfc hba data structure.
6445 *
6446 * This routine is invoked to allocate and initizlize the driver's IOCB
6447 * list and set up the IOCB tag array accordingly.
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 **/
James Smart6c621a22017-05-15 15:20:45 -07006453int
James Smart3772a992009-05-22 14:50:54 -04006454lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
6455{
6456 struct lpfc_iocbq *iocbq_entry = NULL;
6457 uint16_t iotag;
6458 int i;
dea31012005-04-17 16:05:31 -05006459
6460 /* Initialize and populate the iocb list per host. */
6461 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04006462 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07006463 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05006464 if (iocbq_entry == NULL) {
6465 printk(KERN_ERR "%s: only allocated %d iocbs of "
6466 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07006467 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05006468 goto out_free_iocbq;
6469 }
6470
James Bottomley604a3e32005-10-29 10:28:33 -05006471 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
6472 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04006473 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05006474 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04006475 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05006476 goto out_free_iocbq;
6477 }
James Smart6d368e52011-05-24 11:44:12 -04006478 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04006479 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05006480
6481 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006482 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
6483 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05006484 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006485 }
6486
James Smart3772a992009-05-22 14:50:54 -04006487 return 0;
6488
6489out_free_iocbq:
6490 lpfc_free_iocb_list(phba);
6491
6492 return -ENOMEM;
6493}
6494
6495/**
James Smart8a9d2e82012-05-09 21:16:12 -04006496 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04006497 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04006498 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04006499 *
James Smart8a9d2e82012-05-09 21:16:12 -04006500 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04006501 **/
James Smart8a9d2e82012-05-09 21:16:12 -04006502void
6503lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04006504{
6505 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04006506
6507 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
6508 list_del(&sglq_entry->list);
6509 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
6510 kfree(sglq_entry);
6511 }
6512}
6513
6514/**
6515 * lpfc_free_els_sgl_list - Free els sgl list.
6516 * @phba: pointer to lpfc hba data structure.
6517 *
6518 * This routine is invoked to free the driver's els sgl list and memory.
6519 **/
6520static void
6521lpfc_free_els_sgl_list(struct lpfc_hba *phba)
6522{
James Smartda0436e2009-05-22 14:51:39 -04006523 LIST_HEAD(sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04006524
James Smart8a9d2e82012-05-09 21:16:12 -04006525 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04006526 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08006527 spin_lock(&phba->sli4_hba.sgl_list_lock);
6528 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
6529 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04006530 spin_unlock_irq(&phba->hbalock);
6531
James Smart8a9d2e82012-05-09 21:16:12 -04006532 /* Now free the sgl list */
6533 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04006534}
6535
6536/**
James Smartf358dd02017-02-12 13:52:34 -08006537 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
6538 * @phba: pointer to lpfc hba data structure.
6539 *
6540 * This routine is invoked to free the driver's nvmet sgl list and memory.
6541 **/
6542static void
6543lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
6544{
6545 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6546 LIST_HEAD(sglq_list);
6547
6548 /* Retrieve all nvmet sgls from driver list */
6549 spin_lock_irq(&phba->hbalock);
6550 spin_lock(&phba->sli4_hba.sgl_list_lock);
6551 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
6552 spin_unlock(&phba->sli4_hba.sgl_list_lock);
6553 spin_unlock_irq(&phba->hbalock);
6554
6555 /* Now free the sgl list */
6556 list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
6557 list_del(&sglq_entry->list);
6558 lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
6559 kfree(sglq_entry);
6560 }
Dick Kennedy4b40d022017-08-23 16:55:38 -07006561
6562 /* Update the nvmet_xri_cnt to reflect no current sgls.
6563 * The next initialization cycle sets the count and allocates
6564 * the sgls over again.
6565 */
6566 phba->sli4_hba.nvmet_xri_cnt = 0;
James Smartf358dd02017-02-12 13:52:34 -08006567}
6568
6569/**
James Smartda0436e2009-05-22 14:51:39 -04006570 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
6571 * @phba: pointer to lpfc hba data structure.
6572 *
6573 * This routine is invoked to allocate the driver's active sgl memory.
6574 * This array will hold the sglq_entry's for active IOs.
6575 **/
6576static int
6577lpfc_init_active_sgl_array(struct lpfc_hba *phba)
6578{
6579 int size;
6580 size = sizeof(struct lpfc_sglq *);
6581 size *= phba->sli4_hba.max_cfg_param.max_xri;
6582
6583 phba->sli4_hba.lpfc_sglq_active_list =
6584 kzalloc(size, GFP_KERNEL);
6585 if (!phba->sli4_hba.lpfc_sglq_active_list)
6586 return -ENOMEM;
6587 return 0;
6588}
6589
6590/**
6591 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
6592 * @phba: pointer to lpfc hba data structure.
6593 *
6594 * This routine is invoked to walk through the array of active sglq entries
6595 * and free all of the resources.
6596 * This is just a place holder for now.
6597 **/
6598static void
6599lpfc_free_active_sgl(struct lpfc_hba *phba)
6600{
6601 kfree(phba->sli4_hba.lpfc_sglq_active_list);
6602}
6603
6604/**
6605 * lpfc_init_sgl_list - Allocate and initialize sgl list.
6606 * @phba: pointer to lpfc hba data structure.
6607 *
6608 * This routine is invoked to allocate and initizlize the driver's sgl
6609 * list and set up the sgl xritag tag array accordingly.
6610 *
James Smartda0436e2009-05-22 14:51:39 -04006611 **/
James Smart8a9d2e82012-05-09 21:16:12 -04006612static void
James Smartda0436e2009-05-22 14:51:39 -04006613lpfc_init_sgl_list(struct lpfc_hba *phba)
6614{
James Smartda0436e2009-05-22 14:51:39 -04006615 /* Initialize and populate the sglq list per host/VF. */
James Smart895427b2017-02-12 13:52:30 -08006616 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
James Smartda0436e2009-05-22 14:51:39 -04006617 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -08006618 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
James Smart86c67372017-04-21 16:05:04 -07006619 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
James Smartda0436e2009-05-22 14:51:39 -04006620
James Smart8a9d2e82012-05-09 21:16:12 -04006621 /* els xri-sgl book keeping */
6622 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04006623
James Smart8a9d2e82012-05-09 21:16:12 -04006624 /* scsi xri-buffer book keeping */
James Smartda0436e2009-05-22 14:51:39 -04006625 phba->sli4_hba.scsi_xri_cnt = 0;
James Smart895427b2017-02-12 13:52:30 -08006626
6627 /* nvme xri-buffer book keeping */
6628 phba->sli4_hba.nvme_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04006629}
6630
6631/**
6632 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
6633 * @phba: pointer to lpfc hba data structure.
6634 *
6635 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04006636 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04006637 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04006638 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
6639 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04006640 *
6641 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006642 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04006643 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04006644 **/
6645int
6646lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
6647{
6648 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04006649 struct lpfc_rpi_hdr *rpi_hdr;
6650
6651 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05006652 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04006653 return rc;
James Smart6d368e52011-05-24 11:44:12 -04006654 if (phba->sli4_hba.extents_in_use)
6655 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04006656
6657 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
6658 if (!rpi_hdr) {
6659 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6660 "0391 Error during rpi post operation\n");
6661 lpfc_sli4_remove_rpis(phba);
6662 rc = -ENODEV;
6663 }
6664
6665 return rc;
6666}
6667
6668/**
6669 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
6670 * @phba: pointer to lpfc hba data structure.
6671 *
6672 * This routine is invoked to allocate a single 4KB memory region to
6673 * support rpis and stores them in the phba. This single region
6674 * provides support for up to 64 rpis. The region is used globally
6675 * by the device.
6676 *
6677 * Returns:
6678 * A valid rpi hdr on success.
6679 * A NULL pointer on any failure.
6680 **/
6681struct lpfc_rpi_hdr *
6682lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
6683{
6684 uint16_t rpi_limit, curr_rpi_range;
6685 struct lpfc_dmabuf *dmabuf;
6686 struct lpfc_rpi_hdr *rpi_hdr;
6687
James Smart6d368e52011-05-24 11:44:12 -04006688 /*
6689 * If the SLI4 port supports extents, posting the rpi header isn't
6690 * required. Set the expected maximum count and let the actual value
6691 * get set when extents are fully allocated.
6692 */
6693 if (!phba->sli4_hba.rpi_hdrs_in_use)
6694 return NULL;
6695 if (phba->sli4_hba.extents_in_use)
6696 return NULL;
6697
6698 /* The limit on the logical index is just the max_rpi count. */
James Smart845d9e82017-05-15 15:20:38 -07006699 rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi;
James Smartda0436e2009-05-22 14:51:39 -04006700
6701 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006702 /*
6703 * Establish the starting RPI in this header block. The starting
6704 * rpi is normalized to a zero base because the physical rpi is
6705 * port based.
6706 */
James Smart97f2ecf2012-03-01 22:35:23 -05006707 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04006708 spin_unlock_irq(&phba->hbalock);
6709
James Smart845d9e82017-05-15 15:20:38 -07006710 /* Reached full RPI range */
6711 if (curr_rpi_range == rpi_limit)
James Smart6d368e52011-05-24 11:44:12 -04006712 return NULL;
James Smart845d9e82017-05-15 15:20:38 -07006713
James Smartda0436e2009-05-22 14:51:39 -04006714 /*
6715 * First allocate the protocol header region for the port. The
6716 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
6717 */
6718 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6719 if (!dmabuf)
6720 return NULL;
6721
Joe Perches1aee3832014-09-03 12:56:12 -04006722 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
6723 LPFC_HDR_TEMPLATE_SIZE,
6724 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04006725 if (!dmabuf->virt) {
6726 rpi_hdr = NULL;
6727 goto err_free_dmabuf;
6728 }
6729
James Smartda0436e2009-05-22 14:51:39 -04006730 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
6731 rpi_hdr = NULL;
6732 goto err_free_coherent;
6733 }
6734
6735 /* Save the rpi header data for cleanup later. */
6736 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
6737 if (!rpi_hdr)
6738 goto err_free_coherent;
6739
6740 rpi_hdr->dmabuf = dmabuf;
6741 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
6742 rpi_hdr->page_count = 1;
6743 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006744
6745 /* The rpi_hdr stores the logical index only. */
6746 rpi_hdr->start_rpi = curr_rpi_range;
James Smart845d9e82017-05-15 15:20:38 -07006747 rpi_hdr->next_rpi = phba->sli4_hba.next_rpi + LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04006748 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
6749
James Smartda0436e2009-05-22 14:51:39 -04006750 spin_unlock_irq(&phba->hbalock);
6751 return rpi_hdr;
6752
6753 err_free_coherent:
6754 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
6755 dmabuf->virt, dmabuf->phys);
6756 err_free_dmabuf:
6757 kfree(dmabuf);
6758 return NULL;
6759}
6760
6761/**
6762 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
6763 * @phba: pointer to lpfc hba data structure.
6764 *
6765 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04006766 * to support rpis for SLI4 ports not supporting extents. This routine
6767 * presumes the caller has released all rpis consumed by fabric or port
6768 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04006769 **/
6770void
6771lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
6772{
6773 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
6774
James Smart6d368e52011-05-24 11:44:12 -04006775 if (!phba->sli4_hba.rpi_hdrs_in_use)
6776 goto exit;
6777
James Smartda0436e2009-05-22 14:51:39 -04006778 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
6779 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
6780 list_del(&rpi_hdr->list);
6781 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
6782 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
6783 kfree(rpi_hdr->dmabuf);
6784 kfree(rpi_hdr);
6785 }
James Smart6d368e52011-05-24 11:44:12 -04006786 exit:
6787 /* There are no rpis available to the port now. */
6788 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04006789}
6790
6791/**
James Smart3772a992009-05-22 14:50:54 -04006792 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
6793 * @pdev: pointer to pci device data structure.
6794 *
6795 * This routine is invoked to allocate the driver hba data structure for an
6796 * HBA device. If the allocation is successful, the phba reference to the
6797 * PCI device data structure is set.
6798 *
6799 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006800 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04006801 * NULL - error
6802 **/
6803static struct lpfc_hba *
6804lpfc_hba_alloc(struct pci_dev *pdev)
6805{
6806 struct lpfc_hba *phba;
6807
6808 /* Allocate memory for HBA structure */
6809 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
6810 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02006811 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04006812 return NULL;
6813 }
6814
6815 /* Set reference to PCI device in HBA structure */
6816 phba->pcidev = pdev;
6817
6818 /* Assign an unused board number */
6819 phba->brd_no = lpfc_get_instance();
6820 if (phba->brd_no < 0) {
6821 kfree(phba);
6822 return NULL;
6823 }
James Smart65791f12016-07-06 12:35:56 -07006824 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
James Smart3772a992009-05-22 14:50:54 -04006825
James Smart4fede782010-01-26 23:08:55 -05006826 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04006827 INIT_LIST_HEAD(&phba->ct_ev_waiters);
6828
James Smart3772a992009-05-22 14:50:54 -04006829 return phba;
6830}
6831
6832/**
6833 * lpfc_hba_free - Free driver hba data structure with a device.
6834 * @phba: pointer to lpfc hba data structure.
6835 *
6836 * This routine is invoked to free the driver hba data structure with an
6837 * HBA device.
6838 **/
6839static void
6840lpfc_hba_free(struct lpfc_hba *phba)
6841{
6842 /* Release the driver assigned board number */
6843 idr_remove(&lpfc_hba_index, phba->brd_no);
6844
James Smart895427b2017-02-12 13:52:30 -08006845 /* Free memory allocated with sli3 rings */
6846 kfree(phba->sli.sli3_ring);
6847 phba->sli.sli3_ring = NULL;
James Smart2a76a282012-08-03 12:35:54 -04006848
James Smart3772a992009-05-22 14:50:54 -04006849 kfree(phba);
6850 return;
6851}
6852
6853/**
6854 * lpfc_create_shost - Create hba physical port with associated scsi host.
6855 * @phba: pointer to lpfc hba data structure.
6856 *
6857 * This routine is invoked to create HBA physical port and associate a SCSI
6858 * host with it.
6859 *
6860 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006861 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006862 * other values - error
6863 **/
6864static int
6865lpfc_create_shost(struct lpfc_hba *phba)
6866{
6867 struct lpfc_vport *vport;
6868 struct Scsi_Host *shost;
6869
6870 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05006871 phba->fc_edtov = FF_DEF_EDTOV;
6872 phba->fc_ratov = FF_DEF_RATOV;
6873 phba->fc_altov = FF_DEF_ALTOV;
6874 phba->fc_arbtov = FF_DEF_ARBTOV;
6875
James Smartd7c47992010-06-08 18:31:54 -04006876 atomic_set(&phba->sdev_cnt, 0);
James Smart2cee7802017-06-01 21:07:02 -07006877 atomic_set(&phba->fc4ScsiInputRequests, 0);
6878 atomic_set(&phba->fc4ScsiOutputRequests, 0);
6879 atomic_set(&phba->fc4ScsiControlRequests, 0);
6880 atomic_set(&phba->fc4ScsiIoCmpls, 0);
6881 atomic_set(&phba->fc4NvmeInputRequests, 0);
6882 atomic_set(&phba->fc4NvmeOutputRequests, 0);
6883 atomic_set(&phba->fc4NvmeControlRequests, 0);
6884 atomic_set(&phba->fc4NvmeIoCmpls, 0);
6885 atomic_set(&phba->fc4NvmeLsRequests, 0);
6886 atomic_set(&phba->fc4NvmeLsCmpls, 0);
James Smart3de2a652007-08-02 11:09:59 -04006887 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05006888 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04006889 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05006890
6891 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05006892 phba->pport = vport;
James Smart2ea259e2017-02-12 13:52:27 -08006893
James Smartf358dd02017-02-12 13:52:34 -08006894 if (phba->nvmet_support) {
6895 /* Only 1 vport (pport) will support NVME target */
6896 if (phba->txrdy_payload_pool == NULL) {
Romain Perier771db5c2017-07-06 10:13:05 +02006897 phba->txrdy_payload_pool = dma_pool_create(
6898 "txrdy_pool", &phba->pcidev->dev,
James Smartf358dd02017-02-12 13:52:34 -08006899 TXRDY_PAYLOAD_LEN, 16, 0);
6900 if (phba->txrdy_payload_pool) {
6901 phba->targetport = NULL;
6902 phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
6903 lpfc_printf_log(phba, KERN_INFO,
6904 LOG_INIT | LOG_NVME_DISC,
6905 "6076 NVME Target Found\n");
6906 }
6907 }
6908 }
6909
James Smart858c9f62007-06-17 19:56:39 -05006910 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04006911 /* Put reference to SCSI host to driver's device private data */
6912 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05006913
James Smart4258e982015-12-16 18:11:58 -05006914 /*
6915 * At this point we are fully registered with PSA. In addition,
6916 * any initial discovery should be completed.
6917 */
6918 vport->load_flag |= FC_ALLOW_FDMI;
James Smart8663cbb2016-03-31 14:12:33 -07006919 if (phba->cfg_enable_SmartSAN ||
6920 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -05006921
6922 /* Setup appropriate attribute masks */
6923 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -07006924 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -05006925 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
6926 else
6927 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
6928 }
James Smart3772a992009-05-22 14:50:54 -04006929 return 0;
6930}
dea31012005-04-17 16:05:31 -05006931
James Smart3772a992009-05-22 14:50:54 -04006932/**
6933 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
6934 * @phba: pointer to lpfc hba data structure.
6935 *
6936 * This routine is invoked to destroy HBA physical port and the associated
6937 * SCSI host.
6938 **/
6939static void
6940lpfc_destroy_shost(struct lpfc_hba *phba)
6941{
6942 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04006943
James Smart3772a992009-05-22 14:50:54 -04006944 /* Destroy physical port that associated with the SCSI host */
6945 destroy_port(vport);
6946
6947 return;
6948}
6949
6950/**
6951 * lpfc_setup_bg - Setup Block guard structures and debug areas.
6952 * @phba: pointer to lpfc hba data structure.
6953 * @shost: the shost to be used to detect Block guard settings.
6954 *
6955 * This routine sets up the local Block guard protocol settings for @shost.
6956 * This routine also allocates memory for debugging bg buffers.
6957 **/
6958static void
6959lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
6960{
James Smartbbeb79b2012-06-12 13:54:27 -04006961 uint32_t old_mask;
6962 uint32_t old_guard;
6963
James Smart3772a992009-05-22 14:50:54 -04006964 int pagecnt = 10;
James Smartb3b98b72016-10-13 15:06:06 -07006965 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
James Smart3772a992009-05-22 14:50:54 -04006966 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6967 "1478 Registering BlockGuard with the "
6968 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04006969
James Smartb3b98b72016-10-13 15:06:06 -07006970 old_mask = phba->cfg_prot_mask;
6971 old_guard = phba->cfg_prot_guard;
James Smartbbeb79b2012-06-12 13:54:27 -04006972
6973 /* Only allow supported values */
James Smartb3b98b72016-10-13 15:06:06 -07006974 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
James Smartbbeb79b2012-06-12 13:54:27 -04006975 SHOST_DIX_TYPE0_PROTECTION |
6976 SHOST_DIX_TYPE1_PROTECTION);
James Smartb3b98b72016-10-13 15:06:06 -07006977 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
6978 SHOST_DIX_GUARD_CRC);
James Smartbbeb79b2012-06-12 13:54:27 -04006979
6980 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
James Smartb3b98b72016-10-13 15:06:06 -07006981 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
6982 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
James Smartbbeb79b2012-06-12 13:54:27 -04006983
James Smartb3b98b72016-10-13 15:06:06 -07006984 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
6985 if ((old_mask != phba->cfg_prot_mask) ||
6986 (old_guard != phba->cfg_prot_guard))
James Smartbbeb79b2012-06-12 13:54:27 -04006987 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6988 "1475 Registering BlockGuard with the "
6989 "SCSI layer: mask %d guard %d\n",
James Smartb3b98b72016-10-13 15:06:06 -07006990 phba->cfg_prot_mask,
6991 phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04006992
James Smartb3b98b72016-10-13 15:06:06 -07006993 scsi_host_set_prot(shost, phba->cfg_prot_mask);
6994 scsi_host_set_guard(shost, phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04006995 } else
6996 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6997 "1479 Not Registering BlockGuard with the SCSI "
6998 "layer, Bad protection parameters: %d %d\n",
6999 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04007000 }
James Smartbbeb79b2012-06-12 13:54:27 -04007001
James Smart81301a92008-12-04 22:39:46 -05007002 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05007003 while (pagecnt) {
7004 spin_lock_init(&_dump_buf_lock);
7005 _dump_buf_data =
7006 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
7007 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04007008 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7009 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04007010 "_dump_buf_data at 0x%p\n",
7011 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05007012 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04007013 memset(_dump_buf_data, 0,
7014 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05007015 break;
James Smart3772a992009-05-22 14:50:54 -04007016 } else
James Smart81301a92008-12-04 22:39:46 -05007017 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05007018 }
James Smart81301a92008-12-04 22:39:46 -05007019 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04007020 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7021 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04007022 "memory for hexdump\n");
7023 } else
James Smart6a9c52c2009-10-02 15:16:51 -04007024 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7025 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05007026 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05007027 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05007028 while (pagecnt) {
7029 _dump_buf_dif =
7030 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
7031 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04007032 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7033 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04007034 "_dump_buf_dif at 0x%p\n",
7035 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05007036 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04007037 memset(_dump_buf_dif, 0,
7038 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05007039 break;
James Smart3772a992009-05-22 14:50:54 -04007040 } else
James Smart81301a92008-12-04 22:39:46 -05007041 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05007042 }
James Smart81301a92008-12-04 22:39:46 -05007043 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04007044 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7045 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04007046 "memory for hexdump\n");
7047 } else
James Smart6a9c52c2009-10-02 15:16:51 -04007048 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7049 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04007050 _dump_buf_dif);
7051}
7052
7053/**
7054 * lpfc_post_init_setup - Perform necessary device post initialization setup.
7055 * @phba: pointer to lpfc hba data structure.
7056 *
7057 * This routine is invoked to perform all the necessary post initialization
7058 * setup for the device.
7059 **/
7060static void
7061lpfc_post_init_setup(struct lpfc_hba *phba)
7062{
7063 struct Scsi_Host *shost;
7064 struct lpfc_adapter_event_header adapter_event;
7065
7066 /* Get the default values for Model Name and Description */
7067 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
7068
7069 /*
7070 * hba setup may have changed the hba_queue_depth so we need to
7071 * adjust the value of can_queue.
7072 */
7073 shost = pci_get_drvdata(phba->pcidev);
7074 shost->can_queue = phba->cfg_hba_queue_depth - 10;
7075 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
7076 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05007077
7078 lpfc_host_attrib_init(shost);
7079
James Smart2e0fef82007-06-17 19:56:36 -05007080 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
7081 spin_lock_irq(shost->host_lock);
7082 lpfc_poll_start_timer(phba);
7083 spin_unlock_irq(shost->host_lock);
7084 }
James Smart8f6d98d2006-08-01 07:34:00 -04007085
James Smart93996272008-08-24 21:50:30 -04007086 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7087 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04007088 /* Send board arrival event to upper layer */
7089 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
7090 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
7091 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04007092 sizeof(adapter_event),
7093 (char *) &adapter_event,
7094 LPFC_NL_VENDOR_ID);
7095 return;
7096}
7097
7098/**
7099 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
7100 * @phba: pointer to lpfc hba data structure.
7101 *
7102 * This routine is invoked to set up the PCI device memory space for device
7103 * with SLI-3 interface spec.
7104 *
7105 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007106 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007107 * other values - error
7108 **/
7109static int
7110lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
7111{
7112 struct pci_dev *pdev;
7113 unsigned long bar0map_len, bar2map_len;
7114 int i, hbq_count;
7115 void *ptr;
7116 int error = -ENODEV;
7117
7118 /* Obtain PCI device reference */
7119 if (!phba->pcidev)
7120 return error;
7121 else
7122 pdev = phba->pcidev;
7123
7124 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05007125 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
7126 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
7127 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
7128 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smart3772a992009-05-22 14:50:54 -04007129 return error;
Michael Reed8e685972009-09-18 12:02:05 -05007130 }
7131 }
James Smart3772a992009-05-22 14:50:54 -04007132
7133 /* Get the bus address of Bar0 and Bar2 and the number of bytes
7134 * required by each mapping.
7135 */
7136 phba->pci_bar0_map = pci_resource_start(pdev, 0);
7137 bar0map_len = pci_resource_len(pdev, 0);
7138
7139 phba->pci_bar2_map = pci_resource_start(pdev, 2);
7140 bar2map_len = pci_resource_len(pdev, 2);
7141
7142 /* Map HBA SLIM to a kernel virtual address. */
7143 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
7144 if (!phba->slim_memmap_p) {
7145 dev_printk(KERN_ERR, &pdev->dev,
7146 "ioremap failed for SLIM memory.\n");
7147 goto out;
7148 }
7149
7150 /* Map HBA Control Registers to a kernel virtual address. */
7151 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
7152 if (!phba->ctrl_regs_memmap_p) {
7153 dev_printk(KERN_ERR, &pdev->dev,
7154 "ioremap failed for HBA control registers.\n");
7155 goto out_iounmap_slim;
7156 }
7157
7158 /* Allocate memory for SLI-2 structures */
Joe Perches1aee3832014-09-03 12:56:12 -04007159 phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7160 &phba->slim2p.phys, GFP_KERNEL);
James Smart3772a992009-05-22 14:50:54 -04007161 if (!phba->slim2p.virt)
7162 goto out_iounmap;
7163
James Smart3772a992009-05-22 14:50:54 -04007164 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04007165 phba->mbox_ext = (phba->slim2p.virt +
7166 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04007167 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
7168 phba->IOCBs = (phba->slim2p.virt +
7169 offsetof(struct lpfc_sli2_slim, IOCBs));
7170
7171 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
7172 lpfc_sli_hbq_size(),
7173 &phba->hbqslimp.phys,
7174 GFP_KERNEL);
7175 if (!phba->hbqslimp.virt)
7176 goto out_free_slim;
7177
7178 hbq_count = lpfc_sli_hbq_count();
7179 ptr = phba->hbqslimp.virt;
7180 for (i = 0; i < hbq_count; ++i) {
7181 phba->hbqs[i].hbq_virt = ptr;
7182 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
7183 ptr += (lpfc_hbq_defs[i]->entry_count *
7184 sizeof(struct lpfc_hbq_entry));
7185 }
7186 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
7187 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
7188
7189 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
7190
James Smart3772a992009-05-22 14:50:54 -04007191 phba->MBslimaddr = phba->slim_memmap_p;
7192 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
7193 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
7194 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
7195 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04007196
dea31012005-04-17 16:05:31 -05007197 return 0;
7198
dea31012005-04-17 16:05:31 -05007199out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04007200 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7201 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05007202out_iounmap:
7203 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05007204out_iounmap_slim:
dea31012005-04-17 16:05:31 -05007205 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05007206out:
7207 return error;
7208}
7209
James Smarte59058c2008-08-24 21:49:00 -04007210/**
James Smart3772a992009-05-22 14:50:54 -04007211 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
7212 * @phba: pointer to lpfc hba data structure.
7213 *
7214 * This routine is invoked to unset the PCI device memory space for device
7215 * with SLI-3 interface spec.
7216 **/
7217static void
7218lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
7219{
7220 struct pci_dev *pdev;
7221
7222 /* Obtain PCI device reference */
7223 if (!phba->pcidev)
7224 return;
7225 else
7226 pdev = phba->pcidev;
7227
7228 /* Free coherent DMA memory allocated */
7229 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
7230 phba->hbqslimp.virt, phba->hbqslimp.phys);
7231 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7232 phba->slim2p.virt, phba->slim2p.phys);
7233
7234 /* I/O memory unmap */
7235 iounmap(phba->ctrl_regs_memmap_p);
7236 iounmap(phba->slim_memmap_p);
7237
7238 return;
7239}
7240
7241/**
James Smartda0436e2009-05-22 14:51:39 -04007242 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
7243 * @phba: pointer to lpfc hba data structure.
7244 *
7245 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
7246 * done and check status.
7247 *
7248 * Return 0 if successful, otherwise -ENODEV.
7249 **/
7250int
7251lpfc_sli4_post_status_check(struct lpfc_hba *phba)
7252{
James Smart2fcee4b2010-12-15 17:57:46 -05007253 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
7254 struct lpfc_register reg_data;
7255 int i, port_error = 0;
7256 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04007257
James Smart9940b972011-03-11 16:06:12 -05007258 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
7259 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05007260 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04007261 return -ENODEV;
7262
James Smartda0436e2009-05-22 14:51:39 -04007263 /* Wait up to 30 seconds for the SLI Port POST done and ready */
7264 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05007265 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
7266 &portsmphr_reg.word0) ||
7267 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007268 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04007269 port_error = -ENODEV;
7270 break;
7271 }
James Smart2fcee4b2010-12-15 17:57:46 -05007272 if (LPFC_POST_STAGE_PORT_READY ==
7273 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04007274 break;
James Smartda0436e2009-05-22 14:51:39 -04007275 msleep(10);
7276 }
7277
James Smart2fcee4b2010-12-15 17:57:46 -05007278 /*
7279 * If there was a port error during POST, then don't proceed with
7280 * other register reads as the data may not be valid. Just exit.
7281 */
7282 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04007283 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05007284 "1408 Port Failed POST - portsmphr=0x%x, "
7285 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
7286 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
7287 portsmphr_reg.word0,
7288 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
7289 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
7290 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
7291 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
7292 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
7293 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
7294 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
7295 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
7296 } else {
James Smart28baac72010-02-12 14:42:03 -05007297 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05007298 "2534 Device Info: SLIFamily=0x%x, "
7299 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
7300 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05007301 bf_get(lpfc_sli_intf_sli_family,
7302 &phba->sli4_hba.sli_intf),
7303 bf_get(lpfc_sli_intf_slirev,
7304 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05007305 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05007306 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05007307 bf_get(lpfc_sli_intf_sli_hint1,
7308 &phba->sli4_hba.sli_intf),
7309 bf_get(lpfc_sli_intf_sli_hint2,
7310 &phba->sli4_hba.sli_intf),
7311 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05007312 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05007313 /*
7314 * Check for other Port errors during the initialization
7315 * process. Fail the load if the port did not come up
7316 * correctly.
7317 */
7318 if_type = bf_get(lpfc_sli_intf_if_type,
7319 &phba->sli4_hba.sli_intf);
7320 switch (if_type) {
7321 case LPFC_SLI_INTF_IF_TYPE_0:
7322 phba->sli4_hba.ue_mask_lo =
7323 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
7324 phba->sli4_hba.ue_mask_hi =
7325 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
7326 uerrlo_reg.word0 =
7327 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
7328 uerrhi_reg.word0 =
7329 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
7330 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
7331 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
7332 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7333 "1422 Unrecoverable Error "
7334 "Detected during POST "
7335 "uerr_lo_reg=0x%x, "
7336 "uerr_hi_reg=0x%x, "
7337 "ue_mask_lo_reg=0x%x, "
7338 "ue_mask_hi_reg=0x%x\n",
7339 uerrlo_reg.word0,
7340 uerrhi_reg.word0,
7341 phba->sli4_hba.ue_mask_lo,
7342 phba->sli4_hba.ue_mask_hi);
7343 port_error = -ENODEV;
7344 }
7345 break;
7346 case LPFC_SLI_INTF_IF_TYPE_2:
7347 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05007348 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
7349 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04007350 (bf_get(lpfc_sliport_status_err, &reg_data) &&
7351 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007352 phba->work_status[0] =
7353 readl(phba->sli4_hba.u.if_type2.
7354 ERR1regaddr);
7355 phba->work_status[1] =
7356 readl(phba->sli4_hba.u.if_type2.
7357 ERR2regaddr);
7358 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05007359 "2888 Unrecoverable port error "
7360 "following POST: port status reg "
7361 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05007362 "error 1=0x%x, error 2=0x%x\n",
7363 reg_data.word0,
7364 portsmphr_reg.word0,
7365 phba->work_status[0],
7366 phba->work_status[1]);
7367 port_error = -ENODEV;
7368 }
7369 break;
7370 case LPFC_SLI_INTF_IF_TYPE_1:
7371 default:
7372 break;
7373 }
James Smart28baac72010-02-12 14:42:03 -05007374 }
James Smartda0436e2009-05-22 14:51:39 -04007375 return port_error;
7376}
7377
7378/**
7379 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
7380 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05007381 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04007382 *
7383 * This routine is invoked to set up SLI4 BAR0 PCI config space register
7384 * memory map.
7385 **/
7386static void
James Smart2fcee4b2010-12-15 17:57:46 -05007387lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04007388{
James Smart2fcee4b2010-12-15 17:57:46 -05007389 switch (if_type) {
7390 case LPFC_SLI_INTF_IF_TYPE_0:
7391 phba->sli4_hba.u.if_type0.UERRLOregaddr =
7392 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
7393 phba->sli4_hba.u.if_type0.UERRHIregaddr =
7394 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
7395 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
7396 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
7397 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
7398 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
7399 phba->sli4_hba.SLIINTFregaddr =
7400 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7401 break;
7402 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart0cf07f842017-06-01 21:07:10 -07007403 phba->sli4_hba.u.if_type2.EQDregaddr =
7404 phba->sli4_hba.conf_regs_memmap_p +
7405 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007406 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007407 phba->sli4_hba.conf_regs_memmap_p +
7408 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007409 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007410 phba->sli4_hba.conf_regs_memmap_p +
7411 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007412 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007413 phba->sli4_hba.conf_regs_memmap_p +
7414 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007415 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007416 phba->sli4_hba.conf_regs_memmap_p +
7417 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007418 phba->sli4_hba.SLIINTFregaddr =
7419 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7420 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007421 phba->sli4_hba.conf_regs_memmap_p +
7422 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007423 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05007424 phba->sli4_hba.conf_regs_memmap_p +
7425 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05007426 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05007427 phba->sli4_hba.conf_regs_memmap_p +
7428 LPFC_ULP0_WQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05007429 phba->sli4_hba.EQCQDBregaddr =
7430 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
7431 phba->sli4_hba.MQDBregaddr =
7432 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
7433 phba->sli4_hba.BMBXregaddr =
7434 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
7435 break;
7436 case LPFC_SLI_INTF_IF_TYPE_1:
7437 default:
7438 dev_printk(KERN_ERR, &phba->pcidev->dev,
7439 "FATAL - unsupported SLI4 interface type - %d\n",
7440 if_type);
7441 break;
7442 }
James Smartda0436e2009-05-22 14:51:39 -04007443}
7444
7445/**
7446 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
7447 * @phba: pointer to lpfc hba data structure.
7448 *
7449 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
7450 * memory map.
7451 **/
7452static void
7453lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
7454{
James Smart2fcee4b2010-12-15 17:57:46 -05007455 phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7456 LPFC_SLIPORT_IF0_SMPHR;
James Smartda0436e2009-05-22 14:51:39 -04007457 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05007458 LPFC_HST_ISR0;
James Smartda0436e2009-05-22 14:51:39 -04007459 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05007460 LPFC_HST_IMR0;
James Smartda0436e2009-05-22 14:51:39 -04007461 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05007462 LPFC_HST_ISCR0;
James Smartda0436e2009-05-22 14:51:39 -04007463}
7464
7465/**
7466 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
7467 * @phba: pointer to lpfc hba data structure.
7468 * @vf: virtual function number
7469 *
7470 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
7471 * based on the given viftual function number, @vf.
7472 *
7473 * Return 0 if successful, otherwise -ENODEV.
7474 **/
7475static int
7476lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
7477{
7478 if (vf > LPFC_VIR_FUNC_MAX)
7479 return -ENODEV;
7480
7481 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05007482 vf * LPFC_VFR_PAGE_SIZE +
7483 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04007484 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05007485 vf * LPFC_VFR_PAGE_SIZE +
7486 LPFC_ULP0_WQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04007487 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7488 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
7489 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7490 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
7491 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7492 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
7493 return 0;
7494}
7495
7496/**
7497 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
7498 * @phba: pointer to lpfc hba data structure.
7499 *
7500 * This routine is invoked to create the bootstrap mailbox
7501 * region consistent with the SLI-4 interface spec. This
7502 * routine allocates all memory necessary to communicate
7503 * mailbox commands to the port and sets up all alignment
7504 * needs. No locks are expected to be held when calling
7505 * this routine.
7506 *
7507 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007508 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04007509 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04007510 **/
7511static int
7512lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
7513{
7514 uint32_t bmbx_size;
7515 struct lpfc_dmabuf *dmabuf;
7516 struct dma_address *dma_address;
7517 uint32_t pa_addr;
7518 uint64_t phys_addr;
7519
7520 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
7521 if (!dmabuf)
7522 return -ENOMEM;
7523
7524 /*
7525 * The bootstrap mailbox region is comprised of 2 parts
7526 * plus an alignment restriction of 16 bytes.
7527 */
7528 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
Joe Perches1aee3832014-09-03 12:56:12 -04007529 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
7530 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04007531 if (!dmabuf->virt) {
7532 kfree(dmabuf);
7533 return -ENOMEM;
7534 }
James Smartda0436e2009-05-22 14:51:39 -04007535
7536 /*
7537 * Initialize the bootstrap mailbox pointers now so that the register
7538 * operations are simple later. The mailbox dma address is required
7539 * to be 16-byte aligned. Also align the virtual memory as each
7540 * maibox is copied into the bmbx mailbox region before issuing the
7541 * command to the port.
7542 */
7543 phba->sli4_hba.bmbx.dmabuf = dmabuf;
7544 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
7545
7546 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
7547 LPFC_ALIGN_16_BYTE);
7548 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
7549 LPFC_ALIGN_16_BYTE);
7550
7551 /*
7552 * Set the high and low physical addresses now. The SLI4 alignment
7553 * requirement is 16 bytes and the mailbox is posted to the port
7554 * as two 30-bit addresses. The other data is a bit marking whether
7555 * the 30-bit address is the high or low address.
7556 * Upcast bmbx aphys to 64bits so shift instruction compiles
7557 * clean on 32 bit machines.
7558 */
7559 dma_address = &phba->sli4_hba.bmbx.dma_address;
7560 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
7561 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
7562 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
7563 LPFC_BMBX_BIT1_ADDR_HI);
7564
7565 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
7566 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
7567 LPFC_BMBX_BIT1_ADDR_LO);
7568 return 0;
7569}
7570
7571/**
7572 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
7573 * @phba: pointer to lpfc hba data structure.
7574 *
7575 * This routine is invoked to teardown the bootstrap mailbox
7576 * region and release all host resources. This routine requires
7577 * the caller to ensure all mailbox commands recovered, no
7578 * additional mailbox comands are sent, and interrupts are disabled
7579 * before calling this routine.
7580 *
7581 **/
7582static void
7583lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
7584{
7585 dma_free_coherent(&phba->pcidev->dev,
7586 phba->sli4_hba.bmbx.bmbx_size,
7587 phba->sli4_hba.bmbx.dmabuf->virt,
7588 phba->sli4_hba.bmbx.dmabuf->phys);
7589
7590 kfree(phba->sli4_hba.bmbx.dmabuf);
7591 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
7592}
7593
7594/**
7595 * lpfc_sli4_read_config - Get the config parameters.
7596 * @phba: pointer to lpfc hba data structure.
7597 *
7598 * This routine is invoked to read the configuration parameters from the HBA.
7599 * The configuration parameters are used to set the base and maximum values
7600 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
7601 * allocation for the port.
7602 *
7603 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007604 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007605 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007606 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007607 **/
James Smartff78d8f2011-12-13 13:21:35 -05007608int
James Smartda0436e2009-05-22 14:51:39 -04007609lpfc_sli4_read_config(struct lpfc_hba *phba)
7610{
7611 LPFC_MBOXQ_t *pmb;
7612 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04007613 union lpfc_sli4_cfg_shdr *shdr;
7614 uint32_t shdr_status, shdr_add_status;
7615 struct lpfc_mbx_get_func_cfg *get_func_cfg;
7616 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04007617 char *pdesc_0;
James Smartc6918162016-10-13 15:06:16 -07007618 uint16_t forced_link_speed;
7619 uint32_t if_type;
James Smart8aa134a2012-08-14 14:25:29 -04007620 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04007621
7622 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7623 if (!pmb) {
7624 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7625 "2011 Unable to allocate memory for issuing "
7626 "SLI_CONFIG_SPECIAL mailbox command\n");
7627 return -ENOMEM;
7628 }
7629
7630 lpfc_read_config(phba, pmb);
7631
7632 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
7633 if (rc != MBX_SUCCESS) {
7634 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7635 "2012 Mailbox failed , mbxCmd x%x "
7636 "READ_CONFIG, mbxStatus x%x\n",
7637 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7638 bf_get(lpfc_mqe_status, &pmb->u.mqe));
7639 rc = -EIO;
7640 } else {
7641 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05007642 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
7643 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
7644 phba->sli4_hba.lnk_info.lnk_tp =
7645 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
7646 phba->sli4_hba.lnk_info.lnk_no =
7647 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
7648 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7649 "3081 lnk_type:%d, lnk_numb:%d\n",
7650 phba->sli4_hba.lnk_info.lnk_tp,
7651 phba->sli4_hba.lnk_info.lnk_no);
7652 } else
7653 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
7654 "3082 Mailbox (x%x) returned ldv:x0\n",
7655 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart44fd7fe2017-08-23 16:55:47 -07007656 if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) {
7657 phba->bbcredit_support = 1;
7658 phba->sli4_hba.bbscn_params.word0 = rd_config->word8;
7659 }
7660
James Smart6d368e52011-05-24 11:44:12 -04007661 phba->sli4_hba.extents_in_use =
7662 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04007663 phba->sli4_hba.max_cfg_param.max_xri =
7664 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
7665 phba->sli4_hba.max_cfg_param.xri_base =
7666 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
7667 phba->sli4_hba.max_cfg_param.max_vpi =
7668 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
7669 phba->sli4_hba.max_cfg_param.vpi_base =
7670 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
7671 phba->sli4_hba.max_cfg_param.max_rpi =
7672 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
7673 phba->sli4_hba.max_cfg_param.rpi_base =
7674 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
7675 phba->sli4_hba.max_cfg_param.max_vfi =
7676 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
7677 phba->sli4_hba.max_cfg_param.vfi_base =
7678 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
7679 phba->sli4_hba.max_cfg_param.max_fcfi =
7680 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04007681 phba->sli4_hba.max_cfg_param.max_eq =
7682 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
7683 phba->sli4_hba.max_cfg_param.max_rq =
7684 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
7685 phba->sli4_hba.max_cfg_param.max_wq =
7686 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
7687 phba->sli4_hba.max_cfg_param.max_cq =
7688 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
7689 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
7690 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
7691 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
7692 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05007693 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
7694 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04007695 phba->max_vports = phba->max_vpi;
7696 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04007697 "2003 cfg params Extents? %d "
7698 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04007699 "VPI(B:%d M:%d) "
7700 "VFI(B:%d M:%d) "
7701 "RPI(B:%d M:%d) "
James Smart2ea259e2017-02-12 13:52:27 -08007702 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n",
James Smart6d368e52011-05-24 11:44:12 -04007703 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04007704 phba->sli4_hba.max_cfg_param.xri_base,
7705 phba->sli4_hba.max_cfg_param.max_xri,
7706 phba->sli4_hba.max_cfg_param.vpi_base,
7707 phba->sli4_hba.max_cfg_param.max_vpi,
7708 phba->sli4_hba.max_cfg_param.vfi_base,
7709 phba->sli4_hba.max_cfg_param.max_vfi,
7710 phba->sli4_hba.max_cfg_param.rpi_base,
7711 phba->sli4_hba.max_cfg_param.max_rpi,
James Smart2ea259e2017-02-12 13:52:27 -08007712 phba->sli4_hba.max_cfg_param.max_fcfi,
7713 phba->sli4_hba.max_cfg_param.max_eq,
7714 phba->sli4_hba.max_cfg_param.max_cq,
7715 phba->sli4_hba.max_cfg_param.max_wq,
7716 phba->sli4_hba.max_cfg_param.max_rq);
7717
James Smartda0436e2009-05-22 14:51:39 -04007718 }
James Smart912e3ac2011-05-24 11:42:11 -04007719
7720 if (rc)
7721 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04007722
James Smartc6918162016-10-13 15:06:16 -07007723 /* Update link speed if forced link speed is supported */
7724 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7725 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
7726 forced_link_speed =
7727 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
7728 if (forced_link_speed) {
7729 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
7730
7731 switch (forced_link_speed) {
7732 case LINK_SPEED_1G:
7733 phba->cfg_link_speed =
7734 LPFC_USER_LINK_SPEED_1G;
7735 break;
7736 case LINK_SPEED_2G:
7737 phba->cfg_link_speed =
7738 LPFC_USER_LINK_SPEED_2G;
7739 break;
7740 case LINK_SPEED_4G:
7741 phba->cfg_link_speed =
7742 LPFC_USER_LINK_SPEED_4G;
7743 break;
7744 case LINK_SPEED_8G:
7745 phba->cfg_link_speed =
7746 LPFC_USER_LINK_SPEED_8G;
7747 break;
7748 case LINK_SPEED_10G:
7749 phba->cfg_link_speed =
7750 LPFC_USER_LINK_SPEED_10G;
7751 break;
7752 case LINK_SPEED_16G:
7753 phba->cfg_link_speed =
7754 LPFC_USER_LINK_SPEED_16G;
7755 break;
7756 case LINK_SPEED_32G:
7757 phba->cfg_link_speed =
7758 LPFC_USER_LINK_SPEED_32G;
7759 break;
7760 case 0xffff:
7761 phba->cfg_link_speed =
7762 LPFC_USER_LINK_SPEED_AUTO;
7763 break;
7764 default:
7765 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7766 "0047 Unrecognized link "
7767 "speed : %d\n",
7768 forced_link_speed);
7769 phba->cfg_link_speed =
7770 LPFC_USER_LINK_SPEED_AUTO;
7771 }
7772 }
7773 }
7774
James Smartda0436e2009-05-22 14:51:39 -04007775 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -04007776 length = phba->sli4_hba.max_cfg_param.max_xri -
7777 lpfc_sli4_get_els_iocb_cnt(phba);
7778 if (phba->cfg_hba_queue_depth > length) {
7779 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7780 "3361 HBA queue depth changed from %d to %d\n",
7781 phba->cfg_hba_queue_depth, length);
7782 phba->cfg_hba_queue_depth = length;
7783 }
James Smart912e3ac2011-05-24 11:42:11 -04007784
7785 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
7786 LPFC_SLI_INTF_IF_TYPE_2)
7787 goto read_cfg_out;
7788
7789 /* get the pf# and vf# for SLI4 if_type 2 port */
7790 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
7791 sizeof(struct lpfc_sli4_cfg_mhdr));
7792 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
7793 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
7794 length, LPFC_SLI4_MBX_EMBED);
7795
James Smart8aa134a2012-08-14 14:25:29 -04007796 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04007797 shdr = (union lpfc_sli4_cfg_shdr *)
7798 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
7799 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7800 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04007801 if (rc2 || shdr_status || shdr_add_status) {
James Smart912e3ac2011-05-24 11:42:11 -04007802 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7803 "3026 Mailbox failed , mbxCmd x%x "
7804 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
7805 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7806 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04007807 goto read_cfg_out;
7808 }
7809
7810 /* search for fc_fcoe resrouce descriptor */
7811 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
James Smart912e3ac2011-05-24 11:42:11 -04007812
James Smart8aa134a2012-08-14 14:25:29 -04007813 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
7814 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
7815 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
7816 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
7817 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
7818 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
7819 goto read_cfg_out;
7820
James Smart912e3ac2011-05-24 11:42:11 -04007821 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04007822 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04007823 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04007824 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04007825 phba->sli4_hba.iov.pf_number =
7826 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
7827 phba->sli4_hba.iov.vf_number =
7828 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
7829 break;
7830 }
7831 }
7832
7833 if (i < LPFC_RSRC_DESC_MAX_NUM)
7834 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7835 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
7836 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
7837 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04007838 else
James Smart912e3ac2011-05-24 11:42:11 -04007839 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7840 "3028 GET_FUNCTION_CONFIG: failed to find "
7841 "Resrouce Descriptor:x%x\n",
7842 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04007843
7844read_cfg_out:
7845 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04007846 return rc;
7847}
7848
7849/**
James Smart2fcee4b2010-12-15 17:57:46 -05007850 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04007851 * @phba: pointer to lpfc hba data structure.
7852 *
James Smart2fcee4b2010-12-15 17:57:46 -05007853 * This routine is invoked to setup the port-side endian order when
7854 * the port if_type is 0. This routine has no function for other
7855 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04007856 *
7857 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007858 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007859 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007860 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007861 **/
7862static int
7863lpfc_setup_endian_order(struct lpfc_hba *phba)
7864{
7865 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05007866 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04007867 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
7868 HOST_ENDIAN_HIGH_WORD1};
7869
James Smart2fcee4b2010-12-15 17:57:46 -05007870 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7871 switch (if_type) {
7872 case LPFC_SLI_INTF_IF_TYPE_0:
7873 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7874 GFP_KERNEL);
7875 if (!mboxq) {
7876 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7877 "0492 Unable to allocate memory for "
7878 "issuing SLI_CONFIG_SPECIAL mailbox "
7879 "command\n");
7880 return -ENOMEM;
7881 }
James Smartda0436e2009-05-22 14:51:39 -04007882
James Smart2fcee4b2010-12-15 17:57:46 -05007883 /*
7884 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
7885 * two words to contain special data values and no other data.
7886 */
7887 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
7888 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
7889 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7890 if (rc != MBX_SUCCESS) {
7891 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7892 "0493 SLI_CONFIG_SPECIAL mailbox "
7893 "failed with status x%x\n",
7894 rc);
7895 rc = -EIO;
7896 }
7897 mempool_free(mboxq, phba->mbox_mem_pool);
7898 break;
7899 case LPFC_SLI_INTF_IF_TYPE_2:
7900 case LPFC_SLI_INTF_IF_TYPE_1:
7901 default:
7902 break;
James Smartda0436e2009-05-22 14:51:39 -04007903 }
James Smartda0436e2009-05-22 14:51:39 -04007904 return rc;
7905}
7906
7907/**
James Smart895427b2017-02-12 13:52:30 -08007908 * lpfc_sli4_queue_verify - Verify and update EQ counts
James Smartda0436e2009-05-22 14:51:39 -04007909 * @phba: pointer to lpfc hba data structure.
7910 *
James Smart895427b2017-02-12 13:52:30 -08007911 * This routine is invoked to check the user settable queue counts for EQs.
7912 * After this routine is called the counts will be set to valid values that
James Smart5350d872011-10-10 21:33:49 -04007913 * adhere to the constraints of the system's interrupt vectors and the port's
7914 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04007915 *
7916 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007917 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007918 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007919 **/
7920static int
James Smart5350d872011-10-10 21:33:49 -04007921lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04007922{
James Smart895427b2017-02-12 13:52:30 -08007923 int io_channel;
James Smart1ba981f2014-02-20 09:56:45 -05007924 int fof_vectors = phba->cfg_fof ? 1 : 0;
James Smartda0436e2009-05-22 14:51:39 -04007925
7926 /*
James Smart67d12732012-08-03 12:36:13 -04007927 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04007928 * device parameters
7929 */
7930
James Smart67d12732012-08-03 12:36:13 -04007931 /* Sanity check on HBA EQ parameters */
James Smart895427b2017-02-12 13:52:30 -08007932 io_channel = phba->io_channel_irqs;
James Smartda0436e2009-05-22 14:51:39 -04007933
James Smart895427b2017-02-12 13:52:30 -08007934 if (phba->sli4_hba.num_online_cpu < io_channel) {
James Smart82c3e9b2012-09-29 11:29:50 -04007935 lpfc_printf_log(phba,
7936 KERN_ERR, LOG_INIT,
James Smart90695ee2012-08-14 14:25:36 -04007937 "3188 Reducing IO channels to match number of "
James Smart7bb03bb2013-04-17 20:19:16 -04007938 "online CPUs: from %d to %d\n",
James Smart895427b2017-02-12 13:52:30 -08007939 io_channel, phba->sli4_hba.num_online_cpu);
7940 io_channel = phba->sli4_hba.num_online_cpu;
James Smart90695ee2012-08-14 14:25:36 -04007941 }
7942
James Smart895427b2017-02-12 13:52:30 -08007943 if (io_channel + fof_vectors > phba->sli4_hba.max_cfg_param.max_eq) {
James Smart82c3e9b2012-09-29 11:29:50 -04007944 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7945 "2575 Reducing IO channels to match number of "
7946 "available EQs: from %d to %d\n",
James Smart895427b2017-02-12 13:52:30 -08007947 io_channel,
James Smart82c3e9b2012-09-29 11:29:50 -04007948 phba->sli4_hba.max_cfg_param.max_eq);
James Smart895427b2017-02-12 13:52:30 -08007949 io_channel = phba->sli4_hba.max_cfg_param.max_eq - fof_vectors;
James Smartda0436e2009-05-22 14:51:39 -04007950 }
James Smart67d12732012-08-03 12:36:13 -04007951
James Smart895427b2017-02-12 13:52:30 -08007952 /* The actual number of FCP / NVME event queues adopted */
7953 if (io_channel != phba->io_channel_irqs)
7954 phba->io_channel_irqs = io_channel;
7955 if (phba->cfg_fcp_io_channel > io_channel)
7956 phba->cfg_fcp_io_channel = io_channel;
7957 if (phba->cfg_nvme_io_channel > io_channel)
7958 phba->cfg_nvme_io_channel = io_channel;
James Smartbcb24f62017-11-20 16:00:36 -08007959 if (phba->nvmet_support) {
7960 if (phba->cfg_nvme_io_channel < phba->cfg_nvmet_mrq)
7961 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
7962 }
7963 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
7964 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
James Smart895427b2017-02-12 13:52:30 -08007965
7966 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2d7dbc42017-02-12 13:52:35 -08007967 "2574 IO channels: irqs %d fcp %d nvme %d MRQ: %d\n",
James Smart895427b2017-02-12 13:52:30 -08007968 phba->io_channel_irqs, phba->cfg_fcp_io_channel,
James Smart2d7dbc42017-02-12 13:52:35 -08007969 phba->cfg_nvme_io_channel, phba->cfg_nvmet_mrq);
James Smartda0436e2009-05-22 14:51:39 -04007970
James Smartda0436e2009-05-22 14:51:39 -04007971 /* Get EQ depth from module parameter, fake the default for now */
7972 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
7973 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
7974
James Smart5350d872011-10-10 21:33:49 -04007975 /* Get CQ depth from module parameter, fake the default for now */
7976 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
7977 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart5350d872011-10-10 21:33:49 -04007978 return 0;
James Smart895427b2017-02-12 13:52:30 -08007979}
7980
7981static int
7982lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx)
7983{
7984 struct lpfc_queue *qdesc;
James Smart895427b2017-02-12 13:52:30 -08007985
James Smarta51e41b2017-12-08 17:18:06 -08007986 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
James Smart81b96ed2017-11-20 16:00:29 -08007987 phba->sli4_hba.cq_esize,
James Smarta51e41b2017-12-08 17:18:06 -08007988 LPFC_CQE_EXP_COUNT);
James Smart895427b2017-02-12 13:52:30 -08007989 if (!qdesc) {
7990 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7991 "0508 Failed allocate fast-path NVME CQ (%d)\n",
7992 wqidx);
7993 return 1;
7994 }
7995 phba->sli4_hba.nvme_cq[wqidx] = qdesc;
7996
James Smarta51e41b2017-12-08 17:18:06 -08007997 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
7998 LPFC_WQE128_SIZE, LPFC_WQE_EXP_COUNT);
James Smart895427b2017-02-12 13:52:30 -08007999 if (!qdesc) {
8000 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8001 "0509 Failed allocate fast-path NVME WQ (%d)\n",
8002 wqidx);
8003 return 1;
8004 }
8005 phba->sli4_hba.nvme_wq[wqidx] = qdesc;
8006 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8007 return 0;
8008}
8009
8010static int
8011lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx)
8012{
8013 struct lpfc_queue *qdesc;
James Smart895427b2017-02-12 13:52:30 -08008014
8015 /* Create Fast Path FCP CQs */
James Smarta51e41b2017-12-08 17:18:06 -08008016 if (phba->fcp_embed_io)
8017 /* Increase the CQ size when WQEs contain an embedded cdb */
8018 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8019 phba->sli4_hba.cq_esize,
8020 LPFC_CQE_EXP_COUNT);
8021
8022 else
8023 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8024 phba->sli4_hba.cq_esize,
8025 phba->sli4_hba.cq_ecount);
James Smart895427b2017-02-12 13:52:30 -08008026 if (!qdesc) {
8027 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8028 "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx);
8029 return 1;
8030 }
8031 phba->sli4_hba.fcp_cq[wqidx] = qdesc;
8032
8033 /* Create Fast Path FCP WQs */
James Smarta51e41b2017-12-08 17:18:06 -08008034 if (phba->fcp_embed_io)
8035 /* Increase the WQ size when WQEs contain an embedded cdb */
8036 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8037 LPFC_WQE128_SIZE,
8038 LPFC_WQE_EXP_COUNT);
8039 else
8040 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8041 phba->sli4_hba.wq_esize,
8042 phba->sli4_hba.wq_ecount);
James Smart895427b2017-02-12 13:52:30 -08008043 if (!qdesc) {
8044 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8045 "0503 Failed allocate fast-path FCP WQ (%d)\n",
8046 wqidx);
8047 return 1;
8048 }
8049 phba->sli4_hba.fcp_wq[wqidx] = qdesc;
8050 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8051 return 0;
James Smart5350d872011-10-10 21:33:49 -04008052}
8053
8054/**
8055 * lpfc_sli4_queue_create - Create all the SLI4 queues
8056 * @phba: pointer to lpfc hba data structure.
8057 *
8058 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
8059 * operation. For each SLI4 queue type, the parameters such as queue entry
8060 * count (queue depth) shall be taken from the module parameter. For now,
8061 * we just use some constant number as place holder.
8062 *
8063 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07008064 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04008065 * -ENOMEM - No availble memory
8066 * -EIO - The mailbox failed to complete successfully.
8067 **/
8068int
8069lpfc_sli4_queue_create(struct lpfc_hba *phba)
8070{
8071 struct lpfc_queue *qdesc;
James Smartd1f525a2017-04-21 16:04:55 -07008072 int idx, io_channel;
James Smart5350d872011-10-10 21:33:49 -04008073
8074 /*
James Smart67d12732012-08-03 12:36:13 -04008075 * Create HBA Record arrays.
James Smart895427b2017-02-12 13:52:30 -08008076 * Both NVME and FCP will share that same vectors / EQs
James Smart5350d872011-10-10 21:33:49 -04008077 */
James Smart895427b2017-02-12 13:52:30 -08008078 io_channel = phba->io_channel_irqs;
8079 if (!io_channel)
James Smart67d12732012-08-03 12:36:13 -04008080 return -ERANGE;
James Smart5350d872011-10-10 21:33:49 -04008081
James Smart67d12732012-08-03 12:36:13 -04008082 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
8083 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
8084 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
8085 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
8086 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
8087 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
James Smart895427b2017-02-12 13:52:30 -08008088 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8089 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8090 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8091 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart67d12732012-08-03 12:36:13 -04008092
James Smart895427b2017-02-12 13:52:30 -08008093 phba->sli4_hba.hba_eq = kcalloc(io_channel,
8094 sizeof(struct lpfc_queue *),
8095 GFP_KERNEL);
James Smart67d12732012-08-03 12:36:13 -04008096 if (!phba->sli4_hba.hba_eq) {
James Smartda0436e2009-05-22 14:51:39 -04008097 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04008098 "2576 Failed allocate memory for "
8099 "fast-path EQ record array\n");
James Smartda0436e2009-05-22 14:51:39 -04008100 goto out_error;
8101 }
James Smart67d12732012-08-03 12:36:13 -04008102
James Smart895427b2017-02-12 13:52:30 -08008103 if (phba->cfg_fcp_io_channel) {
8104 phba->sli4_hba.fcp_cq = kcalloc(phba->cfg_fcp_io_channel,
8105 sizeof(struct lpfc_queue *),
8106 GFP_KERNEL);
8107 if (!phba->sli4_hba.fcp_cq) {
8108 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8109 "2577 Failed allocate memory for "
8110 "fast-path CQ record array\n");
8111 goto out_error;
8112 }
8113 phba->sli4_hba.fcp_wq = kcalloc(phba->cfg_fcp_io_channel,
8114 sizeof(struct lpfc_queue *),
8115 GFP_KERNEL);
8116 if (!phba->sli4_hba.fcp_wq) {
8117 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8118 "2578 Failed allocate memory for "
8119 "fast-path FCP WQ record array\n");
8120 goto out_error;
8121 }
8122 /*
8123 * Since the first EQ can have multiple CQs associated with it,
8124 * this array is used to quickly see if we have a FCP fast-path
8125 * CQ match.
8126 */
8127 phba->sli4_hba.fcp_cq_map = kcalloc(phba->cfg_fcp_io_channel,
8128 sizeof(uint16_t),
8129 GFP_KERNEL);
8130 if (!phba->sli4_hba.fcp_cq_map) {
8131 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8132 "2545 Failed allocate memory for "
8133 "fast-path CQ map\n");
8134 goto out_error;
8135 }
James Smart67d12732012-08-03 12:36:13 -04008136 }
8137
James Smart895427b2017-02-12 13:52:30 -08008138 if (phba->cfg_nvme_io_channel) {
8139 phba->sli4_hba.nvme_cq = kcalloc(phba->cfg_nvme_io_channel,
8140 sizeof(struct lpfc_queue *),
8141 GFP_KERNEL);
8142 if (!phba->sli4_hba.nvme_cq) {
8143 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8144 "6077 Failed allocate memory for "
8145 "fast-path CQ record array\n");
8146 goto out_error;
8147 }
8148
James Smart895427b2017-02-12 13:52:30 -08008149 phba->sli4_hba.nvme_wq = kcalloc(phba->cfg_nvme_io_channel,
8150 sizeof(struct lpfc_queue *),
8151 GFP_KERNEL);
8152 if (!phba->sli4_hba.nvme_wq) {
8153 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8154 "2581 Failed allocate memory for "
8155 "fast-path NVME WQ record array\n");
8156 goto out_error;
8157 }
8158
8159 /*
8160 * Since the first EQ can have multiple CQs associated with it,
8161 * this array is used to quickly see if we have a NVME fast-path
8162 * CQ match.
8163 */
8164 phba->sli4_hba.nvme_cq_map = kcalloc(phba->cfg_nvme_io_channel,
8165 sizeof(uint16_t),
8166 GFP_KERNEL);
8167 if (!phba->sli4_hba.nvme_cq_map) {
8168 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8169 "6078 Failed allocate memory for "
8170 "fast-path CQ map\n");
8171 goto out_error;
8172 }
James Smart2d7dbc42017-02-12 13:52:35 -08008173
8174 if (phba->nvmet_support) {
8175 phba->sli4_hba.nvmet_cqset = kcalloc(
8176 phba->cfg_nvmet_mrq,
8177 sizeof(struct lpfc_queue *),
8178 GFP_KERNEL);
8179 if (!phba->sli4_hba.nvmet_cqset) {
8180 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8181 "3121 Fail allocate memory for "
8182 "fast-path CQ set array\n");
8183 goto out_error;
8184 }
8185 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
8186 phba->cfg_nvmet_mrq,
8187 sizeof(struct lpfc_queue *),
8188 GFP_KERNEL);
8189 if (!phba->sli4_hba.nvmet_mrq_hdr) {
8190 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8191 "3122 Fail allocate memory for "
8192 "fast-path RQ set hdr array\n");
8193 goto out_error;
8194 }
8195 phba->sli4_hba.nvmet_mrq_data = kcalloc(
8196 phba->cfg_nvmet_mrq,
8197 sizeof(struct lpfc_queue *),
8198 GFP_KERNEL);
8199 if (!phba->sli4_hba.nvmet_mrq_data) {
8200 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8201 "3124 Fail allocate memory for "
8202 "fast-path RQ set data array\n");
8203 goto out_error;
8204 }
8205 }
James Smart67d12732012-08-03 12:36:13 -04008206 }
James Smartda0436e2009-05-22 14:51:39 -04008207
James Smart895427b2017-02-12 13:52:30 -08008208 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
James Smart67d12732012-08-03 12:36:13 -04008209
James Smart895427b2017-02-12 13:52:30 -08008210 /* Create HBA Event Queues (EQs) */
8211 for (idx = 0; idx < io_channel; idx++) {
James Smart67d12732012-08-03 12:36:13 -04008212 /* Create EQs */
James Smart81b96ed2017-11-20 16:00:29 -08008213 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8214 phba->sli4_hba.eq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008215 phba->sli4_hba.eq_ecount);
8216 if (!qdesc) {
8217 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04008218 "0497 Failed allocate EQ (%d)\n", idx);
8219 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008220 }
James Smart67d12732012-08-03 12:36:13 -04008221 phba->sli4_hba.hba_eq[idx] = qdesc;
James Smartda0436e2009-05-22 14:51:39 -04008222 }
8223
James Smart895427b2017-02-12 13:52:30 -08008224 /* FCP and NVME io channels are not required to be balanced */
8225
8226 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
8227 if (lpfc_alloc_fcp_wq_cq(phba, idx))
8228 goto out_error;
8229
8230 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
8231 if (lpfc_alloc_nvme_wq_cq(phba, idx))
8232 goto out_error;
James Smart67d12732012-08-03 12:36:13 -04008233
James Smart2d7dbc42017-02-12 13:52:35 -08008234 if (phba->nvmet_support) {
8235 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8236 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08008237 LPFC_DEFAULT_PAGE_SIZE,
8238 phba->sli4_hba.cq_esize,
8239 phba->sli4_hba.cq_ecount);
James Smart2d7dbc42017-02-12 13:52:35 -08008240 if (!qdesc) {
8241 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8242 "3142 Failed allocate NVME "
8243 "CQ Set (%d)\n", idx);
8244 goto out_error;
8245 }
8246 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
8247 }
8248 }
8249
James Smartda0436e2009-05-22 14:51:39 -04008250 /*
James Smart67d12732012-08-03 12:36:13 -04008251 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04008252 */
8253
James Smartda0436e2009-05-22 14:51:39 -04008254 /* Create slow-path Mailbox Command Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008255 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8256 phba->sli4_hba.cq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008257 phba->sli4_hba.cq_ecount);
8258 if (!qdesc) {
8259 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8260 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04008261 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008262 }
8263 phba->sli4_hba.mbx_cq = qdesc;
8264
8265 /* Create slow-path ELS Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008266 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8267 phba->sli4_hba.cq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008268 phba->sli4_hba.cq_ecount);
8269 if (!qdesc) {
8270 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8271 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -04008272 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008273 }
8274 phba->sli4_hba.els_cq = qdesc;
8275
James Smartda0436e2009-05-22 14:51:39 -04008276
James Smart5350d872011-10-10 21:33:49 -04008277 /*
James Smart67d12732012-08-03 12:36:13 -04008278 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04008279 */
James Smartda0436e2009-05-22 14:51:39 -04008280
8281 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04008282
James Smart81b96ed2017-11-20 16:00:29 -08008283 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8284 phba->sli4_hba.mq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008285 phba->sli4_hba.mq_ecount);
8286 if (!qdesc) {
8287 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8288 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04008289 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008290 }
8291 phba->sli4_hba.mbx_wq = qdesc;
8292
8293 /*
James Smart67d12732012-08-03 12:36:13 -04008294 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04008295 */
James Smartda0436e2009-05-22 14:51:39 -04008296
8297 /* Create slow-path ELS Work Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008298 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8299 phba->sli4_hba.wq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008300 phba->sli4_hba.wq_ecount);
8301 if (!qdesc) {
8302 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8303 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04008304 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008305 }
8306 phba->sli4_hba.els_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08008307 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8308
8309 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8310 /* Create NVME LS Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008311 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8312 phba->sli4_hba.cq_esize,
James Smart895427b2017-02-12 13:52:30 -08008313 phba->sli4_hba.cq_ecount);
8314 if (!qdesc) {
8315 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8316 "6079 Failed allocate NVME LS CQ\n");
8317 goto out_error;
8318 }
8319 phba->sli4_hba.nvmels_cq = qdesc;
8320
8321 /* Create NVME LS Work Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008322 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8323 phba->sli4_hba.wq_esize,
James Smart895427b2017-02-12 13:52:30 -08008324 phba->sli4_hba.wq_ecount);
8325 if (!qdesc) {
8326 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8327 "6080 Failed allocate NVME LS WQ\n");
8328 goto out_error;
8329 }
8330 phba->sli4_hba.nvmels_wq = qdesc;
8331 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8332 }
James Smartda0436e2009-05-22 14:51:39 -04008333
James Smartda0436e2009-05-22 14:51:39 -04008334 /*
8335 * Create Receive Queue (RQ)
8336 */
James Smartda0436e2009-05-22 14:51:39 -04008337
8338 /* Create Receive Queue for header */
James Smart81b96ed2017-11-20 16:00:29 -08008339 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8340 phba->sli4_hba.rq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008341 phba->sli4_hba.rq_ecount);
8342 if (!qdesc) {
8343 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8344 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04008345 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008346 }
8347 phba->sli4_hba.hdr_rq = qdesc;
8348
8349 /* Create Receive Queue for data */
James Smart81b96ed2017-11-20 16:00:29 -08008350 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8351 phba->sli4_hba.rq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008352 phba->sli4_hba.rq_ecount);
8353 if (!qdesc) {
8354 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8355 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04008356 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008357 }
8358 phba->sli4_hba.dat_rq = qdesc;
8359
James Smart2d7dbc42017-02-12 13:52:35 -08008360 if (phba->nvmet_support) {
8361 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8362 /* Create NVMET Receive Queue for header */
8363 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08008364 LPFC_DEFAULT_PAGE_SIZE,
James Smart2d7dbc42017-02-12 13:52:35 -08008365 phba->sli4_hba.rq_esize,
James Smart61f3d4b2017-05-15 15:20:41 -07008366 LPFC_NVMET_RQE_DEF_COUNT);
James Smart2d7dbc42017-02-12 13:52:35 -08008367 if (!qdesc) {
8368 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8369 "3146 Failed allocate "
8370 "receive HRQ\n");
8371 goto out_error;
8372 }
8373 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
8374
8375 /* Only needed for header of RQ pair */
8376 qdesc->rqbp = kzalloc(sizeof(struct lpfc_rqb),
8377 GFP_KERNEL);
8378 if (qdesc->rqbp == NULL) {
8379 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8380 "6131 Failed allocate "
8381 "Header RQBP\n");
8382 goto out_error;
8383 }
8384
Dick Kennedy4b40d022017-08-23 16:55:38 -07008385 /* Put list in known state in case driver load fails. */
8386 INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list);
8387
James Smart2d7dbc42017-02-12 13:52:35 -08008388 /* Create NVMET Receive Queue for data */
8389 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08008390 LPFC_DEFAULT_PAGE_SIZE,
James Smart2d7dbc42017-02-12 13:52:35 -08008391 phba->sli4_hba.rq_esize,
James Smart61f3d4b2017-05-15 15:20:41 -07008392 LPFC_NVMET_RQE_DEF_COUNT);
James Smart2d7dbc42017-02-12 13:52:35 -08008393 if (!qdesc) {
8394 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8395 "3156 Failed allocate "
8396 "receive DRQ\n");
8397 goto out_error;
8398 }
8399 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
8400 }
8401 }
8402
James Smart1ba981f2014-02-20 09:56:45 -05008403 /* Create the Queues needed for Flash Optimized Fabric operations */
8404 if (phba->cfg_fof)
8405 lpfc_fof_queue_create(phba);
James Smartda0436e2009-05-22 14:51:39 -04008406 return 0;
8407
James Smartda0436e2009-05-22 14:51:39 -04008408out_error:
James Smart67d12732012-08-03 12:36:13 -04008409 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04008410 return -ENOMEM;
8411}
8412
James Smart895427b2017-02-12 13:52:30 -08008413static inline void
8414__lpfc_sli4_release_queue(struct lpfc_queue **qp)
8415{
8416 if (*qp != NULL) {
8417 lpfc_sli4_queue_free(*qp);
8418 *qp = NULL;
8419 }
8420}
8421
8422static inline void
8423lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
8424{
8425 int idx;
8426
8427 if (*qs == NULL)
8428 return;
8429
8430 for (idx = 0; idx < max; idx++)
8431 __lpfc_sli4_release_queue(&(*qs)[idx]);
8432
8433 kfree(*qs);
8434 *qs = NULL;
8435}
8436
8437static inline void
8438lpfc_sli4_release_queue_map(uint16_t **qmap)
8439{
8440 if (*qmap != NULL) {
8441 kfree(*qmap);
8442 *qmap = NULL;
8443 }
8444}
8445
James Smartda0436e2009-05-22 14:51:39 -04008446/**
8447 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
8448 * @phba: pointer to lpfc hba data structure.
8449 *
8450 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
8451 * operation.
8452 *
8453 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008454 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008455 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008456 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008457 **/
James Smart5350d872011-10-10 21:33:49 -04008458void
James Smartda0436e2009-05-22 14:51:39 -04008459lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
8460{
James Smart1ba981f2014-02-20 09:56:45 -05008461 if (phba->cfg_fof)
8462 lpfc_fof_queue_destroy(phba);
8463
James Smart895427b2017-02-12 13:52:30 -08008464 /* Release HBA eqs */
8465 lpfc_sli4_release_queues(&phba->sli4_hba.hba_eq, phba->io_channel_irqs);
James Smart67d12732012-08-03 12:36:13 -04008466
James Smart895427b2017-02-12 13:52:30 -08008467 /* Release FCP cqs */
8468 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_cq,
James Smartd1f525a2017-04-21 16:04:55 -07008469 phba->cfg_fcp_io_channel);
James Smart67d12732012-08-03 12:36:13 -04008470
James Smart895427b2017-02-12 13:52:30 -08008471 /* Release FCP wqs */
8472 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_wq,
James Smartd1f525a2017-04-21 16:04:55 -07008473 phba->cfg_fcp_io_channel);
James Smart67d12732012-08-03 12:36:13 -04008474
8475 /* Release FCP CQ mapping array */
James Smart895427b2017-02-12 13:52:30 -08008476 lpfc_sli4_release_queue_map(&phba->sli4_hba.fcp_cq_map);
8477
8478 /* Release NVME cqs */
8479 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_cq,
8480 phba->cfg_nvme_io_channel);
8481
8482 /* Release NVME wqs */
8483 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_wq,
8484 phba->cfg_nvme_io_channel);
8485
8486 /* Release NVME CQ mapping array */
8487 lpfc_sli4_release_queue_map(&phba->sli4_hba.nvme_cq_map);
James Smartda0436e2009-05-22 14:51:39 -04008488
James Smartbcb24f62017-11-20 16:00:36 -08008489 if (phba->nvmet_support) {
8490 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
8491 phba->cfg_nvmet_mrq);
James Smart2d7dbc42017-02-12 13:52:35 -08008492
James Smartbcb24f62017-11-20 16:00:36 -08008493 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
8494 phba->cfg_nvmet_mrq);
8495 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
8496 phba->cfg_nvmet_mrq);
8497 }
James Smart2d7dbc42017-02-12 13:52:35 -08008498
James Smartda0436e2009-05-22 14:51:39 -04008499 /* Release mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08008500 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
James Smartda0436e2009-05-22 14:51:39 -04008501
8502 /* Release ELS work queue */
James Smart895427b2017-02-12 13:52:30 -08008503 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
8504
8505 /* Release ELS work queue */
8506 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
James Smartda0436e2009-05-22 14:51:39 -04008507
8508 /* Release unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08008509 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
8510 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
James Smartda0436e2009-05-22 14:51:39 -04008511
James Smartda0436e2009-05-22 14:51:39 -04008512 /* Release ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08008513 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
8514
8515 /* Release NVME LS complete queue */
8516 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
James Smartda0436e2009-05-22 14:51:39 -04008517
8518 /* Release mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08008519 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
8520
8521 /* Everything on this list has been freed */
8522 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
8523}
8524
8525int
James Smart895427b2017-02-12 13:52:30 -08008526lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
8527{
8528 struct lpfc_rqb *rqbp;
8529 struct lpfc_dmabuf *h_buf;
8530 struct rqb_dmabuf *rqb_buffer;
8531
8532 rqbp = rq->rqbp;
8533 while (!list_empty(&rqbp->rqb_buffer_list)) {
8534 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
8535 struct lpfc_dmabuf, list);
8536
8537 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
8538 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
8539 rqbp->buffer_count--;
8540 }
8541 return 1;
8542}
8543
8544static int
8545lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
8546 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
8547 int qidx, uint32_t qtype)
8548{
8549 struct lpfc_sli_ring *pring;
8550 int rc;
8551
8552 if (!eq || !cq || !wq) {
8553 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8554 "6085 Fast-path %s (%d) not allocated\n",
8555 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
8556 return -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04008557 }
James Smartda0436e2009-05-22 14:51:39 -04008558
James Smart895427b2017-02-12 13:52:30 -08008559 /* create the Cq first */
8560 rc = lpfc_cq_create(phba, cq, eq,
8561 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
8562 if (rc) {
8563 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8564 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
8565 qidx, (uint32_t)rc);
8566 return rc;
8567 }
James Smart81b96ed2017-11-20 16:00:29 -08008568 cq->chann = qidx;
James Smart895427b2017-02-12 13:52:30 -08008569
8570 if (qtype != LPFC_MBOX) {
8571 /* Setup nvme_cq_map for fast lookup */
8572 if (cq_map)
8573 *cq_map = cq->queue_id;
8574
8575 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8576 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
8577 qidx, cq->queue_id, qidx, eq->queue_id);
8578
8579 /* create the wq */
8580 rc = lpfc_wq_create(phba, wq, cq, qtype);
8581 if (rc) {
8582 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8583 "6123 Fail setup fastpath WQ (%d), rc = 0x%x\n",
8584 qidx, (uint32_t)rc);
8585 /* no need to tear down cq - caller will do so */
8586 return rc;
8587 }
James Smart81b96ed2017-11-20 16:00:29 -08008588 wq->chann = qidx;
James Smart895427b2017-02-12 13:52:30 -08008589
8590 /* Bind this CQ/WQ to the NVME ring */
8591 pring = wq->pring;
8592 pring->sli.sli4.wqp = (void *)wq;
8593 cq->pring = pring;
8594
8595 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8596 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
8597 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
8598 } else {
8599 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
8600 if (rc) {
8601 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8602 "0539 Failed setup of slow-path MQ: "
8603 "rc = 0x%x\n", rc);
8604 /* no need to tear down cq - caller will do so */
8605 return rc;
8606 }
8607
8608 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8609 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
8610 phba->sli4_hba.mbx_wq->queue_id,
8611 phba->sli4_hba.mbx_cq->queue_id);
8612 }
8613
8614 return 0;
James Smartda0436e2009-05-22 14:51:39 -04008615}
8616
8617/**
8618 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
8619 * @phba: pointer to lpfc hba data structure.
8620 *
8621 * This routine is invoked to set up all the SLI4 queues for 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 **/
8629int
8630lpfc_sli4_queue_setup(struct lpfc_hba *phba)
8631{
James Smart962bc512013-01-03 15:44:00 -05008632 uint32_t shdr_status, shdr_add_status;
8633 union lpfc_sli4_cfg_shdr *shdr;
8634 LPFC_MBOXQ_t *mboxq;
James Smart895427b2017-02-12 13:52:30 -08008635 int qidx;
8636 uint32_t length, io_channel;
8637 int rc = -ENOMEM;
James Smart962bc512013-01-03 15:44:00 -05008638
8639 /* Check for dual-ULP support */
8640 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8641 if (!mboxq) {
8642 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8643 "3249 Unable to allocate memory for "
8644 "QUERY_FW_CFG mailbox command\n");
8645 return -ENOMEM;
8646 }
8647 length = (sizeof(struct lpfc_mbx_query_fw_config) -
8648 sizeof(struct lpfc_sli4_cfg_mhdr));
8649 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8650 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
8651 length, LPFC_SLI4_MBX_EMBED);
8652
8653 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8654
8655 shdr = (union lpfc_sli4_cfg_shdr *)
8656 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
8657 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8658 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
8659 if (shdr_status || shdr_add_status || rc) {
8660 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8661 "3250 QUERY_FW_CFG mailbox failed with status "
8662 "x%x add_status x%x, mbx status x%x\n",
8663 shdr_status, shdr_add_status, rc);
8664 if (rc != MBX_TIMEOUT)
8665 mempool_free(mboxq, phba->mbox_mem_pool);
8666 rc = -ENXIO;
8667 goto out_error;
8668 }
8669
8670 phba->sli4_hba.fw_func_mode =
8671 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
8672 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
8673 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
James Smart8b017a32015-05-21 13:55:18 -04008674 phba->sli4_hba.physical_port =
8675 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
James Smart962bc512013-01-03 15:44:00 -05008676 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8677 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
8678 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
8679 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
8680
8681 if (rc != MBX_TIMEOUT)
8682 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04008683
8684 /*
James Smart67d12732012-08-03 12:36:13 -04008685 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04008686 */
James Smart895427b2017-02-12 13:52:30 -08008687 io_channel = phba->io_channel_irqs;
James Smartda0436e2009-05-22 14:51:39 -04008688
James Smart67d12732012-08-03 12:36:13 -04008689 /* Set up HBA event queue */
James Smart895427b2017-02-12 13:52:30 -08008690 if (io_channel && !phba->sli4_hba.hba_eq) {
James Smart2e90f4b2011-12-13 13:22:37 -05008691 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8692 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05008693 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04008694 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05008695 }
James Smart895427b2017-02-12 13:52:30 -08008696 for (qidx = 0; qidx < io_channel; qidx++) {
8697 if (!phba->sli4_hba.hba_eq[qidx]) {
James Smartda0436e2009-05-22 14:51:39 -04008698 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8699 "0522 Fast-path EQ (%d) not "
James Smart895427b2017-02-12 13:52:30 -08008700 "allocated\n", qidx);
James Smart1b511972011-12-13 13:23:09 -05008701 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008702 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008703 }
James Smart895427b2017-02-12 13:52:30 -08008704 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[qidx],
8705 phba->cfg_fcp_imax);
James Smartda0436e2009-05-22 14:51:39 -04008706 if (rc) {
8707 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8708 "0523 Failed setup of fast-path EQ "
James Smart895427b2017-02-12 13:52:30 -08008709 "(%d), rc = 0x%x\n", qidx,
James Smarta2fc4aef2014-09-03 12:57:55 -04008710 (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08008711 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008712 }
8713 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008714 "2584 HBA EQ setup: queue[%d]-id=%d\n",
8715 qidx, phba->sli4_hba.hba_eq[qidx]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04008716 }
8717
James Smart895427b2017-02-12 13:52:30 -08008718 if (phba->cfg_nvme_io_channel) {
8719 if (!phba->sli4_hba.nvme_cq || !phba->sli4_hba.nvme_wq) {
James Smart67d12732012-08-03 12:36:13 -04008720 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008721 "6084 Fast-path NVME %s array not allocated\n",
8722 (phba->sli4_hba.nvme_cq) ? "CQ" : "WQ");
James Smart67d12732012-08-03 12:36:13 -04008723 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008724 goto out_destroy;
James Smart67d12732012-08-03 12:36:13 -04008725 }
8726
James Smart895427b2017-02-12 13:52:30 -08008727 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
8728 rc = lpfc_create_wq_cq(phba,
8729 phba->sli4_hba.hba_eq[
8730 qidx % io_channel],
8731 phba->sli4_hba.nvme_cq[qidx],
8732 phba->sli4_hba.nvme_wq[qidx],
8733 &phba->sli4_hba.nvme_cq_map[qidx],
8734 qidx, LPFC_NVME);
8735 if (rc) {
8736 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8737 "6123 Failed to setup fastpath "
8738 "NVME WQ/CQ (%d), rc = 0x%x\n",
8739 qidx, (uint32_t)rc);
8740 goto out_destroy;
8741 }
8742 }
James Smart67d12732012-08-03 12:36:13 -04008743 }
8744
James Smart895427b2017-02-12 13:52:30 -08008745 if (phba->cfg_fcp_io_channel) {
8746 /* Set up fast-path FCP Response Complete Queue */
8747 if (!phba->sli4_hba.fcp_cq || !phba->sli4_hba.fcp_wq) {
James Smart67d12732012-08-03 12:36:13 -04008748 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008749 "3148 Fast-path FCP %s array not allocated\n",
8750 phba->sli4_hba.fcp_cq ? "WQ" : "CQ");
James Smart67d12732012-08-03 12:36:13 -04008751 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008752 goto out_destroy;
James Smart67d12732012-08-03 12:36:13 -04008753 }
8754
James Smart895427b2017-02-12 13:52:30 -08008755 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
8756 rc = lpfc_create_wq_cq(phba,
8757 phba->sli4_hba.hba_eq[
8758 qidx % io_channel],
8759 phba->sli4_hba.fcp_cq[qidx],
8760 phba->sli4_hba.fcp_wq[qidx],
8761 &phba->sli4_hba.fcp_cq_map[qidx],
8762 qidx, LPFC_FCP);
8763 if (rc) {
8764 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8765 "0535 Failed to setup fastpath "
8766 "FCP WQ/CQ (%d), rc = 0x%x\n",
8767 qidx, (uint32_t)rc);
8768 goto out_destroy;
8769 }
8770 }
James Smart67d12732012-08-03 12:36:13 -04008771 }
James Smartda0436e2009-05-22 14:51:39 -04008772
8773 /*
James Smart895427b2017-02-12 13:52:30 -08008774 * Set up Slow Path Complete Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04008775 */
8776
James Smart895427b2017-02-12 13:52:30 -08008777 /* Set up slow-path MBOX CQ/MQ */
8778
8779 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
James Smartda0436e2009-05-22 14:51:39 -04008780 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008781 "0528 %s not allocated\n",
8782 phba->sli4_hba.mbx_cq ?
James Smartd1f525a2017-04-21 16:04:55 -07008783 "Mailbox WQ" : "Mailbox CQ");
James Smart1b511972011-12-13 13:23:09 -05008784 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008785 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008786 }
James Smart895427b2017-02-12 13:52:30 -08008787
8788 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
James Smartd1f525a2017-04-21 16:04:55 -07008789 phba->sli4_hba.mbx_cq,
8790 phba->sli4_hba.mbx_wq,
8791 NULL, 0, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04008792 if (rc) {
8793 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008794 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
8795 (uint32_t)rc);
8796 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008797 }
James Smart2d7dbc42017-02-12 13:52:35 -08008798 if (phba->nvmet_support) {
8799 if (!phba->sli4_hba.nvmet_cqset) {
8800 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8801 "3165 Fast-path NVME CQ Set "
8802 "array not allocated\n");
8803 rc = -ENOMEM;
8804 goto out_destroy;
8805 }
8806 if (phba->cfg_nvmet_mrq > 1) {
8807 rc = lpfc_cq_create_set(phba,
8808 phba->sli4_hba.nvmet_cqset,
8809 phba->sli4_hba.hba_eq,
8810 LPFC_WCQ, LPFC_NVMET);
8811 if (rc) {
8812 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8813 "3164 Failed setup of NVME CQ "
8814 "Set, rc = 0x%x\n",
8815 (uint32_t)rc);
8816 goto out_destroy;
8817 }
8818 } else {
8819 /* Set up NVMET Receive Complete Queue */
8820 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
8821 phba->sli4_hba.hba_eq[0],
8822 LPFC_WCQ, LPFC_NVMET);
8823 if (rc) {
8824 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8825 "6089 Failed setup NVMET CQ: "
8826 "rc = 0x%x\n", (uint32_t)rc);
8827 goto out_destroy;
8828 }
James Smart81b96ed2017-11-20 16:00:29 -08008829 phba->sli4_hba.nvmet_cqset[0]->chann = 0;
8830
James Smart2d7dbc42017-02-12 13:52:35 -08008831 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8832 "6090 NVMET CQ setup: cq-id=%d, "
8833 "parent eq-id=%d\n",
8834 phba->sli4_hba.nvmet_cqset[0]->queue_id,
8835 phba->sli4_hba.hba_eq[0]->queue_id);
8836 }
8837 }
James Smartda0436e2009-05-22 14:51:39 -04008838
James Smart895427b2017-02-12 13:52:30 -08008839 /* Set up slow-path ELS WQ/CQ */
8840 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
James Smartda0436e2009-05-22 14:51:39 -04008841 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008842 "0530 ELS %s not allocated\n",
8843 phba->sli4_hba.els_cq ? "WQ" : "CQ");
James Smart1b511972011-12-13 13:23:09 -05008844 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008845 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008846 }
James Smart895427b2017-02-12 13:52:30 -08008847 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8848 phba->sli4_hba.els_cq,
8849 phba->sli4_hba.els_wq,
8850 NULL, 0, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04008851 if (rc) {
8852 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008853 "0529 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
8854 (uint32_t)rc);
8855 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008856 }
8857 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8858 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
8859 phba->sli4_hba.els_wq->queue_id,
8860 phba->sli4_hba.els_cq->queue_id);
8861
James Smart895427b2017-02-12 13:52:30 -08008862 if (phba->cfg_nvme_io_channel) {
8863 /* Set up NVME LS Complete Queue */
8864 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
8865 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8866 "6091 LS %s not allocated\n",
8867 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
8868 rc = -ENOMEM;
8869 goto out_destroy;
8870 }
8871 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8872 phba->sli4_hba.nvmels_cq,
8873 phba->sli4_hba.nvmels_wq,
8874 NULL, 0, LPFC_NVME_LS);
8875 if (rc) {
8876 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8877 "0529 Failed setup of NVVME LS WQ/CQ: "
8878 "rc = 0x%x\n", (uint32_t)rc);
8879 goto out_destroy;
8880 }
8881
8882 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8883 "6096 ELS WQ setup: wq-id=%d, "
8884 "parent cq-id=%d\n",
8885 phba->sli4_hba.nvmels_wq->queue_id,
8886 phba->sli4_hba.nvmels_cq->queue_id);
8887 }
8888
James Smart2d7dbc42017-02-12 13:52:35 -08008889 /*
8890 * Create NVMET Receive Queue (RQ)
8891 */
8892 if (phba->nvmet_support) {
8893 if ((!phba->sli4_hba.nvmet_cqset) ||
8894 (!phba->sli4_hba.nvmet_mrq_hdr) ||
8895 (!phba->sli4_hba.nvmet_mrq_data)) {
8896 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8897 "6130 MRQ CQ Queues not "
8898 "allocated\n");
8899 rc = -ENOMEM;
8900 goto out_destroy;
8901 }
8902 if (phba->cfg_nvmet_mrq > 1) {
8903 rc = lpfc_mrq_create(phba,
8904 phba->sli4_hba.nvmet_mrq_hdr,
8905 phba->sli4_hba.nvmet_mrq_data,
8906 phba->sli4_hba.nvmet_cqset,
8907 LPFC_NVMET);
8908 if (rc) {
8909 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8910 "6098 Failed setup of NVMET "
8911 "MRQ: rc = 0x%x\n",
8912 (uint32_t)rc);
8913 goto out_destroy;
8914 }
8915
8916 } else {
8917 rc = lpfc_rq_create(phba,
8918 phba->sli4_hba.nvmet_mrq_hdr[0],
8919 phba->sli4_hba.nvmet_mrq_data[0],
8920 phba->sli4_hba.nvmet_cqset[0],
8921 LPFC_NVMET);
8922 if (rc) {
8923 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8924 "6057 Failed setup of NVMET "
8925 "Receive Queue: rc = 0x%x\n",
8926 (uint32_t)rc);
8927 goto out_destroy;
8928 }
8929
8930 lpfc_printf_log(
8931 phba, KERN_INFO, LOG_INIT,
8932 "6099 NVMET RQ setup: hdr-rq-id=%d, "
8933 "dat-rq-id=%d parent cq-id=%d\n",
8934 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
8935 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
8936 phba->sli4_hba.nvmet_cqset[0]->queue_id);
8937
8938 }
8939 }
8940
James Smartda0436e2009-05-22 14:51:39 -04008941 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
8942 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8943 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05008944 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008945 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008946 }
James Smart73d91e52011-10-10 21:32:10 -04008947
James Smartda0436e2009-05-22 14:51:39 -04008948 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04008949 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04008950 if (rc) {
8951 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8952 "0541 Failed setup of Receive Queue: "
James Smarta2fc4aef2014-09-03 12:57:55 -04008953 "rc = 0x%x\n", (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08008954 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008955 }
James Smart73d91e52011-10-10 21:32:10 -04008956
James Smartda0436e2009-05-22 14:51:39 -04008957 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8958 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
8959 "parent cq-id=%d\n",
8960 phba->sli4_hba.hdr_rq->queue_id,
8961 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04008962 phba->sli4_hba.els_cq->queue_id);
James Smart1ba981f2014-02-20 09:56:45 -05008963
8964 if (phba->cfg_fof) {
8965 rc = lpfc_fof_queue_setup(phba);
8966 if (rc) {
8967 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8968 "0549 Failed setup of FOF Queues: "
8969 "rc = 0x%x\n", rc);
James Smart895427b2017-02-12 13:52:30 -08008970 goto out_destroy;
James Smart1ba981f2014-02-20 09:56:45 -05008971 }
8972 }
James Smart2c9c5a02015-04-07 15:07:15 -04008973
James Smart43140ca2017-03-04 09:30:34 -08008974 for (qidx = 0; qidx < io_channel; qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
James Smart0cf07f842017-06-01 21:07:10 -07008975 lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT,
8976 phba->cfg_fcp_imax);
James Smart43140ca2017-03-04 09:30:34 -08008977
James Smartda0436e2009-05-22 14:51:39 -04008978 return 0;
8979
James Smart895427b2017-02-12 13:52:30 -08008980out_destroy:
8981 lpfc_sli4_queue_unset(phba);
James Smartda0436e2009-05-22 14:51:39 -04008982out_error:
8983 return rc;
8984}
8985
8986/**
8987 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
8988 * @phba: pointer to lpfc hba data structure.
8989 *
8990 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
8991 * operation.
8992 *
8993 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008994 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008995 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008996 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008997 **/
8998void
8999lpfc_sli4_queue_unset(struct lpfc_hba *phba)
9000{
James Smart895427b2017-02-12 13:52:30 -08009001 int qidx;
James Smartda0436e2009-05-22 14:51:39 -04009002
James Smart1ba981f2014-02-20 09:56:45 -05009003 /* Unset the queues created for Flash Optimized Fabric operations */
9004 if (phba->cfg_fof)
9005 lpfc_fof_queue_destroy(phba);
James Smart895427b2017-02-12 13:52:30 -08009006
James Smartda0436e2009-05-22 14:51:39 -04009007 /* Unset mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08009008 if (phba->sli4_hba.mbx_wq)
9009 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
9010
9011 /* Unset NVME LS work queue */
9012 if (phba->sli4_hba.nvmels_wq)
9013 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
9014
James Smartda0436e2009-05-22 14:51:39 -04009015 /* Unset ELS work queue */
Colin Ian King019c0d62017-05-06 23:13:55 +01009016 if (phba->sli4_hba.els_wq)
James Smart895427b2017-02-12 13:52:30 -08009017 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
9018
James Smartda0436e2009-05-22 14:51:39 -04009019 /* Unset unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08009020 if (phba->sli4_hba.hdr_rq)
9021 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
9022 phba->sli4_hba.dat_rq);
9023
James Smartda0436e2009-05-22 14:51:39 -04009024 /* Unset FCP work queue */
James Smart895427b2017-02-12 13:52:30 -08009025 if (phba->sli4_hba.fcp_wq)
9026 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
9027 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[qidx]);
9028
9029 /* Unset NVME work queue */
9030 if (phba->sli4_hba.nvme_wq) {
9031 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
9032 lpfc_wq_destroy(phba, phba->sli4_hba.nvme_wq[qidx]);
James Smart67d12732012-08-03 12:36:13 -04009033 }
James Smart895427b2017-02-12 13:52:30 -08009034
James Smartda0436e2009-05-22 14:51:39 -04009035 /* Unset mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08009036 if (phba->sli4_hba.mbx_cq)
9037 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
9038
James Smartda0436e2009-05-22 14:51:39 -04009039 /* Unset ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08009040 if (phba->sli4_hba.els_cq)
9041 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
9042
9043 /* Unset NVME LS complete queue */
9044 if (phba->sli4_hba.nvmels_cq)
9045 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
9046
9047 /* Unset NVME response complete queue */
9048 if (phba->sli4_hba.nvme_cq)
9049 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
9050 lpfc_cq_destroy(phba, phba->sli4_hba.nvme_cq[qidx]);
9051
James Smartbcb24f62017-11-20 16:00:36 -08009052 if (phba->nvmet_support) {
9053 /* Unset NVMET MRQ queue */
9054 if (phba->sli4_hba.nvmet_mrq_hdr) {
9055 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9056 lpfc_rq_destroy(
9057 phba,
James Smart2d7dbc42017-02-12 13:52:35 -08009058 phba->sli4_hba.nvmet_mrq_hdr[qidx],
9059 phba->sli4_hba.nvmet_mrq_data[qidx]);
James Smartbcb24f62017-11-20 16:00:36 -08009060 }
James Smart2d7dbc42017-02-12 13:52:35 -08009061
James Smartbcb24f62017-11-20 16:00:36 -08009062 /* Unset NVMET CQ Set complete queue */
9063 if (phba->sli4_hba.nvmet_cqset) {
9064 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9065 lpfc_cq_destroy(
9066 phba, phba->sli4_hba.nvmet_cqset[qidx]);
9067 }
James Smart2d7dbc42017-02-12 13:52:35 -08009068 }
9069
James Smartda0436e2009-05-22 14:51:39 -04009070 /* Unset FCP response complete queue */
James Smart895427b2017-02-12 13:52:30 -08009071 if (phba->sli4_hba.fcp_cq)
9072 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
9073 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[qidx]);
9074
James Smartda0436e2009-05-22 14:51:39 -04009075 /* Unset fast-path event queue */
James Smart895427b2017-02-12 13:52:30 -08009076 if (phba->sli4_hba.hba_eq)
9077 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++)
9078 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[qidx]);
James Smartda0436e2009-05-22 14:51:39 -04009079}
9080
9081/**
9082 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
9083 * @phba: pointer to lpfc hba data structure.
9084 *
9085 * This routine is invoked to allocate and set up a pool of completion queue
9086 * events. The body of the completion queue event is a completion queue entry
9087 * CQE. For now, this pool is used for the interrupt service routine to queue
9088 * the following HBA completion queue events for the worker thread to process:
9089 * - Mailbox asynchronous events
9090 * - Receive queue completion unsolicited events
9091 * Later, this can be used for all the slow-path events.
9092 *
9093 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009094 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009095 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04009096 **/
9097static int
9098lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
9099{
9100 struct lpfc_cq_event *cq_event;
9101 int i;
9102
9103 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
9104 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
9105 if (!cq_event)
9106 goto out_pool_create_fail;
9107 list_add_tail(&cq_event->list,
9108 &phba->sli4_hba.sp_cqe_event_pool);
9109 }
9110 return 0;
9111
9112out_pool_create_fail:
9113 lpfc_sli4_cq_event_pool_destroy(phba);
9114 return -ENOMEM;
9115}
9116
9117/**
9118 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
9119 * @phba: pointer to lpfc hba data structure.
9120 *
9121 * This routine is invoked to free the pool of completion queue events at
9122 * driver unload time. Note that, it is the responsibility of the driver
9123 * cleanup routine to free all the outstanding completion-queue events
9124 * allocated from this pool back into the pool before invoking this routine
9125 * to destroy the pool.
9126 **/
9127static void
9128lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
9129{
9130 struct lpfc_cq_event *cq_event, *next_cq_event;
9131
9132 list_for_each_entry_safe(cq_event, next_cq_event,
9133 &phba->sli4_hba.sp_cqe_event_pool, list) {
9134 list_del(&cq_event->list);
9135 kfree(cq_event);
9136 }
9137}
9138
9139/**
9140 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9141 * @phba: pointer to lpfc hba data structure.
9142 *
9143 * This routine is the lock free version of the API invoked to allocate a
9144 * completion-queue event from the free pool.
9145 *
9146 * Return: Pointer to the newly allocated completion-queue event if successful
9147 * NULL otherwise.
9148 **/
9149struct lpfc_cq_event *
9150__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9151{
9152 struct lpfc_cq_event *cq_event = NULL;
9153
9154 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
9155 struct lpfc_cq_event, list);
9156 return cq_event;
9157}
9158
9159/**
9160 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9161 * @phba: pointer to lpfc hba data structure.
9162 *
9163 * This routine is the lock version of the API invoked to allocate a
9164 * completion-queue event from the free pool.
9165 *
9166 * Return: Pointer to the newly allocated completion-queue event if successful
9167 * NULL otherwise.
9168 **/
9169struct lpfc_cq_event *
9170lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9171{
9172 struct lpfc_cq_event *cq_event;
9173 unsigned long iflags;
9174
9175 spin_lock_irqsave(&phba->hbalock, iflags);
9176 cq_event = __lpfc_sli4_cq_event_alloc(phba);
9177 spin_unlock_irqrestore(&phba->hbalock, iflags);
9178 return cq_event;
9179}
9180
9181/**
9182 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9183 * @phba: pointer to lpfc hba data structure.
9184 * @cq_event: pointer to the completion queue event to be freed.
9185 *
9186 * This routine is the lock free version of the API invoked to release a
9187 * completion-queue event back into the free pool.
9188 **/
9189void
9190__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9191 struct lpfc_cq_event *cq_event)
9192{
9193 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
9194}
9195
9196/**
9197 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9198 * @phba: pointer to lpfc hba data structure.
9199 * @cq_event: pointer to the completion queue event to be freed.
9200 *
9201 * This routine is the lock version of the API invoked to release a
9202 * completion-queue event back into the free pool.
9203 **/
9204void
9205lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9206 struct lpfc_cq_event *cq_event)
9207{
9208 unsigned long iflags;
9209 spin_lock_irqsave(&phba->hbalock, iflags);
9210 __lpfc_sli4_cq_event_release(phba, cq_event);
9211 spin_unlock_irqrestore(&phba->hbalock, iflags);
9212}
9213
9214/**
9215 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
9216 * @phba: pointer to lpfc hba data structure.
9217 *
9218 * This routine is to free all the pending completion-queue events to the
9219 * back into the free pool for device reset.
9220 **/
9221static void
9222lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
9223{
9224 LIST_HEAD(cqelist);
9225 struct lpfc_cq_event *cqe;
9226 unsigned long iflags;
9227
9228 /* Retrieve all the pending WCQEs from pending WCQE lists */
9229 spin_lock_irqsave(&phba->hbalock, iflags);
9230 /* Pending FCP XRI abort events */
9231 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
9232 &cqelist);
9233 /* Pending ELS XRI abort events */
9234 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
9235 &cqelist);
9236 /* Pending asynnc events */
9237 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
9238 &cqelist);
9239 spin_unlock_irqrestore(&phba->hbalock, iflags);
9240
9241 while (!list_empty(&cqelist)) {
9242 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
9243 lpfc_sli4_cq_event_release(phba, cqe);
9244 }
9245}
9246
9247/**
9248 * lpfc_pci_function_reset - Reset pci function.
9249 * @phba: pointer to lpfc hba data structure.
9250 *
9251 * This routine is invoked to request a PCI function reset. It will destroys
9252 * all resources assigned to the PCI function which originates this request.
9253 *
9254 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009255 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009256 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009257 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009258 **/
9259int
9260lpfc_pci_function_reset(struct lpfc_hba *phba)
9261{
9262 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05009263 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04009264 uint32_t shdr_status, shdr_add_status;
James Smart2f6fa2c2014-09-03 12:57:08 -04009265 uint32_t rdy_chk;
9266 uint32_t port_reset = 0;
James Smartda0436e2009-05-22 14:51:39 -04009267 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05009268 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -05009269 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -04009270
James Smart2fcee4b2010-12-15 17:57:46 -05009271 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9272 switch (if_type) {
9273 case LPFC_SLI_INTF_IF_TYPE_0:
9274 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
9275 GFP_KERNEL);
9276 if (!mboxq) {
9277 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9278 "0494 Unable to allocate memory for "
9279 "issuing SLI_FUNCTION_RESET mailbox "
9280 "command\n");
9281 return -ENOMEM;
9282 }
9283
9284 /* Setup PCI function reset mailbox-ioctl command */
9285 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9286 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
9287 LPFC_SLI4_MBX_EMBED);
9288 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9289 shdr = (union lpfc_sli4_cfg_shdr *)
9290 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
9291 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9292 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
9293 &shdr->response);
9294 if (rc != MBX_TIMEOUT)
9295 mempool_free(mboxq, phba->mbox_mem_pool);
9296 if (shdr_status || shdr_add_status || rc) {
9297 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9298 "0495 SLI_FUNCTION_RESET mailbox "
9299 "failed with status x%x add_status x%x,"
9300 " mbx status x%x\n",
9301 shdr_status, shdr_add_status, rc);
9302 rc = -ENXIO;
9303 }
9304 break;
9305 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2f6fa2c2014-09-03 12:57:08 -04009306wait:
9307 /*
9308 * Poll the Port Status Register and wait for RDY for
9309 * up to 30 seconds. If the port doesn't respond, treat
9310 * it as an error.
9311 */
James Smart77d093f2015-04-07 15:07:08 -04009312 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
James Smart2f6fa2c2014-09-03 12:57:08 -04009313 if (lpfc_readl(phba->sli4_hba.u.if_type2.
9314 STATUSregaddr, &reg_data.word0)) {
9315 rc = -ENODEV;
9316 goto out;
9317 }
9318 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
9319 break;
9320 msleep(20);
9321 }
9322
9323 if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
9324 phba->work_status[0] = readl(
9325 phba->sli4_hba.u.if_type2.ERR1regaddr);
9326 phba->work_status[1] = readl(
9327 phba->sli4_hba.u.if_type2.ERR2regaddr);
9328 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9329 "2890 Port not ready, port status reg "
9330 "0x%x error 1=0x%x, error 2=0x%x\n",
9331 reg_data.word0,
9332 phba->work_status[0],
9333 phba->work_status[1]);
9334 rc = -ENODEV;
9335 goto out;
9336 }
9337
9338 if (!port_reset) {
9339 /*
9340 * Reset the port now
9341 */
James Smart2fcee4b2010-12-15 17:57:46 -05009342 reg_data.word0 = 0;
9343 bf_set(lpfc_sliport_ctrl_end, &reg_data,
9344 LPFC_SLIPORT_LITTLE_ENDIAN);
9345 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
9346 LPFC_SLIPORT_INIT_PORT);
9347 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
9348 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -05009349 /* flush */
James Smart2b81f942012-03-01 22:37:18 -05009350 pci_read_config_word(phba->pcidev,
9351 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -05009352
James Smart2f6fa2c2014-09-03 12:57:08 -04009353 port_reset = 1;
9354 msleep(20);
9355 goto wait;
9356 } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
9357 rc = -ENODEV;
9358 goto out;
James Smart2fcee4b2010-12-15 17:57:46 -05009359 }
9360 break;
James Smart2f6fa2c2014-09-03 12:57:08 -04009361
James Smart2fcee4b2010-12-15 17:57:46 -05009362 case LPFC_SLI_INTF_IF_TYPE_1:
9363 default:
9364 break;
James Smartda0436e2009-05-22 14:51:39 -04009365 }
9366
James Smart73d91e52011-10-10 21:32:10 -04009367out:
James Smart2fcee4b2010-12-15 17:57:46 -05009368 /* Catch the not-ready port failure after a port reset. */
James Smart2f6fa2c2014-09-03 12:57:08 -04009369 if (rc) {
James Smart229adb02013-04-17 20:16:51 -04009370 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9371 "3317 HBA not functional: IP Reset Failed "
James Smart2f6fa2c2014-09-03 12:57:08 -04009372 "try: echo fw_reset > board_mode\n");
James Smart2fcee4b2010-12-15 17:57:46 -05009373 rc = -ENODEV;
James Smart229adb02013-04-17 20:16:51 -04009374 }
James Smart2fcee4b2010-12-15 17:57:46 -05009375
James Smartda0436e2009-05-22 14:51:39 -04009376 return rc;
9377}
9378
9379/**
James Smartda0436e2009-05-22 14:51:39 -04009380 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
9381 * @phba: pointer to lpfc hba data structure.
9382 *
9383 * This routine is invoked to set up the PCI device memory space for device
9384 * with SLI-4 interface spec.
9385 *
9386 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009387 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009388 * other values - error
9389 **/
9390static int
9391lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
9392{
9393 struct pci_dev *pdev;
9394 unsigned long bar0map_len, bar1map_len, bar2map_len;
9395 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05009396 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04009397
9398 /* Obtain PCI device reference */
9399 if (!phba->pcidev)
9400 return error;
9401 else
9402 pdev = phba->pcidev;
9403
9404 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05009405 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
9406 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
9407 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
9408 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smartda0436e2009-05-22 14:51:39 -04009409 return error;
Michael Reed8e685972009-09-18 12:02:05 -05009410 }
9411 }
James Smartda0436e2009-05-22 14:51:39 -04009412
James Smart2fcee4b2010-12-15 17:57:46 -05009413 /*
9414 * The BARs and register set definitions and offset locations are
9415 * dependent on the if_type.
9416 */
9417 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
9418 &phba->sli4_hba.sli_intf.word0)) {
9419 return error;
9420 }
9421
9422 /* There is no SLI3 failback for SLI4 devices. */
9423 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
9424 LPFC_SLI_INTF_VALID) {
9425 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9426 "2894 SLI_INTF reg contents invalid "
9427 "sli_intf reg 0x%x\n",
9428 phba->sli4_hba.sli_intf.word0);
9429 return error;
9430 }
9431
9432 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9433 /*
9434 * Get the bus address of SLI4 device Bar regions and the
9435 * number of bytes required by each mapping. The mapping of the
9436 * particular PCI BARs regions is dependent on the type of
9437 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04009438 */
James Smartf5ca6f22013-09-06 12:21:09 -04009439 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
9440 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
9441 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
James Smart2fcee4b2010-12-15 17:57:46 -05009442
9443 /*
9444 * Map SLI4 PCI Config Space Register base to a kernel virtual
9445 * addr
9446 */
9447 phba->sli4_hba.conf_regs_memmap_p =
9448 ioremap(phba->pci_bar0_map, bar0map_len);
9449 if (!phba->sli4_hba.conf_regs_memmap_p) {
9450 dev_printk(KERN_ERR, &pdev->dev,
9451 "ioremap failed for SLI4 PCI config "
9452 "registers.\n");
9453 goto out;
9454 }
James Smartf5ca6f22013-09-06 12:21:09 -04009455 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05009456 /* Set up BAR0 PCI config space register memory map */
9457 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05009458 } else {
9459 phba->pci_bar0_map = pci_resource_start(pdev, 1);
9460 bar0map_len = pci_resource_len(pdev, 1);
James Smart2fcee4b2010-12-15 17:57:46 -05009461 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
9462 dev_printk(KERN_ERR, &pdev->dev,
9463 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
9464 goto out;
9465 }
9466 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04009467 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05009468 if (!phba->sli4_hba.conf_regs_memmap_p) {
9469 dev_printk(KERN_ERR, &pdev->dev,
9470 "ioremap failed for SLI4 PCI config "
9471 "registers.\n");
9472 goto out;
9473 }
9474 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04009475 }
9476
James Smarte4b97942017-11-20 16:00:31 -08009477 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
9478 if (pci_resource_start(pdev, PCI_64BIT_BAR2)) {
9479 /*
9480 * Map SLI4 if type 0 HBA Control Register base to a
9481 * kernel virtual address and setup the registers.
9482 */
9483 phba->pci_bar1_map = pci_resource_start(pdev,
9484 PCI_64BIT_BAR2);
9485 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
9486 phba->sli4_hba.ctrl_regs_memmap_p =
9487 ioremap(phba->pci_bar1_map,
9488 bar1map_len);
9489 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
9490 dev_err(&pdev->dev,
9491 "ioremap failed for SLI4 HBA "
9492 "control registers.\n");
9493 error = -ENOMEM;
9494 goto out_iounmap_conf;
9495 }
9496 phba->pci_bar2_memmap_p =
9497 phba->sli4_hba.ctrl_regs_memmap_p;
9498 lpfc_sli4_bar1_register_memmap(phba);
9499 } else {
9500 error = -ENOMEM;
James Smart2fcee4b2010-12-15 17:57:46 -05009501 goto out_iounmap_conf;
9502 }
James Smartda0436e2009-05-22 14:51:39 -04009503 }
9504
James Smarte4b97942017-11-20 16:00:31 -08009505 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
9506 if (pci_resource_start(pdev, PCI_64BIT_BAR4)) {
9507 /*
9508 * Map SLI4 if type 0 HBA Doorbell Register base to
9509 * a kernel virtual address and setup the registers.
9510 */
9511 phba->pci_bar2_map = pci_resource_start(pdev,
9512 PCI_64BIT_BAR4);
9513 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
9514 phba->sli4_hba.drbl_regs_memmap_p =
9515 ioremap(phba->pci_bar2_map,
9516 bar2map_len);
9517 if (!phba->sli4_hba.drbl_regs_memmap_p) {
9518 dev_err(&pdev->dev,
9519 "ioremap failed for SLI4 HBA"
9520 " doorbell registers.\n");
9521 error = -ENOMEM;
9522 goto out_iounmap_ctrl;
9523 }
9524 phba->pci_bar4_memmap_p =
9525 phba->sli4_hba.drbl_regs_memmap_p;
9526 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
9527 if (error)
9528 goto out_iounmap_all;
9529 } else {
9530 error = -ENOMEM;
James Smart2fcee4b2010-12-15 17:57:46 -05009531 goto out_iounmap_all;
James Smarte4b97942017-11-20 16:00:31 -08009532 }
James Smartda0436e2009-05-22 14:51:39 -04009533 }
9534
James Smartda0436e2009-05-22 14:51:39 -04009535 return 0;
9536
9537out_iounmap_all:
9538 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9539out_iounmap_ctrl:
9540 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9541out_iounmap_conf:
9542 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9543out:
9544 return error;
9545}
9546
9547/**
9548 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
9549 * @phba: pointer to lpfc hba data structure.
9550 *
9551 * This routine is invoked to unset the PCI device memory space for device
9552 * with SLI-4 interface spec.
9553 **/
9554static void
9555lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
9556{
James Smart2e90f4b2011-12-13 13:22:37 -05009557 uint32_t if_type;
9558 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -04009559
James Smart2e90f4b2011-12-13 13:22:37 -05009560 switch (if_type) {
9561 case LPFC_SLI_INTF_IF_TYPE_0:
9562 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9563 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9564 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9565 break;
9566 case LPFC_SLI_INTF_IF_TYPE_2:
9567 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9568 break;
9569 case LPFC_SLI_INTF_IF_TYPE_1:
9570 default:
9571 dev_printk(KERN_ERR, &phba->pcidev->dev,
9572 "FATAL - unsupported SLI4 interface type - %d\n",
9573 if_type);
9574 break;
9575 }
James Smartda0436e2009-05-22 14:51:39 -04009576}
9577
9578/**
James Smart3772a992009-05-22 14:50:54 -04009579 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
9580 * @phba: pointer to lpfc hba data structure.
9581 *
9582 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009583 * with SLI-3 interface specs.
James Smart3772a992009-05-22 14:50:54 -04009584 *
9585 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009586 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009587 * other values - error
9588 **/
9589static int
9590lpfc_sli_enable_msix(struct lpfc_hba *phba)
9591{
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009592 int rc;
James Smart3772a992009-05-22 14:50:54 -04009593 LPFC_MBOXQ_t *pmb;
9594
9595 /* Set up MSI-X multi-message vectors */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009596 rc = pci_alloc_irq_vectors(phba->pcidev,
9597 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
9598 if (rc < 0) {
James Smart3772a992009-05-22 14:50:54 -04009599 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9600 "0420 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009601 goto vec_fail_out;
James Smart3772a992009-05-22 14:50:54 -04009602 }
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009603
James Smart3772a992009-05-22 14:50:54 -04009604 /*
9605 * Assign MSI-X vectors to interrupt handlers
9606 */
9607
9608 /* vector-0 is associated to slow-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009609 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
James Smarted243d32015-05-21 13:55:25 -04009610 &lpfc_sli_sp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04009611 LPFC_SP_DRIVER_HANDLER_NAME, phba);
9612 if (rc) {
9613 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9614 "0421 MSI-X slow-path request_irq failed "
9615 "(%d)\n", rc);
9616 goto msi_fail_out;
9617 }
9618
9619 /* vector-1 is associated to fast-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009620 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
James Smarted243d32015-05-21 13:55:25 -04009621 &lpfc_sli_fp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04009622 LPFC_FP_DRIVER_HANDLER_NAME, phba);
9623
9624 if (rc) {
9625 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9626 "0429 MSI-X fast-path request_irq failed "
9627 "(%d)\n", rc);
9628 goto irq_fail_out;
9629 }
9630
9631 /*
9632 * Configure HBA MSI-X attention conditions to messages
9633 */
9634 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9635
9636 if (!pmb) {
9637 rc = -ENOMEM;
9638 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9639 "0474 Unable to allocate memory for issuing "
9640 "MBOX_CONFIG_MSI command\n");
9641 goto mem_fail_out;
9642 }
9643 rc = lpfc_config_msi(phba, pmb);
9644 if (rc)
9645 goto mbx_fail_out;
9646 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
9647 if (rc != MBX_SUCCESS) {
9648 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
9649 "0351 Config MSI mailbox command failed, "
9650 "mbxCmd x%x, mbxStatus x%x\n",
9651 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
9652 goto mbx_fail_out;
9653 }
9654
9655 /* Free memory allocated for mailbox command */
9656 mempool_free(pmb, phba->mbox_mem_pool);
9657 return rc;
9658
9659mbx_fail_out:
9660 /* Free memory allocated for mailbox command */
9661 mempool_free(pmb, phba->mbox_mem_pool);
9662
9663mem_fail_out:
9664 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009665 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
James Smart3772a992009-05-22 14:50:54 -04009666
9667irq_fail_out:
9668 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009669 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
James Smart3772a992009-05-22 14:50:54 -04009670
9671msi_fail_out:
9672 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009673 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009674
9675vec_fail_out:
James Smart3772a992009-05-22 14:50:54 -04009676 return rc;
9677}
9678
9679/**
James Smart3772a992009-05-22 14:50:54 -04009680 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
9681 * @phba: pointer to lpfc hba data structure.
9682 *
9683 * This routine is invoked to enable the MSI interrupt mode to device with
9684 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
9685 * enable the MSI vector. The device driver is responsible for calling the
9686 * request_irq() to register MSI vector with a interrupt the handler, which
9687 * is done in this function.
9688 *
9689 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009690 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009691 * other values - error
9692 */
9693static int
9694lpfc_sli_enable_msi(struct lpfc_hba *phba)
9695{
9696 int rc;
9697
9698 rc = pci_enable_msi(phba->pcidev);
9699 if (!rc)
9700 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9701 "0462 PCI enable MSI mode success.\n");
9702 else {
9703 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9704 "0471 PCI enable MSI mode failed (%d)\n", rc);
9705 return rc;
9706 }
9707
9708 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04009709 0, LPFC_DRIVER_NAME, phba);
James Smart3772a992009-05-22 14:50:54 -04009710 if (rc) {
9711 pci_disable_msi(phba->pcidev);
9712 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9713 "0478 MSI request_irq failed (%d)\n", rc);
9714 }
9715 return rc;
9716}
9717
9718/**
James Smart3772a992009-05-22 14:50:54 -04009719 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
9720 * @phba: pointer to lpfc hba data structure.
9721 *
9722 * This routine is invoked to enable device interrupt and associate driver's
9723 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
9724 * spec. Depends on the interrupt mode configured to the driver, the driver
9725 * will try to fallback from the configured interrupt mode to an interrupt
9726 * mode which is supported by the platform, kernel, and device in the order
9727 * of:
9728 * MSI-X -> MSI -> IRQ.
9729 *
9730 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009731 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009732 * other values - error
9733 **/
9734static uint32_t
9735lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9736{
9737 uint32_t intr_mode = LPFC_INTR_ERROR;
9738 int retval;
9739
9740 if (cfg_mode == 2) {
9741 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
9742 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
9743 if (!retval) {
9744 /* Now, try to enable MSI-X interrupt mode */
9745 retval = lpfc_sli_enable_msix(phba);
9746 if (!retval) {
9747 /* Indicate initialization to MSI-X mode */
9748 phba->intr_type = MSIX;
9749 intr_mode = 2;
9750 }
9751 }
9752 }
9753
9754 /* Fallback to MSI if MSI-X initialization failed */
9755 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9756 retval = lpfc_sli_enable_msi(phba);
9757 if (!retval) {
9758 /* Indicate initialization to MSI mode */
9759 phba->intr_type = MSI;
9760 intr_mode = 1;
9761 }
9762 }
9763
9764 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9765 if (phba->intr_type == NONE) {
9766 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
9767 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9768 if (!retval) {
9769 /* Indicate initialization to INTx mode */
9770 phba->intr_type = INTx;
9771 intr_mode = 0;
9772 }
9773 }
9774 return intr_mode;
9775}
9776
9777/**
9778 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
9779 * @phba: pointer to lpfc hba data structure.
9780 *
9781 * This routine is invoked to disable device interrupt and disassociate the
9782 * driver's interrupt handler(s) from interrupt vector(s) to device with
9783 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
9784 * release the interrupt vector(s) for the message signaled interrupt.
9785 **/
9786static void
9787lpfc_sli_disable_intr(struct lpfc_hba *phba)
9788{
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009789 int nr_irqs, i;
9790
James Smart3772a992009-05-22 14:50:54 -04009791 if (phba->intr_type == MSIX)
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009792 nr_irqs = LPFC_MSIX_VECTORS;
9793 else
9794 nr_irqs = 1;
9795
9796 for (i = 0; i < nr_irqs; i++)
9797 free_irq(pci_irq_vector(phba->pcidev, i), phba);
9798 pci_free_irq_vectors(phba->pcidev);
James Smart3772a992009-05-22 14:50:54 -04009799
9800 /* Reset interrupt management states */
9801 phba->intr_type = NONE;
9802 phba->sli.slistat.sli_intr = 0;
James Smart3772a992009-05-22 14:50:54 -04009803}
9804
9805/**
James Smart895427b2017-02-12 13:52:30 -08009806 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
James Smart7bb03bb2013-04-17 20:19:16 -04009807 * @phba: pointer to lpfc hba data structure.
James Smart895427b2017-02-12 13:52:30 -08009808 * @vectors: number of msix vectors allocated.
James Smart7bb03bb2013-04-17 20:19:16 -04009809 *
James Smart895427b2017-02-12 13:52:30 -08009810 * The routine will figure out the CPU affinity assignment for every
9811 * MSI-X vector allocated for the HBA. The hba_eq_hdl will be updated
9812 * with a pointer to the CPU mask that defines ALL the CPUs this vector
9813 * can be associated with. If the vector can be unquely associated with
9814 * a single CPU, that CPU will be recorded in hba_eq_hdl[index].cpu.
9815 * In addition, the CPU to IO channel mapping will be calculated
9816 * and the phba->sli4_hba.cpu_map array will reflect this.
James Smart7bb03bb2013-04-17 20:19:16 -04009817 */
James Smart895427b2017-02-12 13:52:30 -08009818static void
9819lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
James Smart7bb03bb2013-04-17 20:19:16 -04009820{
9821 struct lpfc_vector_map_info *cpup;
James Smart895427b2017-02-12 13:52:30 -08009822 int index = 0;
9823 int vec = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04009824 int cpu;
James Smart7bb03bb2013-04-17 20:19:16 -04009825#ifdef CONFIG_X86
9826 struct cpuinfo_x86 *cpuinfo;
9827#endif
James Smart7bb03bb2013-04-17 20:19:16 -04009828
9829 /* Init cpu_map array */
9830 memset(phba->sli4_hba.cpu_map, 0xff,
9831 (sizeof(struct lpfc_vector_map_info) *
James Smart895427b2017-02-12 13:52:30 -08009832 phba->sli4_hba.num_present_cpu));
James Smart7bb03bb2013-04-17 20:19:16 -04009833
9834 /* Update CPU map with physical id and core id of each CPU */
9835 cpup = phba->sli4_hba.cpu_map;
9836 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
9837#ifdef CONFIG_X86
9838 cpuinfo = &cpu_data(cpu);
9839 cpup->phys_id = cpuinfo->phys_proc_id;
9840 cpup->core_id = cpuinfo->cpu_core_id;
9841#else
9842 /* No distinction between CPUs for other platforms */
9843 cpup->phys_id = 0;
9844 cpup->core_id = 0;
9845#endif
James Smart895427b2017-02-12 13:52:30 -08009846 cpup->channel_id = index; /* For now round robin */
9847 cpup->irq = pci_irq_vector(phba->pcidev, vec);
9848 vec++;
9849 if (vec >= vectors)
9850 vec = 0;
9851 index++;
9852 if (index >= phba->cfg_fcp_io_channel)
9853 index = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04009854 cpup++;
9855 }
James Smart7bb03bb2013-04-17 20:19:16 -04009856}
9857
9858
9859/**
James Smartda0436e2009-05-22 14:51:39 -04009860 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
9861 * @phba: pointer to lpfc hba data structure.
9862 *
9863 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009864 * with SLI-4 interface spec.
James Smartda0436e2009-05-22 14:51:39 -04009865 *
9866 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009867 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009868 * other values - error
9869 **/
9870static int
9871lpfc_sli4_enable_msix(struct lpfc_hba *phba)
9872{
James Smart75baf692010-06-08 18:31:21 -04009873 int vectors, rc, index;
James Smartb83d0052017-06-01 21:07:05 -07009874 char *name;
James Smartda0436e2009-05-22 14:51:39 -04009875
9876 /* Set up MSI-X multi-message vectors */
James Smart895427b2017-02-12 13:52:30 -08009877 vectors = phba->io_channel_irqs;
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009878 if (phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05009879 vectors++;
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009880
James Smartf358dd02017-02-12 13:52:34 -08009881 rc = pci_alloc_irq_vectors(phba->pcidev,
9882 (phba->nvmet_support) ? 1 : 2,
9883 vectors, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY);
Alexander Gordeev4f871e12014-09-03 12:56:29 -04009884 if (rc < 0) {
James Smartda0436e2009-05-22 14:51:39 -04009885 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9886 "0484 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009887 goto vec_fail_out;
James Smartda0436e2009-05-22 14:51:39 -04009888 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -04009889 vectors = rc;
James Smart75baf692010-06-08 18:31:21 -04009890
James Smart7bb03bb2013-04-17 20:19:16 -04009891 /* Assign MSI-X vectors to interrupt handlers */
James Smart67d12732012-08-03 12:36:13 -04009892 for (index = 0; index < vectors; index++) {
James Smartb83d0052017-06-01 21:07:05 -07009893 name = phba->sli4_hba.hba_eq_hdl[index].handler_name;
9894 memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ);
9895 snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ,
James Smart4305f182012-08-03 12:36:33 -04009896 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -04009897
James Smart895427b2017-02-12 13:52:30 -08009898 phba->sli4_hba.hba_eq_hdl[index].idx = index;
9899 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
9900 atomic_set(&phba->sli4_hba.hba_eq_hdl[index].hba_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -05009901 if (phba->cfg_fof && (index == (vectors - 1)))
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009902 rc = request_irq(pci_irq_vector(phba->pcidev, index),
James Smarted243d32015-05-21 13:55:25 -04009903 &lpfc_sli4_fof_intr_handler, 0,
James Smartb83d0052017-06-01 21:07:05 -07009904 name,
James Smart895427b2017-02-12 13:52:30 -08009905 &phba->sli4_hba.hba_eq_hdl[index]);
James Smart1ba981f2014-02-20 09:56:45 -05009906 else
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009907 rc = request_irq(pci_irq_vector(phba->pcidev, index),
James Smarted243d32015-05-21 13:55:25 -04009908 &lpfc_sli4_hba_intr_handler, 0,
James Smartb83d0052017-06-01 21:07:05 -07009909 name,
James Smart895427b2017-02-12 13:52:30 -08009910 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -04009911 if (rc) {
9912 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9913 "0486 MSI-X fast-path (%d) "
9914 "request_irq failed (%d)\n", index, rc);
9915 goto cfg_fail_out;
9916 }
9917 }
9918
James Smart1ba981f2014-02-20 09:56:45 -05009919 if (phba->cfg_fof)
9920 vectors--;
9921
James Smart895427b2017-02-12 13:52:30 -08009922 if (vectors != phba->io_channel_irqs) {
James Smart82c3e9b2012-09-29 11:29:50 -04009923 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9924 "3238 Reducing IO channels to match number of "
9925 "MSI-X vectors, requested %d got %d\n",
James Smart895427b2017-02-12 13:52:30 -08009926 phba->io_channel_irqs, vectors);
9927 if (phba->cfg_fcp_io_channel > vectors)
9928 phba->cfg_fcp_io_channel = vectors;
9929 if (phba->cfg_nvme_io_channel > vectors)
9930 phba->cfg_nvme_io_channel = vectors;
9931 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
9932 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
9933 else
9934 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
James Smart82c3e9b2012-09-29 11:29:50 -04009935 }
James Smart895427b2017-02-12 13:52:30 -08009936 lpfc_cpu_affinity_check(phba, vectors);
James Smart7bb03bb2013-04-17 20:19:16 -04009937
James Smartda0436e2009-05-22 14:51:39 -04009938 return rc;
9939
9940cfg_fail_out:
9941 /* free the irq already requested */
James Smart895427b2017-02-12 13:52:30 -08009942 for (--index; index >= 0; index--)
9943 free_irq(pci_irq_vector(phba->pcidev, index),
9944 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -04009945
James Smartda0436e2009-05-22 14:51:39 -04009946 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009947 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009948
9949vec_fail_out:
James Smartda0436e2009-05-22 14:51:39 -04009950 return rc;
9951}
9952
9953/**
James Smartda0436e2009-05-22 14:51:39 -04009954 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
9955 * @phba: pointer to lpfc hba data structure.
9956 *
9957 * This routine is invoked to enable the MSI interrupt mode to device with
9958 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
9959 * to enable the MSI vector. The device driver is responsible for calling
9960 * the request_irq() to register MSI vector with a interrupt the handler,
9961 * which is done in this function.
9962 *
9963 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009964 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009965 * other values - error
9966 **/
9967static int
9968lpfc_sli4_enable_msi(struct lpfc_hba *phba)
9969{
9970 int rc, index;
9971
9972 rc = pci_enable_msi(phba->pcidev);
9973 if (!rc)
9974 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9975 "0487 PCI enable MSI mode success.\n");
9976 else {
9977 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9978 "0488 PCI enable MSI mode failed (%d)\n", rc);
9979 return rc;
9980 }
9981
9982 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04009983 0, LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -04009984 if (rc) {
9985 pci_disable_msi(phba->pcidev);
9986 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9987 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -04009988 return rc;
James Smartda0436e2009-05-22 14:51:39 -04009989 }
9990
James Smart895427b2017-02-12 13:52:30 -08009991 for (index = 0; index < phba->io_channel_irqs; index++) {
9992 phba->sli4_hba.hba_eq_hdl[index].idx = index;
9993 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smartda0436e2009-05-22 14:51:39 -04009994 }
9995
James Smart1ba981f2014-02-20 09:56:45 -05009996 if (phba->cfg_fof) {
James Smart895427b2017-02-12 13:52:30 -08009997 phba->sli4_hba.hba_eq_hdl[index].idx = index;
9998 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smart1ba981f2014-02-20 09:56:45 -05009999 }
James Smart75baf692010-06-08 18:31:21 -040010000 return 0;
James Smartda0436e2009-05-22 14:51:39 -040010001}
10002
10003/**
James Smartda0436e2009-05-22 14:51:39 -040010004 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
10005 * @phba: pointer to lpfc hba data structure.
10006 *
10007 * This routine is invoked to enable device interrupt and associate driver's
10008 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
10009 * interface spec. Depends on the interrupt mode configured to the driver,
10010 * the driver will try to fallback from the configured interrupt mode to an
10011 * interrupt mode which is supported by the platform, kernel, and device in
10012 * the order of:
10013 * MSI-X -> MSI -> IRQ.
10014 *
10015 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010016 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040010017 * other values - error
10018 **/
10019static uint32_t
10020lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
10021{
10022 uint32_t intr_mode = LPFC_INTR_ERROR;
James Smart895427b2017-02-12 13:52:30 -080010023 int retval, idx;
James Smartda0436e2009-05-22 14:51:39 -040010024
10025 if (cfg_mode == 2) {
10026 /* Preparation before conf_msi mbox cmd */
10027 retval = 0;
10028 if (!retval) {
10029 /* Now, try to enable MSI-X interrupt mode */
10030 retval = lpfc_sli4_enable_msix(phba);
10031 if (!retval) {
10032 /* Indicate initialization to MSI-X mode */
10033 phba->intr_type = MSIX;
10034 intr_mode = 2;
10035 }
10036 }
10037 }
10038
10039 /* Fallback to MSI if MSI-X initialization failed */
10040 if (cfg_mode >= 1 && phba->intr_type == NONE) {
10041 retval = lpfc_sli4_enable_msi(phba);
10042 if (!retval) {
10043 /* Indicate initialization to MSI mode */
10044 phba->intr_type = MSI;
10045 intr_mode = 1;
10046 }
10047 }
10048
10049 /* Fallback to INTx if both MSI-X/MSI initalization failed */
10050 if (phba->intr_type == NONE) {
10051 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
10052 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
10053 if (!retval) {
James Smart895427b2017-02-12 13:52:30 -080010054 struct lpfc_hba_eq_hdl *eqhdl;
10055
James Smartda0436e2009-05-22 14:51:39 -040010056 /* Indicate initialization to INTx mode */
10057 phba->intr_type = INTx;
10058 intr_mode = 0;
James Smart895427b2017-02-12 13:52:30 -080010059
10060 for (idx = 0; idx < phba->io_channel_irqs; idx++) {
10061 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
10062 eqhdl->idx = idx;
10063 eqhdl->phba = phba;
10064 atomic_set(&eqhdl->hba_eq_in_use, 1);
James Smartda0436e2009-05-22 14:51:39 -040010065 }
James Smart1ba981f2014-02-20 09:56:45 -050010066 if (phba->cfg_fof) {
James Smart895427b2017-02-12 13:52:30 -080010067 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
10068 eqhdl->idx = idx;
10069 eqhdl->phba = phba;
10070 atomic_set(&eqhdl->hba_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -050010071 }
James Smartda0436e2009-05-22 14:51:39 -040010072 }
10073 }
10074 return intr_mode;
10075}
10076
10077/**
10078 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
10079 * @phba: pointer to lpfc hba data structure.
10080 *
10081 * This routine is invoked to disable device interrupt and disassociate
10082 * the driver's interrupt handler(s) from interrupt vector(s) to device
10083 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
10084 * will release the interrupt vector(s) for the message signaled interrupt.
10085 **/
10086static void
10087lpfc_sli4_disable_intr(struct lpfc_hba *phba)
10088{
10089 /* Disable the currently initialized interrupt mode */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010090 if (phba->intr_type == MSIX) {
10091 int index;
10092
10093 /* Free up MSI-X multi-message vectors */
James Smart895427b2017-02-12 13:52:30 -080010094 for (index = 0; index < phba->io_channel_irqs; index++)
10095 free_irq(pci_irq_vector(phba->pcidev, index),
10096 &phba->sli4_hba.hba_eq_hdl[index]);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010097
10098 if (phba->cfg_fof)
James Smart895427b2017-02-12 13:52:30 -080010099 free_irq(pci_irq_vector(phba->pcidev, index),
10100 &phba->sli4_hba.hba_eq_hdl[index]);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010101 } else {
James Smartda0436e2009-05-22 14:51:39 -040010102 free_irq(phba->pcidev->irq, phba);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010103 }
10104
10105 pci_free_irq_vectors(phba->pcidev);
James Smartda0436e2009-05-22 14:51:39 -040010106
10107 /* Reset interrupt management states */
10108 phba->intr_type = NONE;
10109 phba->sli.slistat.sli_intr = 0;
James Smartda0436e2009-05-22 14:51:39 -040010110}
10111
10112/**
James Smart3772a992009-05-22 14:50:54 -040010113 * lpfc_unset_hba - Unset SLI3 hba device initialization
10114 * @phba: pointer to lpfc hba data structure.
10115 *
10116 * This routine is invoked to unset the HBA device initialization steps to
10117 * a device with SLI-3 interface spec.
10118 **/
10119static void
10120lpfc_unset_hba(struct lpfc_hba *phba)
10121{
10122 struct lpfc_vport *vport = phba->pport;
10123 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
10124
10125 spin_lock_irq(shost->host_lock);
10126 vport->load_flag |= FC_UNLOADING;
10127 spin_unlock_irq(shost->host_lock);
10128
James Smart72859902012-01-18 16:25:38 -050010129 kfree(phba->vpi_bmask);
10130 kfree(phba->vpi_ids);
10131
James Smart3772a992009-05-22 14:50:54 -040010132 lpfc_stop_hba_timers(phba);
10133
10134 phba->pport->work_port_events = 0;
10135
10136 lpfc_sli_hba_down(phba);
10137
10138 lpfc_sli_brdrestart(phba);
10139
10140 lpfc_sli_disable_intr(phba);
10141
10142 return;
10143}
10144
10145/**
James Smart5af5eee2010-10-22 11:06:38 -040010146 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
10147 * @phba: Pointer to HBA context object.
10148 *
10149 * This function is called in the SLI4 code path to wait for completion
10150 * of device's XRIs exchange busy. It will check the XRI exchange busy
10151 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
10152 * that, it will check the XRI exchange busy on outstanding FCP and ELS
10153 * I/Os every 30 seconds, log error message, and wait forever. Only when
10154 * all XRI exchange busy complete, the driver unload shall proceed with
10155 * invoking the function reset ioctl mailbox command to the CNA and the
10156 * the rest of the driver unload resource release.
10157 **/
10158static void
10159lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
10160{
10161 int wait_time = 0;
James Smart895427b2017-02-12 13:52:30 -080010162 int nvme_xri_cmpl = 1;
James Smart86c67372017-04-21 16:05:04 -070010163 int nvmet_xri_cmpl = 1;
James Smart895427b2017-02-12 13:52:30 -080010164 int fcp_xri_cmpl = 1;
James Smart5af5eee2010-10-22 11:06:38 -040010165 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
10166
James Smartc3725bd2017-11-20 16:00:42 -080010167 /* Driver just aborted IOs during the hba_unset process. Pause
10168 * here to give the HBA time to complete the IO and get entries
10169 * into the abts lists.
10170 */
10171 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5);
10172
10173 /* Wait for NVME pending IO to flush back to transport. */
10174 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
10175 lpfc_nvme_wait_for_io_drain(phba);
10176
James Smart895427b2017-02-12 13:52:30 -080010177 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
10178 fcp_xri_cmpl =
10179 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
James Smart86c67372017-04-21 16:05:04 -070010180 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -080010181 nvme_xri_cmpl =
10182 list_empty(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
James Smart86c67372017-04-21 16:05:04 -070010183 nvmet_xri_cmpl =
10184 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
10185 }
James Smart895427b2017-02-12 13:52:30 -080010186
James Smartf358dd02017-02-12 13:52:34 -080010187 while (!fcp_xri_cmpl || !els_xri_cmpl || !nvme_xri_cmpl ||
10188 !nvmet_xri_cmpl) {
James Smart5af5eee2010-10-22 11:06:38 -040010189 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
James Smart895427b2017-02-12 13:52:30 -080010190 if (!nvme_xri_cmpl)
10191 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10192 "6100 NVME XRI exchange busy "
10193 "wait time: %d seconds.\n",
10194 wait_time/1000);
James Smart5af5eee2010-10-22 11:06:38 -040010195 if (!fcp_xri_cmpl)
10196 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10197 "2877 FCP XRI exchange busy "
10198 "wait time: %d seconds.\n",
10199 wait_time/1000);
10200 if (!els_xri_cmpl)
10201 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10202 "2878 ELS XRI exchange busy "
10203 "wait time: %d seconds.\n",
10204 wait_time/1000);
10205 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
10206 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
10207 } else {
10208 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
10209 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
10210 }
James Smart86c67372017-04-21 16:05:04 -070010211 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -080010212 nvme_xri_cmpl = list_empty(
10213 &phba->sli4_hba.lpfc_abts_nvme_buf_list);
James Smart86c67372017-04-21 16:05:04 -070010214 nvmet_xri_cmpl = list_empty(
10215 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
10216 }
James Smart895427b2017-02-12 13:52:30 -080010217
10218 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
10219 fcp_xri_cmpl = list_empty(
10220 &phba->sli4_hba.lpfc_abts_scsi_buf_list);
10221
James Smart5af5eee2010-10-22 11:06:38 -040010222 els_xri_cmpl =
10223 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -080010224
James Smart5af5eee2010-10-22 11:06:38 -040010225 }
10226}
10227
10228/**
James Smartda0436e2009-05-22 14:51:39 -040010229 * lpfc_sli4_hba_unset - Unset the fcoe hba
10230 * @phba: Pointer to HBA context object.
10231 *
10232 * This function is called in the SLI4 code path to reset the HBA's FCoE
10233 * function. The caller is not required to hold any lock. This routine
10234 * issues PCI function reset mailbox command to reset the FCoE function.
10235 * At the end of the function, it calls lpfc_hba_down_post function to
10236 * free any pending commands.
10237 **/
10238static void
10239lpfc_sli4_hba_unset(struct lpfc_hba *phba)
10240{
10241 int wait_cnt = 0;
10242 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -040010243 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -040010244
10245 lpfc_stop_hba_timers(phba);
10246 phba->sli4_hba.intr_enable = 0;
10247
10248 /*
10249 * Gracefully wait out the potential current outstanding asynchronous
10250 * mailbox command.
10251 */
10252
10253 /* First, block any pending async mailbox command from posted */
10254 spin_lock_irq(&phba->hbalock);
10255 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
10256 spin_unlock_irq(&phba->hbalock);
10257 /* Now, trying to wait it out if we can */
10258 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
10259 msleep(10);
10260 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
10261 break;
10262 }
10263 /* Forcefully release the outstanding mailbox command if timed out */
10264 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
10265 spin_lock_irq(&phba->hbalock);
10266 mboxq = phba->sli.mbox_active;
10267 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
10268 __lpfc_mbox_cmpl_put(phba, mboxq);
10269 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
10270 phba->sli.mbox_active = NULL;
10271 spin_unlock_irq(&phba->hbalock);
10272 }
10273
James Smart5af5eee2010-10-22 11:06:38 -040010274 /* Abort all iocbs associated with the hba */
10275 lpfc_sli_hba_iocb_abort(phba);
10276
10277 /* Wait for completion of device XRI exchange busy */
10278 lpfc_sli4_xri_exchange_busy_wait(phba);
10279
James Smartda0436e2009-05-22 14:51:39 -040010280 /* Disable PCI subsystem interrupt */
10281 lpfc_sli4_disable_intr(phba);
10282
James Smart912e3ac2011-05-24 11:42:11 -040010283 /* Disable SR-IOV if enabled */
10284 if (phba->cfg_sriov_nr_virtfn)
10285 pci_disable_sriov(pdev);
10286
James Smartda0436e2009-05-22 14:51:39 -040010287 /* Stop kthread signal shall trigger work_done one more time */
10288 kthread_stop(phba->worker_thread);
10289
James Smartd1f525a2017-04-21 16:04:55 -070010290 /* Unset the queues shared with the hardware then release all
10291 * allocated resources.
10292 */
10293 lpfc_sli4_queue_unset(phba);
10294 lpfc_sli4_queue_destroy(phba);
10295
James Smart3677a3a2010-09-29 11:19:14 -040010296 /* Reset SLI4 HBA FCoE function */
10297 lpfc_pci_function_reset(phba);
10298
James Smartda0436e2009-05-22 14:51:39 -040010299 /* Stop the SLI4 device port */
10300 phba->pport->work_port_events = 0;
10301}
10302
James Smart28baac72010-02-12 14:42:03 -050010303 /**
10304 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
10305 * @phba: Pointer to HBA context object.
10306 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10307 *
10308 * This function is called in the SLI4 code path to read the port's
10309 * sli4 capabilities.
10310 *
10311 * This function may be be called from any context that can block-wait
10312 * for the completion. The expectation is that this routine is called
10313 * typically from probe_one or from the online routine.
10314 **/
10315int
10316lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10317{
10318 int rc;
10319 struct lpfc_mqe *mqe;
10320 struct lpfc_pc_sli4_params *sli4_params;
10321 uint32_t mbox_tmo;
10322
10323 rc = 0;
10324 mqe = &mboxq->u.mqe;
10325
10326 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -050010327 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -050010328 if (!phba->sli4_hba.intr_enable)
10329 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10330 else {
James Smarta183a152011-10-10 21:32:43 -040010331 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -050010332 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10333 }
10334
10335 if (unlikely(rc))
10336 return 1;
10337
10338 sli4_params = &phba->sli4_hba.pc_sli4_params;
10339 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
10340 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
10341 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
10342 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
10343 &mqe->un.sli4_params);
10344 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
10345 &mqe->un.sli4_params);
10346 sli4_params->proto_types = mqe->un.sli4_params.word3;
10347 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
10348 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
10349 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
10350 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
10351 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
10352 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
10353 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
10354 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
10355 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
10356 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
10357 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
10358 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
10359 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
10360 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
10361 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
10362 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
10363 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
10364 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
10365 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
10366 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -040010367
10368 /* Make sure that sge_supp_len can be handled by the driver */
10369 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10370 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10371
James Smart28baac72010-02-12 14:42:03 -050010372 return rc;
10373}
10374
James Smartda0436e2009-05-22 14:51:39 -040010375/**
James Smartfedd3b72011-02-16 12:39:24 -050010376 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
10377 * @phba: Pointer to HBA context object.
10378 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10379 *
10380 * This function is called in the SLI4 code path to read the port's
10381 * sli4 capabilities.
10382 *
10383 * This function may be be called from any context that can block-wait
10384 * for the completion. The expectation is that this routine is called
10385 * typically from probe_one or from the online routine.
10386 **/
10387int
10388lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10389{
10390 int rc;
10391 struct lpfc_mqe *mqe = &mboxq->u.mqe;
10392 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -040010393 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -050010394 int length;
10395 struct lpfc_sli4_parameters *mbx_sli4_parameters;
10396
James Smart6d368e52011-05-24 11:44:12 -040010397 /*
10398 * By default, the driver assumes the SLI4 port requires RPI
10399 * header postings. The SLI4_PARAM response will correct this
10400 * assumption.
10401 */
10402 phba->sli4_hba.rpi_hdrs_in_use = 1;
10403
James Smartfedd3b72011-02-16 12:39:24 -050010404 /* Read the port's SLI4 Config Parameters */
10405 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
10406 sizeof(struct lpfc_sli4_cfg_mhdr));
10407 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
10408 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
10409 length, LPFC_SLI4_MBX_EMBED);
10410 if (!phba->sli4_hba.intr_enable)
10411 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -040010412 else {
10413 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
10414 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10415 }
James Smartfedd3b72011-02-16 12:39:24 -050010416 if (unlikely(rc))
10417 return rc;
10418 sli4_params = &phba->sli4_hba.pc_sli4_params;
10419 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
10420 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
10421 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
10422 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
10423 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
10424 mbx_sli4_parameters);
10425 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
10426 mbx_sli4_parameters);
10427 if (bf_get(cfg_phwq, mbx_sli4_parameters))
10428 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
10429 else
10430 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
10431 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
10432 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
James Smart1ba981f2014-02-20 09:56:45 -050010433 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010434 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
10435 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
10436 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
10437 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
James Smart0c651872013-07-15 18:33:23 -040010438 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010439 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
10440 mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080010441 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010442 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
10443 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -040010444 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
10445 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080010446 phba->nvme_support = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
10447 bf_get(cfg_xib, mbx_sli4_parameters));
10448
10449 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) ||
10450 !phba->nvme_support) {
10451 phba->nvme_support = 0;
10452 phba->nvmet_support = 0;
James Smartbcb24f62017-11-20 16:00:36 -080010453 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_OFF;
James Smart895427b2017-02-12 13:52:30 -080010454 phba->cfg_nvme_io_channel = 0;
10455 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
10456 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
10457 "6101 Disabling NVME support: "
10458 "Not supported by firmware: %d %d\n",
10459 bf_get(cfg_nvme, mbx_sli4_parameters),
10460 bf_get(cfg_xib, mbx_sli4_parameters));
10461
10462 /* If firmware doesn't support NVME, just use SCSI support */
10463 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
10464 return -ENODEV;
10465 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
10466 }
James Smart05580562011-05-24 11:40:48 -040010467
James Smartf358dd02017-02-12 13:52:34 -080010468 if (bf_get(cfg_xib, mbx_sli4_parameters) && phba->cfg_suppress_rsp)
10469 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
10470
James Smart0cf07f842017-06-01 21:07:10 -070010471 if (bf_get(cfg_eqdr, mbx_sli4_parameters))
10472 phba->sli.sli_flag |= LPFC_SLI_USE_EQDR;
10473
James Smart05580562011-05-24 11:40:48 -040010474 /* Make sure that sge_supp_len can be handled by the driver */
10475 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10476 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10477
James Smartb5c53952016-03-31 14:12:30 -070010478 /*
10479 * Issue IOs with CDB embedded in WQE to minimized the number
10480 * of DMAs the firmware has to do. Setting this to 1 also forces
10481 * the driver to use 128 bytes WQEs for FCP IOs.
10482 */
10483 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
10484 phba->fcp_embed_io = 1;
10485 else
10486 phba->fcp_embed_io = 0;
James Smart7bdedb32016-07-06 12:36:00 -070010487
10488 /*
10489 * Check if the SLI port supports MDS Diagnostics
10490 */
10491 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
10492 phba->mds_diags_support = 1;
10493 else
10494 phba->mds_diags_support = 0;
James Smartfedd3b72011-02-16 12:39:24 -050010495 return 0;
10496}
10497
10498/**
James Smart3772a992009-05-22 14:50:54 -040010499 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
10500 * @pdev: pointer to PCI device
10501 * @pid: pointer to PCI device identifier
10502 *
10503 * This routine is to be called to attach a device with SLI-3 interface spec
10504 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10505 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10506 * information of the device and driver to see if the driver state that it can
10507 * support this kind of device. If the match is successful, the driver core
10508 * invokes this routine. If this routine determines it can claim the HBA, it
10509 * does all the initialization that it needs to do to handle the HBA properly.
10510 *
10511 * Return code
10512 * 0 - driver can claim the device
10513 * negative value - driver can not claim the device
10514 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010515static int
James Smart3772a992009-05-22 14:50:54 -040010516lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
10517{
10518 struct lpfc_hba *phba;
10519 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040010520 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -040010521 int error;
10522 uint32_t cfg_mode, intr_mode;
10523
10524 /* Allocate memory for HBA structure */
10525 phba = lpfc_hba_alloc(pdev);
10526 if (!phba)
10527 return -ENOMEM;
10528
10529 /* Perform generic PCI device enabling operation */
10530 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040010531 if (error)
James Smart3772a992009-05-22 14:50:54 -040010532 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -040010533
10534 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
10535 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
10536 if (error)
10537 goto out_disable_pci_dev;
10538
10539 /* Set up SLI-3 specific device PCI memory space */
10540 error = lpfc_sli_pci_mem_setup(phba);
10541 if (error) {
10542 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10543 "1402 Failed to set up pci memory space.\n");
10544 goto out_disable_pci_dev;
10545 }
10546
James Smart3772a992009-05-22 14:50:54 -040010547 /* Set up SLI-3 specific device driver resources */
10548 error = lpfc_sli_driver_resource_setup(phba);
10549 if (error) {
10550 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10551 "1404 Failed to set up driver resource.\n");
10552 goto out_unset_pci_mem_s3;
10553 }
10554
10555 /* Initialize and populate the iocb list per host */
James Smartd1f525a2017-04-21 16:04:55 -070010556
James Smart3772a992009-05-22 14:50:54 -040010557 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
10558 if (error) {
10559 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10560 "1405 Failed to initialize iocb list.\n");
10561 goto out_unset_driver_resource_s3;
10562 }
10563
10564 /* Set up common device driver resources */
10565 error = lpfc_setup_driver_resource_phase2(phba);
10566 if (error) {
10567 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10568 "1406 Failed to set up driver resource.\n");
10569 goto out_free_iocb_list;
10570 }
10571
James Smart079b5c92011-08-21 21:48:49 -040010572 /* Get the default values for Model Name and Description */
10573 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
10574
James Smart3772a992009-05-22 14:50:54 -040010575 /* Create SCSI host to the physical port */
10576 error = lpfc_create_shost(phba);
10577 if (error) {
10578 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10579 "1407 Failed to create scsi host.\n");
10580 goto out_unset_driver_resource;
10581 }
10582
10583 /* Configure sysfs attributes */
10584 vport = phba->pport;
10585 error = lpfc_alloc_sysfs_attr(vport);
10586 if (error) {
10587 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10588 "1476 Failed to allocate sysfs attr\n");
10589 goto out_destroy_shost;
10590 }
10591
James Smart6669f9b2009-10-02 15:16:45 -040010592 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -040010593 /* Now, trying to enable interrupt and bring up the device */
10594 cfg_mode = phba->cfg_use_msi;
10595 while (true) {
10596 /* Put device to a known state before enabling interrupt */
10597 lpfc_stop_port(phba);
10598 /* Configure and enable interrupt */
10599 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
10600 if (intr_mode == LPFC_INTR_ERROR) {
10601 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10602 "0431 Failed to enable interrupt.\n");
10603 error = -ENODEV;
10604 goto out_free_sysfs_attr;
10605 }
10606 /* SLI-3 HBA setup */
10607 if (lpfc_sli_hba_setup(phba)) {
10608 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10609 "1477 Failed to set up hba\n");
10610 error = -ENODEV;
10611 goto out_remove_device;
10612 }
10613
10614 /* Wait 50ms for the interrupts of previous mailbox commands */
10615 msleep(50);
10616 /* Check active interrupts on message signaled interrupts */
10617 if (intr_mode == 0 ||
10618 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
10619 /* Log the current active interrupt mode */
10620 phba->intr_mode = intr_mode;
10621 lpfc_log_intr_mode(phba, intr_mode);
10622 break;
10623 } else {
10624 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10625 "0447 Configure interrupt mode (%d) "
10626 "failed active interrupt test.\n",
10627 intr_mode);
10628 /* Disable the current interrupt mode */
10629 lpfc_sli_disable_intr(phba);
10630 /* Try next level of interrupt mode */
10631 cfg_mode = --intr_mode;
10632 }
10633 }
10634
10635 /* Perform post initialization setup */
10636 lpfc_post_init_setup(phba);
10637
10638 /* Check if there are static vports to be created. */
10639 lpfc_create_static_vport(phba);
10640
10641 return 0;
10642
10643out_remove_device:
10644 lpfc_unset_hba(phba);
10645out_free_sysfs_attr:
10646 lpfc_free_sysfs_attr(vport);
10647out_destroy_shost:
10648 lpfc_destroy_shost(phba);
10649out_unset_driver_resource:
10650 lpfc_unset_driver_resource_phase2(phba);
10651out_free_iocb_list:
10652 lpfc_free_iocb_list(phba);
10653out_unset_driver_resource_s3:
10654 lpfc_sli_driver_resource_unset(phba);
10655out_unset_pci_mem_s3:
10656 lpfc_sli_pci_mem_unset(phba);
10657out_disable_pci_dev:
10658 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040010659 if (shost)
10660 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -040010661out_free_phba:
10662 lpfc_hba_free(phba);
10663 return error;
10664}
10665
10666/**
10667 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -040010668 * @pdev: pointer to PCI device
10669 *
James Smart3772a992009-05-22 14:50:54 -040010670 * This routine is to be called to disattach a device with SLI-3 interface
10671 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10672 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10673 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -040010674 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010675static void
James Smart3772a992009-05-22 14:50:54 -040010676lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -050010677{
James Smart2e0fef82007-06-17 19:56:36 -050010678 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10679 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -050010680 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -050010681 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -050010682 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -050010683
James Smart549e55c2007-08-02 11:09:51 -040010684 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -040010685 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -040010686 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -050010687
James Smart858c9f62007-06-17 19:56:39 -050010688 lpfc_free_sysfs_attr(vport);
10689
James Smarteada2722008-12-04 22:39:13 -050010690 /* Release all the vports against this physical port */
10691 vports = lpfc_create_vport_work_array(phba);
10692 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040010693 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10694 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
10695 continue;
James Smarteada2722008-12-04 22:39:13 -050010696 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040010697 }
James Smarteada2722008-12-04 22:39:13 -050010698 lpfc_destroy_vport_work_array(phba, vports);
10699
10700 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -050010701 fc_remove_host(shost);
10702 scsi_remove_host(shost);
James Smartd613b6a2017-02-12 13:52:37 -080010703
James Smart87af33f2007-10-27 13:37:43 -040010704 lpfc_cleanup(vport);
10705
James Smart2e0fef82007-06-17 19:56:36 -050010706 /*
10707 * Bring down the SLI Layer. This step disable all interrupts,
10708 * clears the rings, discards all mailbox commands, and resets
10709 * the HBA.
10710 */
James Smarta257bf92009-04-06 18:48:10 -040010711
Justin P. Mattock48e34d02010-12-30 15:07:58 -080010712 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -050010713 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -040010714 /* Stop kthread signal shall trigger work_done one more time */
10715 kthread_stop(phba->worker_thread);
10716 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -050010717 lpfc_sli_brdrestart(phba);
10718
James Smart72859902012-01-18 16:25:38 -050010719 kfree(phba->vpi_bmask);
10720 kfree(phba->vpi_ids);
10721
James Smart3772a992009-05-22 14:50:54 -040010722 lpfc_stop_hba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -050010723 spin_lock_irq(&phba->hbalock);
10724 list_del_init(&vport->listentry);
10725 spin_unlock_irq(&phba->hbalock);
10726
James Smart858c9f62007-06-17 19:56:39 -050010727 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -050010728
James Smart912e3ac2011-05-24 11:42:11 -040010729 /* Disable SR-IOV if enabled */
10730 if (phba->cfg_sriov_nr_virtfn)
10731 pci_disable_sriov(pdev);
10732
James Smart5b75da22008-12-04 22:39:35 -050010733 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -040010734 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -050010735
James Smart858c9f62007-06-17 19:56:39 -050010736 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -050010737
10738 /*
10739 * Call scsi_free before mem_free since scsi bufs are released to their
10740 * corresponding pools here.
10741 */
10742 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -040010743 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -050010744
James Smart34b02dc2008-08-24 21:49:55 -040010745 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
10746 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -050010747
James Smart2e0fef82007-06-17 19:56:36 -050010748 /* Free resources associated with SLI2 interface */
10749 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -040010750 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -050010751
10752 /* unmap adapter SLIM and Control Registers */
10753 iounmap(phba->ctrl_regs_memmap_p);
10754 iounmap(phba->slim_memmap_p);
10755
James Smart3772a992009-05-22 14:50:54 -040010756 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -050010757
Johannes Thumshirne0c04832016-06-07 09:44:03 +020010758 pci_release_mem_regions(pdev);
James Smart2e0fef82007-06-17 19:56:36 -050010759 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -050010760}
10761
Linas Vepstas8d63f372007-02-14 14:28:36 -060010762/**
James Smart3772a992009-05-22 14:50:54 -040010763 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050010764 * @pdev: pointer to PCI device
10765 * @msg: power management message
10766 *
James Smart3772a992009-05-22 14:50:54 -040010767 * This routine is to be called from the kernel's PCI subsystem to support
10768 * system Power Management (PM) to device with SLI-3 interface spec. When
10769 * PM invokes this method, it quiesces the device by stopping the driver's
10770 * worker thread for the device, turning off device's interrupt and DMA,
10771 * and bring the device offline. Note that as the driver implements the
10772 * minimum PM requirements to a power-aware driver's PM support for the
10773 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10774 * to the suspend() method call will be treated as SUSPEND and the driver will
10775 * fully reinitialize its device during resume() method call, the driver will
10776 * set device to PCI_D3hot state in PCI config space instead of setting it
10777 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -050010778 *
10779 * Return code
James Smart3772a992009-05-22 14:50:54 -040010780 * 0 - driver suspended the device
10781 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050010782 **/
10783static int
James Smart3772a992009-05-22 14:50:54 -040010784lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -050010785{
10786 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10787 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10788
10789 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10790 "0473 PCI device Power Management suspend.\n");
10791
10792 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040010793 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -050010794 lpfc_offline(phba);
10795 kthread_stop(phba->worker_thread);
10796
10797 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -040010798 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -050010799
10800 /* Save device state to PCI config space */
10801 pci_save_state(pdev);
10802 pci_set_power_state(pdev, PCI_D3hot);
10803
10804 return 0;
10805}
10806
10807/**
James Smart3772a992009-05-22 14:50:54 -040010808 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050010809 * @pdev: pointer to PCI device
10810 *
James Smart3772a992009-05-22 14:50:54 -040010811 * This routine is to be called from the kernel's PCI subsystem to support
10812 * system Power Management (PM) to device with SLI-3 interface spec. When PM
10813 * invokes this method, it restores the device's PCI config space state and
10814 * fully reinitializes the device and brings it online. Note that as the
10815 * driver implements the minimum PM requirements to a power-aware driver's
10816 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
10817 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
10818 * driver will fully reinitialize its device during resume() method call,
10819 * the device will be set to PCI_D0 directly in PCI config space before
10820 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -050010821 *
10822 * Return code
James Smart3772a992009-05-22 14:50:54 -040010823 * 0 - driver suspended the device
10824 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050010825 **/
10826static int
James Smart3772a992009-05-22 14:50:54 -040010827lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -050010828{
10829 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10830 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -050010831 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050010832 int error;
10833
10834 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10835 "0452 PCI device Power Management resume.\n");
10836
10837 /* Restore device state from PCI config space */
10838 pci_set_power_state(pdev, PCI_D0);
10839 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -040010840
James Smart1dfb5a42010-02-12 14:40:50 -050010841 /*
10842 * As the new kernel behavior of pci_restore_state() API call clears
10843 * device saved_state flag, need to save the restored state again.
10844 */
10845 pci_save_state(pdev);
10846
James Smart3a55b532008-12-04 22:38:54 -050010847 if (pdev->is_busmaster)
10848 pci_set_master(pdev);
10849
10850 /* Startup the kernel thread for this host adapter. */
10851 phba->worker_thread = kthread_run(lpfc_do_work, phba,
10852 "lpfc_worker_%d", phba->brd_no);
10853 if (IS_ERR(phba->worker_thread)) {
10854 error = PTR_ERR(phba->worker_thread);
10855 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10856 "0434 PM resume failed to start worker "
10857 "thread: error=x%x.\n", error);
10858 return error;
10859 }
10860
James Smart5b75da22008-12-04 22:39:35 -050010861 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040010862 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050010863 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -050010864 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -050010865 "0430 PM resume Failed to enable interrupt\n");
10866 return -EIO;
10867 } else
10868 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050010869
10870 /* Restart HBA and bring it online */
10871 lpfc_sli_brdrestart(phba);
10872 lpfc_online(phba);
10873
James Smart5b75da22008-12-04 22:39:35 -050010874 /* Log the current active interrupt mode */
10875 lpfc_log_intr_mode(phba, phba->intr_mode);
10876
James Smart3a55b532008-12-04 22:38:54 -050010877 return 0;
10878}
10879
10880/**
James Smart891478a2009-11-18 15:40:23 -050010881 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
10882 * @phba: pointer to lpfc hba data structure.
10883 *
10884 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -040010885 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -050010886 **/
10887static void
10888lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
10889{
10890 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10891 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -040010892
10893 /*
10894 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10895 * and let the SCSI mid-layer to retry them to recover.
10896 */
James Smartdb55fba2014-04-04 13:52:02 -040010897 lpfc_sli_abort_fcp_rings(phba);
James Smart891478a2009-11-18 15:40:23 -050010898}
10899
10900/**
James Smart0d878412009-10-02 15:16:56 -040010901 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
10902 * @phba: pointer to lpfc hba data structure.
10903 *
10904 * This routine is called to prepare the SLI3 device for PCI slot reset. It
10905 * disables the device interrupt and pci device, and aborts the internal FCP
10906 * pending I/Os.
10907 **/
10908static void
10909lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
10910{
James Smart0d878412009-10-02 15:16:56 -040010911 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050010912 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -040010913
James Smart75baf692010-06-08 18:31:21 -040010914 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040010915 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010916
James Smarte2af0d22010-03-15 11:25:32 -040010917 /* Block all SCSI devices' I/Os on the host */
10918 lpfc_scsi_dev_block(phba);
10919
James Smartea714f32013-04-17 20:18:47 -040010920 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10921 lpfc_sli_flush_fcp_rings(phba);
10922
James Smarte2af0d22010-03-15 11:25:32 -040010923 /* stop all timers */
10924 lpfc_stop_hba_timers(phba);
10925
James Smart0d878412009-10-02 15:16:56 -040010926 /* Disable interrupt and pci device */
10927 lpfc_sli_disable_intr(phba);
10928 pci_disable_device(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -040010929}
10930
10931/**
10932 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
10933 * @phba: pointer to lpfc hba data structure.
10934 *
10935 * This routine is called to prepare the SLI3 device for PCI slot permanently
10936 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10937 * pending I/Os.
10938 **/
10939static void
James Smart75baf692010-06-08 18:31:21 -040010940lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -040010941{
10942 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050010943 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -040010944 /* Block all SCSI devices' I/Os on the host */
10945 lpfc_scsi_dev_block(phba);
10946
10947 /* stop all timers */
10948 lpfc_stop_hba_timers(phba);
10949
James Smart0d878412009-10-02 15:16:56 -040010950 /* Clean up all driver's outstanding SCSI I/Os */
10951 lpfc_sli_flush_fcp_rings(phba);
10952}
10953
10954/**
James Smart3772a992009-05-22 14:50:54 -040010955 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -040010956 * @pdev: pointer to PCI device.
10957 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010958 *
James Smart3772a992009-05-22 14:50:54 -040010959 * This routine is called from the PCI subsystem for I/O error handling to
10960 * device with SLI-3 interface spec. This function is called by the PCI
10961 * subsystem after a PCI bus error affecting this device has been detected.
10962 * When this function is invoked, it will need to stop all the I/Os and
10963 * interrupt(s) to the device. Once that is done, it will return
10964 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
10965 * as desired.
James Smarte59058c2008-08-24 21:49:00 -040010966 *
10967 * Return codes
James Smart0d878412009-10-02 15:16:56 -040010968 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -040010969 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10970 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -040010971 **/
James Smart3772a992009-05-22 14:50:54 -040010972static pci_ers_result_t
10973lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010974{
James Smart51ef4c22007-08-02 11:10:31 -040010975 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10976 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010977
James Smart0d878412009-10-02 15:16:56 -040010978 switch (state) {
10979 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -050010980 /* Non-fatal error, prepare for recovery */
10981 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -040010982 return PCI_ERS_RESULT_CAN_RECOVER;
10983 case pci_channel_io_frozen:
10984 /* Fatal error, prepare for slot reset */
10985 lpfc_sli_prep_dev_for_reset(phba);
10986 return PCI_ERS_RESULT_NEED_RESET;
10987 case pci_channel_io_perm_failure:
10988 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -040010989 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010990 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -040010991 default:
10992 /* Unknown state, prepare and request slot reset */
10993 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10994 "0472 Unknown PCI error state: x%x\n", state);
10995 lpfc_sli_prep_dev_for_reset(phba);
10996 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -040010997 }
Linas Vepstas8d63f372007-02-14 14:28:36 -060010998}
10999
11000/**
James Smart3772a992009-05-22 14:50:54 -040011001 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -040011002 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -060011003 *
James Smart3772a992009-05-22 14:50:54 -040011004 * This routine is called from the PCI subsystem for error handling to
11005 * device with SLI-3 interface spec. This is called after PCI bus has been
11006 * reset to restart the PCI card from scratch, as if from a cold-boot.
11007 * During the PCI subsystem error recovery, after driver returns
11008 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
11009 * recovery and then call this routine before calling the .resume method
11010 * to recover the device. This function will initialize the HBA device,
11011 * enable the interrupt, but it will just put the HBA to offline state
11012 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -040011013 *
11014 * Return codes
James Smart3772a992009-05-22 14:50:54 -040011015 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11016 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -060011017 */
James Smart3772a992009-05-22 14:50:54 -040011018static pci_ers_result_t
11019lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060011020{
James Smart51ef4c22007-08-02 11:10:31 -040011021 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11022 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011023 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -050011024 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011025
11026 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +110011027 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -060011028 printk(KERN_ERR "lpfc: Cannot re-enable "
11029 "PCI device after reset.\n");
11030 return PCI_ERS_RESULT_DISCONNECT;
11031 }
11032
James Smart97207482008-12-04 22:39:19 -050011033 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050011034
11035 /*
11036 * As the new kernel behavior of pci_restore_state() API call clears
11037 * device saved_state flag, need to save the restored state again.
11038 */
11039 pci_save_state(pdev);
11040
James Smart97207482008-12-04 22:39:19 -050011041 if (pdev->is_busmaster)
11042 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011043
James Smart92d7f7b2007-06-17 19:56:38 -050011044 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040011045 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -050011046 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011047
James Smart5b75da22008-12-04 22:39:35 -050011048 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040011049 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050011050 if (intr_mode == LPFC_INTR_ERROR) {
11051 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11052 "0427 Cannot re-enable interrupt after "
11053 "slot reset.\n");
11054 return PCI_ERS_RESULT_DISCONNECT;
11055 } else
11056 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011057
James Smart75baf692010-06-08 18:31:21 -040011058 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -040011059 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011060 lpfc_offline(phba);
11061 lpfc_sli_brdrestart(phba);
11062
James Smart5b75da22008-12-04 22:39:35 -050011063 /* Log the current active interrupt mode */
11064 lpfc_log_intr_mode(phba, phba->intr_mode);
11065
Linas Vepstas8d63f372007-02-14 14:28:36 -060011066 return PCI_ERS_RESULT_RECOVERED;
11067}
11068
11069/**
James Smart3772a992009-05-22 14:50:54 -040011070 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -040011071 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -060011072 *
James Smart3772a992009-05-22 14:50:54 -040011073 * This routine is called from the PCI subsystem for error handling to device
11074 * with SLI-3 interface spec. It is called when kernel error recovery tells
11075 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
11076 * error recovery. After this call, traffic can start to flow from this device
11077 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -060011078 */
James Smart3772a992009-05-22 14:50:54 -040011079static void
11080lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060011081{
James Smart51ef4c22007-08-02 11:10:31 -040011082 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11083 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011084
James Smarte2af0d22010-03-15 11:25:32 -040011085 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -040011086 lpfc_online(phba);
James Smart0d878412009-10-02 15:16:56 -040011087
11088 /* Clean up Advanced Error Reporting (AER) if needed */
11089 if (phba->hba_flag & HBA_AER_ENABLED)
11090 pci_cleanup_aer_uncorrect_error_status(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011091}
11092
James Smart3772a992009-05-22 14:50:54 -040011093/**
James Smartda0436e2009-05-22 14:51:39 -040011094 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
11095 * @phba: pointer to lpfc hba data structure.
11096 *
11097 * returns the number of ELS/CT IOCBs to reserve
11098 **/
11099int
11100lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
11101{
11102 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
11103
James Smartf1126682009-06-10 17:22:44 -040011104 if (phba->sli_rev == LPFC_SLI_REV4) {
11105 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -040011106 return 10;
James Smartf1126682009-06-10 17:22:44 -040011107 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -040011108 return 25;
James Smartf1126682009-06-10 17:22:44 -040011109 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -040011110 return 50;
James Smartf1126682009-06-10 17:22:44 -040011111 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -040011112 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -040011113 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -040011114 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -040011115 else if (max_xri <= 2048)
11116 return 200;
11117 else
11118 return 250;
James Smartf1126682009-06-10 17:22:44 -040011119 } else
11120 return 0;
James Smartda0436e2009-05-22 14:51:39 -040011121}
11122
11123/**
James Smart895427b2017-02-12 13:52:30 -080011124 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
11125 * @phba: pointer to lpfc hba data structure.
11126 *
James Smartf358dd02017-02-12 13:52:34 -080011127 * returns the number of ELS/CT + NVMET IOCBs to reserve
James Smart895427b2017-02-12 13:52:30 -080011128 **/
11129int
11130lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
11131{
11132 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
11133
James Smartf358dd02017-02-12 13:52:34 -080011134 if (phba->nvmet_support)
11135 max_xri += LPFC_NVMET_BUF_POST;
James Smart895427b2017-02-12 13:52:30 -080011136 return max_xri;
11137}
11138
11139
11140/**
James Smart52d52442011-05-24 11:42:45 -040011141 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -040011142 * @fw: pointer to firmware image returned from request_firmware.
James Smartce396282012-09-29 11:30:56 -040011143 * @phba: pointer to lpfc hba data structure.
James Smart52d52442011-05-24 11:42:45 -040011144 *
James Smart52d52442011-05-24 11:42:45 -040011145 **/
James Smartce396282012-09-29 11:30:56 -040011146static void
11147lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -040011148{
James Smartce396282012-09-29 11:30:56 -040011149 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -050011150 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -040011151 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -040011152 struct list_head dma_buffer_list;
11153 int i, rc = 0;
11154 struct lpfc_dmabuf *dmabuf, *next;
11155 uint32_t offset = 0, temp_offset = 0;
James Smart6b6ef5d2016-10-13 15:06:17 -070011156 uint32_t magic_number, ftype, fid, fsize;
James Smart52d52442011-05-24 11:42:45 -040011157
James Smartc71ab862012-10-31 14:44:33 -040011158 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -040011159 if (!fw) {
11160 rc = -ENXIO;
11161 goto out;
11162 }
11163 image = (struct lpfc_grp_hdr *)fw->data;
11164
James Smart6b6ef5d2016-10-13 15:06:17 -070011165 magic_number = be32_to_cpu(image->magic_number);
11166 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
11167 fid = bf_get_be32(lpfc_grp_hdr_id, image),
11168 fsize = be32_to_cpu(image->size);
11169
James Smart52d52442011-05-24 11:42:45 -040011170 INIT_LIST_HEAD(&dma_buffer_list);
James Smart6b6ef5d2016-10-13 15:06:17 -070011171 if ((magic_number != LPFC_GROUP_OJECT_MAGIC_G5 &&
11172 magic_number != LPFC_GROUP_OJECT_MAGIC_G6) ||
11173 ftype != LPFC_FILE_TYPE_GROUP || fsize != fw->size) {
James Smart52d52442011-05-24 11:42:45 -040011174 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11175 "3022 Invalid FW image found. "
Arnd Bergmannefe583c2016-10-17 14:35:46 +020011176 "Magic:%x Type:%x ID:%x Size %d %zd\n",
James Smart6b6ef5d2016-10-13 15:06:17 -070011177 magic_number, ftype, fid, fsize, fw->size);
James Smartce396282012-09-29 11:30:56 -040011178 rc = -EINVAL;
11179 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040011180 }
11181 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -040011182 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -040011183 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartce396282012-09-29 11:30:56 -040011184 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -040011185 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -040011186 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -040011187 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
11188 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
11189 GFP_KERNEL);
11190 if (!dmabuf) {
11191 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040011192 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040011193 }
11194 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
11195 SLI4_PAGE_SIZE,
11196 &dmabuf->phys,
11197 GFP_KERNEL);
11198 if (!dmabuf->virt) {
11199 kfree(dmabuf);
11200 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040011201 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040011202 }
11203 list_add_tail(&dmabuf->list, &dma_buffer_list);
11204 }
11205 while (offset < fw->size) {
11206 temp_offset = offset;
11207 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -040011208 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -040011209 memcpy(dmabuf->virt,
11210 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -040011211 fw->size - temp_offset);
11212 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -040011213 break;
11214 }
James Smart52d52442011-05-24 11:42:45 -040011215 memcpy(dmabuf->virt, fw->data + temp_offset,
11216 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -040011217 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -040011218 }
11219 rc = lpfc_wr_object(phba, &dma_buffer_list,
11220 (fw->size - offset), &offset);
James Smartce396282012-09-29 11:30:56 -040011221 if (rc)
11222 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040011223 }
11224 rc = offset;
11225 }
James Smartce396282012-09-29 11:30:56 -040011226
11227release_out:
James Smart52d52442011-05-24 11:42:45 -040011228 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
11229 list_del(&dmabuf->list);
11230 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
11231 dmabuf->virt, dmabuf->phys);
11232 kfree(dmabuf);
11233 }
James Smartce396282012-09-29 11:30:56 -040011234 release_firmware(fw);
11235out:
11236 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc71ab862012-10-31 14:44:33 -040011237 "3024 Firmware update done: %d.\n", rc);
James Smartce396282012-09-29 11:30:56 -040011238 return;
James Smart52d52442011-05-24 11:42:45 -040011239}
11240
11241/**
James Smartc71ab862012-10-31 14:44:33 -040011242 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
11243 * @phba: pointer to lpfc hba data structure.
11244 *
11245 * This routine is called to perform Linux generic firmware upgrade on device
11246 * that supports such feature.
11247 **/
11248int
11249lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
11250{
11251 uint8_t file_name[ELX_MODEL_NAME_SIZE];
11252 int ret;
11253 const struct firmware *fw;
11254
11255 /* Only supported on SLI4 interface type 2 for now */
11256 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
11257 LPFC_SLI_INTF_IF_TYPE_2)
11258 return -EPERM;
11259
11260 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
11261
11262 if (fw_upgrade == INT_FW_UPGRADE) {
11263 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
11264 file_name, &phba->pcidev->dev,
11265 GFP_KERNEL, (void *)phba,
11266 lpfc_write_firmware);
11267 } else if (fw_upgrade == RUN_FW_UPGRADE) {
11268 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
11269 if (!ret)
11270 lpfc_write_firmware(fw, (void *)phba);
11271 } else {
11272 ret = -EINVAL;
11273 }
11274
11275 return ret;
11276}
11277
11278/**
James Smartda0436e2009-05-22 14:51:39 -040011279 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
11280 * @pdev: pointer to PCI device
11281 * @pid: pointer to PCI device identifier
11282 *
11283 * This routine is called from the kernel's PCI subsystem to device with
11284 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11285 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
11286 * information of the device and driver to see if the driver state that it
11287 * can support this kind of device. If the match is successful, the driver
11288 * core invokes this routine. If this routine determines it can claim the HBA,
11289 * it does all the initialization that it needs to do to handle the HBA
11290 * properly.
11291 *
11292 * Return code
11293 * 0 - driver can claim the device
11294 * negative value - driver can not claim the device
11295 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011296static int
James Smartda0436e2009-05-22 14:51:39 -040011297lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
11298{
11299 struct lpfc_hba *phba;
11300 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040011301 struct Scsi_Host *shost = NULL;
James Smart6c621a22017-05-15 15:20:45 -070011302 int error;
James Smartda0436e2009-05-22 14:51:39 -040011303 uint32_t cfg_mode, intr_mode;
James Smartda0436e2009-05-22 14:51:39 -040011304
11305 /* Allocate memory for HBA structure */
11306 phba = lpfc_hba_alloc(pdev);
11307 if (!phba)
11308 return -ENOMEM;
11309
11310 /* Perform generic PCI device enabling operation */
11311 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040011312 if (error)
James Smartda0436e2009-05-22 14:51:39 -040011313 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -040011314
11315 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
11316 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
11317 if (error)
11318 goto out_disable_pci_dev;
11319
11320 /* Set up SLI-4 specific device PCI memory space */
11321 error = lpfc_sli4_pci_mem_setup(phba);
11322 if (error) {
11323 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11324 "1410 Failed to set up pci memory space.\n");
11325 goto out_disable_pci_dev;
11326 }
11327
James Smartda0436e2009-05-22 14:51:39 -040011328 /* Set up SLI-4 Specific device driver resources */
11329 error = lpfc_sli4_driver_resource_setup(phba);
11330 if (error) {
11331 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11332 "1412 Failed to set up driver resource.\n");
11333 goto out_unset_pci_mem_s4;
11334 }
11335
James Smart19ca7602010-11-20 23:11:55 -050011336 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -040011337 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -050011338
James Smartda0436e2009-05-22 14:51:39 -040011339 /* Set up common device driver resources */
11340 error = lpfc_setup_driver_resource_phase2(phba);
11341 if (error) {
11342 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11343 "1414 Failed to set up driver resource.\n");
James Smart6c621a22017-05-15 15:20:45 -070011344 goto out_unset_driver_resource_s4;
James Smartda0436e2009-05-22 14:51:39 -040011345 }
11346
James Smart079b5c92011-08-21 21:48:49 -040011347 /* Get the default values for Model Name and Description */
11348 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
11349
James Smartda0436e2009-05-22 14:51:39 -040011350 /* Create SCSI host to the physical port */
11351 error = lpfc_create_shost(phba);
11352 if (error) {
11353 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11354 "1415 Failed to create scsi host.\n");
11355 goto out_unset_driver_resource;
11356 }
11357
11358 /* Configure sysfs attributes */
11359 vport = phba->pport;
11360 error = lpfc_alloc_sysfs_attr(vport);
11361 if (error) {
11362 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11363 "1416 Failed to allocate sysfs attr\n");
11364 goto out_destroy_shost;
11365 }
11366
James Smart6669f9b2009-10-02 15:16:45 -040011367 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -040011368 /* Now, trying to enable interrupt and bring up the device */
11369 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -040011370
James Smart7b15db32013-01-03 15:43:29 -050011371 /* Put device to a known state before enabling interrupt */
11372 lpfc_stop_port(phba);
James Smart895427b2017-02-12 13:52:30 -080011373
James Smart7b15db32013-01-03 15:43:29 -050011374 /* Configure and enable interrupt */
11375 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
11376 if (intr_mode == LPFC_INTR_ERROR) {
11377 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11378 "0426 Failed to enable interrupt.\n");
11379 error = -ENODEV;
11380 goto out_free_sysfs_attr;
James Smartda0436e2009-05-22 14:51:39 -040011381 }
James Smart7b15db32013-01-03 15:43:29 -050011382 /* Default to single EQ for non-MSI-X */
James Smart895427b2017-02-12 13:52:30 -080011383 if (phba->intr_type != MSIX) {
11384 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
11385 phba->cfg_fcp_io_channel = 1;
James Smart2d7dbc42017-02-12 13:52:35 -080011386 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -080011387 phba->cfg_nvme_io_channel = 1;
James Smart2d7dbc42017-02-12 13:52:35 -080011388 if (phba->nvmet_support)
11389 phba->cfg_nvmet_mrq = 1;
11390 }
James Smart895427b2017-02-12 13:52:30 -080011391 phba->io_channel_irqs = 1;
11392 }
11393
James Smart7b15db32013-01-03 15:43:29 -050011394 /* Set up SLI-4 HBA */
11395 if (lpfc_sli4_hba_setup(phba)) {
11396 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11397 "1421 Failed to set up hba\n");
11398 error = -ENODEV;
11399 goto out_disable_intr;
11400 }
11401
11402 /* Log the current active interrupt mode */
11403 phba->intr_mode = intr_mode;
11404 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -040011405
11406 /* Perform post initialization setup */
11407 lpfc_post_init_setup(phba);
11408
James Smart01649562017-02-12 13:52:32 -080011409 /* NVME support in FW earlier in the driver load corrects the
11410 * FC4 type making a check for nvme_support unnecessary.
11411 */
11412 if ((phba->nvmet_support == 0) &&
11413 (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
11414 /* Create NVME binding with nvme_fc_transport. This
James Smartd1f525a2017-04-21 16:04:55 -070011415 * ensures the vport is initialized. If the localport
11416 * create fails, it should not unload the driver to
11417 * support field issues.
James Smart01649562017-02-12 13:52:32 -080011418 */
11419 error = lpfc_nvme_create_localport(vport);
11420 if (error) {
11421 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11422 "6004 NVME registration failed, "
11423 "error x%x\n",
11424 error);
James Smart01649562017-02-12 13:52:32 -080011425 }
11426 }
James Smart895427b2017-02-12 13:52:30 -080011427
James Smartc71ab862012-10-31 14:44:33 -040011428 /* check for firmware upgrade or downgrade */
11429 if (phba->cfg_request_firmware_upgrade)
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040011430 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -040011431
James Smart1c6834a2009-07-19 10:01:26 -040011432 /* Check if there are static vports to be created. */
11433 lpfc_create_static_vport(phba);
James Smartda0436e2009-05-22 14:51:39 -040011434 return 0;
11435
11436out_disable_intr:
11437 lpfc_sli4_disable_intr(phba);
11438out_free_sysfs_attr:
11439 lpfc_free_sysfs_attr(vport);
11440out_destroy_shost:
11441 lpfc_destroy_shost(phba);
11442out_unset_driver_resource:
11443 lpfc_unset_driver_resource_phase2(phba);
James Smartda0436e2009-05-22 14:51:39 -040011444out_unset_driver_resource_s4:
11445 lpfc_sli4_driver_resource_unset(phba);
11446out_unset_pci_mem_s4:
11447 lpfc_sli4_pci_mem_unset(phba);
11448out_disable_pci_dev:
11449 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040011450 if (shost)
11451 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -040011452out_free_phba:
11453 lpfc_hba_free(phba);
11454 return error;
11455}
11456
11457/**
11458 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
11459 * @pdev: pointer to PCI device
11460 *
11461 * This routine is called from the kernel's PCI subsystem to device with
11462 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11463 * removed from PCI bus, it performs all the necessary cleanup for the HBA
11464 * device to be removed from the PCI subsystem properly.
11465 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011466static void
James Smartda0436e2009-05-22 14:51:39 -040011467lpfc_pci_remove_one_s4(struct pci_dev *pdev)
11468{
11469 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11470 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
11471 struct lpfc_vport **vports;
11472 struct lpfc_hba *phba = vport->phba;
11473 int i;
11474
11475 /* Mark the device unloading flag */
11476 spin_lock_irq(&phba->hbalock);
11477 vport->load_flag |= FC_UNLOADING;
11478 spin_unlock_irq(&phba->hbalock);
11479
11480 /* Free the HBA sysfs attributes */
11481 lpfc_free_sysfs_attr(vport);
11482
11483 /* Release all the vports against this physical port */
11484 vports = lpfc_create_vport_work_array(phba);
11485 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040011486 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
11487 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
11488 continue;
James Smartda0436e2009-05-22 14:51:39 -040011489 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040011490 }
James Smartda0436e2009-05-22 14:51:39 -040011491 lpfc_destroy_vport_work_array(phba, vports);
11492
11493 /* Remove FC host and then SCSI host with the physical port */
11494 fc_remove_host(shost);
11495 scsi_remove_host(shost);
James Smartda0436e2009-05-22 14:51:39 -040011496 /*
11497 * Bring down the SLI Layer. This step disables all interrupts,
11498 * clears the rings, discards all mailbox commands, and resets
11499 * the HBA FCoE function.
11500 */
11501 lpfc_debugfs_terminate(vport);
11502 lpfc_sli4_hba_unset(phba);
11503
James Smartda0436e2009-05-22 14:51:39 -040011504 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
11505 * localports are destroyed after to cleanup all transport memory.
11506 */
11507 lpfc_cleanup(vport);
11508 lpfc_nvmet_destroy_targetport(phba);
11509 lpfc_nvme_destroy_localport(vport);
11510
James Smartda0436e2009-05-22 14:51:39 -040011511
Dick Kennedy19017622017-09-29 17:34:27 -070011512 lpfc_stop_hba_timers(phba);
James Smartda0436e2009-05-22 14:51:39 -040011513 spin_lock_irq(&phba->hbalock);
11514 list_del_init(&vport->listentry);
11515 spin_unlock_irq(&phba->hbalock);
11516
James Smart3677a3a2010-09-29 11:19:14 -040011517 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -040011518 * buffers are released to their corresponding pools here.
11519 */
11520 lpfc_scsi_free(phba);
James Smart895427b2017-02-12 13:52:30 -080011521 lpfc_nvme_free(phba);
James Smart01649562017-02-12 13:52:32 -080011522 lpfc_free_iocb_list(phba);
James Smart67d12732012-08-03 12:36:13 -040011523
James Smartda0436e2009-05-22 14:51:39 -040011524 lpfc_sli4_driver_resource_unset(phba);
11525
11526 /* Unmap adapter Control and Doorbell registers */
11527 lpfc_sli4_pci_mem_unset(phba);
11528
11529 /* Release PCI resources and disable device's PCI function */
11530 scsi_host_put(shost);
11531 lpfc_disable_pci_dev(phba);
11532
11533 /* Finally, free the driver's device data structure */
11534 lpfc_hba_free(phba);
11535
11536 return;
11537}
11538
11539/**
11540 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
11541 * @pdev: pointer to PCI device
11542 * @msg: power management message
11543 *
11544 * This routine is called from the kernel's PCI subsystem to support system
11545 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
11546 * this method, it quiesces the device by stopping the driver's worker
11547 * thread for the device, turning off device's interrupt and DMA, and bring
11548 * the device offline. Note that as the driver implements the minimum PM
11549 * requirements to a power-aware driver's PM support for suspend/resume -- all
11550 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
11551 * method call will be treated as SUSPEND and the driver will fully
11552 * reinitialize its device during resume() method call, the driver will set
11553 * device to PCI_D3hot state in PCI config space instead of setting it
11554 * according to the @msg provided by the PM.
11555 *
11556 * Return code
11557 * 0 - driver suspended the device
11558 * Error otherwise
11559 **/
11560static int
11561lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
11562{
11563 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11564 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11565
11566 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -040011567 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -040011568
11569 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040011570 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -040011571 lpfc_offline(phba);
11572 kthread_stop(phba->worker_thread);
11573
11574 /* Disable interrupt from device */
11575 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040011576 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040011577
11578 /* Save device state to PCI config space */
11579 pci_save_state(pdev);
11580 pci_set_power_state(pdev, PCI_D3hot);
11581
11582 return 0;
11583}
11584
11585/**
11586 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
11587 * @pdev: pointer to PCI device
11588 *
11589 * This routine is called from the kernel's PCI subsystem to support system
11590 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
11591 * this method, it restores the device's PCI config space state and fully
11592 * reinitializes the device and brings it online. Note that as the driver
11593 * implements the minimum PM requirements to a power-aware driver's PM for
11594 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
11595 * to the suspend() method call will be treated as SUSPEND and the driver
11596 * will fully reinitialize its device during resume() method call, the device
11597 * will be set to PCI_D0 directly in PCI config space before restoring the
11598 * state.
11599 *
11600 * Return code
11601 * 0 - driver suspended the device
11602 * Error otherwise
11603 **/
11604static int
11605lpfc_pci_resume_one_s4(struct pci_dev *pdev)
11606{
11607 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11608 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11609 uint32_t intr_mode;
11610 int error;
11611
11612 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11613 "0292 PCI device Power Management resume.\n");
11614
11615 /* Restore device state from PCI config space */
11616 pci_set_power_state(pdev, PCI_D0);
11617 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050011618
11619 /*
11620 * As the new kernel behavior of pci_restore_state() API call clears
11621 * device saved_state flag, need to save the restored state again.
11622 */
11623 pci_save_state(pdev);
11624
James Smartda0436e2009-05-22 14:51:39 -040011625 if (pdev->is_busmaster)
11626 pci_set_master(pdev);
11627
11628 /* Startup the kernel thread for this host adapter. */
11629 phba->worker_thread = kthread_run(lpfc_do_work, phba,
11630 "lpfc_worker_%d", phba->brd_no);
11631 if (IS_ERR(phba->worker_thread)) {
11632 error = PTR_ERR(phba->worker_thread);
11633 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11634 "0293 PM resume failed to start worker "
11635 "thread: error=x%x.\n", error);
11636 return error;
11637 }
11638
11639 /* Configure and enable interrupt */
11640 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
11641 if (intr_mode == LPFC_INTR_ERROR) {
11642 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11643 "0294 PM resume Failed to enable interrupt\n");
11644 return -EIO;
11645 } else
11646 phba->intr_mode = intr_mode;
11647
11648 /* Restart HBA and bring it online */
11649 lpfc_sli_brdrestart(phba);
11650 lpfc_online(phba);
11651
11652 /* Log the current active interrupt mode */
11653 lpfc_log_intr_mode(phba, phba->intr_mode);
11654
11655 return 0;
11656}
11657
11658/**
James Smart75baf692010-06-08 18:31:21 -040011659 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
11660 * @phba: pointer to lpfc hba data structure.
11661 *
11662 * This routine is called to prepare the SLI4 device for PCI slot recover. It
11663 * aborts all the outstanding SCSI I/Os to the pci device.
11664 **/
11665static void
11666lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
11667{
James Smart75baf692010-06-08 18:31:21 -040011668 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11669 "2828 PCI channel I/O abort preparing for recovery\n");
11670 /*
11671 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
11672 * and let the SCSI mid-layer to retry them to recover.
11673 */
James Smartdb55fba2014-04-04 13:52:02 -040011674 lpfc_sli_abort_fcp_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040011675}
11676
11677/**
11678 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
11679 * @phba: pointer to lpfc hba data structure.
11680 *
11681 * This routine is called to prepare the SLI4 device for PCI slot reset. It
11682 * disables the device interrupt and pci device, and aborts the internal FCP
11683 * pending I/Os.
11684 **/
11685static void
11686lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
11687{
11688 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11689 "2826 PCI channel disable preparing for reset\n");
11690
11691 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040011692 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -040011693
11694 /* Block all SCSI devices' I/Os on the host */
11695 lpfc_scsi_dev_block(phba);
11696
James Smartea714f32013-04-17 20:18:47 -040011697 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
11698 lpfc_sli_flush_fcp_rings(phba);
11699
James Smartc3725bd2017-11-20 16:00:42 -080011700 /* Flush the outstanding NVME IOs if fc4 type enabled. */
11701 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
11702 lpfc_sli_flush_nvme_rings(phba);
11703
James Smart75baf692010-06-08 18:31:21 -040011704 /* stop all timers */
11705 lpfc_stop_hba_timers(phba);
11706
11707 /* Disable interrupt and pci device */
11708 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040011709 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -040011710 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -040011711}
11712
11713/**
11714 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
11715 * @phba: pointer to lpfc hba data structure.
11716 *
11717 * This routine is called to prepare the SLI4 device for PCI slot permanently
11718 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
11719 * pending I/Os.
11720 **/
11721static void
11722lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
11723{
11724 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11725 "2827 PCI channel permanent disable for failure\n");
11726
11727 /* Block all SCSI devices' I/Os on the host */
11728 lpfc_scsi_dev_block(phba);
11729
11730 /* stop all timers */
11731 lpfc_stop_hba_timers(phba);
11732
11733 /* Clean up all driver's outstanding SCSI I/Os */
11734 lpfc_sli_flush_fcp_rings(phba);
James Smartc3725bd2017-11-20 16:00:42 -080011735
11736 /* Flush the outstanding NVME IOs if fc4 type enabled. */
11737 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
11738 lpfc_sli_flush_nvme_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040011739}
11740
11741/**
James Smartda0436e2009-05-22 14:51:39 -040011742 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
11743 * @pdev: pointer to PCI device.
11744 * @state: the current PCI connection state.
11745 *
11746 * This routine is called from the PCI subsystem for error handling to device
11747 * with SLI-4 interface spec. This function is called by the PCI subsystem
11748 * after a PCI bus error affecting this device has been detected. When this
11749 * function is invoked, it will need to stop all the I/Os and interrupt(s)
11750 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
11751 * for the PCI subsystem to perform proper recovery as desired.
11752 *
11753 * Return codes
11754 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11755 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11756 **/
11757static pci_ers_result_t
11758lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
11759{
James Smart75baf692010-06-08 18:31:21 -040011760 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11761 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11762
11763 switch (state) {
11764 case pci_channel_io_normal:
11765 /* Non-fatal error, prepare for recovery */
11766 lpfc_sli4_prep_dev_for_recover(phba);
11767 return PCI_ERS_RESULT_CAN_RECOVER;
11768 case pci_channel_io_frozen:
11769 /* Fatal error, prepare for slot reset */
11770 lpfc_sli4_prep_dev_for_reset(phba);
11771 return PCI_ERS_RESULT_NEED_RESET;
11772 case pci_channel_io_perm_failure:
11773 /* Permanent failure, prepare for device down */
11774 lpfc_sli4_prep_dev_for_perm_failure(phba);
11775 return PCI_ERS_RESULT_DISCONNECT;
11776 default:
11777 /* Unknown state, prepare and request slot reset */
11778 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11779 "2825 Unknown PCI error state: x%x\n", state);
11780 lpfc_sli4_prep_dev_for_reset(phba);
11781 return PCI_ERS_RESULT_NEED_RESET;
11782 }
James Smartda0436e2009-05-22 14:51:39 -040011783}
11784
11785/**
11786 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
11787 * @pdev: pointer to PCI device.
11788 *
11789 * This routine is called from the PCI subsystem for error handling to device
11790 * with SLI-4 interface spec. It is called after PCI bus has been reset to
11791 * restart the PCI card from scratch, as if from a cold-boot. During the
11792 * PCI subsystem error recovery, after the driver returns
11793 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
11794 * recovery and then call this routine before calling the .resume method to
11795 * recover the device. This function will initialize the HBA device, enable
11796 * the interrupt, but it will just put the HBA to offline state without
11797 * passing any I/O traffic.
11798 *
11799 * Return codes
11800 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11801 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11802 */
11803static pci_ers_result_t
11804lpfc_io_slot_reset_s4(struct pci_dev *pdev)
11805{
James Smart75baf692010-06-08 18:31:21 -040011806 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11807 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11808 struct lpfc_sli *psli = &phba->sli;
11809 uint32_t intr_mode;
11810
11811 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
11812 if (pci_enable_device_mem(pdev)) {
11813 printk(KERN_ERR "lpfc: Cannot re-enable "
11814 "PCI device after reset.\n");
11815 return PCI_ERS_RESULT_DISCONNECT;
11816 }
11817
11818 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040011819
11820 /*
11821 * As the new kernel behavior of pci_restore_state() API call clears
11822 * device saved_state flag, need to save the restored state again.
11823 */
11824 pci_save_state(pdev);
11825
James Smart75baf692010-06-08 18:31:21 -040011826 if (pdev->is_busmaster)
11827 pci_set_master(pdev);
11828
11829 spin_lock_irq(&phba->hbalock);
11830 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
11831 spin_unlock_irq(&phba->hbalock);
11832
11833 /* Configure and enable interrupt */
11834 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
11835 if (intr_mode == LPFC_INTR_ERROR) {
11836 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11837 "2824 Cannot re-enable interrupt after "
11838 "slot reset.\n");
11839 return PCI_ERS_RESULT_DISCONNECT;
11840 } else
11841 phba->intr_mode = intr_mode;
11842
11843 /* Log the current active interrupt mode */
11844 lpfc_log_intr_mode(phba, phba->intr_mode);
11845
James Smartda0436e2009-05-22 14:51:39 -040011846 return PCI_ERS_RESULT_RECOVERED;
11847}
11848
11849/**
11850 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
11851 * @pdev: pointer to PCI device
11852 *
11853 * This routine is called from the PCI subsystem for error handling to device
11854 * with SLI-4 interface spec. It is called when kernel error recovery tells
11855 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
11856 * error recovery. After this call, traffic can start to flow from this device
11857 * again.
11858 **/
11859static void
11860lpfc_io_resume_s4(struct pci_dev *pdev)
11861{
James Smart75baf692010-06-08 18:31:21 -040011862 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11863 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11864
11865 /*
11866 * In case of slot reset, as function reset is performed through
11867 * mailbox command which needs DMA to be enabled, this operation
11868 * has to be moved to the io resume phase. Taking device offline
11869 * will perform the necessary cleanup.
11870 */
11871 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
11872 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040011873 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040011874 lpfc_offline(phba);
11875 lpfc_sli_brdrestart(phba);
11876 /* Bring the device back online */
11877 lpfc_online(phba);
11878 }
11879
11880 /* Clean up Advanced Error Reporting (AER) if needed */
11881 if (phba->hba_flag & HBA_AER_ENABLED)
11882 pci_cleanup_aer_uncorrect_error_status(pdev);
James Smartda0436e2009-05-22 14:51:39 -040011883}
11884
11885/**
James Smart3772a992009-05-22 14:50:54 -040011886 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
11887 * @pdev: pointer to PCI device
11888 * @pid: pointer to PCI device identifier
11889 *
11890 * This routine is to be registered to the kernel's PCI subsystem. When an
11891 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
11892 * at PCI device-specific information of the device and driver to see if the
11893 * driver state that it can support this kind of device. If the match is
11894 * successful, the driver core invokes this routine. This routine dispatches
11895 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
11896 * do all the initialization that it needs to do to handle the HBA device
11897 * properly.
11898 *
11899 * Return code
11900 * 0 - driver can claim the device
11901 * negative value - driver can not claim the device
11902 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011903static int
James Smart3772a992009-05-22 14:50:54 -040011904lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
11905{
11906 int rc;
James Smart8fa38512009-07-19 10:01:03 -040011907 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040011908
James Smart28baac72010-02-12 14:42:03 -050011909 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040011910 return -ENODEV;
11911
James Smart8fa38512009-07-19 10:01:03 -040011912 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050011913 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040011914 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040011915 else
James Smart3772a992009-05-22 14:50:54 -040011916 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040011917
James Smart3772a992009-05-22 14:50:54 -040011918 return rc;
11919}
11920
11921/**
11922 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
11923 * @pdev: pointer to PCI device
11924 *
11925 * This routine is to be registered to the kernel's PCI subsystem. When an
11926 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
11927 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
11928 * remove routine, which will perform all the necessary cleanup for the
11929 * device to be removed from the PCI subsystem properly.
11930 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011931static void
James Smart3772a992009-05-22 14:50:54 -040011932lpfc_pci_remove_one(struct pci_dev *pdev)
11933{
11934 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11935 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11936
11937 switch (phba->pci_dev_grp) {
11938 case LPFC_PCI_DEV_LP:
11939 lpfc_pci_remove_one_s3(pdev);
11940 break;
James Smartda0436e2009-05-22 14:51:39 -040011941 case LPFC_PCI_DEV_OC:
11942 lpfc_pci_remove_one_s4(pdev);
11943 break;
James Smart3772a992009-05-22 14:50:54 -040011944 default:
11945 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11946 "1424 Invalid PCI device group: 0x%x\n",
11947 phba->pci_dev_grp);
11948 break;
11949 }
11950 return;
11951}
11952
11953/**
11954 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
11955 * @pdev: pointer to PCI device
11956 * @msg: power management message
11957 *
11958 * This routine is to be registered to the kernel's PCI subsystem to support
11959 * system Power Management (PM). When PM invokes this method, it dispatches
11960 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
11961 * suspend the device.
11962 *
11963 * Return code
11964 * 0 - driver suspended the device
11965 * Error otherwise
11966 **/
11967static int
11968lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
11969{
11970 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11971 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11972 int rc = -ENODEV;
11973
11974 switch (phba->pci_dev_grp) {
11975 case LPFC_PCI_DEV_LP:
11976 rc = lpfc_pci_suspend_one_s3(pdev, msg);
11977 break;
James Smartda0436e2009-05-22 14:51:39 -040011978 case LPFC_PCI_DEV_OC:
11979 rc = lpfc_pci_suspend_one_s4(pdev, msg);
11980 break;
James Smart3772a992009-05-22 14:50:54 -040011981 default:
11982 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11983 "1425 Invalid PCI device group: 0x%x\n",
11984 phba->pci_dev_grp);
11985 break;
11986 }
11987 return rc;
11988}
11989
11990/**
11991 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
11992 * @pdev: pointer to PCI device
11993 *
11994 * This routine is to be registered to the kernel's PCI subsystem to support
11995 * system Power Management (PM). When PM invokes this method, it dispatches
11996 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
11997 * resume the device.
11998 *
11999 * Return code
12000 * 0 - driver suspended the device
12001 * Error otherwise
12002 **/
12003static int
12004lpfc_pci_resume_one(struct pci_dev *pdev)
12005{
12006 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12007 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12008 int rc = -ENODEV;
12009
12010 switch (phba->pci_dev_grp) {
12011 case LPFC_PCI_DEV_LP:
12012 rc = lpfc_pci_resume_one_s3(pdev);
12013 break;
James Smartda0436e2009-05-22 14:51:39 -040012014 case LPFC_PCI_DEV_OC:
12015 rc = lpfc_pci_resume_one_s4(pdev);
12016 break;
James Smart3772a992009-05-22 14:50:54 -040012017 default:
12018 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12019 "1426 Invalid PCI device group: 0x%x\n",
12020 phba->pci_dev_grp);
12021 break;
12022 }
12023 return rc;
12024}
12025
12026/**
12027 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
12028 * @pdev: pointer to PCI device.
12029 * @state: the current PCI connection state.
12030 *
12031 * This routine is registered to the PCI subsystem for error handling. This
12032 * function is called by the PCI subsystem after a PCI bus error affecting
12033 * this device has been detected. When this routine is invoked, it dispatches
12034 * the action to the proper SLI-3 or SLI-4 device error detected handling
12035 * routine, which will perform the proper error detected operation.
12036 *
12037 * Return codes
12038 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
12039 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12040 **/
12041static pci_ers_result_t
12042lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
12043{
12044 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12045 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12046 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
12047
12048 switch (phba->pci_dev_grp) {
12049 case LPFC_PCI_DEV_LP:
12050 rc = lpfc_io_error_detected_s3(pdev, state);
12051 break;
James Smartda0436e2009-05-22 14:51:39 -040012052 case LPFC_PCI_DEV_OC:
12053 rc = lpfc_io_error_detected_s4(pdev, state);
12054 break;
James Smart3772a992009-05-22 14:50:54 -040012055 default:
12056 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12057 "1427 Invalid PCI device group: 0x%x\n",
12058 phba->pci_dev_grp);
12059 break;
12060 }
12061 return rc;
12062}
12063
12064/**
12065 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
12066 * @pdev: pointer to PCI device.
12067 *
12068 * This routine is registered to the PCI subsystem for error handling. This
12069 * function is called after PCI bus has been reset to restart the PCI card
12070 * from scratch, as if from a cold-boot. When this routine is invoked, it
12071 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
12072 * routine, which will perform the proper device reset.
12073 *
12074 * Return codes
12075 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
12076 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12077 **/
12078static pci_ers_result_t
12079lpfc_io_slot_reset(struct pci_dev *pdev)
12080{
12081 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12082 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12083 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
12084
12085 switch (phba->pci_dev_grp) {
12086 case LPFC_PCI_DEV_LP:
12087 rc = lpfc_io_slot_reset_s3(pdev);
12088 break;
James Smartda0436e2009-05-22 14:51:39 -040012089 case LPFC_PCI_DEV_OC:
12090 rc = lpfc_io_slot_reset_s4(pdev);
12091 break;
James Smart3772a992009-05-22 14:50:54 -040012092 default:
12093 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12094 "1428 Invalid PCI device group: 0x%x\n",
12095 phba->pci_dev_grp);
12096 break;
12097 }
12098 return rc;
12099}
12100
12101/**
12102 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
12103 * @pdev: pointer to PCI device
12104 *
12105 * This routine is registered to the PCI subsystem for error handling. It
12106 * is called when kernel error recovery tells the lpfc driver that it is
12107 * OK to resume normal PCI operation after PCI bus error recovery. When
12108 * this routine is invoked, it dispatches the action to the proper SLI-3
12109 * or SLI-4 device io_resume routine, which will resume the device operation.
12110 **/
12111static void
12112lpfc_io_resume(struct pci_dev *pdev)
12113{
12114 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12115 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12116
12117 switch (phba->pci_dev_grp) {
12118 case LPFC_PCI_DEV_LP:
12119 lpfc_io_resume_s3(pdev);
12120 break;
James Smartda0436e2009-05-22 14:51:39 -040012121 case LPFC_PCI_DEV_OC:
12122 lpfc_io_resume_s4(pdev);
12123 break;
James Smart3772a992009-05-22 14:50:54 -040012124 default:
12125 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12126 "1429 Invalid PCI device group: 0x%x\n",
12127 phba->pci_dev_grp);
12128 break;
12129 }
12130 return;
12131}
12132
James Smart1ba981f2014-02-20 09:56:45 -050012133/**
12134 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
12135 * @phba: pointer to lpfc hba data structure.
12136 *
12137 * This routine checks to see if OAS is supported for this adapter. If
12138 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
12139 * the enable oas flag is cleared and the pool created for OAS device data
12140 * is destroyed.
12141 *
12142 **/
12143void
12144lpfc_sli4_oas_verify(struct lpfc_hba *phba)
12145{
12146
12147 if (!phba->cfg_EnableXLane)
12148 return;
12149
12150 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
12151 phba->cfg_fof = 1;
12152 } else {
James Smartf38fa0b2014-04-04 13:52:21 -040012153 phba->cfg_fof = 0;
James Smart1ba981f2014-02-20 09:56:45 -050012154 if (phba->device_data_mem_pool)
12155 mempool_destroy(phba->device_data_mem_pool);
12156 phba->device_data_mem_pool = NULL;
12157 }
12158
12159 return;
12160}
12161
12162/**
12163 * lpfc_fof_queue_setup - Set up all the fof queues
12164 * @phba: pointer to lpfc hba data structure.
12165 *
12166 * This routine is invoked to set up all the fof queues for the FC HBA
12167 * operation.
12168 *
12169 * Return codes
12170 * 0 - successful
12171 * -ENOMEM - No available memory
12172 **/
12173int
12174lpfc_fof_queue_setup(struct lpfc_hba *phba)
12175{
James Smart895427b2017-02-12 13:52:30 -080012176 struct lpfc_sli_ring *pring;
James Smart1ba981f2014-02-20 09:56:45 -050012177 int rc;
12178
12179 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
12180 if (rc)
12181 return -ENOMEM;
12182
James Smartf38fa0b2014-04-04 13:52:21 -040012183 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050012184
12185 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
12186 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
12187 if (rc)
12188 goto out_oas_cq;
12189
12190 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
12191 phba->sli4_hba.oas_cq, LPFC_FCP);
12192 if (rc)
12193 goto out_oas_wq;
12194
James Smart895427b2017-02-12 13:52:30 -080012195 /* Bind this CQ/WQ to the NVME ring */
12196 pring = phba->sli4_hba.oas_wq->pring;
12197 pring->sli.sli4.wqp =
12198 (void *)phba->sli4_hba.oas_wq;
12199 phba->sli4_hba.oas_cq->pring = pring;
James Smart1ba981f2014-02-20 09:56:45 -050012200 }
12201
12202 return 0;
12203
12204out_oas_wq:
James Smartf38fa0b2014-04-04 13:52:21 -040012205 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
James Smart1ba981f2014-02-20 09:56:45 -050012206out_oas_cq:
12207 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
12208 return rc;
12209
12210}
12211
12212/**
12213 * lpfc_fof_queue_create - Create all the fof queues
12214 * @phba: pointer to lpfc hba data structure.
12215 *
12216 * This routine is invoked to allocate all the fof queues for the FC HBA
12217 * operation. For each SLI4 queue type, the parameters such as queue entry
12218 * count (queue depth) shall be taken from the module parameter. For now,
12219 * we just use some constant number as place holder.
12220 *
12221 * Return codes
12222 * 0 - successful
12223 * -ENOMEM - No availble memory
12224 * -EIO - The mailbox failed to complete successfully.
12225 **/
12226int
12227lpfc_fof_queue_create(struct lpfc_hba *phba)
12228{
12229 struct lpfc_queue *qdesc;
12230
12231 /* Create FOF EQ */
James Smart81b96ed2017-11-20 16:00:29 -080012232 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
12233 phba->sli4_hba.eq_esize,
James Smart1ba981f2014-02-20 09:56:45 -050012234 phba->sli4_hba.eq_ecount);
12235 if (!qdesc)
12236 goto out_error;
12237
12238 phba->sli4_hba.fof_eq = qdesc;
12239
James Smartf38fa0b2014-04-04 13:52:21 -040012240 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050012241
12242 /* Create OAS CQ */
James Smarta51e41b2017-12-08 17:18:06 -080012243 if (phba->fcp_embed_io)
12244 qdesc = lpfc_sli4_queue_alloc(phba,
12245 LPFC_EXPANDED_PAGE_SIZE,
12246 phba->sli4_hba.cq_esize,
12247 LPFC_CQE_EXP_COUNT);
12248 else
12249 qdesc = lpfc_sli4_queue_alloc(phba,
12250 LPFC_DEFAULT_PAGE_SIZE,
12251 phba->sli4_hba.cq_esize,
12252 phba->sli4_hba.cq_ecount);
James Smart1ba981f2014-02-20 09:56:45 -050012253 if (!qdesc)
12254 goto out_error;
12255
12256 phba->sli4_hba.oas_cq = qdesc;
12257
12258 /* Create OAS WQ */
James Smarta51e41b2017-12-08 17:18:06 -080012259 if (phba->fcp_embed_io)
12260 qdesc = lpfc_sli4_queue_alloc(phba,
12261 LPFC_EXPANDED_PAGE_SIZE,
12262 LPFC_WQE128_SIZE,
12263 LPFC_WQE_EXP_COUNT);
12264 else
12265 qdesc = lpfc_sli4_queue_alloc(phba,
12266 LPFC_DEFAULT_PAGE_SIZE,
12267 phba->sli4_hba.wq_esize,
12268 phba->sli4_hba.wq_ecount);
James Smart1ba981f2014-02-20 09:56:45 -050012269 if (!qdesc)
12270 goto out_error;
12271
12272 phba->sli4_hba.oas_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -080012273 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
James Smart1ba981f2014-02-20 09:56:45 -050012274
12275 }
12276 return 0;
12277
12278out_error:
12279 lpfc_fof_queue_destroy(phba);
12280 return -ENOMEM;
12281}
12282
12283/**
12284 * lpfc_fof_queue_destroy - Destroy all the fof queues
12285 * @phba: pointer to lpfc hba data structure.
12286 *
12287 * This routine is invoked to release all the SLI4 queues with the FC HBA
12288 * operation.
12289 *
12290 * Return codes
12291 * 0 - successful
12292 **/
12293int
12294lpfc_fof_queue_destroy(struct lpfc_hba *phba)
12295{
12296 /* Release FOF Event queue */
12297 if (phba->sli4_hba.fof_eq != NULL) {
12298 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
12299 phba->sli4_hba.fof_eq = NULL;
12300 }
12301
12302 /* Release OAS Completion queue */
12303 if (phba->sli4_hba.oas_cq != NULL) {
12304 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
12305 phba->sli4_hba.oas_cq = NULL;
12306 }
12307
12308 /* Release OAS Work queue */
12309 if (phba->sli4_hba.oas_wq != NULL) {
12310 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
12311 phba->sli4_hba.oas_wq = NULL;
12312 }
12313 return 0;
12314}
12315
dea31012005-04-17 16:05:31 -050012316MODULE_DEVICE_TABLE(pci, lpfc_id_table);
12317
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070012318static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060012319 .error_detected = lpfc_io_error_detected,
12320 .slot_reset = lpfc_io_slot_reset,
12321 .resume = lpfc_io_resume,
12322};
12323
dea31012005-04-17 16:05:31 -050012324static struct pci_driver lpfc_driver = {
12325 .name = LPFC_DRIVER_NAME,
12326 .id_table = lpfc_id_table,
12327 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012328 .remove = lpfc_pci_remove_one,
Anton Blanchard85e8a232017-02-13 08:49:20 +110012329 .shutdown = lpfc_pci_remove_one,
James Smart3a55b532008-12-04 22:38:54 -050012330 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040012331 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050012332 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050012333};
12334
James Smart3ef6d242012-01-18 16:23:48 -050012335static const struct file_operations lpfc_mgmt_fop = {
Al Viro858feac2013-04-14 22:39:37 -040012336 .owner = THIS_MODULE,
James Smart3ef6d242012-01-18 16:23:48 -050012337};
12338
12339static struct miscdevice lpfc_mgmt_dev = {
12340 .minor = MISC_DYNAMIC_MINOR,
12341 .name = "lpfcmgmt",
12342 .fops = &lpfc_mgmt_fop,
12343};
12344
James Smarte59058c2008-08-24 21:49:00 -040012345/**
James Smart3621a712009-04-06 18:47:14 -040012346 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040012347 *
12348 * This routine is to be invoked when the lpfc module is loaded into the
12349 * kernel. The special kernel macro module_init() is used to indicate the
12350 * role of this routine to the kernel as lpfc module entry point.
12351 *
12352 * Return codes
12353 * 0 - successful
12354 * -ENOMEM - FC attach transport failed
12355 * all others - failed
12356 */
dea31012005-04-17 16:05:31 -050012357static int __init
12358lpfc_init(void)
12359{
12360 int error = 0;
12361
12362 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012363 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050012364
James Smart3ef6d242012-01-18 16:23:48 -050012365 error = misc_register(&lpfc_mgmt_dev);
12366 if (error)
12367 printk(KERN_ERR "Could not register lpfcmgmt device, "
12368 "misc_register returned with status %d", error);
12369
James Smart458c0832016-07-06 12:36:07 -070012370 lpfc_transport_functions.vport_create = lpfc_vport_create;
12371 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
dea31012005-04-17 16:05:31 -050012372 lpfc_transport_template =
12373 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040012374 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050012375 return -ENOMEM;
James Smart458c0832016-07-06 12:36:07 -070012376 lpfc_vport_transport_template =
12377 fc_attach_transport(&lpfc_vport_transport_functions);
12378 if (lpfc_vport_transport_template == NULL) {
12379 fc_release_transport(lpfc_transport_template);
12380 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040012381 }
James Smart7bb03bb2013-04-17 20:19:16 -040012382
12383 /* Initialize in case vector mapping is needed */
James Smartb246de12013-05-31 17:03:07 -040012384 lpfc_used_cpu = NULL;
James Smart2ea259e2017-02-12 13:52:27 -080012385 lpfc_present_cpu = num_present_cpus();
James Smart7bb03bb2013-04-17 20:19:16 -040012386
dea31012005-04-17 16:05:31 -050012387 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050012388 if (error) {
dea31012005-04-17 16:05:31 -050012389 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070012390 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050012391 }
dea31012005-04-17 16:05:31 -050012392
12393 return error;
12394}
12395
James Smarte59058c2008-08-24 21:49:00 -040012396/**
James Smart3621a712009-04-06 18:47:14 -040012397 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040012398 *
12399 * This routine is invoked when the lpfc module is removed from the kernel.
12400 * The special kernel macro module_exit() is used to indicate the role of
12401 * this routine to the kernel as lpfc module exit point.
12402 */
dea31012005-04-17 16:05:31 -050012403static void __exit
12404lpfc_exit(void)
12405{
James Smart3ef6d242012-01-18 16:23:48 -050012406 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050012407 pci_unregister_driver(&lpfc_driver);
12408 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070012409 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050012410 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040012411 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
12412 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050012413 (1L << _dump_buf_data_order), _dump_buf_data);
12414 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
12415 }
12416
12417 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040012418 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
12419 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050012420 (1L << _dump_buf_dif_order), _dump_buf_dif);
12421 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
12422 }
James Smartb246de12013-05-31 17:03:07 -040012423 kfree(lpfc_used_cpu);
Johannes Thumshirn79739672015-08-31 16:48:11 -040012424 idr_destroy(&lpfc_hba_index);
dea31012005-04-17 16:05:31 -050012425}
12426
12427module_init(lpfc_init);
12428module_exit(lpfc_exit);
12429MODULE_LICENSE("GPL");
12430MODULE_DESCRIPTION(LPFC_MODULE_DESC);
James Smartd080abe2017-02-12 13:52:39 -080012431MODULE_AUTHOR("Broadcom");
dea31012005-04-17 16:05:31 -050012432MODULE_VERSION("0:" LPFC_DRIVER_VERSION);