blob: 716add289397472d47145f3a488bf7c0342ac7da [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart128bdda2018-01-30 15:59:03 -08004 * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
James Smart3e21d1c2018-05-04 20:37:59 -07005 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
James Smart50611572016-03-31 14:12:34 -07006 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * EMULEX and SLI are trademarks of Emulex. *
James Smartd080abe2017-02-12 13:52:39 -08008 * www.broadcom.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04009 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -050010 * *
11 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
dea31012005-04-17 16:05:31 -050022 *******************************************************************/
23
dea31012005-04-17 16:05:31 -050024#include <linux/blkdev.h>
25#include <linux/delay.h>
26#include <linux/dma-mapping.h>
27#include <linux/idr.h>
28#include <linux/interrupt.h>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040029#include <linux/module.h>
dea31012005-04-17 16:05:31 -050030#include <linux/kthread.h>
31#include <linux/pci.h>
32#include <linux/spinlock.h>
James Smart92d7f7b2007-06-17 19:56:38 -050033#include <linux/ctype.h>
James Smart0d878412009-10-02 15:16:56 -040034#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
James Smart52d52442011-05-24 11:42:45 -040036#include <linux/firmware.h>
James Smart3ef6d242012-01-18 16:23:48 -050037#include <linux/miscdevice.h>
James Smart7bb03bb2013-04-17 20:19:16 -040038#include <linux/percpu.h>
James Smart895427b2017-02-12 13:52:30 -080039#include <linux/msi.h>
Maurizio Lombardi286871a2017-08-23 16:55:48 -070040#include <linux/bitops.h>
dea31012005-04-17 16:05:31 -050041
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040042#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050043#include <scsi/scsi_device.h>
44#include <scsi/scsi_host.h>
45#include <scsi/scsi_transport_fc.h>
James Smart86c67372017-04-21 16:05:04 -070046#include <scsi/scsi_tcq.h>
47#include <scsi/fc/fc_fs.h>
48
49#include <linux/nvme-fc-driver.h>
dea31012005-04-17 16:05:31 -050050
James Smartda0436e2009-05-22 14:51:39 -040051#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050052#include "lpfc_hw.h"
53#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040054#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040055#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050056#include "lpfc_disc.h"
dea31012005-04-17 16:05:31 -050057#include "lpfc.h"
James Smart895427b2017-02-12 13:52:30 -080058#include "lpfc_scsi.h"
59#include "lpfc_nvme.h"
James Smart86c67372017-04-21 16:05:04 -070060#include "lpfc_nvmet.h"
dea31012005-04-17 16:05:31 -050061#include "lpfc_logmsg.h"
62#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050063#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050064#include "lpfc_version.h"
James Smart12f44452016-07-06 12:36:03 -070065#include "lpfc_ids.h"
dea31012005-04-17 16:05:31 -050066
James Smart81301a92008-12-04 22:39:46 -050067char *_dump_buf_data;
68unsigned long _dump_buf_data_order;
69char *_dump_buf_dif;
70unsigned long _dump_buf_dif_order;
71spinlock_t _dump_buf_lock;
72
James Smart7bb03bb2013-04-17 20:19:16 -040073/* Used when mapping IRQ vectors in a driver centric manner */
James Smartb246de12013-05-31 17:03:07 -040074uint16_t *lpfc_used_cpu;
75uint32_t lpfc_present_cpu;
James Smart7bb03bb2013-04-17 20:19:16 -040076
dea31012005-04-17 16:05:31 -050077static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
78static int lpfc_post_rcv_buf(struct lpfc_hba *);
James Smart5350d872011-10-10 21:33:49 -040079static int lpfc_sli4_queue_verify(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040080static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
81static int lpfc_setup_endian_order(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040082static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040083static void lpfc_free_els_sgl_list(struct lpfc_hba *);
James Smartf358dd02017-02-12 13:52:34 -080084static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040085static void lpfc_init_sgl_list(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040086static int lpfc_init_active_sgl_array(struct lpfc_hba *);
87static void lpfc_free_active_sgl(struct lpfc_hba *);
88static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
89static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
90static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
91static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
92static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
James Smart618a5232012-06-12 13:54:36 -040093static void lpfc_sli4_disable_intr(struct lpfc_hba *);
94static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
James Smart1ba981f2014-02-20 09:56:45 -050095static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
dea31012005-04-17 16:05:31 -050096
97static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050098static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -050099static DEFINE_IDR(lpfc_hba_index);
James Smartf358dd02017-02-12 13:52:34 -0800100#define LPFC_NVMET_BUF_POST 254
dea31012005-04-17 16:05:31 -0500101
James Smarte59058c2008-08-24 21:49:00 -0400102/**
James Smart3621a712009-04-06 18:47:14 -0400103 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
James Smarte59058c2008-08-24 21:49:00 -0400104 * @phba: pointer to lpfc hba data structure.
105 *
106 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
107 * mailbox command. It retrieves the revision information from the HBA and
108 * collects the Vital Product Data (VPD) about the HBA for preparing the
109 * configuration of the HBA.
110 *
111 * Return codes:
112 * 0 - success.
113 * -ERESTART - requests the SLI layer to reset the HBA and try again.
114 * Any other value - indicates an error.
115 **/
dea31012005-04-17 16:05:31 -0500116int
James Smart2e0fef82007-06-17 19:56:36 -0500117lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500118{
119 lpfc_vpd_t *vp = &phba->vpd;
120 int i = 0, rc;
121 LPFC_MBOXQ_t *pmb;
122 MAILBOX_t *mb;
123 char *lpfc_vpd_data = NULL;
124 uint16_t offset = 0;
125 static char licensed[56] =
126 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -0400127 static int init_key = 1;
dea31012005-04-17 16:05:31 -0500128
129 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
130 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500131 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500132 return -ENOMEM;
133 }
134
James Smart04c68492009-05-22 14:52:52 -0400135 mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -0500136 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -0500137
138 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -0400139 if (init_key) {
140 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -0500141
James Smart65a29c12006-07-06 15:50:50 -0400142 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
143 *ptext = cpu_to_be32(*ptext);
144 init_key = 0;
145 }
dea31012005-04-17 16:05:31 -0500146
147 lpfc_read_nv(phba, pmb);
148 memset((char*)mb->un.varRDnvp.rsvd3, 0,
149 sizeof (mb->un.varRDnvp.rsvd3));
150 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
151 sizeof (licensed));
152
153 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
154
155 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500156 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400157 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500158 "error, mbxCmd x%x READ_NVPARM, "
159 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500160 mb->mbxCommand, mb->mbxStatus);
161 mempool_free(pmb, phba->mbox_mem_pool);
162 return -ERESTART;
163 }
164 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500165 sizeof(phba->wwnn));
166 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
167 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500168 }
169
James Smart92d7f7b2007-06-17 19:56:38 -0500170 phba->sli3_options = 0x0;
171
dea31012005-04-17 16:05:31 -0500172 /* Setup and issue mailbox READ REV command */
173 lpfc_read_rev(phba, pmb);
174 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
175 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500176 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400177 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500178 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500179 mb->mbxCommand, mb->mbxStatus);
180 mempool_free( pmb, phba->mbox_mem_pool);
181 return -ERESTART;
182 }
183
James Smart92d7f7b2007-06-17 19:56:38 -0500184
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500185 /*
186 * The value of rr must be 1 since the driver set the cv field to 1.
187 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500188 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500189 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500190 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500191 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400192 "0440 Adapter failed to init, READ_REV has "
193 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500194 mempool_free(pmb, phba->mbox_mem_pool);
195 return -ERESTART;
dea31012005-04-17 16:05:31 -0500196 }
197
James Smart495a7142008-06-14 22:52:59 -0400198 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
199 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500200 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400201 }
James Smarted957682007-06-17 19:56:37 -0500202
dea31012005-04-17 16:05:31 -0500203 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500204 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500205 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500206 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
207 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
208 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
209 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500210 vp->rev.biuRev = mb->un.varRdRev.biuRev;
211 vp->rev.smRev = mb->un.varRdRev.smRev;
212 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
213 vp->rev.endecRev = mb->un.varRdRev.endecRev;
214 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
215 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
216 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
217 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
218 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
219 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
220
James Smart92d7f7b2007-06-17 19:56:38 -0500221 /* If the sli feature level is less then 9, we must
222 * tear down all RPIs and VPIs on link down if NPIV
223 * is enabled.
224 */
225 if (vp->rev.feaLevelHigh < 9)
226 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
227
dea31012005-04-17 16:05:31 -0500228 if (lpfc_is_LC_HBA(phba->pcidev->device))
229 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
230 sizeof (phba->RandomData));
231
dea31012005-04-17 16:05:31 -0500232 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500233 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
234 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400235 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500236 do {
James Smarta0c87cb2009-07-19 10:01:10 -0400237 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
dea31012005-04-17 16:05:31 -0500238 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
239
240 if (rc != MBX_SUCCESS) {
241 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400242 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500243 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500244 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500245 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500246 }
James Smart04c68492009-05-22 14:52:52 -0400247 /* dump mem may return a zero when finished or we got a
248 * mailbox error, either way we are done.
249 */
250 if (mb->un.varDmp.word_cnt == 0)
251 break;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500252 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
253 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400254 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
255 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500256 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500257 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500258 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
259 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500260
261 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500262out_free_mbox:
263 mempool_free(pmb, phba->mbox_mem_pool);
264 return 0;
265}
266
James Smarte59058c2008-08-24 21:49:00 -0400267/**
James Smart3621a712009-04-06 18:47:14 -0400268 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
James Smarte59058c2008-08-24 21:49:00 -0400269 * @phba: pointer to lpfc hba data structure.
270 * @pmboxq: pointer to the driver internal queue element for mailbox command.
271 *
272 * This is the completion handler for driver's configuring asynchronous event
273 * mailbox command to the device. If the mailbox command returns successfully,
274 * it will set internal async event support flag to 1; otherwise, it will
275 * set internal async event support flag to 0.
276 **/
James Smart57127f12007-10-27 13:37:05 -0400277static void
278lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
279{
James Smart04c68492009-05-22 14:52:52 -0400280 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
James Smart57127f12007-10-27 13:37:05 -0400281 phba->temp_sensor_support = 1;
282 else
283 phba->temp_sensor_support = 0;
284 mempool_free(pmboxq, phba->mbox_mem_pool);
285 return;
286}
287
James Smarte59058c2008-08-24 21:49:00 -0400288/**
James Smart3621a712009-04-06 18:47:14 -0400289 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
James Smart97207482008-12-04 22:39:19 -0500290 * @phba: pointer to lpfc hba data structure.
291 * @pmboxq: pointer to the driver internal queue element for mailbox command.
292 *
293 * This is the completion handler for dump mailbox command for getting
294 * wake up parameters. When this command complete, the response contain
295 * Option rom version of the HBA. This function translate the version number
296 * into a human readable string and store it in OptionROMVersion.
297 **/
298static void
299lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
300{
301 struct prog_id *prg;
302 uint32_t prog_id_word;
303 char dist = ' ';
304 /* character array used for decoding dist type. */
305 char dist_char[] = "nabx";
306
James Smart04c68492009-05-22 14:52:52 -0400307 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
James Smart9f1e1b52008-12-04 22:39:40 -0500308 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500309 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500310 }
James Smart97207482008-12-04 22:39:19 -0500311
312 prg = (struct prog_id *) &prog_id_word;
313
314 /* word 7 contain option rom version */
James Smart04c68492009-05-22 14:52:52 -0400315 prog_id_word = pmboxq->u.mb.un.varWords[7];
James Smart97207482008-12-04 22:39:19 -0500316
317 /* Decode the Option rom version word to a readable string */
318 if (prg->dist < 4)
319 dist = dist_char[prg->dist];
320
321 if ((prg->dist == 3) && (prg->num == 0))
James Smarta2fc4aef2014-09-03 12:57:55 -0400322 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
James Smart97207482008-12-04 22:39:19 -0500323 prg->ver, prg->rev, prg->lev);
324 else
James Smarta2fc4aef2014-09-03 12:57:55 -0400325 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
James Smart97207482008-12-04 22:39:19 -0500326 prg->ver, prg->rev, prg->lev,
327 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500328 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500329 return;
330}
331
332/**
James Smart05580562011-05-24 11:40:48 -0400333 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
334 * cfg_soft_wwnn, cfg_soft_wwpn
335 * @vport: pointer to lpfc vport data structure.
336 *
337 *
338 * Return codes
339 * None.
340 **/
341void
342lpfc_update_vport_wwn(struct lpfc_vport *vport)
343{
James Smartaeb3c812017-04-21 16:05:02 -0700344 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
345 u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0];
346
James Smart05580562011-05-24 11:40:48 -0400347 /* If the soft name exists then update it using the service params */
348 if (vport->phba->cfg_soft_wwnn)
349 u64_to_wwn(vport->phba->cfg_soft_wwnn,
350 vport->fc_sparam.nodeName.u.wwn);
351 if (vport->phba->cfg_soft_wwpn)
352 u64_to_wwn(vport->phba->cfg_soft_wwpn,
353 vport->fc_sparam.portName.u.wwn);
354
355 /*
356 * If the name is empty or there exists a soft name
357 * then copy the service params name, otherwise use the fc name
358 */
359 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
360 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
361 sizeof(struct lpfc_name));
362 else
363 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
364 sizeof(struct lpfc_name));
365
James Smartaeb3c812017-04-21 16:05:02 -0700366 /*
367 * If the port name has changed, then set the Param changes flag
368 * to unreg the login
369 */
370 if (vport->fc_portname.u.wwn[0] != 0 &&
371 memcmp(&vport->fc_portname, &vport->fc_sparam.portName,
372 sizeof(struct lpfc_name)))
373 vport->vport_flag |= FAWWPN_PARAM_CHG;
374
375 if (vport->fc_portname.u.wwn[0] == 0 ||
376 vport->phba->cfg_soft_wwpn ||
377 (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) ||
378 vport->vport_flag & FAWWPN_SET) {
James Smart05580562011-05-24 11:40:48 -0400379 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
380 sizeof(struct lpfc_name));
James Smartaeb3c812017-04-21 16:05:02 -0700381 vport->vport_flag &= ~FAWWPN_SET;
382 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR)
383 vport->vport_flag |= FAWWPN_SET;
384 }
James Smart05580562011-05-24 11:40:48 -0400385 else
386 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
387 sizeof(struct lpfc_name));
388}
389
390/**
James Smart3621a712009-04-06 18:47:14 -0400391 * lpfc_config_port_post - Perform lpfc initialization after config port
James Smarte59058c2008-08-24 21:49:00 -0400392 * @phba: pointer to lpfc hba data structure.
393 *
394 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
395 * command call. It performs all internal resource and state setups on the
396 * port: post IOCB buffers, enable appropriate host interrupt attentions,
397 * ELS ring timers, etc.
398 *
399 * Return codes
400 * 0 - success.
401 * Any other value - error.
402 **/
dea31012005-04-17 16:05:31 -0500403int
James Smart2e0fef82007-06-17 19:56:36 -0500404lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500405{
James Smart2e0fef82007-06-17 19:56:36 -0500406 struct lpfc_vport *vport = phba->pport;
James Smarta257bf92009-04-06 18:48:10 -0400407 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500408 LPFC_MBOXQ_t *pmb;
409 MAILBOX_t *mb;
410 struct lpfc_dmabuf *mp;
411 struct lpfc_sli *psli = &phba->sli;
412 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500413 int i, j;
414 int rc;
dea31012005-04-17 16:05:31 -0500415
James Smart7af67052007-10-27 13:38:11 -0400416 spin_lock_irq(&phba->hbalock);
417 /*
418 * If the Config port completed correctly the HBA is not
419 * over heated any more.
420 */
421 if (phba->over_temp_state == HBA_OVER_TEMP)
422 phba->over_temp_state = HBA_NORMAL_TEMP;
423 spin_unlock_irq(&phba->hbalock);
424
dea31012005-04-17 16:05:31 -0500425 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
426 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500427 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500428 return -ENOMEM;
429 }
James Smart04c68492009-05-22 14:52:52 -0400430 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500431
dea31012005-04-17 16:05:31 -0500432 /* Get login parameters for NID. */
James Smart9f1177a2010-02-26 14:12:57 -0500433 rc = lpfc_read_sparam(phba, pmb, 0);
434 if (rc) {
435 mempool_free(pmb, phba->mbox_mem_pool);
436 return -ENOMEM;
437 }
438
James Smarted957682007-06-17 19:56:37 -0500439 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500440 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500441 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400442 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500443 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500444 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500445 phba->link_state = LPFC_HBA_ERROR;
James Smart3e1f0712018-11-29 16:09:29 -0800446 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
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
James Smart3e1f0712018-11-29 16:09:29 -0800453 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
dea31012005-04-17 16:05:31 -0500454
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);
James Smart3e1f0712018-11-29 16:09:29 -0800458 pmb->ctx_buf = NULL;
James Smart05580562011-05-24 11:40:48 -0400459 lpfc_update_vport_wwn(vport);
James Smarta257bf92009-04-06 18:48:10 -0400460
461 /* Update the fc_host data structures with new wwn. */
462 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
463 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart21e9a0a2009-05-22 14:53:21 -0400464 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smarta257bf92009-04-06 18:48:10 -0400465
dea31012005-04-17 16:05:31 -0500466 /* If no serial number in VPD data, use low 6 bytes of WWNN */
467 /* This should be consolidated into parse_vpd ? - mr */
468 if (phba->SerialNumber[0] == 0) {
469 uint8_t *outptr;
470
James Smart2e0fef82007-06-17 19:56:36 -0500471 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500472 for (i = 0; i < 12; i++) {
473 status = *outptr++;
474 j = ((status & 0xf0) >> 4);
475 if (j <= 9)
476 phba->SerialNumber[i] =
477 (char)((uint8_t) 0x30 + (uint8_t) j);
478 else
479 phba->SerialNumber[i] =
480 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
481 i++;
482 j = (status & 0xf);
483 if (j <= 9)
484 phba->SerialNumber[i] =
485 (char)((uint8_t) 0x30 + (uint8_t) j);
486 else
487 phba->SerialNumber[i] =
488 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
489 }
490 }
491
dea31012005-04-17 16:05:31 -0500492 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500493 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500494 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500495 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400496 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500497 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500498 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500499 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500500 mempool_free( pmb, phba->mbox_mem_pool);
501 return -EIO;
502 }
503
James Smarta0c87cb2009-07-19 10:01:10 -0400504 /* Check if the port is disabled */
505 lpfc_sli_read_link_ste(phba);
506
dea31012005-04-17 16:05:31 -0500507 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -0400508 i = (mb->un.varRdConfig.max_xri + 1);
509 if (phba->cfg_hba_queue_depth > i) {
510 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
511 "3359 HBA queue depth changed from %d to %d\n",
512 phba->cfg_hba_queue_depth, i);
513 phba->cfg_hba_queue_depth = i;
514 }
515
516 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
517 i = (mb->un.varRdConfig.max_xri >> 3);
518 if (phba->pport->cfg_lun_queue_depth > i) {
519 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
520 "3360 LUN queue depth changed from %d to %d\n",
521 phba->pport->cfg_lun_queue_depth, i);
522 phba->pport->cfg_lun_queue_depth = i;
523 }
dea31012005-04-17 16:05:31 -0500524
525 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500526
527 /* Get the default values for Model Name and Description */
528 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
529
James Smart2e0fef82007-06-17 19:56:36 -0500530 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500531
James Smart0b727fe2007-10-27 13:37:25 -0400532 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smart895427b2017-02-12 13:52:30 -0800533 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
534 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
535 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
536 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500537
538 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500539 if (phba->sli_rev != 3)
540 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500541
James Smart93996272008-08-24 21:50:30 -0400542 /*
543 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
544 */
545 if (phba->intr_type == MSIX) {
546 rc = lpfc_config_msi(phba, pmb);
547 if (rc) {
548 mempool_free(pmb, phba->mbox_mem_pool);
549 return -EIO;
550 }
551 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
552 if (rc != MBX_SUCCESS) {
553 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
554 "0352 Config MSI mailbox command "
555 "failed, mbxCmd x%x, mbxStatus x%x\n",
James Smart04c68492009-05-22 14:52:52 -0400556 pmb->u.mb.mbxCommand,
557 pmb->u.mb.mbxStatus);
James Smart93996272008-08-24 21:50:30 -0400558 mempool_free(pmb, phba->mbox_mem_pool);
559 return -EIO;
560 }
561 }
562
James Smart04c68492009-05-22 14:52:52 -0400563 spin_lock_irq(&phba->hbalock);
James Smart93996272008-08-24 21:50:30 -0400564 /* Initialize ERATT handling flag */
565 phba->hba_flag &= ~HBA_ERATT_HANDLED;
566
dea31012005-04-17 16:05:31 -0500567 /* Enable appropriate host interrupts */
James Smart9940b972011-03-11 16:06:12 -0500568 if (lpfc_readl(phba->HCregaddr, &status)) {
569 spin_unlock_irq(&phba->hbalock);
570 return -EIO;
571 }
dea31012005-04-17 16:05:31 -0500572 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
573 if (psli->num_rings > 0)
574 status |= HC_R0INT_ENA;
575 if (psli->num_rings > 1)
576 status |= HC_R1INT_ENA;
577 if (psli->num_rings > 2)
578 status |= HC_R2INT_ENA;
579 if (psli->num_rings > 3)
580 status |= HC_R3INT_ENA;
581
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500582 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
583 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400584 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500585
dea31012005-04-17 16:05:31 -0500586 writel(status, phba->HCregaddr);
587 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500588 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500589
James Smart93996272008-08-24 21:50:30 -0400590 /* Set up ring-0 (ELS) timer */
591 timeout = phba->fc_ratov * 2;
James Smart256ec0d2013-04-17 20:14:58 -0400592 mod_timer(&vport->els_tmofunc,
593 jiffies + msecs_to_jiffies(1000 * timeout));
James Smart93996272008-08-24 21:50:30 -0400594 /* Set up heart beat (HB) timer */
James Smart256ec0d2013-04-17 20:14:58 -0400595 mod_timer(&phba->hb_tmofunc,
596 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -0500597 phba->hb_outstanding = 0;
598 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400599 /* Set up error attention (ERATT) polling timer */
James Smart256ec0d2013-04-17 20:14:58 -0400600 mod_timer(&phba->eratt_poll,
James Smart65791f12016-07-06 12:35:56 -0700601 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
dea31012005-04-17 16:05:31 -0500602
James Smarta0c87cb2009-07-19 10:01:10 -0400603 if (phba->hba_flag & LINK_DISABLED) {
604 lpfc_printf_log(phba,
605 KERN_ERR, LOG_INIT,
606 "2598 Adapter Link is disabled.\n");
607 lpfc_down_link(phba, pmb);
608 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
609 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
610 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
611 lpfc_printf_log(phba,
612 KERN_ERR, LOG_INIT,
613 "2599 Adapter failed to issue DOWN_LINK"
614 " mbox command rc 0x%x\n", rc);
615
616 mempool_free(pmb, phba->mbox_mem_pool);
617 return -EIO;
618 }
James Smarte40a02c2010-02-26 14:13:54 -0500619 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
James Smart026abb82011-12-13 13:20:45 -0500620 mempool_free(pmb, phba->mbox_mem_pool);
621 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
622 if (rc)
623 return rc;
dea31012005-04-17 16:05:31 -0500624 }
625 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400626 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500627 if (!pmb) {
628 phba->link_state = LPFC_HBA_ERROR;
629 return -ENOMEM;
630 }
631
James Smart57127f12007-10-27 13:37:05 -0400632 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
633 pmb->mbox_cmpl = lpfc_config_async_cmpl;
634 pmb->vport = phba->pport;
635 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500636
James Smart57127f12007-10-27 13:37:05 -0400637 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
638 lpfc_printf_log(phba,
639 KERN_ERR,
640 LOG_INIT,
641 "0456 Adapter failed to issue "
James Smarte4e74272009-07-19 10:01:38 -0400642 "ASYNCEVT_ENABLE mbox status x%x\n",
James Smart57127f12007-10-27 13:37:05 -0400643 rc);
644 mempool_free(pmb, phba->mbox_mem_pool);
645 }
James Smart97207482008-12-04 22:39:19 -0500646
647 /* Get Option rom version */
648 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500649 if (!pmb) {
650 phba->link_state = LPFC_HBA_ERROR;
651 return -ENOMEM;
652 }
653
James Smart97207482008-12-04 22:39:19 -0500654 lpfc_dump_wakeup_param(phba, pmb);
655 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
656 pmb->vport = phba->pport;
657 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
658
659 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
660 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
James Smarte4e74272009-07-19 10:01:38 -0400661 "to get Option ROM version status x%x\n", rc);
James Smart97207482008-12-04 22:39:19 -0500662 mempool_free(pmb, phba->mbox_mem_pool);
663 }
664
James Smartd7c255b2008-08-24 21:50:00 -0400665 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400666}
667
James Smarte59058c2008-08-24 21:49:00 -0400668/**
James Smart84d1b002010-02-12 14:42:33 -0500669 * lpfc_hba_init_link - Initialize the FC link
670 * @phba: pointer to lpfc hba data structure.
James Smart6e7288d2010-06-07 15:23:35 -0400671 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500672 *
673 * This routine will issue the INIT_LINK mailbox command call.
674 * It is available to other drivers through the lpfc_hba data
675 * structure for use as a delayed link up mechanism with the
676 * module parameter lpfc_suppress_link_up.
677 *
678 * Return code
679 * 0 - success
680 * Any other value - error
681 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400682static int
James Smart6e7288d2010-06-07 15:23:35 -0400683lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500684{
James Smart1b511972011-12-13 13:23:09 -0500685 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
686}
687
688/**
689 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
690 * @phba: pointer to lpfc hba data structure.
691 * @fc_topology: desired fc topology.
692 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
693 *
694 * This routine will issue the INIT_LINK mailbox command call.
695 * It is available to other drivers through the lpfc_hba data
696 * structure for use as a delayed link up mechanism with the
697 * module parameter lpfc_suppress_link_up.
698 *
699 * Return code
700 * 0 - success
701 * Any other value - error
702 **/
703int
704lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
705 uint32_t flag)
706{
James Smart84d1b002010-02-12 14:42:33 -0500707 struct lpfc_vport *vport = phba->pport;
708 LPFC_MBOXQ_t *pmb;
709 MAILBOX_t *mb;
710 int rc;
711
712 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
713 if (!pmb) {
714 phba->link_state = LPFC_HBA_ERROR;
715 return -ENOMEM;
716 }
717 mb = &pmb->u.mb;
718 pmb->vport = vport;
719
James Smart026abb82011-12-13 13:20:45 -0500720 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
721 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
722 !(phba->lmt & LMT_1Gb)) ||
723 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
724 !(phba->lmt & LMT_2Gb)) ||
725 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
726 !(phba->lmt & LMT_4Gb)) ||
727 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
728 !(phba->lmt & LMT_8Gb)) ||
729 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
730 !(phba->lmt & LMT_10Gb)) ||
731 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
James Smartd38dd522015-08-31 16:48:17 -0400732 !(phba->lmt & LMT_16Gb)) ||
733 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
James Smartfbd8a6b2018-02-22 08:18:45 -0800734 !(phba->lmt & LMT_32Gb)) ||
735 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) &&
736 !(phba->lmt & LMT_64Gb))) {
James Smart026abb82011-12-13 13:20:45 -0500737 /* Reset link speed to auto */
738 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
739 "1302 Invalid speed for this board:%d "
740 "Reset link speed to auto.\n",
741 phba->cfg_link_speed);
742 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
743 }
James Smart1b511972011-12-13 13:23:09 -0500744 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
James Smart84d1b002010-02-12 14:42:33 -0500745 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart1b511972011-12-13 13:23:09 -0500746 if (phba->sli_rev < LPFC_SLI_REV4)
747 lpfc_set_loopback_flag(phba);
James Smart6e7288d2010-06-07 15:23:35 -0400748 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart76a95d72010-11-20 23:11:48 -0500749 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
James Smart84d1b002010-02-12 14:42:33 -0500750 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
751 "0498 Adapter failed to init, mbxCmd x%x "
752 "INIT_LINK, mbxStatus x%x\n",
753 mb->mbxCommand, mb->mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -0500754 if (phba->sli_rev <= LPFC_SLI_REV3) {
755 /* Clear all interrupt enable conditions */
756 writel(0, phba->HCregaddr);
757 readl(phba->HCregaddr); /* flush */
758 /* Clear all pending interrupts */
759 writel(0xffffffff, phba->HAregaddr);
760 readl(phba->HAregaddr); /* flush */
761 }
James Smart84d1b002010-02-12 14:42:33 -0500762 phba->link_state = LPFC_HBA_ERROR;
James Smart6e7288d2010-06-07 15:23:35 -0400763 if (rc != MBX_BUSY || flag == MBX_POLL)
James Smart84d1b002010-02-12 14:42:33 -0500764 mempool_free(pmb, phba->mbox_mem_pool);
765 return -EIO;
766 }
James Smarte40a02c2010-02-26 14:13:54 -0500767 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
James Smart6e7288d2010-06-07 15:23:35 -0400768 if (flag == MBX_POLL)
769 mempool_free(pmb, phba->mbox_mem_pool);
James Smart84d1b002010-02-12 14:42:33 -0500770
771 return 0;
772}
773
774/**
775 * lpfc_hba_down_link - this routine downs the FC link
James Smart6e7288d2010-06-07 15:23:35 -0400776 * @phba: pointer to lpfc hba data structure.
777 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500778 *
779 * This routine will issue the DOWN_LINK mailbox command call.
780 * It is available to other drivers through the lpfc_hba data
781 * structure for use to stop the link.
782 *
783 * Return code
784 * 0 - success
785 * Any other value - error
786 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400787static int
James Smart6e7288d2010-06-07 15:23:35 -0400788lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500789{
790 LPFC_MBOXQ_t *pmb;
791 int rc;
792
793 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
794 if (!pmb) {
795 phba->link_state = LPFC_HBA_ERROR;
796 return -ENOMEM;
797 }
798
799 lpfc_printf_log(phba,
800 KERN_ERR, LOG_INIT,
801 "0491 Adapter Link is disabled.\n");
802 lpfc_down_link(phba, pmb);
803 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart6e7288d2010-06-07 15:23:35 -0400804 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart84d1b002010-02-12 14:42:33 -0500805 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
806 lpfc_printf_log(phba,
807 KERN_ERR, LOG_INIT,
808 "2522 Adapter failed to issue DOWN_LINK"
809 " mbox command rc 0x%x\n", rc);
810
811 mempool_free(pmb, phba->mbox_mem_pool);
812 return -EIO;
813 }
James Smart6e7288d2010-06-07 15:23:35 -0400814 if (flag == MBX_POLL)
815 mempool_free(pmb, phba->mbox_mem_pool);
816
James Smart84d1b002010-02-12 14:42:33 -0500817 return 0;
818}
819
820/**
James Smart3621a712009-04-06 18:47:14 -0400821 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400822 * @phba: pointer to lpfc HBA data structure.
823 *
824 * This routine will do LPFC uninitialization before the HBA is reset when
825 * bringing down the SLI Layer.
826 *
827 * Return codes
828 * 0 - success.
829 * Any other value - error.
830 **/
dea31012005-04-17 16:05:31 -0500831int
James Smart2e0fef82007-06-17 19:56:36 -0500832lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500833{
James Smart1b32f6a2008-02-08 18:49:39 -0500834 struct lpfc_vport **vports;
835 int i;
James Smart3772a992009-05-22 14:50:54 -0400836
837 if (phba->sli_rev <= LPFC_SLI_REV3) {
838 /* Disable interrupts */
839 writel(0, phba->HCregaddr);
840 readl(phba->HCregaddr); /* flush */
841 }
dea31012005-04-17 16:05:31 -0500842
James Smart1b32f6a2008-02-08 18:49:39 -0500843 if (phba->pport->load_flag & FC_UNLOADING)
844 lpfc_cleanup_discovery_resources(phba->pport);
845 else {
846 vports = lpfc_create_vport_work_array(phba);
847 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -0400848 for (i = 0; i <= phba->max_vports &&
849 vports[i] != NULL; i++)
James Smart1b32f6a2008-02-08 18:49:39 -0500850 lpfc_cleanup_discovery_resources(vports[i]);
851 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500852 }
853 return 0;
dea31012005-04-17 16:05:31 -0500854}
855
James Smarte59058c2008-08-24 21:49:00 -0400856/**
James Smart68e814f2014-05-21 08:04:59 -0400857 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
858 * rspiocb which got deferred
859 *
860 * @phba: pointer to lpfc HBA data structure.
861 *
862 * This routine will cleanup completed slow path events after HBA is reset
863 * when bringing down the SLI Layer.
864 *
865 *
866 * Return codes
867 * void.
868 **/
869static void
870lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
871{
872 struct lpfc_iocbq *rspiocbq;
873 struct hbq_dmabuf *dmabuf;
874 struct lpfc_cq_event *cq_event;
875
876 spin_lock_irq(&phba->hbalock);
877 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
878 spin_unlock_irq(&phba->hbalock);
879
880 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
881 /* Get the response iocb from the head of work queue */
882 spin_lock_irq(&phba->hbalock);
883 list_remove_head(&phba->sli4_hba.sp_queue_event,
884 cq_event, struct lpfc_cq_event, list);
885 spin_unlock_irq(&phba->hbalock);
886
887 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
888 case CQE_CODE_COMPL_WQE:
889 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
890 cq_event);
891 lpfc_sli_release_iocbq(phba, rspiocbq);
892 break;
893 case CQE_CODE_RECEIVE:
894 case CQE_CODE_RECEIVE_V1:
895 dmabuf = container_of(cq_event, struct hbq_dmabuf,
896 cq_event);
897 lpfc_in_buf_free(phba, &dmabuf->dbuf);
898 }
899 }
900}
901
902/**
James Smartbcece5f2014-04-04 13:51:34 -0400903 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
904 * @phba: pointer to lpfc HBA data structure.
905 *
906 * This routine will cleanup posted ELS buffers after the HBA is reset
907 * when bringing down the SLI Layer.
908 *
909 *
910 * Return codes
911 * void.
912 **/
913static void
914lpfc_hba_free_post_buf(struct lpfc_hba *phba)
915{
916 struct lpfc_sli *psli = &phba->sli;
917 struct lpfc_sli_ring *pring;
918 struct lpfc_dmabuf *mp, *next_mp;
James Smart07eab622014-04-04 13:51:44 -0400919 LIST_HEAD(buflist);
920 int count;
James Smartbcece5f2014-04-04 13:51:34 -0400921
922 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
923 lpfc_sli_hbqbuf_free_all(phba);
924 else {
925 /* Cleanup preposted buffers on the ELS ring */
James Smart895427b2017-02-12 13:52:30 -0800926 pring = &psli->sli3_ring[LPFC_ELS_RING];
James Smart07eab622014-04-04 13:51:44 -0400927 spin_lock_irq(&phba->hbalock);
928 list_splice_init(&pring->postbufq, &buflist);
929 spin_unlock_irq(&phba->hbalock);
930
931 count = 0;
932 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
James Smartbcece5f2014-04-04 13:51:34 -0400933 list_del(&mp->list);
James Smart07eab622014-04-04 13:51:44 -0400934 count++;
James Smartbcece5f2014-04-04 13:51:34 -0400935 lpfc_mbuf_free(phba, mp->virt, mp->phys);
936 kfree(mp);
937 }
James Smart07eab622014-04-04 13:51:44 -0400938
939 spin_lock_irq(&phba->hbalock);
940 pring->postbufq_cnt -= count;
James Smartbcece5f2014-04-04 13:51:34 -0400941 spin_unlock_irq(&phba->hbalock);
942 }
943}
944
945/**
946 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
947 * @phba: pointer to lpfc HBA data structure.
948 *
949 * This routine will cleanup the txcmplq after the HBA is reset when bringing
950 * down the SLI Layer.
951 *
952 * Return codes
953 * void
954 **/
955static void
956lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
957{
958 struct lpfc_sli *psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -0800959 struct lpfc_queue *qp = NULL;
James Smartbcece5f2014-04-04 13:51:34 -0400960 struct lpfc_sli_ring *pring;
961 LIST_HEAD(completions);
962 int i;
James Smartc1dd9112018-01-30 15:58:57 -0800963 struct lpfc_iocbq *piocb, *next_iocb;
James Smartbcece5f2014-04-04 13:51:34 -0400964
James Smart895427b2017-02-12 13:52:30 -0800965 if (phba->sli_rev != LPFC_SLI_REV4) {
966 for (i = 0; i < psli->num_rings; i++) {
967 pring = &psli->sli3_ring[i];
James Smartbcece5f2014-04-04 13:51:34 -0400968 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -0800969 /* At this point in time the HBA is either reset or DOA
970 * Nothing should be on txcmplq as it will
971 * NEVER complete.
972 */
973 list_splice_init(&pring->txcmplq, &completions);
974 pring->txcmplq_cnt = 0;
James Smartbcece5f2014-04-04 13:51:34 -0400975 spin_unlock_irq(&phba->hbalock);
976
James Smart895427b2017-02-12 13:52:30 -0800977 lpfc_sli_abort_iocb_ring(phba, pring);
978 }
James Smartbcece5f2014-04-04 13:51:34 -0400979 /* Cancel all the IOCBs from the completions list */
James Smart895427b2017-02-12 13:52:30 -0800980 lpfc_sli_cancel_iocbs(phba, &completions,
981 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
982 return;
983 }
984 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
985 pring = qp->pring;
986 if (!pring)
987 continue;
988 spin_lock_irq(&pring->ring_lock);
James Smartc1dd9112018-01-30 15:58:57 -0800989 list_for_each_entry_safe(piocb, next_iocb,
990 &pring->txcmplq, list)
991 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
James Smart895427b2017-02-12 13:52:30 -0800992 list_splice_init(&pring->txcmplq, &completions);
993 pring->txcmplq_cnt = 0;
994 spin_unlock_irq(&pring->ring_lock);
James Smartbcece5f2014-04-04 13:51:34 -0400995 lpfc_sli_abort_iocb_ring(phba, pring);
996 }
James Smart895427b2017-02-12 13:52:30 -0800997 /* Cancel all the IOCBs from the completions list */
998 lpfc_sli_cancel_iocbs(phba, &completions,
999 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smartbcece5f2014-04-04 13:51:34 -04001000}
1001
1002/**
James Smart3772a992009-05-22 14:50:54 -04001003 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smartbcece5f2014-04-04 13:51:34 -04001004 int i;
James Smarte59058c2008-08-24 21:49:00 -04001005 * @phba: pointer to lpfc HBA data structure.
1006 *
1007 * This routine will do uninitialization after the HBA is reset when bring
1008 * down the SLI Layer.
1009 *
1010 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001011 * 0 - success.
James Smarte59058c2008-08-24 21:49:00 -04001012 * Any other value - error.
1013 **/
James Smart3772a992009-05-22 14:50:54 -04001014static int
1015lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001016{
James Smartbcece5f2014-04-04 13:51:34 -04001017 lpfc_hba_free_post_buf(phba);
1018 lpfc_hba_clean_txcmplq(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001019 return 0;
1020}
James Smart5af5eee2010-10-22 11:06:38 -04001021
James Smartda0436e2009-05-22 14:51:39 -04001022/**
1023 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
1024 * @phba: pointer to lpfc HBA data structure.
1025 *
1026 * This routine will do uninitialization after the HBA is reset when bring
1027 * down the SLI Layer.
1028 *
1029 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001030 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001031 * Any other value - error.
1032 **/
1033static int
1034lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1035{
1036 struct lpfc_scsi_buf *psb, *psb_next;
James Smart86c67372017-04-21 16:05:04 -07001037 struct lpfc_nvmet_rcv_ctx *ctxp, *ctxp_next;
James Smartda0436e2009-05-22 14:51:39 -04001038 LIST_HEAD(aborts);
James Smart895427b2017-02-12 13:52:30 -08001039 LIST_HEAD(nvme_aborts);
James Smart86c67372017-04-21 16:05:04 -07001040 LIST_HEAD(nvmet_aborts);
James Smartda0436e2009-05-22 14:51:39 -04001041 unsigned long iflag = 0;
James Smart0f65ff62010-02-26 14:14:23 -05001042 struct lpfc_sglq *sglq_entry = NULL;
James Smartcf1a1d32017-12-08 17:18:03 -08001043 int cnt;
James Smart0f65ff62010-02-26 14:14:23 -05001044
James Smart895427b2017-02-12 13:52:30 -08001045
1046 lpfc_sli_hbqbuf_free_all(phba);
James Smartbcece5f2014-04-04 13:51:34 -04001047 lpfc_hba_clean_txcmplq(phba);
1048
James Smartda0436e2009-05-22 14:51:39 -04001049 /* At this point in time the HBA is either reset or DOA. Either
1050 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
James Smart895427b2017-02-12 13:52:30 -08001051 * on the lpfc_els_sgl_list so that it can either be freed if the
James Smartda0436e2009-05-22 14:51:39 -04001052 * driver is unloading or reposted if the driver is restarting
1053 * the port.
1054 */
James Smart895427b2017-02-12 13:52:30 -08001055 spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */
James Smartda0436e2009-05-22 14:51:39 -04001056 /* scsl_buf_list */
James Smart895427b2017-02-12 13:52:30 -08001057 /* sgl_list_lock required because worker thread uses this
James Smartda0436e2009-05-22 14:51:39 -04001058 * list.
1059 */
James Smart895427b2017-02-12 13:52:30 -08001060 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05001061 list_for_each_entry(sglq_entry,
1062 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1063 sglq_entry->state = SGL_FREED;
1064
James Smartda0436e2009-05-22 14:51:39 -04001065 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
James Smart895427b2017-02-12 13:52:30 -08001066 &phba->sli4_hba.lpfc_els_sgl_list);
1067
James Smartf358dd02017-02-12 13:52:34 -08001068
James Smart895427b2017-02-12 13:52:30 -08001069 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04001070 /* abts_scsi_buf_list_lock required because worker thread uses this
1071 * list.
1072 */
James Smart895427b2017-02-12 13:52:30 -08001073 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
1074 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1075 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
1076 &aborts);
1077 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1078 }
1079
1080 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1081 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1082 list_splice_init(&phba->sli4_hba.lpfc_abts_nvme_buf_list,
1083 &nvme_aborts);
James Smart86c67372017-04-21 16:05:04 -07001084 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1085 &nvmet_aborts);
James Smart895427b2017-02-12 13:52:30 -08001086 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1087 }
1088
James Smartda0436e2009-05-22 14:51:39 -04001089 spin_unlock_irq(&phba->hbalock);
1090
1091 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1092 psb->pCmd = NULL;
1093 psb->status = IOSTAT_SUCCESS;
1094 }
James Smarta40fc5f2013-04-17 20:17:40 -04001095 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1096 list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
1097 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
James Smart68e814f2014-05-21 08:04:59 -04001098
James Smart86c67372017-04-21 16:05:04 -07001099 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smartcf1a1d32017-12-08 17:18:03 -08001100 cnt = 0;
James Smart86c67372017-04-21 16:05:04 -07001101 list_for_each_entry_safe(psb, psb_next, &nvme_aborts, list) {
1102 psb->pCmd = NULL;
1103 psb->status = IOSTAT_SUCCESS;
James Smartcf1a1d32017-12-08 17:18:03 -08001104 cnt++;
James Smart86c67372017-04-21 16:05:04 -07001105 }
1106 spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag);
James Smartcf1a1d32017-12-08 17:18:03 -08001107 phba->put_nvme_bufs += cnt;
James Smart86c67372017-04-21 16:05:04 -07001108 list_splice(&nvme_aborts, &phba->lpfc_nvme_buf_list_put);
1109 spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag);
1110
1111 list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) {
1112 ctxp->flag &= ~(LPFC_NVMET_XBUSY | LPFC_NVMET_ABORT_OP);
James Smart6c621a22017-05-15 15:20:45 -07001113 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
James Smart86c67372017-04-21 16:05:04 -07001114 }
James Smart895427b2017-02-12 13:52:30 -08001115 }
James Smart895427b2017-02-12 13:52:30 -08001116
James Smart68e814f2014-05-21 08:04:59 -04001117 lpfc_sli4_free_sp_events(phba);
James Smartda0436e2009-05-22 14:51:39 -04001118 return 0;
1119}
1120
1121/**
1122 * lpfc_hba_down_post - Wrapper func for hba down post routine
1123 * @phba: pointer to lpfc HBA data structure.
1124 *
1125 * This routine wraps the actual SLI3 or SLI4 routine for performing
1126 * uninitialization after the HBA is reset when bring down the SLI Layer.
1127 *
1128 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001129 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001130 * Any other value - error.
1131 **/
1132int
1133lpfc_hba_down_post(struct lpfc_hba *phba)
1134{
1135 return (*phba->lpfc_hba_down_post)(phba);
1136}
Jamie Wellnitz41415862006-02-28 19:25:27 -05001137
James Smarte59058c2008-08-24 21:49:00 -04001138/**
James Smart3621a712009-04-06 18:47:14 -04001139 * lpfc_hb_timeout - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001140 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1141 *
1142 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1143 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1144 * work-port-events bitmap and the worker thread is notified. This timeout
1145 * event will be used by the worker thread to invoke the actual timeout
1146 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1147 * be performed in the timeout handler and the HBA timeout event bit shall
1148 * be cleared by the worker thread after it has taken the event bitmap out.
1149 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001150static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07001151lpfc_hb_timeout(struct timer_list *t)
James Smart858c9f62007-06-17 19:56:39 -05001152{
1153 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001154 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -05001155 unsigned long iflag;
1156
Kees Cookf22eb4d2017-09-06 20:24:26 -07001157 phba = from_timer(phba, t, hb_tmofunc);
James Smart93996272008-08-24 21:50:30 -04001158
1159 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -05001160 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001161 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1162 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -05001163 phba->pport->work_port_events |= WORKER_HB_TMO;
1164 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1165
James Smart93996272008-08-24 21:50:30 -04001166 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -04001167 if (!tmo_posted)
1168 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -05001169 return;
1170}
1171
James Smarte59058c2008-08-24 21:49:00 -04001172/**
James Smart19ca7602010-11-20 23:11:55 -05001173 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1174 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1175 *
1176 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1177 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1178 * work-port-events bitmap and the worker thread is notified. This timeout
1179 * event will be used by the worker thread to invoke the actual timeout
1180 * handler routine, lpfc_rrq_handler. Any periodical operations will
1181 * be performed in the timeout handler and the RRQ timeout event bit shall
1182 * be cleared by the worker thread after it has taken the event bitmap out.
1183 **/
1184static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07001185lpfc_rrq_timeout(struct timer_list *t)
James Smart19ca7602010-11-20 23:11:55 -05001186{
1187 struct lpfc_hba *phba;
James Smart19ca7602010-11-20 23:11:55 -05001188 unsigned long iflag;
1189
Kees Cookf22eb4d2017-09-06 20:24:26 -07001190 phba = from_timer(phba, t, rrq_tmr);
James Smart19ca7602010-11-20 23:11:55 -05001191 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001192 if (!(phba->pport->load_flag & FC_UNLOADING))
1193 phba->hba_flag |= HBA_RRQ_ACTIVE;
1194 else
1195 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
James Smart19ca7602010-11-20 23:11:55 -05001196 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001197
1198 if (!(phba->pport->load_flag & FC_UNLOADING))
1199 lpfc_worker_wake_up(phba);
James Smart19ca7602010-11-20 23:11:55 -05001200}
1201
1202/**
James Smart3621a712009-04-06 18:47:14 -04001203 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -04001204 * @phba: pointer to lpfc hba data structure.
1205 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1206 *
1207 * This is the callback function to the lpfc heart-beat mailbox command.
1208 * If configured, the lpfc driver issues the heart-beat mailbox command to
1209 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1210 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1211 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1212 * heart-beat outstanding state. Once the mailbox command comes back and
1213 * no error conditions detected, the heart-beat mailbox command timer is
1214 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1215 * state is cleared for the next heart-beat. If the timer expired with the
1216 * heart-beat outstanding state set, the driver will put the HBA offline.
1217 **/
James Smart858c9f62007-06-17 19:56:39 -05001218static void
1219lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1220{
1221 unsigned long drvr_flag;
1222
1223 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1224 phba->hb_outstanding = 0;
1225 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1226
James Smart93996272008-08-24 21:50:30 -04001227 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -05001228 mempool_free(pmboxq, phba->mbox_mem_pool);
1229 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1230 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -04001231 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -05001232 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001233 jiffies +
1234 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001235 return;
1236}
1237
James Smarte59058c2008-08-24 21:49:00 -04001238/**
James Smart3621a712009-04-06 18:47:14 -04001239 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001240 * @phba: pointer to lpfc hba data structure.
1241 *
1242 * This is the actual HBA-timer timeout handler to be invoked by the worker
1243 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1244 * handler performs any periodic operations needed for the device. If such
1245 * periodic event has already been attended to either in the interrupt handler
1246 * or by processing slow-ring or fast-ring events within the HBA-timer
1247 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1248 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1249 * is configured and there is no heart-beat mailbox command outstanding, a
1250 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1251 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1252 * to offline.
1253 **/
James Smart858c9f62007-06-17 19:56:39 -05001254void
1255lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1256{
James Smart45ed1192009-10-02 15:17:02 -04001257 struct lpfc_vport **vports;
James Smart858c9f62007-06-17 19:56:39 -05001258 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -05001259 struct lpfc_dmabuf *buf_ptr;
James Smart45ed1192009-10-02 15:17:02 -04001260 int retval, i;
James Smart858c9f62007-06-17 19:56:39 -05001261 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -05001262 LIST_HEAD(completions);
James Smart0cf07f842017-06-01 21:07:10 -07001263 struct lpfc_queue *qp;
1264 unsigned long time_elapsed;
1265 uint32_t tick_cqe, max_cqe, val;
1266 uint64_t tot, data1, data2, data3;
Dick Kennedy66d7ce92017-08-23 16:55:42 -07001267 struct lpfc_nvmet_tgtport *tgtp;
James Smart0cf07f842017-06-01 21:07:10 -07001268 struct lpfc_register reg_data;
James Smart66a210f2018-04-09 14:24:23 -07001269 struct nvme_fc_local_port *localport;
1270 struct lpfc_nvme_lport *lport;
1271 struct lpfc_nvme_ctrl_stat *cstat;
James Smart0cf07f842017-06-01 21:07:10 -07001272 void __iomem *eqdreg = phba->sli4_hba.u.if_type2.EQDregaddr;
James Smart858c9f62007-06-17 19:56:39 -05001273
James Smart45ed1192009-10-02 15:17:02 -04001274 vports = lpfc_create_vport_work_array(phba);
1275 if (vports != NULL)
James Smart4258e982015-12-16 18:11:58 -05001276 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart45ed1192009-10-02 15:17:02 -04001277 lpfc_rcv_seq_check_edtov(vports[i]);
James Smart4258e982015-12-16 18:11:58 -05001278 lpfc_fdmi_num_disc_check(vports[i]);
1279 }
James Smart45ed1192009-10-02 15:17:02 -04001280 lpfc_destroy_vport_work_array(phba, vports);
1281
James Smart858c9f62007-06-17 19:56:39 -05001282 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -04001283 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -05001284 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1285 return;
1286
James Smart0cf07f842017-06-01 21:07:10 -07001287 if (phba->cfg_auto_imax) {
1288 if (!phba->last_eqdelay_time) {
1289 phba->last_eqdelay_time = jiffies;
1290 goto skip_eqdelay;
1291 }
1292 time_elapsed = jiffies - phba->last_eqdelay_time;
1293 phba->last_eqdelay_time = jiffies;
1294
1295 tot = 0xffff;
1296 /* Check outstanding IO count */
1297 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1298 if (phba->nvmet_support) {
Dick Kennedy66d7ce92017-08-23 16:55:42 -07001299 tgtp = phba->targetport->private;
1300 /* Calculate outstanding IOs */
1301 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
1302 tot += atomic_read(&tgtp->xmt_fcp_release);
1303 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
James Smart0cf07f842017-06-01 21:07:10 -07001304 } else {
James Smart66a210f2018-04-09 14:24:23 -07001305 localport = phba->pport->localport;
1306 if (!localport || !localport->private)
1307 goto skip_eqdelay;
1308 lport = (struct lpfc_nvme_lport *)
1309 localport->private;
1310 tot = 0;
1311 for (i = 0;
1312 i < phba->cfg_nvme_io_channel; i++) {
1313 cstat = &lport->cstat[i];
1314 data1 = atomic_read(
1315 &cstat->fc4NvmeInputRequests);
1316 data2 = atomic_read(
1317 &cstat->fc4NvmeOutputRequests);
1318 data3 = atomic_read(
1319 &cstat->fc4NvmeControlRequests);
1320 tot += (data1 + data2 + data3);
1321 tot -= atomic_read(
1322 &cstat->fc4NvmeIoCmpls);
1323 }
James Smart0cf07f842017-06-01 21:07:10 -07001324 }
1325 }
1326
1327 /* Interrupts per sec per EQ */
1328 val = phba->cfg_fcp_imax / phba->io_channel_irqs;
1329 tick_cqe = val / CONFIG_HZ; /* Per tick per EQ */
1330
1331 /* Assume 1 CQE/ISR, calc max CQEs allowed for time duration */
1332 max_cqe = time_elapsed * tick_cqe;
1333
1334 for (i = 0; i < phba->io_channel_irqs; i++) {
1335 /* Fast-path EQ */
1336 qp = phba->sli4_hba.hba_eq[i];
1337 if (!qp)
1338 continue;
1339
1340 /* Use no EQ delay if we don't have many outstanding
1341 * IOs, or if we are only processing 1 CQE/ISR or less.
1342 * Otherwise, assume we can process up to lpfc_fcp_imax
1343 * interrupts per HBA.
1344 */
1345 if (tot < LPFC_NODELAY_MAX_IO ||
1346 qp->EQ_cqe_cnt <= max_cqe)
1347 val = 0;
1348 else
1349 val = phba->cfg_fcp_imax;
1350
1351 if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) {
1352 /* Use EQ Delay Register method */
1353
1354 /* Convert for EQ Delay register */
1355 if (val) {
1356 /* First, interrupts per sec per EQ */
1357 val = phba->cfg_fcp_imax /
1358 phba->io_channel_irqs;
1359
1360 /* us delay between each interrupt */
1361 val = LPFC_SEC_TO_USEC / val;
1362 }
1363 if (val != qp->q_mode) {
1364 reg_data.word0 = 0;
1365 bf_set(lpfc_sliport_eqdelay_id,
1366 &reg_data, qp->queue_id);
1367 bf_set(lpfc_sliport_eqdelay_delay,
1368 &reg_data, val);
1369 writel(reg_data.word0, eqdreg);
1370 }
1371 } else {
1372 /* Use mbox command method */
1373 if (val != qp->q_mode)
1374 lpfc_modify_hba_eq_delay(phba, i,
1375 1, val);
1376 }
1377
1378 /*
1379 * val is cfg_fcp_imax or 0 for mbox delay or us delay
1380 * between interrupts for EQDR.
1381 */
1382 qp->q_mode = val;
1383 qp->EQ_cqe_cnt = 0;
1384 }
1385 }
1386
1387skip_eqdelay:
James Smart858c9f62007-06-17 19:56:39 -05001388 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -05001389
James Smart256ec0d2013-04-17 20:14:58 -04001390 if (time_after(phba->last_completion_time +
1391 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1392 jiffies)) {
James Smart858c9f62007-06-17 19:56:39 -05001393 spin_unlock_irq(&phba->pport->work_port_lock);
1394 if (!phba->hb_outstanding)
1395 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001396 jiffies +
1397 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001398 else
1399 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001400 jiffies +
1401 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001402 return;
1403 }
1404 spin_unlock_irq(&phba->pport->work_port_lock);
1405
James Smart0ff10d42008-01-11 01:52:36 -05001406 if (phba->elsbuf_cnt &&
1407 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1408 spin_lock_irq(&phba->hbalock);
1409 list_splice_init(&phba->elsbuf, &completions);
1410 phba->elsbuf_cnt = 0;
1411 phba->elsbuf_prev_cnt = 0;
1412 spin_unlock_irq(&phba->hbalock);
1413
1414 while (!list_empty(&completions)) {
1415 list_remove_head(&completions, buf_ptr,
1416 struct lpfc_dmabuf, list);
1417 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1418 kfree(buf_ptr);
1419 }
1420 }
1421 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1422
James Smart858c9f62007-06-17 19:56:39 -05001423 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -05001424 if (phba->cfg_enable_hba_heartbeat) {
1425 if (!phba->hb_outstanding) {
James Smartbc739052010-08-04 16:11:18 -04001426 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1427 (list_empty(&psli->mboxq))) {
1428 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1429 GFP_KERNEL);
1430 if (!pmboxq) {
1431 mod_timer(&phba->hb_tmofunc,
1432 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001433 msecs_to_jiffies(1000 *
1434 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001435 return;
1436 }
James Smart13815c82008-01-11 01:52:48 -05001437
James Smartbc739052010-08-04 16:11:18 -04001438 lpfc_heart_beat(phba, pmboxq);
1439 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1440 pmboxq->vport = phba->pport;
1441 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1442 MBX_NOWAIT);
James Smart13815c82008-01-11 01:52:48 -05001443
James Smartbc739052010-08-04 16:11:18 -04001444 if (retval != MBX_BUSY &&
1445 retval != MBX_SUCCESS) {
1446 mempool_free(pmboxq,
1447 phba->mbox_mem_pool);
1448 mod_timer(&phba->hb_tmofunc,
1449 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001450 msecs_to_jiffies(1000 *
1451 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001452 return;
1453 }
1454 phba->skipped_hb = 0;
1455 phba->hb_outstanding = 1;
1456 } else if (time_before_eq(phba->last_completion_time,
1457 phba->skipped_hb)) {
1458 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1459 "2857 Last completion time not "
1460 " updated in %d ms\n",
1461 jiffies_to_msecs(jiffies
1462 - phba->last_completion_time));
1463 } else
1464 phba->skipped_hb = jiffies;
1465
James Smart858c9f62007-06-17 19:56:39 -05001466 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001467 jiffies +
1468 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001469 return;
James Smart13815c82008-01-11 01:52:48 -05001470 } else {
1471 /*
1472 * If heart beat timeout called with hb_outstanding set
James Smartdcf2a4e2010-09-29 11:18:53 -04001473 * we need to give the hb mailbox cmd a chance to
1474 * complete or TMO.
James Smart13815c82008-01-11 01:52:48 -05001475 */
James Smartdcf2a4e2010-09-29 11:18:53 -04001476 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1477 "0459 Adapter heartbeat still out"
1478 "standing:last compl time was %d ms.\n",
1479 jiffies_to_msecs(jiffies
1480 - phba->last_completion_time));
1481 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001482 jiffies +
1483 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001484 }
James Smart4258e982015-12-16 18:11:58 -05001485 } else {
1486 mod_timer(&phba->hb_tmofunc,
1487 jiffies +
1488 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001489 }
1490}
1491
James Smarte59058c2008-08-24 21:49:00 -04001492/**
James Smart3621a712009-04-06 18:47:14 -04001493 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -04001494 * @phba: pointer to lpfc hba data structure.
1495 *
1496 * This routine is called to bring the HBA offline when HBA hardware error
1497 * other than Port Error 6 has been detected.
1498 **/
James Smart09372822008-01-11 01:52:54 -05001499static void
1500lpfc_offline_eratt(struct lpfc_hba *phba)
1501{
1502 struct lpfc_sli *psli = &phba->sli;
1503
1504 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001505 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -05001506 spin_unlock_irq(&phba->hbalock);
James Smart618a5232012-06-12 13:54:36 -04001507 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart09372822008-01-11 01:52:54 -05001508
1509 lpfc_offline(phba);
1510 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001511 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001512 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001513 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001514 lpfc_hba_down_post(phba);
1515 lpfc_sli_brdready(phba, HS_MBRDY);
1516 lpfc_unblock_mgmt_io(phba);
1517 phba->link_state = LPFC_HBA_ERROR;
1518 return;
1519}
1520
James Smarte59058c2008-08-24 21:49:00 -04001521/**
James Smartda0436e2009-05-22 14:51:39 -04001522 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1523 * @phba: pointer to lpfc hba data structure.
1524 *
1525 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1526 * other than Port Error 6 has been detected.
1527 **/
James Smarta88dbb62013-04-17 20:18:39 -04001528void
James Smartda0436e2009-05-22 14:51:39 -04001529lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1530{
James Smart946727d2015-04-07 15:07:09 -04001531 spin_lock_irq(&phba->hbalock);
1532 phba->link_state = LPFC_HBA_ERROR;
1533 spin_unlock_irq(&phba->hbalock);
1534
James Smart618a5232012-06-12 13:54:36 -04001535 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smartda0436e2009-05-22 14:51:39 -04001536 lpfc_offline(phba);
James Smartda0436e2009-05-22 14:51:39 -04001537 lpfc_hba_down_post(phba);
James Smartda0436e2009-05-22 14:51:39 -04001538 lpfc_unblock_mgmt_io(phba);
James Smartda0436e2009-05-22 14:51:39 -04001539}
1540
1541/**
James Smarta257bf92009-04-06 18:48:10 -04001542 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1543 * @phba: pointer to lpfc hba data structure.
1544 *
1545 * This routine is invoked to handle the deferred HBA hardware error
1546 * conditions. This type of error is indicated by HBA by setting ER1
1547 * and another ER bit in the host status register. The driver will
1548 * wait until the ER1 bit clears before handling the error condition.
1549 **/
1550static void
1551lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1552{
1553 uint32_t old_host_status = phba->work_hs;
James Smarta257bf92009-04-06 18:48:10 -04001554 struct lpfc_sli *psli = &phba->sli;
1555
James Smartf4b4c682009-05-22 14:53:12 -04001556 /* If the pci channel is offline, ignore possible errors,
1557 * since we cannot communicate with the pci card anyway.
1558 */
1559 if (pci_channel_offline(phba->pcidev)) {
1560 spin_lock_irq(&phba->hbalock);
1561 phba->hba_flag &= ~DEFER_ERATT;
1562 spin_unlock_irq(&phba->hbalock);
1563 return;
1564 }
1565
James Smarta257bf92009-04-06 18:48:10 -04001566 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1567 "0479 Deferred Adapter Hardware Error "
1568 "Data: x%x x%x x%x\n",
1569 phba->work_hs,
1570 phba->work_status[0], phba->work_status[1]);
1571
1572 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001573 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001574 spin_unlock_irq(&phba->hbalock);
1575
1576
1577 /*
1578 * Firmware stops when it triggred erratt. That could cause the I/Os
1579 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1580 * SCSI layer retry it after re-establishing link.
1581 */
James Smartdb55fba2014-04-04 13:52:02 -04001582 lpfc_sli_abort_fcp_rings(phba);
James Smarta257bf92009-04-06 18:48:10 -04001583
1584 /*
1585 * There was a firmware error. Take the hba offline and then
1586 * attempt to restart it.
1587 */
James Smart618a5232012-06-12 13:54:36 -04001588 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smarta257bf92009-04-06 18:48:10 -04001589 lpfc_offline(phba);
1590
1591 /* Wait for the ER1 bit to clear.*/
1592 while (phba->work_hs & HS_FFER1) {
1593 msleep(100);
James Smart9940b972011-03-11 16:06:12 -05001594 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1595 phba->work_hs = UNPLUG_ERR ;
1596 break;
1597 }
James Smarta257bf92009-04-06 18:48:10 -04001598 /* If driver is unloading let the worker thread continue */
1599 if (phba->pport->load_flag & FC_UNLOADING) {
1600 phba->work_hs = 0;
1601 break;
1602 }
1603 }
1604
1605 /*
1606 * This is to ptrotect against a race condition in which
1607 * first write to the host attention register clear the
1608 * host status register.
1609 */
1610 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1611 phba->work_hs = old_host_status & ~HS_FFER1;
1612
James Smart3772a992009-05-22 14:50:54 -04001613 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001614 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001615 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001616 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1617 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1618}
1619
James Smart3772a992009-05-22 14:50:54 -04001620static void
1621lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1622{
1623 struct lpfc_board_event_header board_event;
1624 struct Scsi_Host *shost;
1625
1626 board_event.event_type = FC_REG_BOARD_EVENT;
1627 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1628 shost = lpfc_shost_from_vport(phba->pport);
1629 fc_host_post_vendor_event(shost, fc_get_event_number(),
1630 sizeof(board_event),
1631 (char *) &board_event,
1632 LPFC_NL_VENDOR_ID);
1633}
1634
James Smarta257bf92009-04-06 18:48:10 -04001635/**
James Smart3772a992009-05-22 14:50:54 -04001636 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001637 * @phba: pointer to lpfc hba data structure.
1638 *
1639 * This routine is invoked to handle the following HBA hardware error
1640 * conditions:
1641 * 1 - HBA error attention interrupt
1642 * 2 - DMA ring index out of range
1643 * 3 - Mailbox command came back as unknown
1644 **/
James Smart3772a992009-05-22 14:50:54 -04001645static void
1646lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001647{
James Smart2e0fef82007-06-17 19:56:36 -05001648 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001649 struct lpfc_sli *psli = &phba->sli;
James Smartd2873e42006-08-18 17:46:43 -04001650 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001651 unsigned long temperature;
1652 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001653 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001654
Linas Vepstas8d63f372007-02-14 14:28:36 -06001655 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001656 * since we cannot communicate with the pci card anyway.
1657 */
1658 if (pci_channel_offline(phba->pcidev)) {
1659 spin_lock_irq(&phba->hbalock);
1660 phba->hba_flag &= ~DEFER_ERATT;
1661 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001662 return;
James Smart3772a992009-05-22 14:50:54 -04001663 }
1664
James Smart13815c82008-01-11 01:52:48 -05001665 /* If resets are disabled then leave the HBA alone and return */
1666 if (!phba->cfg_enable_hba_reset)
1667 return;
dea31012005-04-17 16:05:31 -05001668
James Smartea2151b2008-09-07 11:52:10 -04001669 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001670 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001671
James Smarta257bf92009-04-06 18:48:10 -04001672 if (phba->hba_flag & DEFER_ERATT)
1673 lpfc_handle_deferred_eratt(phba);
1674
James Smartdcf2a4e2010-09-29 11:18:53 -04001675 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1676 if (phba->work_hs & HS_FFER6)
1677 /* Re-establishing Link */
1678 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1679 "1301 Re-establishing Link "
1680 "Data: x%x x%x x%x\n",
1681 phba->work_hs, phba->work_status[0],
1682 phba->work_status[1]);
1683 if (phba->work_hs & HS_FFER8)
1684 /* Device Zeroization */
1685 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1686 "2861 Host Authentication device "
1687 "zeroization Data:x%x x%x x%x\n",
1688 phba->work_hs, phba->work_status[0],
1689 phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001690
James Smart92d7f7b2007-06-17 19:56:38 -05001691 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001692 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001693 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001694
1695 /*
1696 * Firmware stops when it triggled erratt with HS_FFER6.
1697 * That could cause the I/Os dropped by the firmware.
1698 * Error iocb (I/O) on txcmplq and let the SCSI layer
1699 * retry it after re-establishing link.
1700 */
James Smartdb55fba2014-04-04 13:52:02 -04001701 lpfc_sli_abort_fcp_rings(phba);
dea31012005-04-17 16:05:31 -05001702
dea31012005-04-17 16:05:31 -05001703 /*
1704 * There was a firmware error. Take the hba offline and then
1705 * attempt to restart it.
1706 */
James Smart618a5232012-06-12 13:54:36 -04001707 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
dea31012005-04-17 16:05:31 -05001708 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001709 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001710 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001711 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001712 return;
1713 }
James Smart46fa3112007-04-25 09:51:45 -04001714 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001715 } else if (phba->work_hs & HS_CRIT_TEMP) {
1716 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1717 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1718 temp_event_data.event_code = LPFC_CRIT_TEMP;
1719 temp_event_data.data = (uint32_t)temperature;
1720
1721 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001722 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001723 "(%ld), taking this port offline "
1724 "Data: x%x x%x x%x\n",
1725 temperature, phba->work_hs,
1726 phba->work_status[0], phba->work_status[1]);
1727
1728 shost = lpfc_shost_from_vport(phba->pport);
1729 fc_host_post_vendor_event(shost, fc_get_event_number(),
1730 sizeof(temp_event_data),
1731 (char *) &temp_event_data,
1732 SCSI_NL_VID_TYPE_PCI
1733 | PCI_VENDOR_ID_EMULEX);
1734
James Smart7af67052007-10-27 13:38:11 -04001735 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001736 phba->over_temp_state = HBA_OVER_TEMP;
1737 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001738 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001739
dea31012005-04-17 16:05:31 -05001740 } else {
1741 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001742 * failure is a value other than FFER6. Do not call the offline
1743 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001744 */
1745 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001746 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001747 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001748 phba->work_hs,
dea31012005-04-17 16:05:31 -05001749 phba->work_status[0], phba->work_status[1]);
1750
James Smartd2873e42006-08-18 17:46:43 -04001751 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001752 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001753 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001754 sizeof(event_data), (char *) &event_data,
1755 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1756
James Smart09372822008-01-11 01:52:54 -05001757 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001758 }
James Smart93996272008-08-24 21:50:30 -04001759 return;
dea31012005-04-17 16:05:31 -05001760}
1761
James Smarte59058c2008-08-24 21:49:00 -04001762/**
James Smart618a5232012-06-12 13:54:36 -04001763 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1764 * @phba: pointer to lpfc hba data structure.
1765 * @mbx_action: flag for mailbox shutdown action.
1766 *
1767 * This routine is invoked to perform an SLI4 port PCI function reset in
1768 * response to port status register polling attention. It waits for port
1769 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1770 * During this process, interrupt vectors are freed and later requested
1771 * for handling possible port resource change.
1772 **/
1773static int
James Smarte10b2022014-02-20 09:57:43 -05001774lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1775 bool en_rn_msg)
James Smart618a5232012-06-12 13:54:36 -04001776{
1777 int rc;
1778 uint32_t intr_mode;
1779
James Smart27d6ac02018-02-22 08:18:42 -08001780 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
James Smart65791f12016-07-06 12:35:56 -07001781 LPFC_SLI_INTF_IF_TYPE_2) {
1782 /*
1783 * On error status condition, driver need to wait for port
1784 * ready before performing reset.
1785 */
1786 rc = lpfc_sli4_pdev_status_reg_wait(phba);
James Smart0e916ee2016-07-06 12:36:06 -07001787 if (rc)
James Smart65791f12016-07-06 12:35:56 -07001788 return rc;
James Smart618a5232012-06-12 13:54:36 -04001789 }
James Smart0e916ee2016-07-06 12:36:06 -07001790
James Smart65791f12016-07-06 12:35:56 -07001791 /* need reset: attempt for port recovery */
1792 if (en_rn_msg)
1793 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1794 "2887 Reset Needed: Attempting Port "
1795 "Recovery...\n");
1796 lpfc_offline_prep(phba, mbx_action);
1797 lpfc_offline(phba);
1798 /* release interrupt for possible resource change */
1799 lpfc_sli4_disable_intr(phba);
James Smart5a9eeff2018-11-29 16:09:32 -08001800 rc = lpfc_sli_brdrestart(phba);
1801 if (rc) {
1802 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1803 "6309 Failed to restart board\n");
1804 return rc;
1805 }
James Smart65791f12016-07-06 12:35:56 -07001806 /* request and enable interrupt */
1807 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1808 if (intr_mode == LPFC_INTR_ERROR) {
1809 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1810 "3175 Failed to enable interrupt\n");
1811 return -EIO;
1812 }
1813 phba->intr_mode = intr_mode;
1814 rc = lpfc_online(phba);
1815 if (rc == 0)
1816 lpfc_unblock_mgmt_io(phba);
1817
James Smart618a5232012-06-12 13:54:36 -04001818 return rc;
1819}
1820
1821/**
James Smartda0436e2009-05-22 14:51:39 -04001822 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1823 * @phba: pointer to lpfc hba data structure.
1824 *
1825 * This routine is invoked to handle the SLI4 HBA hardware error attention
1826 * conditions.
1827 **/
1828static void
1829lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1830{
1831 struct lpfc_vport *vport = phba->pport;
1832 uint32_t event_data;
1833 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001834 uint32_t if_type;
James Smart2e90f4b2011-12-13 13:22:37 -05001835 struct lpfc_register portstat_reg = {0};
1836 uint32_t reg_err1, reg_err2;
1837 uint32_t uerrlo_reg, uemasklo_reg;
James Smart65791f12016-07-06 12:35:56 -07001838 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
James Smarte10b2022014-02-20 09:57:43 -05001839 bool en_rn_msg = true;
James Smart946727d2015-04-07 15:07:09 -04001840 struct temp_event temp_event_data;
James Smart65791f12016-07-06 12:35:56 -07001841 struct lpfc_register portsmphr_reg;
1842 int rc, i;
James Smartda0436e2009-05-22 14:51:39 -04001843
1844 /* If the pci channel is offline, ignore possible errors, since
1845 * we cannot communicate with the pci card anyway.
1846 */
1847 if (pci_channel_offline(phba->pcidev))
1848 return;
James Smartda0436e2009-05-22 14:51:39 -04001849
James Smart65791f12016-07-06 12:35:56 -07001850 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
James Smart2fcee4b2010-12-15 17:57:46 -05001851 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1852 switch (if_type) {
1853 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart2e90f4b2011-12-13 13:22:37 -05001854 pci_rd_rc1 = lpfc_readl(
1855 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1856 &uerrlo_reg);
1857 pci_rd_rc2 = lpfc_readl(
1858 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1859 &uemasklo_reg);
1860 /* consider PCI bus read error as pci_channel_offline */
1861 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1862 return;
James Smart65791f12016-07-06 12:35:56 -07001863 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
1864 lpfc_sli4_offline_eratt(phba);
1865 return;
1866 }
1867 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1868 "7623 Checking UE recoverable");
1869
1870 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
1871 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1872 &portsmphr_reg.word0))
1873 continue;
1874
1875 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
1876 &portsmphr_reg);
1877 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1878 LPFC_PORT_SEM_UE_RECOVERABLE)
1879 break;
1880 /*Sleep for 1Sec, before checking SEMAPHORE */
1881 msleep(1000);
1882 }
1883
1884 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1885 "4827 smphr_port_status x%x : Waited %dSec",
1886 smphr_port_status, i);
1887
1888 /* Recoverable UE, reset the HBA device */
1889 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1890 LPFC_PORT_SEM_UE_RECOVERABLE) {
1891 for (i = 0; i < 20; i++) {
1892 msleep(1000);
1893 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1894 &portsmphr_reg.word0) &&
1895 (LPFC_POST_STAGE_PORT_READY ==
1896 bf_get(lpfc_port_smphr_port_status,
1897 &portsmphr_reg))) {
1898 rc = lpfc_sli4_port_sta_fn_reset(phba,
1899 LPFC_MBX_NO_WAIT, en_rn_msg);
1900 if (rc == 0)
1901 return;
1902 lpfc_printf_log(phba,
1903 KERN_ERR, LOG_INIT,
1904 "4215 Failed to recover UE");
1905 break;
1906 }
1907 }
1908 }
1909 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1910 "7624 Firmware not ready: Failing UE recovery,"
1911 " waited %dSec", i);
James Smart2fcee4b2010-12-15 17:57:46 -05001912 lpfc_sli4_offline_eratt(phba);
1913 break;
James Smart946727d2015-04-07 15:07:09 -04001914
James Smart2fcee4b2010-12-15 17:57:46 -05001915 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08001916 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2e90f4b2011-12-13 13:22:37 -05001917 pci_rd_rc1 = lpfc_readl(
1918 phba->sli4_hba.u.if_type2.STATUSregaddr,
1919 &portstat_reg.word0);
1920 /* consider PCI bus read error as pci_channel_offline */
James Smart6b5151f2012-01-18 16:24:06 -05001921 if (pci_rd_rc1 == -EIO) {
1922 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1923 "3151 PCI bus read access failure: x%x\n",
1924 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
James Smart2e90f4b2011-12-13 13:22:37 -05001925 return;
James Smart6b5151f2012-01-18 16:24:06 -05001926 }
James Smart2e90f4b2011-12-13 13:22:37 -05001927 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1928 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
James Smart2fcee4b2010-12-15 17:57:46 -05001929 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
James Smart2fcee4b2010-12-15 17:57:46 -05001930 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1931 "2889 Port Overtemperature event, "
James Smart946727d2015-04-07 15:07:09 -04001932 "taking port offline Data: x%x x%x\n",
1933 reg_err1, reg_err2);
1934
James Smart310429e2016-07-06 12:35:54 -07001935 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04001936 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1937 temp_event_data.event_code = LPFC_CRIT_TEMP;
1938 temp_event_data.data = 0xFFFFFFFF;
1939
1940 shost = lpfc_shost_from_vport(phba->pport);
1941 fc_host_post_vendor_event(shost, fc_get_event_number(),
1942 sizeof(temp_event_data),
1943 (char *)&temp_event_data,
1944 SCSI_NL_VID_TYPE_PCI
1945 | PCI_VENDOR_ID_EMULEX);
1946
James Smart2fcee4b2010-12-15 17:57:46 -05001947 spin_lock_irq(&phba->hbalock);
1948 phba->over_temp_state = HBA_OVER_TEMP;
1949 spin_unlock_irq(&phba->hbalock);
1950 lpfc_sli4_offline_eratt(phba);
James Smart946727d2015-04-07 15:07:09 -04001951 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001952 }
James Smart2e90f4b2011-12-13 13:22:37 -05001953 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smarte10b2022014-02-20 09:57:43 -05001954 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
James Smart2e90f4b2011-12-13 13:22:37 -05001955 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte10b2022014-02-20 09:57:43 -05001956 "3143 Port Down: Firmware Update "
1957 "Detected\n");
1958 en_rn_msg = false;
1959 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smart2e90f4b2011-12-13 13:22:37 -05001960 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1961 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1962 "3144 Port Down: Debug Dump\n");
1963 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1964 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1965 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1966 "3145 Port Down: Provisioning\n");
James Smart618a5232012-06-12 13:54:36 -04001967
James Smart946727d2015-04-07 15:07:09 -04001968 /* If resets are disabled then leave the HBA alone and return */
1969 if (!phba->cfg_enable_hba_reset)
1970 return;
1971
James Smart618a5232012-06-12 13:54:36 -04001972 /* Check port status register for function reset */
James Smarte10b2022014-02-20 09:57:43 -05001973 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1974 en_rn_msg);
James Smart618a5232012-06-12 13:54:36 -04001975 if (rc == 0) {
1976 /* don't report event on forced debug dump */
1977 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1978 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1979 return;
1980 else
1981 break;
James Smart2fcee4b2010-12-15 17:57:46 -05001982 }
James Smart618a5232012-06-12 13:54:36 -04001983 /* fall through for not able to recover */
James Smart6b5151f2012-01-18 16:24:06 -05001984 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1985 "3152 Unrecoverable error, bring the port "
1986 "offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05001987 lpfc_sli4_offline_eratt(phba);
1988 break;
1989 case LPFC_SLI_INTF_IF_TYPE_1:
1990 default:
1991 break;
1992 }
James Smart2e90f4b2011-12-13 13:22:37 -05001993 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1994 "3123 Report dump event to upper layer\n");
1995 /* Send an internal error event to mgmt application */
1996 lpfc_board_errevt_to_mgmt(phba);
1997
1998 event_data = FC_REG_DUMP_EVENT;
1999 shost = lpfc_shost_from_vport(vport);
2000 fc_host_post_vendor_event(shost, fc_get_event_number(),
2001 sizeof(event_data), (char *) &event_data,
2002 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
James Smartda0436e2009-05-22 14:51:39 -04002003}
2004
2005/**
2006 * lpfc_handle_eratt - Wrapper func for handling hba error attention
2007 * @phba: pointer to lpfc HBA data structure.
2008 *
2009 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
2010 * routine from the API jump table function pointer from the lpfc_hba struct.
2011 *
2012 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02002013 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04002014 * Any other value - error.
2015 **/
2016void
2017lpfc_handle_eratt(struct lpfc_hba *phba)
2018{
2019 (*phba->lpfc_handle_eratt)(phba);
2020}
2021
2022/**
James Smart3621a712009-04-06 18:47:14 -04002023 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04002024 * @phba: pointer to lpfc hba data structure.
2025 *
2026 * This routine is invoked from the worker thread to handle a HBA host
James Smart895427b2017-02-12 13:52:30 -08002027 * attention link event. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002028 **/
dea31012005-04-17 16:05:31 -05002029void
James Smart2e0fef82007-06-17 19:56:36 -05002030lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002031{
James Smart2e0fef82007-06-17 19:56:36 -05002032 struct lpfc_vport *vport = phba->pport;
2033 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05002034 LPFC_MBOXQ_t *pmb;
2035 volatile uint32_t control;
2036 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05002037 int rc = 0;
dea31012005-04-17 16:05:31 -05002038
2039 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05002040 if (!pmb) {
2041 rc = 1;
dea31012005-04-17 16:05:31 -05002042 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05002043 }
dea31012005-04-17 16:05:31 -05002044
2045 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05002046 if (!mp) {
2047 rc = 2;
dea31012005-04-17 16:05:31 -05002048 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05002049 }
dea31012005-04-17 16:05:31 -05002050
2051 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05002052 if (!mp->virt) {
2053 rc = 3;
dea31012005-04-17 16:05:31 -05002054 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05002055 }
dea31012005-04-17 16:05:31 -05002056
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05002057 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04002058 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05002059
2060 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05002061 lpfc_read_topology(phba, pmb, mp);
2062 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05002063 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04002064 /* Block ELS IOCBs until we have processed this mbox command */
James Smart895427b2017-02-12 13:52:30 -08002065 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04002066 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05002067 if (rc == MBX_NOT_FINISHED) {
2068 rc = 4;
James Smart14691152006-12-02 13:34:28 -05002069 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05002070 }
dea31012005-04-17 16:05:31 -05002071
2072 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05002073 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002074 writel(HA_LATT, phba->HAregaddr);
2075 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05002076 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002077
2078 return;
2079
James Smart14691152006-12-02 13:34:28 -05002080lpfc_handle_latt_free_mbuf:
James Smart895427b2017-02-12 13:52:30 -08002081 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05002082 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05002083lpfc_handle_latt_free_mp:
2084 kfree(mp);
2085lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04002086 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002087lpfc_handle_latt_err_exit:
2088 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05002089 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002090 psli->sli_flag |= LPFC_PROCESS_LA;
2091 control = readl(phba->HCregaddr);
2092 control |= HC_LAINT_ENA;
2093 writel(control, phba->HCregaddr);
2094 readl(phba->HCregaddr); /* flush */
2095
2096 /* Clear Link Attention in HA REG */
2097 writel(HA_LATT, phba->HAregaddr);
2098 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05002099 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002100 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002101 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002102
James Smart09372822008-01-11 01:52:54 -05002103 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
2104 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05002105
2106 return;
2107}
2108
James Smarte59058c2008-08-24 21:49:00 -04002109/**
James Smart3621a712009-04-06 18:47:14 -04002110 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04002111 * @phba: pointer to lpfc hba data structure.
2112 * @vpd: pointer to the vital product data.
2113 * @len: length of the vital product data in bytes.
2114 *
2115 * This routine parses the Vital Product Data (VPD). The VPD is treated as
2116 * an array of characters. In this routine, the ModelName, ProgramType, and
2117 * ModelDesc, etc. fields of the phba data structure will be populated.
2118 *
2119 * Return codes
2120 * 0 - pointer to the VPD passed in is NULL
2121 * 1 - success
2122 **/
James Smart3772a992009-05-22 14:50:54 -04002123int
James Smart2e0fef82007-06-17 19:56:36 -05002124lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05002125{
2126 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05002127 int Length;
dea31012005-04-17 16:05:31 -05002128 int i, j;
2129 int finished = 0;
2130 int index = 0;
2131
2132 if (!vpd)
2133 return 0;
2134
2135 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05002136 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002137 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05002138 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
2139 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002140 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05002141 switch (vpd[index]) {
2142 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002143 case 0x91:
dea31012005-04-17 16:05:31 -05002144 index += 1;
2145 lenlo = vpd[index];
2146 index += 1;
2147 lenhi = vpd[index];
2148 index += 1;
2149 i = ((((unsigned short)lenhi) << 8) + lenlo);
2150 index += i;
2151 break;
2152 case 0x90:
2153 index += 1;
2154 lenlo = vpd[index];
2155 index += 1;
2156 lenhi = vpd[index];
2157 index += 1;
2158 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002159 if (Length > len - index)
2160 Length = len - index;
dea31012005-04-17 16:05:31 -05002161 while (Length > 0) {
2162 /* Look for Serial Number */
2163 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
2164 index += 2;
2165 i = vpd[index];
2166 index += 1;
2167 j = 0;
2168 Length -= (3+i);
2169 while(i--) {
2170 phba->SerialNumber[j++] = vpd[index++];
2171 if (j == 31)
2172 break;
2173 }
2174 phba->SerialNumber[j] = 0;
2175 continue;
2176 }
2177 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
2178 phba->vpd_flag |= VPD_MODEL_DESC;
2179 index += 2;
2180 i = vpd[index];
2181 index += 1;
2182 j = 0;
2183 Length -= (3+i);
2184 while(i--) {
2185 phba->ModelDesc[j++] = vpd[index++];
2186 if (j == 255)
2187 break;
2188 }
2189 phba->ModelDesc[j] = 0;
2190 continue;
2191 }
2192 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
2193 phba->vpd_flag |= VPD_MODEL_NAME;
2194 index += 2;
2195 i = vpd[index];
2196 index += 1;
2197 j = 0;
2198 Length -= (3+i);
2199 while(i--) {
2200 phba->ModelName[j++] = vpd[index++];
2201 if (j == 79)
2202 break;
2203 }
2204 phba->ModelName[j] = 0;
2205 continue;
2206 }
2207 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2208 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2209 index += 2;
2210 i = vpd[index];
2211 index += 1;
2212 j = 0;
2213 Length -= (3+i);
2214 while(i--) {
2215 phba->ProgramType[j++] = vpd[index++];
2216 if (j == 255)
2217 break;
2218 }
2219 phba->ProgramType[j] = 0;
2220 continue;
2221 }
2222 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2223 phba->vpd_flag |= VPD_PORT;
2224 index += 2;
2225 i = vpd[index];
2226 index += 1;
2227 j = 0;
2228 Length -= (3+i);
2229 while(i--) {
James Smartcd1c8302011-10-10 21:33:25 -04002230 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2231 (phba->sli4_hba.pport_name_sta ==
2232 LPFC_SLI4_PPNAME_GET)) {
2233 j++;
2234 index++;
2235 } else
2236 phba->Port[j++] = vpd[index++];
2237 if (j == 19)
2238 break;
dea31012005-04-17 16:05:31 -05002239 }
James Smartcd1c8302011-10-10 21:33:25 -04002240 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2241 (phba->sli4_hba.pport_name_sta ==
2242 LPFC_SLI4_PPNAME_NON))
2243 phba->Port[j] = 0;
dea31012005-04-17 16:05:31 -05002244 continue;
2245 }
2246 else {
2247 index += 2;
2248 i = vpd[index];
2249 index += 1;
2250 index += i;
2251 Length -= (3 + i);
2252 }
2253 }
2254 finished = 0;
2255 break;
2256 case 0x78:
2257 finished = 1;
2258 break;
2259 default:
2260 index ++;
2261 break;
2262 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002263 }
dea31012005-04-17 16:05:31 -05002264
2265 return(1);
2266}
2267
James Smarte59058c2008-08-24 21:49:00 -04002268/**
James Smart3621a712009-04-06 18:47:14 -04002269 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04002270 * @phba: pointer to lpfc hba data structure.
2271 * @mdp: pointer to the data structure to hold the derived model name.
2272 * @descp: pointer to the data structure to hold the derived description.
2273 *
2274 * This routine retrieves HBA's description based on its registered PCI device
2275 * ID. The @descp passed into this function points to an array of 256 chars. It
2276 * shall be returned with the model name, maximum speed, and the host bus type.
2277 * The @mdp passed into this function points to an array of 80 chars. When the
2278 * function returns, the @mdp will be filled with the model name.
2279 **/
dea31012005-04-17 16:05:31 -05002280static void
James Smart2e0fef82007-06-17 19:56:36 -05002281lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05002282{
2283 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05002284 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002285 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04002286 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04002287 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002288 struct {
James Smarta747c9c2009-11-18 15:41:10 -05002289 char *name;
2290 char *bus;
2291 char *function;
2292 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002293
2294 if (mdp && mdp[0] != '\0'
2295 && descp && descp[0] != '\0')
2296 return;
2297
James Smartfbd8a6b2018-02-22 08:18:45 -08002298 if (phba->lmt & LMT_64Gb)
2299 max_speed = 64;
2300 else if (phba->lmt & LMT_32Gb)
James Smartd38dd522015-08-31 16:48:17 -04002301 max_speed = 32;
2302 else if (phba->lmt & LMT_16Gb)
James Smartc0c11512011-05-24 11:41:34 -04002303 max_speed = 16;
2304 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002305 max_speed = 10;
2306 else if (phba->lmt & LMT_8Gb)
2307 max_speed = 8;
2308 else if (phba->lmt & LMT_4Gb)
2309 max_speed = 4;
2310 else if (phba->lmt & LMT_2Gb)
2311 max_speed = 2;
James Smart4169d862012-09-29 11:32:09 -04002312 else if (phba->lmt & LMT_1Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002313 max_speed = 1;
James Smart4169d862012-09-29 11:32:09 -04002314 else
2315 max_speed = 0;
dea31012005-04-17 16:05:31 -05002316
2317 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05002318
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002319 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002320 case PCI_DEVICE_ID_FIREFLY:
James Smart12222f42014-05-21 08:05:19 -04002321 m = (typeof(m)){"LP6000", "PCI",
2322 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002323 break;
dea31012005-04-17 16:05:31 -05002324 case PCI_DEVICE_ID_SUPERFLY:
2325 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart12222f42014-05-21 08:05:19 -04002326 m = (typeof(m)){"LP7000", "PCI", ""};
dea31012005-04-17 16:05:31 -05002327 else
James Smart12222f42014-05-21 08:05:19 -04002328 m = (typeof(m)){"LP7000E", "PCI", ""};
2329 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002330 break;
2331 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002332 m = (typeof(m)){"LP8000", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002333 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002334 break;
2335 case PCI_DEVICE_ID_CENTAUR:
2336 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart12222f42014-05-21 08:05:19 -04002337 m = (typeof(m)){"LP9002", "PCI", ""};
dea31012005-04-17 16:05:31 -05002338 else
James Smart12222f42014-05-21 08:05:19 -04002339 m = (typeof(m)){"LP9000", "PCI", ""};
2340 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002341 break;
2342 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002343 m = (typeof(m)){"LP952", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002344 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002345 break;
2346 case PCI_DEVICE_ID_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05002347 m = (typeof(m)){"LP9802", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002348 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002349 break;
2350 case PCI_DEVICE_ID_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05002351 m = (typeof(m)){"LP10000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002352 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002353 break;
2354 case PCI_DEVICE_ID_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05002355 m = (typeof(m)){"LPX1000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002356 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002357 break;
2358 case PCI_DEVICE_ID_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002359 m = (typeof(m)){"LP982", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002360 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002361 break;
2362 case PCI_DEVICE_ID_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002363 m = (typeof(m)){"LP1050", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002364 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002365 break;
2366 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05002367 m = (typeof(m)){"LP11000", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002368 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002369 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002370 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002371 m = (typeof(m)){"LP11000-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002372 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002373 break;
2374 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002375 m = (typeof(m)){"LP11002-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002376 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002377 break;
2378 case PCI_DEVICE_ID_NEPTUNE:
James Smart12222f42014-05-21 08:05:19 -04002379 m = (typeof(m)){"LPe1000", "PCIe",
2380 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002381 break;
2382 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart12222f42014-05-21 08:05:19 -04002383 m = (typeof(m)){"LPe1000-SP", "PCIe",
2384 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002385 break;
2386 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart12222f42014-05-21 08:05:19 -04002387 m = (typeof(m)){"LPe1002-SP", "PCIe",
2388 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002389 break;
dea31012005-04-17 16:05:31 -05002390 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05002391 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002392 break;
2393 case PCI_DEVICE_ID_BSMB:
James Smart12222f42014-05-21 08:05:19 -04002394 m = (typeof(m)){"LP111", "PCI-X2",
2395 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002396 break;
2397 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05002398 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002399 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002400 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002401 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002402 break;
2403 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002404 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04002405 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002406 break;
dea31012005-04-17 16:05:31 -05002407 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05002408 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002409 break;
2410 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05002411 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002412 break;
2413 case PCI_DEVICE_ID_LP101:
James Smart12222f42014-05-21 08:05:19 -04002414 m = (typeof(m)){"LP101", "PCI-X",
2415 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002416 break;
2417 case PCI_DEVICE_ID_LP10000S:
James Smart12222f42014-05-21 08:05:19 -04002418 m = (typeof(m)){"LP10000-S", "PCI",
2419 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002420 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002421 case PCI_DEVICE_ID_LP11000S:
James Smart12222f42014-05-21 08:05:19 -04002422 m = (typeof(m)){"LP11000-S", "PCI-X2",
2423 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05002424 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002425 case PCI_DEVICE_ID_LPE11000S:
James Smart12222f42014-05-21 08:05:19 -04002426 m = (typeof(m)){"LPe11000-S", "PCIe",
2427 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002428 break;
James Smartb87eab32007-04-25 09:53:28 -04002429 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05002430 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002431 break;
2432 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05002433 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002434 break;
2435 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05002436 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002437 break;
2438 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002439 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002440 break;
2441 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002442 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002443 break;
2444 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05002445 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002446 break;
James Smart84774a42008-08-24 21:50:06 -04002447 case PCI_DEVICE_ID_HORNET:
James Smart12222f42014-05-21 08:05:19 -04002448 m = (typeof(m)){"LP21000", "PCIe",
2449 "Obsolete, Unsupported FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002450 GE = 1;
2451 break;
2452 case PCI_DEVICE_ID_PROTEUS_VF:
James Smarta747c9c2009-11-18 15:41:10 -05002453 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002454 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002455 break;
2456 case PCI_DEVICE_ID_PROTEUS_PF:
James Smarta747c9c2009-11-18 15:41:10 -05002457 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002458 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002459 break;
2460 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05002461 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002462 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002463 break;
James Smartda0436e2009-05-22 14:51:39 -04002464 case PCI_DEVICE_ID_TIGERSHARK:
2465 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002466 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04002467 break;
James Smarta747c9c2009-11-18 15:41:10 -05002468 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04002469 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002470 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2471 break;
2472 case PCI_DEVICE_ID_FALCON:
2473 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2474 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04002475 break;
James Smart98fc5dd2010-06-07 15:24:29 -04002476 case PCI_DEVICE_ID_BALIUS:
2477 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
James Smart12222f42014-05-21 08:05:19 -04002478 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart98fc5dd2010-06-07 15:24:29 -04002479 break;
James Smart085c6472010-11-20 23:11:37 -05002480 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04002481 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05002482 break;
James Smart12222f42014-05-21 08:05:19 -04002483 case PCI_DEVICE_ID_LANCER_FC_VF:
2484 m = (typeof(m)){"LPe16000", "PCIe",
2485 "Obsolete, Unsupported Fibre Channel Adapter"};
2486 break;
James Smart085c6472010-11-20 23:11:37 -05002487 case PCI_DEVICE_ID_LANCER_FCOE:
2488 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04002489 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05002490 break;
James Smart12222f42014-05-21 08:05:19 -04002491 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2492 oneConnect = 1;
2493 m = (typeof(m)){"OCe15100", "PCIe",
2494 "Obsolete, Unsupported FCoE"};
2495 break;
James Smartd38dd522015-08-31 16:48:17 -04002496 case PCI_DEVICE_ID_LANCER_G6_FC:
2497 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2498 break;
James Smartc238b9b2018-02-22 08:18:44 -08002499 case PCI_DEVICE_ID_LANCER_G7_FC:
2500 m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"};
2501 break;
James Smartf8cafd32012-08-03 12:42:51 -04002502 case PCI_DEVICE_ID_SKYHAWK:
2503 case PCI_DEVICE_ID_SKYHAWK_VF:
2504 oneConnect = 1;
2505 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2506 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002507 default:
James Smarta747c9c2009-11-18 15:41:10 -05002508 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002509 break;
dea31012005-04-17 16:05:31 -05002510 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002511
2512 if (mdp && mdp[0] == '\0')
2513 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04002514 /*
2515 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04002516 * and we put the port number on the end
2517 */
2518 if (descp && descp[0] == '\0') {
2519 if (oneConnect)
2520 snprintf(descp, 255,
James Smart4169d862012-09-29 11:32:09 -04002521 "Emulex OneConnect %s, %s Initiator %s",
James Smarta747c9c2009-11-18 15:41:10 -05002522 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04002523 phba->Port);
James Smart4169d862012-09-29 11:32:09 -04002524 else if (max_speed == 0)
2525 snprintf(descp, 255,
Sebastian Herbszt290237d2015-08-31 16:48:08 -04002526 "Emulex %s %s %s",
James Smart4169d862012-09-29 11:32:09 -04002527 m.name, m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002528 else
2529 snprintf(descp, 255,
2530 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05002531 m.name, max_speed, (GE) ? "GE" : "Gb",
2532 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002533 }
dea31012005-04-17 16:05:31 -05002534}
2535
James Smarte59058c2008-08-24 21:49:00 -04002536/**
James Smart3621a712009-04-06 18:47:14 -04002537 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04002538 * @phba: pointer to lpfc hba data structure.
2539 * @pring: pointer to a IOCB ring.
2540 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2541 *
2542 * This routine posts a given number of IOCBs with the associated DMA buffer
2543 * descriptors specified by the cnt argument to the given IOCB ring.
2544 *
2545 * Return codes
2546 * The number of IOCBs NOT able to be posted to the IOCB ring.
2547 **/
dea31012005-04-17 16:05:31 -05002548int
James Smart495a7142008-06-14 22:52:59 -04002549lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002550{
2551 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002552 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002553 struct lpfc_dmabuf *mp1, *mp2;
2554
2555 cnt += pring->missbufcnt;
2556
2557 /* While there are buffers to post */
2558 while (cnt > 0) {
2559 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002560 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002561 if (iocb == NULL) {
2562 pring->missbufcnt = cnt;
2563 return cnt;
2564 }
dea31012005-04-17 16:05:31 -05002565 icmd = &iocb->iocb;
2566
2567 /* 2 buffers can be posted per command */
2568 /* Allocate buffer to post */
2569 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2570 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002571 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2572 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002573 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002574 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002575 pring->missbufcnt = cnt;
2576 return cnt;
2577 }
2578
2579 INIT_LIST_HEAD(&mp1->list);
2580 /* Allocate buffer to post */
2581 if (cnt > 1) {
2582 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2583 if (mp2)
2584 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2585 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002586 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002587 kfree(mp2);
dea31012005-04-17 16:05:31 -05002588 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2589 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002590 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002591 pring->missbufcnt = cnt;
2592 return cnt;
2593 }
2594
2595 INIT_LIST_HEAD(&mp2->list);
2596 } else {
2597 mp2 = NULL;
2598 }
2599
2600 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2601 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2602 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2603 icmd->ulpBdeCount = 1;
2604 cnt--;
2605 if (mp2) {
2606 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2607 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2608 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2609 cnt--;
2610 icmd->ulpBdeCount = 2;
2611 }
2612
2613 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2614 icmd->ulpLe = 1;
2615
James Smart3772a992009-05-22 14:50:54 -04002616 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2617 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002618 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2619 kfree(mp1);
2620 cnt++;
2621 if (mp2) {
2622 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2623 kfree(mp2);
2624 cnt++;
2625 }
James Bottomley604a3e32005-10-29 10:28:33 -05002626 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002627 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002628 return cnt;
2629 }
dea31012005-04-17 16:05:31 -05002630 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002631 if (mp2)
dea31012005-04-17 16:05:31 -05002632 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002633 }
2634 pring->missbufcnt = 0;
2635 return 0;
2636}
2637
James Smarte59058c2008-08-24 21:49:00 -04002638/**
James Smart3621a712009-04-06 18:47:14 -04002639 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002640 * @phba: pointer to lpfc hba data structure.
2641 *
2642 * This routine posts initial receive IOCB buffers to the ELS ring. The
2643 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
James Smart895427b2017-02-12 13:52:30 -08002644 * set to 64 IOCBs. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002645 *
2646 * Return codes
2647 * 0 - success (currently always success)
2648 **/
dea31012005-04-17 16:05:31 -05002649static int
James Smart2e0fef82007-06-17 19:56:36 -05002650lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002651{
2652 struct lpfc_sli *psli = &phba->sli;
2653
2654 /* Ring 0, ELS / CT buffers */
James Smart895427b2017-02-12 13:52:30 -08002655 lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002656 /* Ring 2 - FCP no buffers needed */
2657
2658 return 0;
2659}
2660
2661#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2662
James Smarte59058c2008-08-24 21:49:00 -04002663/**
James Smart3621a712009-04-06 18:47:14 -04002664 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002665 * @HashResultPointer: pointer to an array as hash table.
2666 *
2667 * This routine sets up the initial values to the array of hash table entries
2668 * for the LC HBAs.
2669 **/
dea31012005-04-17 16:05:31 -05002670static void
2671lpfc_sha_init(uint32_t * HashResultPointer)
2672{
2673 HashResultPointer[0] = 0x67452301;
2674 HashResultPointer[1] = 0xEFCDAB89;
2675 HashResultPointer[2] = 0x98BADCFE;
2676 HashResultPointer[3] = 0x10325476;
2677 HashResultPointer[4] = 0xC3D2E1F0;
2678}
2679
James Smarte59058c2008-08-24 21:49:00 -04002680/**
James Smart3621a712009-04-06 18:47:14 -04002681 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002682 * @HashResultPointer: pointer to an initial/result hash table.
2683 * @HashWorkingPointer: pointer to an working hash table.
2684 *
2685 * This routine iterates an initial hash table pointed by @HashResultPointer
2686 * with the values from the working hash table pointeed by @HashWorkingPointer.
2687 * The results are putting back to the initial hash table, returned through
2688 * the @HashResultPointer as the result hash table.
2689 **/
dea31012005-04-17 16:05:31 -05002690static void
2691lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2692{
2693 int t;
2694 uint32_t TEMP;
2695 uint32_t A, B, C, D, E;
2696 t = 16;
2697 do {
2698 HashWorkingPointer[t] =
2699 S(1,
2700 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2701 8] ^
2702 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2703 } while (++t <= 79);
2704 t = 0;
2705 A = HashResultPointer[0];
2706 B = HashResultPointer[1];
2707 C = HashResultPointer[2];
2708 D = HashResultPointer[3];
2709 E = HashResultPointer[4];
2710
2711 do {
2712 if (t < 20) {
2713 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2714 } else if (t < 40) {
2715 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2716 } else if (t < 60) {
2717 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2718 } else {
2719 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2720 }
2721 TEMP += S(5, A) + E + HashWorkingPointer[t];
2722 E = D;
2723 D = C;
2724 C = S(30, B);
2725 B = A;
2726 A = TEMP;
2727 } while (++t <= 79);
2728
2729 HashResultPointer[0] += A;
2730 HashResultPointer[1] += B;
2731 HashResultPointer[2] += C;
2732 HashResultPointer[3] += D;
2733 HashResultPointer[4] += E;
2734
2735}
2736
James Smarte59058c2008-08-24 21:49:00 -04002737/**
James Smart3621a712009-04-06 18:47:14 -04002738 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002739 * @RandomChallenge: pointer to the entry of host challenge random number array.
2740 * @HashWorking: pointer to the entry of the working hash array.
2741 *
2742 * This routine calculates the working hash array referred by @HashWorking
2743 * from the challenge random numbers associated with the host, referred by
2744 * @RandomChallenge. The result is put into the entry of the working hash
2745 * array and returned by reference through @HashWorking.
2746 **/
dea31012005-04-17 16:05:31 -05002747static void
2748lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2749{
2750 *HashWorking = (*RandomChallenge ^ *HashWorking);
2751}
2752
James Smarte59058c2008-08-24 21:49:00 -04002753/**
James Smart3621a712009-04-06 18:47:14 -04002754 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002755 * @phba: pointer to lpfc hba data structure.
2756 * @hbainit: pointer to an array of unsigned 32-bit integers.
2757 *
2758 * This routine performs the special handling for LC HBA initialization.
2759 **/
dea31012005-04-17 16:05:31 -05002760void
2761lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2762{
2763 int t;
2764 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002765 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002766
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002767 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002768 if (!HashWorking)
2769 return;
2770
dea31012005-04-17 16:05:31 -05002771 HashWorking[0] = HashWorking[78] = *pwwnn++;
2772 HashWorking[1] = HashWorking[79] = *pwwnn;
2773
2774 for (t = 0; t < 7; t++)
2775 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2776
2777 lpfc_sha_init(hbainit);
2778 lpfc_sha_iterate(hbainit, HashWorking);
2779 kfree(HashWorking);
2780}
2781
James Smarte59058c2008-08-24 21:49:00 -04002782/**
James Smart3621a712009-04-06 18:47:14 -04002783 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002784 * @vport: pointer to a virtual N_Port data structure.
2785 *
2786 * This routine performs the necessary cleanups before deleting the @vport.
2787 * It invokes the discovery state machine to perform necessary state
2788 * transitions and to release the ndlps associated with the @vport. Note,
2789 * the physical port is treated as @vport 0.
2790 **/
James Smart87af33f2007-10-27 13:37:43 -04002791void
James Smart2e0fef82007-06-17 19:56:36 -05002792lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002793{
James Smart87af33f2007-10-27 13:37:43 -04002794 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002795 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002796 int i = 0;
dea31012005-04-17 16:05:31 -05002797
James Smart87af33f2007-10-27 13:37:43 -04002798 if (phba->link_state > LPFC_LINK_DOWN)
2799 lpfc_port_link_failure(vport);
2800
2801 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002802 if (!NLP_CHK_NODE_ACT(ndlp)) {
2803 ndlp = lpfc_enable_node(vport, ndlp,
2804 NLP_STE_UNUSED_NODE);
2805 if (!ndlp)
2806 continue;
2807 spin_lock_irq(&phba->ndlp_lock);
2808 NLP_SET_FREE_REQ(ndlp);
2809 spin_unlock_irq(&phba->ndlp_lock);
2810 /* Trigger the release of the ndlp memory */
2811 lpfc_nlp_put(ndlp);
2812 continue;
2813 }
2814 spin_lock_irq(&phba->ndlp_lock);
2815 if (NLP_CHK_FREE_REQ(ndlp)) {
2816 /* The ndlp should not be in memory free mode already */
2817 spin_unlock_irq(&phba->ndlp_lock);
2818 continue;
2819 } else
2820 /* Indicate request for freeing ndlp memory */
2821 NLP_SET_FREE_REQ(ndlp);
2822 spin_unlock_irq(&phba->ndlp_lock);
2823
James Smart58da1ff2008-04-07 10:15:56 -04002824 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2825 ndlp->nlp_DID == Fabric_DID) {
2826 /* Just free up ndlp with Fabric_DID for vports */
2827 lpfc_nlp_put(ndlp);
2828 continue;
2829 }
2830
James Smarteff4a012012-01-18 16:25:25 -05002831 /* take care of nodes in unused state before the state
2832 * machine taking action.
2833 */
2834 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2835 lpfc_nlp_put(ndlp);
2836 continue;
2837 }
2838
James Smart87af33f2007-10-27 13:37:43 -04002839 if (ndlp->nlp_type & NLP_FABRIC)
2840 lpfc_disc_state_machine(vport, ndlp, NULL,
2841 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002842
James Smart87af33f2007-10-27 13:37:43 -04002843 lpfc_disc_state_machine(vport, ndlp, NULL,
2844 NLP_EVT_DEVICE_RM);
2845 }
2846
James Smarta8adb832007-10-27 13:37:53 -04002847 /* At this point, ALL ndlp's should be gone
2848 * because of the previous NLP_EVT_DEVICE_RM.
2849 * Lets wait for this to happen, if needed.
2850 */
James Smart87af33f2007-10-27 13:37:43 -04002851 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002852 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04002853 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04002854 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002855 list_for_each_entry_safe(ndlp, next_ndlp,
2856 &vport->fc_nodes, nlp_listp) {
2857 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2858 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04002859 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05002860 "usgmap:x%x refcnt:%d\n",
2861 ndlp->nlp_DID, (void *)ndlp,
2862 ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01002863 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05002864 }
James Smarta8adb832007-10-27 13:37:53 -04002865 break;
James Smart87af33f2007-10-27 13:37:43 -04002866 }
James Smarta8adb832007-10-27 13:37:53 -04002867
2868 /* Wait for any activity on ndlps to settle */
2869 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002870 }
James Smart1151e3e2011-02-16 12:39:35 -05002871 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002872}
2873
James Smarte59058c2008-08-24 21:49:00 -04002874/**
James Smart3621a712009-04-06 18:47:14 -04002875 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002876 * @vport: pointer to a virtual N_Port data structure.
2877 *
2878 * This routine stops all the timers associated with a @vport. This function
2879 * is invoked before disabling or deleting a @vport. Note that the physical
2880 * port is treated as @vport 0.
2881 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002882void
2883lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002884{
James Smart92d7f7b2007-06-17 19:56:38 -05002885 del_timer_sync(&vport->els_tmofunc);
James Smart92494142011-02-16 12:39:44 -05002886 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002887 lpfc_can_disctmo(vport);
2888 return;
dea31012005-04-17 16:05:31 -05002889}
2890
James Smarte59058c2008-08-24 21:49:00 -04002891/**
James Smartecfd03c2010-02-12 14:41:27 -05002892 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2893 * @phba: pointer to lpfc hba data structure.
2894 *
2895 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2896 * caller of this routine should already hold the host lock.
2897 **/
2898void
2899__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2900{
James Smart5ac6b302010-10-22 11:05:36 -04002901 /* Clear pending FCF rediscovery wait flag */
2902 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2903
James Smartecfd03c2010-02-12 14:41:27 -05002904 /* Now, try to stop the timer */
2905 del_timer(&phba->fcf.redisc_wait);
2906}
2907
2908/**
2909 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2910 * @phba: pointer to lpfc hba data structure.
2911 *
2912 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2913 * checks whether the FCF rediscovery wait timer is pending with the host
2914 * lock held before proceeding with disabling the timer and clearing the
2915 * wait timer pendig flag.
2916 **/
2917void
2918lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2919{
2920 spin_lock_irq(&phba->hbalock);
2921 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2922 /* FCF rediscovery timer already fired or stopped */
2923 spin_unlock_irq(&phba->hbalock);
2924 return;
2925 }
2926 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002927 /* Clear failover in progress flags */
2928 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002929 spin_unlock_irq(&phba->hbalock);
2930}
2931
2932/**
James Smart3772a992009-05-22 14:50:54 -04002933 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002934 * @phba: pointer to lpfc hba data structure.
2935 *
2936 * This routine stops all the timers associated with a HBA. This function is
2937 * invoked before either putting a HBA offline or unloading the driver.
2938 **/
James Smart3772a992009-05-22 14:50:54 -04002939void
2940lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002941{
James Smart51ef4c22007-08-02 11:10:31 -04002942 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05002943 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002944 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002945 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002946 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002947 if (phba->sli_rev == LPFC_SLI_REV4) {
2948 del_timer_sync(&phba->rrq_tmr);
2949 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2950 }
James Smart3772a992009-05-22 14:50:54 -04002951 phba->hb_outstanding = 0;
2952
2953 switch (phba->pci_dev_grp) {
2954 case LPFC_PCI_DEV_LP:
2955 /* Stop any LightPulse device specific driver timers */
2956 del_timer_sync(&phba->fcp_poll_timer);
2957 break;
2958 case LPFC_PCI_DEV_OC:
2959 /* Stop any OneConnect device sepcific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002960 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002961 break;
2962 default:
2963 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2964 "0297 Invalid device group (x%x)\n",
2965 phba->pci_dev_grp);
2966 break;
2967 }
James Smart2e0fef82007-06-17 19:56:36 -05002968 return;
dea31012005-04-17 16:05:31 -05002969}
2970
James Smarte59058c2008-08-24 21:49:00 -04002971/**
James Smart3621a712009-04-06 18:47:14 -04002972 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002973 * @phba: pointer to lpfc hba data structure.
2974 *
2975 * This routine marks a HBA's management interface as blocked. Once the HBA's
2976 * management interface is marked as blocked, all the user space access to
2977 * the HBA, whether they are from sysfs interface or libdfc interface will
2978 * all be blocked. The HBA is set to block the management interface when the
2979 * driver prepares the HBA interface for online or offline.
2980 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01002981static void
James Smart618a5232012-06-12 13:54:36 -04002982lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
Adrian Bunka6ababd2007-11-05 18:07:33 +01002983{
2984 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04002985 uint8_t actcmd = MBX_HEARTBEAT;
2986 unsigned long timeout;
2987
Adrian Bunka6ababd2007-11-05 18:07:33 +01002988 spin_lock_irqsave(&phba->hbalock, iflag);
2989 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart618a5232012-06-12 13:54:36 -04002990 spin_unlock_irqrestore(&phba->hbalock, iflag);
2991 if (mbx_action == LPFC_MBX_NO_WAIT)
2992 return;
2993 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2994 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002995 if (phba->sli.mbox_active) {
James Smart6e7288d2010-06-07 15:23:35 -04002996 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
James Smarta183a152011-10-10 21:32:43 -04002997 /* Determine how long we might wait for the active mailbox
2998 * command to be gracefully completed by firmware.
2999 */
3000 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
3001 phba->sli.mbox_active) * 1000) + jiffies;
3002 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01003003 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04003004
James Smart6e7288d2010-06-07 15:23:35 -04003005 /* Wait for the outstnading mailbox command to complete */
3006 while (phba->sli.mbox_active) {
3007 /* Check active mailbox complete status every 2ms */
3008 msleep(2);
3009 if (time_after(jiffies, timeout)) {
3010 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3011 "2813 Mgmt IO is Blocked %x "
3012 "- mbox cmd %x still active\n",
3013 phba->sli.sli_flag, actcmd);
3014 break;
3015 }
3016 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01003017}
3018
James Smarte59058c2008-08-24 21:49:00 -04003019/**
James Smart6b5151f2012-01-18 16:24:06 -05003020 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
3021 * @phba: pointer to lpfc hba data structure.
3022 *
3023 * Allocate RPIs for all active remote nodes. This is needed whenever
3024 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
3025 * is to fixup the temporary rpi assignments.
3026 **/
3027void
3028lpfc_sli4_node_prep(struct lpfc_hba *phba)
3029{
3030 struct lpfc_nodelist *ndlp, *next_ndlp;
3031 struct lpfc_vport **vports;
James Smart9d3d3402017-04-21 16:05:00 -07003032 int i, rpi;
3033 unsigned long flags;
James Smart6b5151f2012-01-18 16:24:06 -05003034
3035 if (phba->sli_rev != LPFC_SLI_REV4)
3036 return;
3037
3038 vports = lpfc_create_vport_work_array(phba);
James Smart9d3d3402017-04-21 16:05:00 -07003039 if (vports == NULL)
3040 return;
James Smart6b5151f2012-01-18 16:24:06 -05003041
James Smart9d3d3402017-04-21 16:05:00 -07003042 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3043 if (vports[i]->load_flag & FC_UNLOADING)
3044 continue;
3045
3046 list_for_each_entry_safe(ndlp, next_ndlp,
3047 &vports[i]->fc_nodes,
3048 nlp_listp) {
3049 if (!NLP_CHK_NODE_ACT(ndlp))
3050 continue;
3051 rpi = lpfc_sli4_alloc_rpi(phba);
3052 if (rpi == LPFC_RPI_ALLOC_ERROR) {
3053 spin_lock_irqsave(&phba->ndlp_lock, flags);
3054 NLP_CLR_NODE_ACT(ndlp);
3055 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3056 continue;
James Smart6b5151f2012-01-18 16:24:06 -05003057 }
James Smart9d3d3402017-04-21 16:05:00 -07003058 ndlp->nlp_rpi = rpi;
3059 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3060 "0009 rpi:%x DID:%x "
3061 "flg:%x map:%x %p\n", ndlp->nlp_rpi,
3062 ndlp->nlp_DID, ndlp->nlp_flag,
3063 ndlp->nlp_usg_map, ndlp);
James Smart6b5151f2012-01-18 16:24:06 -05003064 }
3065 }
3066 lpfc_destroy_vport_work_array(phba, vports);
3067}
3068
3069/**
James Smart3621a712009-04-06 18:47:14 -04003070 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04003071 * @phba: pointer to lpfc hba data structure.
3072 *
3073 * This routine initializes the HBA and brings a HBA online. During this
3074 * process, the management interface is blocked to prevent user space access
3075 * to the HBA interfering with the driver initialization.
3076 *
3077 * Return codes
3078 * 0 - successful
3079 * 1 - failed
3080 **/
dea31012005-04-17 16:05:31 -05003081int
James Smart2e0fef82007-06-17 19:56:36 -05003082lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003083{
Julia Lawall372bd282008-12-16 16:15:08 +01003084 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04003085 struct lpfc_vport **vports;
Dick Kennedya145fda2017-08-23 16:55:44 -07003086 int i, error = 0;
James Smart16a3a202013-04-17 20:14:38 -04003087 bool vpis_cleared = false;
James Smart2e0fef82007-06-17 19:56:36 -05003088
dea31012005-04-17 16:05:31 -05003089 if (!phba)
3090 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01003091 vport = phba->pport;
dea31012005-04-17 16:05:31 -05003092
James Smart2e0fef82007-06-17 19:56:36 -05003093 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05003094 return 0;
3095
James Smarted957682007-06-17 19:56:37 -05003096 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003097 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05003098
James Smart618a5232012-06-12 13:54:36 -04003099 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05003100
James Smartda0436e2009-05-22 14:51:39 -04003101 if (phba->sli_rev == LPFC_SLI_REV4) {
3102 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
3103 lpfc_unblock_mgmt_io(phba);
3104 return 1;
3105 }
James Smart16a3a202013-04-17 20:14:38 -04003106 spin_lock_irq(&phba->hbalock);
3107 if (!phba->sli4_hba.max_cfg_param.vpi_used)
3108 vpis_cleared = true;
3109 spin_unlock_irq(&phba->hbalock);
Dick Kennedya145fda2017-08-23 16:55:44 -07003110
3111 /* Reestablish the local initiator port.
3112 * The offline process destroyed the previous lport.
3113 */
3114 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
3115 !phba->nvmet_support) {
3116 error = lpfc_nvme_create_localport(phba->pport);
3117 if (error)
3118 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3119 "6132 NVME restore reg failed "
3120 "on nvmei error x%x\n", error);
3121 }
James Smartda0436e2009-05-22 14:51:39 -04003122 } else {
James Smart895427b2017-02-12 13:52:30 -08003123 lpfc_sli_queue_init(phba);
James Smartda0436e2009-05-22 14:51:39 -04003124 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
3125 lpfc_unblock_mgmt_io(phba);
3126 return 1;
3127 }
James Smart46fa3112007-04-25 09:51:45 -04003128 }
dea31012005-04-17 16:05:31 -05003129
James Smart549e55c2007-08-02 11:09:51 -04003130 vports = lpfc_create_vport_work_array(phba);
Arnd Bergmannaeb66412016-03-14 15:29:44 +01003131 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003132 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003133 struct Scsi_Host *shost;
3134 shost = lpfc_shost_from_vport(vports[i]);
3135 spin_lock_irq(shost->host_lock);
3136 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
3137 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
3138 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart16a3a202013-04-17 20:14:38 -04003139 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart1c6834a2009-07-19 10:01:26 -04003140 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart16a3a202013-04-17 20:14:38 -04003141 if ((vpis_cleared) &&
3142 (vports[i]->port_type !=
3143 LPFC_PHYSICAL_PORT))
3144 vports[i]->vpi = 0;
3145 }
James Smart549e55c2007-08-02 11:09:51 -04003146 spin_unlock_irq(shost->host_lock);
3147 }
Arnd Bergmannaeb66412016-03-14 15:29:44 +01003148 }
3149 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003150
James Smart46fa3112007-04-25 09:51:45 -04003151 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05003152 return 0;
3153}
3154
James Smarte59058c2008-08-24 21:49:00 -04003155/**
James Smart3621a712009-04-06 18:47:14 -04003156 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04003157 * @phba: pointer to lpfc hba data structure.
3158 *
3159 * This routine marks a HBA's management interface as not blocked. Once the
3160 * HBA's management interface is marked as not blocked, all the user space
3161 * access to the HBA, whether they are from sysfs interface or libdfc
3162 * interface will be allowed. The HBA is set to block the management interface
3163 * when the driver prepares the HBA interface for online or offline and then
3164 * set to unblock the management interface afterwards.
3165 **/
James Smart46fa3112007-04-25 09:51:45 -04003166void
James Smart46fa3112007-04-25 09:51:45 -04003167lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
3168{
3169 unsigned long iflag;
3170
James Smart2e0fef82007-06-17 19:56:36 -05003171 spin_lock_irqsave(&phba->hbalock, iflag);
3172 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3173 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04003174}
3175
James Smarte59058c2008-08-24 21:49:00 -04003176/**
James Smart3621a712009-04-06 18:47:14 -04003177 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04003178 * @phba: pointer to lpfc hba data structure.
3179 *
3180 * This routine is invoked to prepare a HBA to be brought offline. It performs
3181 * unregistration login to all the nodes on all vports and flushes the mailbox
3182 * queue to make it ready to be brought offline.
3183 **/
James Smart46fa3112007-04-25 09:51:45 -04003184void
James Smart618a5232012-06-12 13:54:36 -04003185lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04003186{
James Smart2e0fef82007-06-17 19:56:36 -05003187 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04003188 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04003189 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05003190 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04003191 int i;
dea31012005-04-17 16:05:31 -05003192
James Smart2e0fef82007-06-17 19:56:36 -05003193 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003194 return;
dea31012005-04-17 16:05:31 -05003195
James Smart618a5232012-06-12 13:54:36 -04003196 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05003197
3198 lpfc_linkdown(phba);
3199
James Smart87af33f2007-10-27 13:37:43 -04003200 /* Issue an unreg_login to all nodes on all vports */
3201 vports = lpfc_create_vport_work_array(phba);
3202 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003203 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04003204 if (vports[i]->load_flag & FC_UNLOADING)
3205 continue;
James Smart72100cc2010-02-12 14:43:01 -05003206 shost = lpfc_shost_from_vport(vports[i]);
3207 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003208 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003209 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3210 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05003211 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05003212
James Smart87af33f2007-10-27 13:37:43 -04003213 shost = lpfc_shost_from_vport(vports[i]);
3214 list_for_each_entry_safe(ndlp, next_ndlp,
3215 &vports[i]->fc_nodes,
3216 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003217 if (!NLP_CHK_NODE_ACT(ndlp))
3218 continue;
James Smart87af33f2007-10-27 13:37:43 -04003219 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3220 continue;
3221 if (ndlp->nlp_type & NLP_FABRIC) {
3222 lpfc_disc_state_machine(vports[i], ndlp,
3223 NULL, NLP_EVT_DEVICE_RECOVERY);
3224 lpfc_disc_state_machine(vports[i], ndlp,
3225 NULL, NLP_EVT_DEVICE_RM);
3226 }
3227 spin_lock_irq(shost->host_lock);
3228 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart401ee0c2012-03-01 22:35:34 -05003229 spin_unlock_irq(shost->host_lock);
James Smart6b5151f2012-01-18 16:24:06 -05003230 /*
3231 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05003232 * RPI. Get a new RPI when the adapter port
3233 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05003234 */
James Smartbe6bb942015-04-07 15:07:22 -04003235 if (phba->sli_rev == LPFC_SLI_REV4) {
3236 lpfc_printf_vlog(ndlp->vport,
3237 KERN_INFO, LOG_NODE,
3238 "0011 lpfc_offline: "
3239 "ndlp:x%p did %x "
3240 "usgmap:x%x rpi:%x\n",
3241 ndlp, ndlp->nlp_DID,
3242 ndlp->nlp_usg_map,
3243 ndlp->nlp_rpi);
3244
James Smart6b5151f2012-01-18 16:24:06 -05003245 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smartbe6bb942015-04-07 15:07:22 -04003246 }
James Smart87af33f2007-10-27 13:37:43 -04003247 lpfc_unreg_rpi(vports[i], ndlp);
3248 }
3249 }
3250 }
James Smart09372822008-01-11 01:52:54 -05003251 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003252
James Smart618a5232012-06-12 13:54:36 -04003253 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
Dick Kennedyf485c182017-09-29 17:34:34 -07003254
3255 if (phba->wq)
3256 flush_workqueue(phba->wq);
James Smart46fa3112007-04-25 09:51:45 -04003257}
3258
James Smarte59058c2008-08-24 21:49:00 -04003259/**
James Smart3621a712009-04-06 18:47:14 -04003260 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04003261 * @phba: pointer to lpfc hba data structure.
3262 *
3263 * This routine actually brings a HBA offline. It stops all the timers
3264 * associated with the HBA, brings down the SLI layer, and eventually
3265 * marks the HBA as in offline state for the upper layer protocol.
3266 **/
James Smart46fa3112007-04-25 09:51:45 -04003267void
James Smart2e0fef82007-06-17 19:56:36 -05003268lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04003269{
James Smart549e55c2007-08-02 11:09:51 -04003270 struct Scsi_Host *shost;
3271 struct lpfc_vport **vports;
3272 int i;
James Smart46fa3112007-04-25 09:51:45 -04003273
James Smart549e55c2007-08-02 11:09:51 -04003274 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003275 return;
James Smart688a8862006-07-06 15:49:56 -04003276
James Smartda0436e2009-05-22 14:51:39 -04003277 /* stop port and all timers associated with this hba */
3278 lpfc_stop_port(phba);
Dick Kennedy4b40d022017-08-23 16:55:38 -07003279
3280 /* Tear down the local and target port registrations. The
3281 * nvme transports need to cleanup.
3282 */
3283 lpfc_nvmet_destroy_targetport(phba);
3284 lpfc_nvme_destroy_localport(phba->pport);
3285
James Smart51ef4c22007-08-02 11:10:31 -04003286 vports = lpfc_create_vport_work_array(phba);
3287 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003288 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04003289 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05003290 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05003291 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003292 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05003293 /* Bring down the SLI Layer and cleanup. The HBA is offline
3294 now. */
3295 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003296 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04003297 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003298 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04003299 vports = lpfc_create_vport_work_array(phba);
3300 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003301 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003302 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04003303 spin_lock_irq(shost->host_lock);
3304 vports[i]->work_port_events = 0;
3305 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3306 spin_unlock_irq(shost->host_lock);
3307 }
James Smart09372822008-01-11 01:52:54 -05003308 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003309}
3310
James Smarte59058c2008-08-24 21:49:00 -04003311/**
James Smart3621a712009-04-06 18:47:14 -04003312 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04003313 * @phba: pointer to lpfc hba data structure.
3314 *
3315 * This routine is to free all the SCSI buffers and IOCBs from the driver
3316 * list back to kernel. It is called from lpfc_pci_remove_one to free
3317 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04003318 **/
James Smart8a9d2e82012-05-09 21:16:12 -04003319static void
James Smart2e0fef82007-06-17 19:56:36 -05003320lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003321{
3322 struct lpfc_scsi_buf *sb, *sb_next;
dea31012005-04-17 16:05:31 -05003323
James Smart895427b2017-02-12 13:52:30 -08003324 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3325 return;
3326
James Smart2e0fef82007-06-17 19:56:36 -05003327 spin_lock_irq(&phba->hbalock);
James Smarta40fc5f2013-04-17 20:17:40 -04003328
dea31012005-04-17 16:05:31 -05003329 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smarta40fc5f2013-04-17 20:17:40 -04003330
3331 spin_lock(&phba->scsi_buf_list_put_lock);
3332 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3333 list) {
dea31012005-04-17 16:05:31 -05003334 list_del(&sb->list);
Romain Perier771db5c2017-07-06 10:13:05 +02003335 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05003336 sb->dma_handle);
dea31012005-04-17 16:05:31 -05003337 kfree(sb);
3338 phba->total_scsi_bufs--;
3339 }
James Smarta40fc5f2013-04-17 20:17:40 -04003340 spin_unlock(&phba->scsi_buf_list_put_lock);
3341
3342 spin_lock(&phba->scsi_buf_list_get_lock);
3343 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3344 list) {
3345 list_del(&sb->list);
Romain Perier771db5c2017-07-06 10:13:05 +02003346 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smarta40fc5f2013-04-17 20:17:40 -04003347 sb->dma_handle);
3348 kfree(sb);
3349 phba->total_scsi_bufs--;
3350 }
3351 spin_unlock(&phba->scsi_buf_list_get_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003352 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003353}
James Smart8a9d2e82012-05-09 21:16:12 -04003354/**
James Smart895427b2017-02-12 13:52:30 -08003355 * lpfc_nvme_free - Free all the NVME buffers and IOCBs from driver lists
3356 * @phba: pointer to lpfc hba data structure.
3357 *
3358 * This routine is to free all the NVME buffers and IOCBs from the driver
3359 * list back to kernel. It is called from lpfc_pci_remove_one to free
3360 * the internal resources before the device is removed from the system.
3361 **/
3362static void
3363lpfc_nvme_free(struct lpfc_hba *phba)
3364{
3365 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
James Smart895427b2017-02-12 13:52:30 -08003366
3367 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3368 return;
3369
3370 spin_lock_irq(&phba->hbalock);
3371
3372 /* Release all the lpfc_nvme_bufs maintained by this host. */
3373 spin_lock(&phba->nvme_buf_list_put_lock);
3374 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3375 &phba->lpfc_nvme_buf_list_put, list) {
3376 list_del(&lpfc_ncmd->list);
James Smartcf1a1d32017-12-08 17:18:03 -08003377 phba->put_nvme_bufs--;
Romain Perier771db5c2017-07-06 10:13:05 +02003378 dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
James Smart895427b2017-02-12 13:52:30 -08003379 lpfc_ncmd->dma_handle);
3380 kfree(lpfc_ncmd);
3381 phba->total_nvme_bufs--;
3382 }
3383 spin_unlock(&phba->nvme_buf_list_put_lock);
3384
3385 spin_lock(&phba->nvme_buf_list_get_lock);
3386 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3387 &phba->lpfc_nvme_buf_list_get, list) {
3388 list_del(&lpfc_ncmd->list);
James Smartcf1a1d32017-12-08 17:18:03 -08003389 phba->get_nvme_bufs--;
Romain Perier771db5c2017-07-06 10:13:05 +02003390 dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
James Smart895427b2017-02-12 13:52:30 -08003391 lpfc_ncmd->dma_handle);
3392 kfree(lpfc_ncmd);
3393 phba->total_nvme_bufs--;
3394 }
3395 spin_unlock(&phba->nvme_buf_list_get_lock);
James Smart895427b2017-02-12 13:52:30 -08003396 spin_unlock_irq(&phba->hbalock);
3397}
3398/**
3399 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
James Smart8a9d2e82012-05-09 21:16:12 -04003400 * @phba: pointer to lpfc hba data structure.
3401 *
3402 * This routine first calculates the sizes of the current els and allocated
3403 * scsi sgl lists, and then goes through all sgls to updates the physical
3404 * XRIs assigned due to port function reset. During port initialization, the
3405 * current els and allocated scsi sgl lists are 0s.
3406 *
3407 * Return codes
3408 * 0 - successful (for now, it always returns 0)
3409 **/
3410int
James Smart895427b2017-02-12 13:52:30 -08003411lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
James Smart8a9d2e82012-05-09 21:16:12 -04003412{
3413 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
James Smart895427b2017-02-12 13:52:30 -08003414 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart8a9d2e82012-05-09 21:16:12 -04003415 LIST_HEAD(els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003416 int rc;
3417
3418 /*
3419 * update on pci function's els xri-sgl list
3420 */
3421 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart895427b2017-02-12 13:52:30 -08003422
James Smart8a9d2e82012-05-09 21:16:12 -04003423 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3424 /* els xri-sgl expanded */
3425 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3426 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3427 "3157 ELS xri-sgl count increased from "
3428 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3429 els_xri_cnt);
3430 /* allocate the additional els sgls */
3431 for (i = 0; i < xri_cnt; i++) {
3432 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3433 GFP_KERNEL);
3434 if (sglq_entry == NULL) {
3435 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3436 "2562 Failure to allocate an "
3437 "ELS sgl entry:%d\n", i);
3438 rc = -ENOMEM;
3439 goto out_free_mem;
3440 }
3441 sglq_entry->buff_type = GEN_BUFF_TYPE;
3442 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3443 &sglq_entry->phys);
3444 if (sglq_entry->virt == NULL) {
3445 kfree(sglq_entry);
3446 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3447 "2563 Failure to allocate an "
3448 "ELS mbuf:%d\n", i);
3449 rc = -ENOMEM;
3450 goto out_free_mem;
3451 }
3452 sglq_entry->sgl = sglq_entry->virt;
3453 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3454 sglq_entry->state = SGL_FREED;
3455 list_add_tail(&sglq_entry->list, &els_sgl_list);
3456 }
James Smart38c20672013-03-01 16:37:44 -05003457 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003458 spin_lock(&phba->sli4_hba.sgl_list_lock);
3459 list_splice_init(&els_sgl_list,
3460 &phba->sli4_hba.lpfc_els_sgl_list);
3461 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart38c20672013-03-01 16:37:44 -05003462 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003463 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3464 /* els xri-sgl shrinked */
3465 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3466 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3467 "3158 ELS xri-sgl count decreased from "
3468 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3469 els_xri_cnt);
3470 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003471 spin_lock(&phba->sli4_hba.sgl_list_lock);
3472 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
3473 &els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003474 /* release extra els sgls from list */
3475 for (i = 0; i < xri_cnt; i++) {
3476 list_remove_head(&els_sgl_list,
3477 sglq_entry, struct lpfc_sglq, list);
3478 if (sglq_entry) {
James Smart895427b2017-02-12 13:52:30 -08003479 __lpfc_mbuf_free(phba, sglq_entry->virt,
3480 sglq_entry->phys);
James Smart8a9d2e82012-05-09 21:16:12 -04003481 kfree(sglq_entry);
3482 }
3483 }
James Smart895427b2017-02-12 13:52:30 -08003484 list_splice_init(&els_sgl_list,
3485 &phba->sli4_hba.lpfc_els_sgl_list);
3486 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003487 spin_unlock_irq(&phba->hbalock);
3488 } else
3489 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3490 "3163 ELS xri-sgl count unchanged: %d\n",
3491 els_xri_cnt);
3492 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3493
3494 /* update xris to els sgls on the list */
3495 sglq_entry = NULL;
3496 sglq_entry_next = NULL;
3497 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
James Smart895427b2017-02-12 13:52:30 -08003498 &phba->sli4_hba.lpfc_els_sgl_list, list) {
James Smart8a9d2e82012-05-09 21:16:12 -04003499 lxri = lpfc_sli4_next_xritag(phba);
3500 if (lxri == NO_XRI) {
3501 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3502 "2400 Failed to allocate xri for "
3503 "ELS sgl\n");
3504 rc = -ENOMEM;
3505 goto out_free_mem;
3506 }
3507 sglq_entry->sli4_lxritag = lxri;
3508 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3509 }
James Smart895427b2017-02-12 13:52:30 -08003510 return 0;
3511
3512out_free_mem:
3513 lpfc_free_els_sgl_list(phba);
3514 return rc;
3515}
3516
3517/**
James Smartf358dd02017-02-12 13:52:34 -08003518 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
3519 * @phba: pointer to lpfc hba data structure.
3520 *
3521 * This routine first calculates the sizes of the current els and allocated
3522 * scsi sgl lists, and then goes through all sgls to updates the physical
3523 * XRIs assigned due to port function reset. During port initialization, the
3524 * current els and allocated scsi sgl lists are 0s.
3525 *
3526 * Return codes
3527 * 0 - successful (for now, it always returns 0)
3528 **/
3529int
3530lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
3531{
3532 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3533 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart6c621a22017-05-15 15:20:45 -07003534 uint16_t nvmet_xri_cnt;
James Smartf358dd02017-02-12 13:52:34 -08003535 LIST_HEAD(nvmet_sgl_list);
3536 int rc;
3537
3538 /*
3539 * update on pci function's nvmet xri-sgl list
3540 */
3541 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart61f3d4b2017-05-15 15:20:41 -07003542
James Smart6c621a22017-05-15 15:20:45 -07003543 /* For NVMET, ALL remaining XRIs are dedicated for IO processing */
3544 nvmet_xri_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
James Smartf358dd02017-02-12 13:52:34 -08003545 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
3546 /* els xri-sgl expanded */
3547 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
3548 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3549 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
3550 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
3551 /* allocate the additional nvmet sgls */
3552 for (i = 0; i < xri_cnt; i++) {
3553 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3554 GFP_KERNEL);
3555 if (sglq_entry == NULL) {
3556 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3557 "6303 Failure to allocate an "
3558 "NVMET sgl entry:%d\n", i);
3559 rc = -ENOMEM;
3560 goto out_free_mem;
3561 }
3562 sglq_entry->buff_type = NVMET_BUFF_TYPE;
3563 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
3564 &sglq_entry->phys);
3565 if (sglq_entry->virt == NULL) {
3566 kfree(sglq_entry);
3567 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3568 "6304 Failure to allocate an "
3569 "NVMET buf:%d\n", i);
3570 rc = -ENOMEM;
3571 goto out_free_mem;
3572 }
3573 sglq_entry->sgl = sglq_entry->virt;
3574 memset(sglq_entry->sgl, 0,
3575 phba->cfg_sg_dma_buf_size);
3576 sglq_entry->state = SGL_FREED;
3577 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
3578 }
3579 spin_lock_irq(&phba->hbalock);
3580 spin_lock(&phba->sli4_hba.sgl_list_lock);
3581 list_splice_init(&nvmet_sgl_list,
3582 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3583 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3584 spin_unlock_irq(&phba->hbalock);
3585 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
3586 /* nvmet xri-sgl shrunk */
3587 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
3588 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3589 "6305 NVMET xri-sgl count decreased from "
3590 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
3591 nvmet_xri_cnt);
3592 spin_lock_irq(&phba->hbalock);
3593 spin_lock(&phba->sli4_hba.sgl_list_lock);
3594 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
3595 &nvmet_sgl_list);
3596 /* release extra nvmet sgls from list */
3597 for (i = 0; i < xri_cnt; i++) {
3598 list_remove_head(&nvmet_sgl_list,
3599 sglq_entry, struct lpfc_sglq, list);
3600 if (sglq_entry) {
3601 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
3602 sglq_entry->phys);
3603 kfree(sglq_entry);
3604 }
3605 }
3606 list_splice_init(&nvmet_sgl_list,
3607 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3608 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3609 spin_unlock_irq(&phba->hbalock);
3610 } else
3611 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3612 "6306 NVMET xri-sgl count unchanged: %d\n",
3613 nvmet_xri_cnt);
3614 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
3615
3616 /* update xris to nvmet sgls on the list */
3617 sglq_entry = NULL;
3618 sglq_entry_next = NULL;
3619 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3620 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
3621 lxri = lpfc_sli4_next_xritag(phba);
3622 if (lxri == NO_XRI) {
3623 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3624 "6307 Failed to allocate xri for "
3625 "NVMET sgl\n");
3626 rc = -ENOMEM;
3627 goto out_free_mem;
3628 }
3629 sglq_entry->sli4_lxritag = lxri;
3630 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3631 }
3632 return 0;
3633
3634out_free_mem:
3635 lpfc_free_nvmet_sgl_list(phba);
3636 return rc;
3637}
3638
3639/**
James Smart895427b2017-02-12 13:52:30 -08003640 * lpfc_sli4_scsi_sgl_update - update xri-sgl sizing and mapping
3641 * @phba: pointer to lpfc hba data structure.
3642 *
3643 * This routine first calculates the sizes of the current els and allocated
3644 * scsi sgl lists, and then goes through all sgls to updates the physical
3645 * XRIs assigned due to port function reset. During port initialization, the
3646 * current els and allocated scsi sgl lists are 0s.
3647 *
3648 * Return codes
3649 * 0 - successful (for now, it always returns 0)
3650 **/
3651int
3652lpfc_sli4_scsi_sgl_update(struct lpfc_hba *phba)
3653{
3654 struct lpfc_scsi_buf *psb, *psb_next;
3655 uint16_t i, lxri, els_xri_cnt, scsi_xri_cnt;
3656 LIST_HEAD(scsi_sgl_list);
3657 int rc;
3658
3659 /*
3660 * update on pci function's els xri-sgl list
3661 */
3662 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3663 phba->total_scsi_bufs = 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003664
3665 /*
3666 * update on pci function's allocated scsi xri-sgl list
3667 */
James Smart8a9d2e82012-05-09 21:16:12 -04003668 /* maximum number of xris available for scsi buffers */
3669 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3670 els_xri_cnt;
3671
James Smart895427b2017-02-12 13:52:30 -08003672 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3673 return 0;
3674
3675 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3676 phba->sli4_hba.scsi_xri_max = /* Split them up */
3677 (phba->sli4_hba.scsi_xri_max *
3678 phba->cfg_xri_split) / 100;
James Smart8a9d2e82012-05-09 21:16:12 -04003679
James Smarta40fc5f2013-04-17 20:17:40 -04003680 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003681 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003682 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3683 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
James Smart164cecd2013-09-06 12:22:38 -04003684 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003685 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003686
James Smarte8c0a772017-04-21 16:04:49 -07003687 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3688 "6060 Current allocated SCSI xri-sgl count:%d, "
3689 "maximum SCSI xri count:%d (split:%d)\n",
3690 phba->sli4_hba.scsi_xri_cnt,
3691 phba->sli4_hba.scsi_xri_max, phba->cfg_xri_split);
3692
James Smart8a9d2e82012-05-09 21:16:12 -04003693 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3694 /* max scsi xri shrinked below the allocated scsi buffers */
3695 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3696 phba->sli4_hba.scsi_xri_max;
3697 /* release the extra allocated scsi buffers */
3698 for (i = 0; i < scsi_xri_cnt; i++) {
3699 list_remove_head(&scsi_sgl_list, psb,
3700 struct lpfc_scsi_buf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04003701 if (psb) {
Romain Perier771db5c2017-07-06 10:13:05 +02003702 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
James Smarta2fc4aef2014-09-03 12:57:55 -04003703 psb->data, psb->dma_handle);
3704 kfree(psb);
3705 }
James Smart8a9d2e82012-05-09 21:16:12 -04003706 }
James Smarta40fc5f2013-04-17 20:17:40 -04003707 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003708 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
James Smarta40fc5f2013-04-17 20:17:40 -04003709 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003710 }
3711
3712 /* update xris associated to remaining allocated scsi buffers */
3713 psb = NULL;
3714 psb_next = NULL;
3715 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3716 lxri = lpfc_sli4_next_xritag(phba);
3717 if (lxri == NO_XRI) {
3718 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3719 "2560 Failed to allocate xri for "
3720 "scsi buffer\n");
3721 rc = -ENOMEM;
3722 goto out_free_mem;
3723 }
3724 psb->cur_iocbq.sli4_lxritag = lxri;
3725 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3726 }
James Smarta40fc5f2013-04-17 20:17:40 -04003727 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003728 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003729 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3730 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
James Smart164cecd2013-09-06 12:22:38 -04003731 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003732 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
dea31012005-04-17 16:05:31 -05003733 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003734
3735out_free_mem:
James Smart8a9d2e82012-05-09 21:16:12 -04003736 lpfc_scsi_free(phba);
3737 return rc;
dea31012005-04-17 16:05:31 -05003738}
3739
James Smart96418b52017-03-04 09:30:31 -08003740static uint64_t
3741lpfc_get_wwpn(struct lpfc_hba *phba)
3742{
3743 uint64_t wwn;
3744 int rc;
3745 LPFC_MBOXQ_t *mboxq;
3746 MAILBOX_t *mb;
3747
James Smart96418b52017-03-04 09:30:31 -08003748 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
3749 GFP_KERNEL);
3750 if (!mboxq)
3751 return (uint64_t)-1;
3752
3753 /* First get WWN of HBA instance */
3754 lpfc_read_nv(phba, mboxq);
3755 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
3756 if (rc != MBX_SUCCESS) {
3757 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3758 "6019 Mailbox failed , mbxCmd x%x "
3759 "READ_NV, mbxStatus x%x\n",
3760 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
3761 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
3762 mempool_free(mboxq, phba->mbox_mem_pool);
3763 return (uint64_t) -1;
3764 }
3765 mb = &mboxq->u.mb;
3766 memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
3767 /* wwn is WWPN of HBA instance */
3768 mempool_free(mboxq, phba->mbox_mem_pool);
3769 if (phba->sli_rev == LPFC_SLI_REV4)
3770 return be64_to_cpu(wwn);
3771 else
Maurizio Lombardi286871a2017-08-23 16:55:48 -07003772 return rol64(wwn, 32);
James Smart96418b52017-03-04 09:30:31 -08003773}
3774
James Smarte59058c2008-08-24 21:49:00 -04003775/**
James Smart895427b2017-02-12 13:52:30 -08003776 * lpfc_sli4_nvme_sgl_update - update xri-sgl sizing and mapping
3777 * @phba: pointer to lpfc hba data structure.
3778 *
3779 * This routine first calculates the sizes of the current els and allocated
3780 * scsi sgl lists, and then goes through all sgls to updates the physical
3781 * XRIs assigned due to port function reset. During port initialization, the
3782 * current els and allocated scsi sgl lists are 0s.
3783 *
3784 * Return codes
3785 * 0 - successful (for now, it always returns 0)
3786 **/
3787int
3788lpfc_sli4_nvme_sgl_update(struct lpfc_hba *phba)
3789{
3790 struct lpfc_nvme_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
3791 uint16_t i, lxri, els_xri_cnt;
3792 uint16_t nvme_xri_cnt, nvme_xri_max;
3793 LIST_HEAD(nvme_sgl_list);
James Smartcf1a1d32017-12-08 17:18:03 -08003794 int rc, cnt;
James Smart895427b2017-02-12 13:52:30 -08003795
3796 phba->total_nvme_bufs = 0;
James Smartcf1a1d32017-12-08 17:18:03 -08003797 phba->get_nvme_bufs = 0;
3798 phba->put_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08003799
3800 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3801 return 0;
3802 /*
3803 * update on pci function's allocated nvme xri-sgl list
3804 */
3805
3806 /* maximum number of xris available for nvme buffers */
3807 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3808 nvme_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3809 phba->sli4_hba.nvme_xri_max = nvme_xri_max;
3810 phba->sli4_hba.nvme_xri_max -= phba->sli4_hba.scsi_xri_max;
3811
3812 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3813 "6074 Current allocated NVME xri-sgl count:%d, "
3814 "maximum NVME xri count:%d\n",
3815 phba->sli4_hba.nvme_xri_cnt,
3816 phba->sli4_hba.nvme_xri_max);
3817
3818 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3819 spin_lock(&phba->nvme_buf_list_put_lock);
3820 list_splice_init(&phba->lpfc_nvme_buf_list_get, &nvme_sgl_list);
3821 list_splice(&phba->lpfc_nvme_buf_list_put, &nvme_sgl_list);
James Smartcf1a1d32017-12-08 17:18:03 -08003822 cnt = phba->get_nvme_bufs + phba->put_nvme_bufs;
3823 phba->get_nvme_bufs = 0;
3824 phba->put_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08003825 spin_unlock(&phba->nvme_buf_list_put_lock);
3826 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3827
3828 if (phba->sli4_hba.nvme_xri_cnt > phba->sli4_hba.nvme_xri_max) {
3829 /* max nvme xri shrunk below the allocated nvme buffers */
3830 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3831 nvme_xri_cnt = phba->sli4_hba.nvme_xri_cnt -
3832 phba->sli4_hba.nvme_xri_max;
3833 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3834 /* release the extra allocated nvme buffers */
3835 for (i = 0; i < nvme_xri_cnt; i++) {
3836 list_remove_head(&nvme_sgl_list, lpfc_ncmd,
3837 struct lpfc_nvme_buf, list);
3838 if (lpfc_ncmd) {
Romain Perier771db5c2017-07-06 10:13:05 +02003839 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
James Smart895427b2017-02-12 13:52:30 -08003840 lpfc_ncmd->data,
3841 lpfc_ncmd->dma_handle);
3842 kfree(lpfc_ncmd);
3843 }
3844 }
3845 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3846 phba->sli4_hba.nvme_xri_cnt -= nvme_xri_cnt;
3847 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3848 }
3849
3850 /* update xris associated to remaining allocated nvme buffers */
3851 lpfc_ncmd = NULL;
3852 lpfc_ncmd_next = NULL;
3853 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3854 &nvme_sgl_list, list) {
3855 lxri = lpfc_sli4_next_xritag(phba);
3856 if (lxri == NO_XRI) {
3857 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3858 "6075 Failed to allocate xri for "
3859 "nvme buffer\n");
3860 rc = -ENOMEM;
3861 goto out_free_mem;
3862 }
3863 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
3864 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3865 }
3866 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3867 spin_lock(&phba->nvme_buf_list_put_lock);
3868 list_splice_init(&nvme_sgl_list, &phba->lpfc_nvme_buf_list_get);
James Smartcf1a1d32017-12-08 17:18:03 -08003869 phba->get_nvme_bufs = cnt;
James Smart895427b2017-02-12 13:52:30 -08003870 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
3871 spin_unlock(&phba->nvme_buf_list_put_lock);
3872 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3873 return 0;
3874
3875out_free_mem:
3876 lpfc_nvme_free(phba);
3877 return rc;
3878}
3879
3880/**
James Smart3621a712009-04-06 18:47:14 -04003881 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04003882 * @phba: pointer to lpfc hba data structure.
3883 * @instance: a unique integer ID to this FC port.
3884 * @dev: pointer to the device data structure.
3885 *
3886 * This routine creates a FC port for the upper layer protocol. The FC port
3887 * can be created on top of either a physical port or a virtual port provided
3888 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3889 * and associates the FC port created before adding the shost into the SCSI
3890 * layer.
3891 *
3892 * Return codes
3893 * @vport - pointer to the virtual N_Port data structure.
3894 * NULL - port create failed.
3895 **/
James Smart2e0fef82007-06-17 19:56:36 -05003896struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04003897lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04003898{
James Smart2e0fef82007-06-17 19:56:36 -05003899 struct lpfc_vport *vport;
James Smart895427b2017-02-12 13:52:30 -08003900 struct Scsi_Host *shost = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003901 int error = 0;
James Smart96418b52017-03-04 09:30:31 -08003902 int i;
3903 uint64_t wwn;
3904 bool use_no_reset_hba = false;
James Smart56bc8022017-06-15 22:56:43 -07003905 int rc;
James Smart96418b52017-03-04 09:30:31 -08003906
James Smart56bc8022017-06-15 22:56:43 -07003907 if (lpfc_no_hba_reset_cnt) {
3908 if (phba->sli_rev < LPFC_SLI_REV4 &&
3909 dev == &phba->pcidev->dev) {
3910 /* Reset the port first */
3911 lpfc_sli_brdrestart(phba);
3912 rc = lpfc_sli_chipset_init(phba);
3913 if (rc)
3914 return NULL;
3915 }
3916 wwn = lpfc_get_wwpn(phba);
3917 }
James Smart96418b52017-03-04 09:30:31 -08003918
3919 for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
3920 if (wwn == lpfc_no_hba_reset[i]) {
3921 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3922 "6020 Setting use_no_reset port=%llx\n",
3923 wwn);
3924 use_no_reset_hba = true;
3925 break;
3926 }
3927 }
James Smart47a86172007-04-25 09:53:22 -04003928
James Smart895427b2017-02-12 13:52:30 -08003929 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
3930 if (dev != &phba->pcidev->dev) {
3931 shost = scsi_host_alloc(&lpfc_vport_template,
3932 sizeof(struct lpfc_vport));
3933 } else {
James Smart96418b52017-03-04 09:30:31 -08003934 if (!use_no_reset_hba)
James Smart895427b2017-02-12 13:52:30 -08003935 shost = scsi_host_alloc(&lpfc_template,
3936 sizeof(struct lpfc_vport));
3937 else
James Smart96418b52017-03-04 09:30:31 -08003938 shost = scsi_host_alloc(&lpfc_template_no_hr,
James Smart895427b2017-02-12 13:52:30 -08003939 sizeof(struct lpfc_vport));
3940 }
3941 } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
3942 shost = scsi_host_alloc(&lpfc_template_nvme,
James Smartea4142f2015-04-07 15:07:13 -04003943 sizeof(struct lpfc_vport));
3944 }
James Smart2e0fef82007-06-17 19:56:36 -05003945 if (!shost)
3946 goto out;
James Smart47a86172007-04-25 09:53:22 -04003947
James Smart2e0fef82007-06-17 19:56:36 -05003948 vport = (struct lpfc_vport *) shost->hostdata;
3949 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05003950 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05003951 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05003952 vport->fc_rscn_flush = 0;
James Smart3de2a652007-08-02 11:09:59 -04003953 lpfc_get_vport_cfgparam(vport);
James Smart895427b2017-02-12 13:52:30 -08003954
James Smart2e0fef82007-06-17 19:56:36 -05003955 shost->unique_id = instance;
3956 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04003957 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05003958 shost->this_id = -1;
3959 shost->max_cmd_len = 16;
James Smart8b0dff12015-05-22 10:42:38 -04003960 shost->nr_hw_queues = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04003961 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05003962 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04003963 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smart5b9e70b2018-09-10 10:30:42 -07003964 shost->sg_tablesize = phba->cfg_scsi_seg_cnt;
James Smartda0436e2009-05-22 14:51:39 -04003965 }
James Smart81301a92008-12-04 22:39:46 -05003966
James Smart47a86172007-04-25 09:53:22 -04003967 /*
James Smart2e0fef82007-06-17 19:56:36 -05003968 * Set initial can_queue value since 0 is no longer supported and
3969 * scsi_add_host will fail. This will be adjusted later based on the
3970 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04003971 */
James Smart2e0fef82007-06-17 19:56:36 -05003972 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04003973 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05003974 shost->transportt = lpfc_vport_transport_template;
3975 vport->port_type = LPFC_NPIV_PORT;
3976 } else {
3977 shost->transportt = lpfc_transport_template;
3978 vport->port_type = LPFC_PHYSICAL_PORT;
3979 }
James Smart47a86172007-04-25 09:53:22 -04003980
James Smart2e0fef82007-06-17 19:56:36 -05003981 /* Initialize all internally managed lists. */
3982 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04003983 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05003984 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04003985
Kees Cookf22eb4d2017-09-06 20:24:26 -07003986 timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0);
James Smart47a86172007-04-25 09:53:22 -04003987
Kees Cookf22eb4d2017-09-06 20:24:26 -07003988 timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0);
James Smart92494142011-02-16 12:39:44 -05003989
Kees Cookf22eb4d2017-09-06 20:24:26 -07003990 timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0);
James Smart92494142011-02-16 12:39:44 -05003991
James Bottomleyd139b9b2009-11-05 13:33:12 -06003992 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05003993 if (error)
3994 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04003995
James Smart523128e2018-09-10 10:30:46 -07003996 spin_lock_irq(&phba->port_list_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003997 list_add_tail(&vport->listentry, &phba->port_list);
James Smart523128e2018-09-10 10:30:46 -07003998 spin_unlock_irq(&phba->port_list_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003999 return vport;
James Smart47a86172007-04-25 09:53:22 -04004000
James Smart2e0fef82007-06-17 19:56:36 -05004001out_put_shost:
4002 scsi_host_put(shost);
4003out:
4004 return NULL;
James Smart47a86172007-04-25 09:53:22 -04004005}
4006
James Smarte59058c2008-08-24 21:49:00 -04004007/**
James Smart3621a712009-04-06 18:47:14 -04004008 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04004009 * @vport: pointer to an lpfc virtual N_Port data structure.
4010 *
4011 * This routine destroys a FC port from the upper layer protocol. All the
4012 * resources associated with the port are released.
4013 **/
James Smart2e0fef82007-06-17 19:56:36 -05004014void
4015destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04004016{
James Smart92d7f7b2007-06-17 19:56:38 -05004017 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4018 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04004019
James Smart858c9f62007-06-17 19:56:39 -05004020 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05004021 fc_remove_host(shost);
4022 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04004023
James Smart523128e2018-09-10 10:30:46 -07004024 spin_lock_irq(&phba->port_list_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004025 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -07004026 spin_unlock_irq(&phba->port_list_lock);
James Smart47a86172007-04-25 09:53:22 -04004027
James Smart92d7f7b2007-06-17 19:56:38 -05004028 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04004029 return;
James Smart47a86172007-04-25 09:53:22 -04004030}
4031
James Smarte59058c2008-08-24 21:49:00 -04004032/**
James Smart3621a712009-04-06 18:47:14 -04004033 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04004034 *
4035 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
4036 * uses the kernel idr facility to perform the task.
4037 *
4038 * Return codes:
4039 * instance - a unique integer ID allocated as the new instance.
4040 * -1 - lpfc get instance failed.
4041 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004042int
4043lpfc_get_instance(void)
4044{
Tejun Heoab516032013-02-27 17:04:44 -08004045 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05004046
Tejun Heoab516032013-02-27 17:04:44 -08004047 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
4048 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05004049}
4050
James Smarte59058c2008-08-24 21:49:00 -04004051/**
James Smart3621a712009-04-06 18:47:14 -04004052 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04004053 * @shost: pointer to SCSI host data structure.
4054 * @time: elapsed time of the scan in jiffies.
4055 *
4056 * This routine is called by the SCSI layer with a SCSI host to determine
4057 * whether the scan host is finished.
4058 *
4059 * Note: there is no scan_start function as adapter initialization will have
4060 * asynchronously kicked off the link initialization.
4061 *
4062 * Return codes
4063 * 0 - SCSI host scan is not over yet.
4064 * 1 - SCSI host scan is over.
4065 **/
James Smart47a86172007-04-25 09:53:22 -04004066int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
4067{
James Smart2e0fef82007-06-17 19:56:36 -05004068 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4069 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05004070 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04004071
James Smart858c9f62007-06-17 19:56:39 -05004072 spin_lock_irq(shost->host_lock);
4073
James Smart51ef4c22007-08-02 11:10:31 -04004074 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05004075 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004076 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05004077 }
James Smart256ec0d2013-04-17 20:14:58 -04004078 if (time >= msecs_to_jiffies(30 * 1000)) {
James Smart2e0fef82007-06-17 19:56:36 -05004079 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004080 "0461 Scanning longer than 30 "
4081 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05004082 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004083 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004084 }
James Smart256ec0d2013-04-17 20:14:58 -04004085 if (time >= msecs_to_jiffies(15 * 1000) &&
4086 phba->link_state <= LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05004087 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004088 "0465 Link down longer than 15 "
4089 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05004090 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05004091 goto finished;
James Smart47a86172007-04-25 09:53:22 -04004092 }
4093
James Smart2e0fef82007-06-17 19:56:36 -05004094 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05004095 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004096 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05004097 goto finished;
James Smart256ec0d2013-04-17 20:14:58 -04004098 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
James Smart858c9f62007-06-17 19:56:39 -05004099 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004100 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05004101 goto finished;
4102
4103 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004104
4105finished:
James Smart858c9f62007-06-17 19:56:39 -05004106 spin_unlock_irq(shost->host_lock);
4107 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05004108}
4109
James Smartcd713482018-10-23 13:41:01 -07004110void lpfc_host_supported_speeds_set(struct Scsi_Host *shost)
4111{
4112 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4113 struct lpfc_hba *phba = vport->phba;
4114
4115 fc_host_supported_speeds(shost) = 0;
James Smart1dc5ec22018-10-23 13:41:11 -07004116 if (phba->lmt & LMT_128Gb)
4117 fc_host_supported_speeds(shost) |= FC_PORTSPEED_128GBIT;
James Smartcd713482018-10-23 13:41:01 -07004118 if (phba->lmt & LMT_64Gb)
4119 fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT;
4120 if (phba->lmt & LMT_32Gb)
4121 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
4122 if (phba->lmt & LMT_16Gb)
4123 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
4124 if (phba->lmt & LMT_10Gb)
4125 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
4126 if (phba->lmt & LMT_8Gb)
4127 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
4128 if (phba->lmt & LMT_4Gb)
4129 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
4130 if (phba->lmt & LMT_2Gb)
4131 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
4132 if (phba->lmt & LMT_1Gb)
4133 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
4134}
4135
James Smarte59058c2008-08-24 21:49:00 -04004136/**
James Smart3621a712009-04-06 18:47:14 -04004137 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04004138 * @shost: pointer to SCSI host data structure.
4139 *
4140 * This routine initializes a given SCSI host attributes on a FC port. The
4141 * SCSI host can be either on top of a physical port or a virtual port.
4142 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004143void lpfc_host_attrib_init(struct Scsi_Host *shost)
4144{
4145 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4146 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04004147 /*
James Smart2e0fef82007-06-17 19:56:36 -05004148 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04004149 */
4150
James Smart2e0fef82007-06-17 19:56:36 -05004151 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
4152 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04004153 fc_host_supported_classes(shost) = FC_COS_CLASS3;
4154
4155 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05004156 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04004157 fc_host_supported_fc4s(shost)[2] = 1;
4158 fc_host_supported_fc4s(shost)[7] = 1;
4159
James Smart92d7f7b2007-06-17 19:56:38 -05004160 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
4161 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04004162
James Smartcd713482018-10-23 13:41:01 -07004163 lpfc_host_supported_speeds_set(shost);
James Smart47a86172007-04-25 09:53:22 -04004164
4165 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05004166 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
4167 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04004168
Mike Christie0af5d702010-09-15 16:52:31 -05004169 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
4170
James Smart47a86172007-04-25 09:53:22 -04004171 /* This value is also unchanging */
4172 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05004173 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04004174 fc_host_active_fc4s(shost)[2] = 1;
4175 fc_host_active_fc4s(shost)[7] = 1;
4176
James Smart92d7f7b2007-06-17 19:56:38 -05004177 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04004178 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04004179 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04004180 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04004181}
dea31012005-04-17 16:05:31 -05004182
James Smarte59058c2008-08-24 21:49:00 -04004183/**
James Smartda0436e2009-05-22 14:51:39 -04004184 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04004185 * @phba: pointer to lpfc hba data structure.
4186 *
James Smartda0436e2009-05-22 14:51:39 -04004187 * This routine is invoked to stop an SLI3 device port, it stops the device
4188 * from generating interrupts and stops the device driver's timers for the
4189 * device.
James Smarte59058c2008-08-24 21:49:00 -04004190 **/
James Smartdb2378e2008-02-08 18:49:51 -05004191static void
James Smartda0436e2009-05-22 14:51:39 -04004192lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05004193{
James Smartda0436e2009-05-22 14:51:39 -04004194 /* Clear all interrupt enable conditions */
4195 writel(0, phba->HCregaddr);
4196 readl(phba->HCregaddr); /* flush */
4197 /* Clear all pending interrupts */
4198 writel(0xffffffff, phba->HAregaddr);
4199 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04004200
James Smartda0436e2009-05-22 14:51:39 -04004201 /* Reset some HBA SLI setup states */
4202 lpfc_stop_hba_timers(phba);
4203 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05004204}
4205
James Smarte59058c2008-08-24 21:49:00 -04004206/**
James Smartda0436e2009-05-22 14:51:39 -04004207 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05004208 * @phba: pointer to lpfc hba data structure.
4209 *
James Smartda0436e2009-05-22 14:51:39 -04004210 * This routine is invoked to stop an SLI4 device port, it stops the device
4211 * from generating interrupts and stops the device driver's timers for the
4212 * device.
4213 **/
4214static void
4215lpfc_stop_port_s4(struct lpfc_hba *phba)
4216{
4217 /* Reset some HBA SLI4 setup states */
4218 lpfc_stop_hba_timers(phba);
4219 phba->pport->work_port_events = 0;
4220 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04004221}
4222
4223/**
4224 * lpfc_stop_port - Wrapper function for stopping hba port
4225 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05004226 *
James Smartda0436e2009-05-22 14:51:39 -04004227 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
4228 * the API jump table function pointer from the lpfc_hba struct.
4229 **/
4230void
4231lpfc_stop_port(struct lpfc_hba *phba)
4232{
4233 phba->lpfc_stop_port(phba);
Dick Kennedyf485c182017-09-29 17:34:34 -07004234
4235 if (phba->wq)
4236 flush_workqueue(phba->wq);
James Smartda0436e2009-05-22 14:51:39 -04004237}
4238
4239/**
James Smartecfd03c2010-02-12 14:41:27 -05004240 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
4241 * @phba: Pointer to hba for which this call is being executed.
4242 *
4243 * This routine starts the timer waiting for the FCF rediscovery to complete.
4244 **/
4245void
4246lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
4247{
4248 unsigned long fcf_redisc_wait_tmo =
4249 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
4250 /* Start fcf rediscovery wait period timer */
4251 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
4252 spin_lock_irq(&phba->hbalock);
4253 /* Allow action to new fcf asynchronous event */
4254 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
4255 /* Mark the FCF rediscovery pending state */
4256 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
4257 spin_unlock_irq(&phba->hbalock);
4258}
4259
4260/**
4261 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
4262 * @ptr: Map to lpfc_hba data structure pointer.
4263 *
4264 * This routine is invoked when waiting for FCF table rediscover has been
4265 * timed out. If new FCF record(s) has (have) been discovered during the
4266 * wait period, a new FCF event shall be added to the FCOE async event
4267 * list, and then worker thread shall be waked up for processing from the
4268 * worker thread context.
4269 **/
Rashika Kheriae399b222014-09-03 12:55:28 -04004270static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07004271lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t)
James Smartecfd03c2010-02-12 14:41:27 -05004272{
Kees Cookf22eb4d2017-09-06 20:24:26 -07004273 struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait);
James Smartecfd03c2010-02-12 14:41:27 -05004274
4275 /* Don't send FCF rediscovery event if timer cancelled */
4276 spin_lock_irq(&phba->hbalock);
4277 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
4278 spin_unlock_irq(&phba->hbalock);
4279 return;
4280 }
4281 /* Clear FCF rediscovery timer pending flag */
4282 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
4283 /* FCF rediscovery event to worker thread */
4284 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
4285 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004286 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04004287 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05004288 /* wake up worker thread */
4289 lpfc_worker_wake_up(phba);
4290}
4291
4292/**
James Smartda0436e2009-05-22 14:51:39 -04004293 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
4294 * @phba: pointer to lpfc hba data structure.
4295 * @acqe_link: pointer to the async link completion queue entry.
4296 *
James Smart23288b72018-05-04 20:37:53 -07004297 * This routine is to parse the SLI4 link-attention link fault code.
James Smartda0436e2009-05-22 14:51:39 -04004298 **/
James Smart23288b72018-05-04 20:37:53 -07004299static void
James Smartda0436e2009-05-22 14:51:39 -04004300lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
4301 struct lpfc_acqe_link *acqe_link)
4302{
James Smartda0436e2009-05-22 14:51:39 -04004303 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
4304 case LPFC_ASYNC_LINK_FAULT_NONE:
4305 case LPFC_ASYNC_LINK_FAULT_LOCAL:
4306 case LPFC_ASYNC_LINK_FAULT_REMOTE:
James Smart23288b72018-05-04 20:37:53 -07004307 case LPFC_ASYNC_LINK_FAULT_LR_LRR:
James Smartda0436e2009-05-22 14:51:39 -04004308 break;
4309 default:
4310 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart23288b72018-05-04 20:37:53 -07004311 "0398 Unknown link fault code: x%x\n",
James Smartda0436e2009-05-22 14:51:39 -04004312 bf_get(lpfc_acqe_link_fault, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04004313 break;
4314 }
James Smartda0436e2009-05-22 14:51:39 -04004315}
4316
4317/**
4318 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
4319 * @phba: pointer to lpfc hba data structure.
4320 * @acqe_link: pointer to the async link completion queue entry.
4321 *
4322 * This routine is to parse the SLI4 link attention type and translate it
4323 * into the base driver's link attention type coding.
4324 *
4325 * Return: Link attention type in terms of base driver's coding.
4326 **/
4327static uint8_t
4328lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
4329 struct lpfc_acqe_link *acqe_link)
4330{
4331 uint8_t att_type;
4332
4333 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
4334 case LPFC_ASYNC_LINK_STATUS_DOWN:
4335 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05004336 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04004337 break;
4338 case LPFC_ASYNC_LINK_STATUS_UP:
4339 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05004340 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004341 break;
4342 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05004343 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04004344 break;
4345 default:
4346 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4347 "0399 Invalid link attention type: x%x\n",
4348 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05004349 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004350 break;
4351 }
4352 return att_type;
4353}
4354
4355/**
James Smart8b68cd52012-09-29 11:32:37 -04004356 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
4357 * @phba: pointer to lpfc hba data structure.
4358 *
4359 * This routine is to get an SLI3 FC port's link speed in Mbps.
4360 *
4361 * Return: link speed in terms of Mbps.
4362 **/
4363uint32_t
4364lpfc_sli_port_speed_get(struct lpfc_hba *phba)
4365{
4366 uint32_t link_speed;
4367
4368 if (!lpfc_is_link_up(phba))
4369 return 0;
4370
James Smarta085e872015-12-16 18:12:02 -05004371 if (phba->sli_rev <= LPFC_SLI_REV3) {
4372 switch (phba->fc_linkspeed) {
4373 case LPFC_LINK_SPEED_1GHZ:
4374 link_speed = 1000;
4375 break;
4376 case LPFC_LINK_SPEED_2GHZ:
4377 link_speed = 2000;
4378 break;
4379 case LPFC_LINK_SPEED_4GHZ:
4380 link_speed = 4000;
4381 break;
4382 case LPFC_LINK_SPEED_8GHZ:
4383 link_speed = 8000;
4384 break;
4385 case LPFC_LINK_SPEED_10GHZ:
4386 link_speed = 10000;
4387 break;
4388 case LPFC_LINK_SPEED_16GHZ:
4389 link_speed = 16000;
4390 break;
4391 default:
4392 link_speed = 0;
4393 }
4394 } else {
4395 if (phba->sli4_hba.link_state.logical_speed)
4396 link_speed =
4397 phba->sli4_hba.link_state.logical_speed;
4398 else
4399 link_speed = phba->sli4_hba.link_state.speed;
James Smart8b68cd52012-09-29 11:32:37 -04004400 }
4401 return link_speed;
4402}
4403
4404/**
4405 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
4406 * @phba: pointer to lpfc hba data structure.
4407 * @evt_code: asynchronous event code.
4408 * @speed_code: asynchronous event link speed code.
4409 *
4410 * This routine is to parse the giving SLI4 async event link speed code into
4411 * value of Mbps for the link speed.
4412 *
4413 * Return: link speed in terms of Mbps.
4414 **/
4415static uint32_t
4416lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
4417 uint8_t speed_code)
4418{
4419 uint32_t port_speed;
4420
4421 switch (evt_code) {
4422 case LPFC_TRAILER_CODE_LINK:
4423 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004424 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smart8b68cd52012-09-29 11:32:37 -04004425 port_speed = 0;
4426 break;
James Smart26d830e2015-04-07 15:07:17 -04004427 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004428 port_speed = 10;
4429 break;
James Smart26d830e2015-04-07 15:07:17 -04004430 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004431 port_speed = 100;
4432 break;
James Smart26d830e2015-04-07 15:07:17 -04004433 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004434 port_speed = 1000;
4435 break;
James Smart26d830e2015-04-07 15:07:17 -04004436 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004437 port_speed = 10000;
4438 break;
James Smart26d830e2015-04-07 15:07:17 -04004439 case LPFC_ASYNC_LINK_SPEED_20GBPS:
4440 port_speed = 20000;
4441 break;
4442 case LPFC_ASYNC_LINK_SPEED_25GBPS:
4443 port_speed = 25000;
4444 break;
4445 case LPFC_ASYNC_LINK_SPEED_40GBPS:
4446 port_speed = 40000;
4447 break;
James Smart8b68cd52012-09-29 11:32:37 -04004448 default:
4449 port_speed = 0;
4450 }
4451 break;
4452 case LPFC_TRAILER_CODE_FC:
4453 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004454 case LPFC_FC_LA_SPEED_UNKNOWN:
James Smart8b68cd52012-09-29 11:32:37 -04004455 port_speed = 0;
4456 break;
James Smart26d830e2015-04-07 15:07:17 -04004457 case LPFC_FC_LA_SPEED_1G:
James Smart8b68cd52012-09-29 11:32:37 -04004458 port_speed = 1000;
4459 break;
James Smart26d830e2015-04-07 15:07:17 -04004460 case LPFC_FC_LA_SPEED_2G:
James Smart8b68cd52012-09-29 11:32:37 -04004461 port_speed = 2000;
4462 break;
James Smart26d830e2015-04-07 15:07:17 -04004463 case LPFC_FC_LA_SPEED_4G:
James Smart8b68cd52012-09-29 11:32:37 -04004464 port_speed = 4000;
4465 break;
James Smart26d830e2015-04-07 15:07:17 -04004466 case LPFC_FC_LA_SPEED_8G:
James Smart8b68cd52012-09-29 11:32:37 -04004467 port_speed = 8000;
4468 break;
James Smart26d830e2015-04-07 15:07:17 -04004469 case LPFC_FC_LA_SPEED_10G:
James Smart8b68cd52012-09-29 11:32:37 -04004470 port_speed = 10000;
4471 break;
James Smart26d830e2015-04-07 15:07:17 -04004472 case LPFC_FC_LA_SPEED_16G:
James Smart8b68cd52012-09-29 11:32:37 -04004473 port_speed = 16000;
4474 break;
James Smartd38dd522015-08-31 16:48:17 -04004475 case LPFC_FC_LA_SPEED_32G:
4476 port_speed = 32000;
4477 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08004478 case LPFC_FC_LA_SPEED_64G:
4479 port_speed = 64000;
4480 break;
James Smart1dc5ec22018-10-23 13:41:11 -07004481 case LPFC_FC_LA_SPEED_128G:
4482 port_speed = 128000;
4483 break;
James Smart8b68cd52012-09-29 11:32:37 -04004484 default:
4485 port_speed = 0;
4486 }
4487 break;
4488 default:
4489 port_speed = 0;
4490 }
4491 return port_speed;
4492}
4493
4494/**
James Smart70f3c072010-12-15 17:57:33 -05004495 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04004496 * @phba: pointer to lpfc hba data structure.
4497 * @acqe_link: pointer to the async link completion queue entry.
4498 *
James Smart70f3c072010-12-15 17:57:33 -05004499 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04004500 **/
4501static void
4502lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
4503 struct lpfc_acqe_link *acqe_link)
4504{
4505 struct lpfc_dmabuf *mp;
4506 LPFC_MBOXQ_t *pmb;
4507 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05004508 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04004509 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05004510 int rc;
James Smartda0436e2009-05-22 14:51:39 -04004511
4512 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05004513 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04004514 return;
James Smart32b97932009-07-19 10:01:21 -04004515 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004516 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4517 if (!pmb) {
4518 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4519 "0395 The mboxq allocation failed\n");
4520 return;
4521 }
4522 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4523 if (!mp) {
4524 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4525 "0396 The lpfc_dmabuf allocation failed\n");
4526 goto out_free_pmb;
4527 }
4528 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4529 if (!mp->virt) {
4530 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4531 "0397 The mbuf allocation failed\n");
4532 goto out_free_dmabuf;
4533 }
4534
4535 /* Cleanup any outstanding ELS commands */
4536 lpfc_els_flush_all_cmd(phba);
4537
4538 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004539 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smartda0436e2009-05-22 14:51:39 -04004540
4541 /* Update link event statistics */
4542 phba->sli.slistat.link_event++;
4543
James Smart76a95d72010-11-20 23:11:48 -05004544 /* Create lpfc_handle_latt mailbox command from link ACQE */
4545 lpfc_read_topology(phba, pmb, mp);
4546 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04004547 pmb->vport = phba->pport;
4548
James Smartda0436e2009-05-22 14:51:39 -04004549 /* Keep the link status for extra SLI4 state machine reference */
4550 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004551 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
4552 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04004553 phba->sli4_hba.link_state.duplex =
4554 bf_get(lpfc_acqe_link_duplex, acqe_link);
4555 phba->sli4_hba.link_state.status =
4556 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05004557 phba->sli4_hba.link_state.type =
4558 bf_get(lpfc_acqe_link_type, acqe_link);
4559 phba->sli4_hba.link_state.number =
4560 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04004561 phba->sli4_hba.link_state.fault =
4562 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05004563 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004564 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
4565
James Smart70f3c072010-12-15 17:57:33 -05004566 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04004567 "2900 Async FC/FCoE Link event - Speed:%dGBit "
4568 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
4569 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05004570 phba->sli4_hba.link_state.speed,
4571 phba->sli4_hba.link_state.topology,
4572 phba->sli4_hba.link_state.status,
4573 phba->sli4_hba.link_state.type,
4574 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004575 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004576 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05004577 /*
4578 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
4579 * topology info. Note: Optional for non FC-AL ports.
4580 */
4581 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
4582 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4583 if (rc == MBX_NOT_FINISHED)
4584 goto out_free_dmabuf;
4585 return;
4586 }
4587 /*
4588 * For FCoE Mode: fill in all the topology information we need and call
4589 * the READ_TOPOLOGY completion routine to continue without actually
4590 * sending the READ_TOPOLOGY mailbox command to the port.
4591 */
James Smart23288b72018-05-04 20:37:53 -07004592 /* Initialize completion status */
James Smart76a95d72010-11-20 23:11:48 -05004593 mb = &pmb->u.mb;
James Smart23288b72018-05-04 20:37:53 -07004594 mb->mbxStatus = MBX_SUCCESS;
4595
4596 /* Parse port fault information field */
4597 lpfc_sli4_parse_latt_fault(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05004598
4599 /* Parse and translate link attention fields */
4600 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
4601 la->eventTag = acqe_link->event_tag;
4602 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
4603 bf_set(lpfc_mbx_read_top_link_spd, la,
James Smarta085e872015-12-16 18:12:02 -05004604 (bf_get(lpfc_acqe_link_speed, acqe_link)));
James Smart76a95d72010-11-20 23:11:48 -05004605
4606 /* Fake the the following irrelvant fields */
4607 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
4608 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
4609 bf_set(lpfc_mbx_read_top_il, la, 0);
4610 bf_set(lpfc_mbx_read_top_pb, la, 0);
4611 bf_set(lpfc_mbx_read_top_fa, la, 0);
4612 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04004613
4614 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05004615 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04004616
4617 return;
4618
4619out_free_dmabuf:
4620 kfree(mp);
4621out_free_pmb:
4622 mempool_free(pmb, phba->mbox_mem_pool);
4623}
4624
4625/**
James Smart1dc5ec22018-10-23 13:41:11 -07004626 * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read
4627 * topology.
4628 * @phba: pointer to lpfc hba data structure.
4629 * @evt_code: asynchronous event code.
4630 * @speed_code: asynchronous event link speed code.
4631 *
4632 * This routine is to parse the giving SLI4 async event link speed code into
4633 * value of Read topology link speed.
4634 *
4635 * Return: link speed in terms of Read topology.
4636 **/
4637static uint8_t
4638lpfc_async_link_speed_to_read_top(struct lpfc_hba *phba, uint8_t speed_code)
4639{
4640 uint8_t port_speed;
4641
4642 switch (speed_code) {
4643 case LPFC_FC_LA_SPEED_1G:
4644 port_speed = LPFC_LINK_SPEED_1GHZ;
4645 break;
4646 case LPFC_FC_LA_SPEED_2G:
4647 port_speed = LPFC_LINK_SPEED_2GHZ;
4648 break;
4649 case LPFC_FC_LA_SPEED_4G:
4650 port_speed = LPFC_LINK_SPEED_4GHZ;
4651 break;
4652 case LPFC_FC_LA_SPEED_8G:
4653 port_speed = LPFC_LINK_SPEED_8GHZ;
4654 break;
4655 case LPFC_FC_LA_SPEED_16G:
4656 port_speed = LPFC_LINK_SPEED_16GHZ;
4657 break;
4658 case LPFC_FC_LA_SPEED_32G:
4659 port_speed = LPFC_LINK_SPEED_32GHZ;
4660 break;
4661 case LPFC_FC_LA_SPEED_64G:
4662 port_speed = LPFC_LINK_SPEED_64GHZ;
4663 break;
4664 case LPFC_FC_LA_SPEED_128G:
4665 port_speed = LPFC_LINK_SPEED_128GHZ;
4666 break;
4667 case LPFC_FC_LA_SPEED_256G:
4668 port_speed = LPFC_LINK_SPEED_256GHZ;
4669 break;
4670 default:
4671 port_speed = 0;
4672 break;
4673 }
4674
4675 return port_speed;
4676}
4677
4678#define trunk_link_status(__idx)\
4679 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
4680 ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\
4681 "Link up" : "Link down") : "NA"
4682/* Did port __idx reported an error */
4683#define trunk_port_fault(__idx)\
4684 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
4685 (port_fault & (1 << __idx) ? "YES" : "NO") : "NA"
4686
4687static void
4688lpfc_update_trunk_link_status(struct lpfc_hba *phba,
4689 struct lpfc_acqe_fc_la *acqe_fc)
4690{
4691 uint8_t port_fault = bf_get(lpfc_acqe_fc_la_trunk_linkmask, acqe_fc);
4692 uint8_t err = bf_get(lpfc_acqe_fc_la_trunk_fault, acqe_fc);
4693
4694 phba->sli4_hba.link_state.speed =
4695 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
4696 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
4697
4698 phba->sli4_hba.link_state.logical_speed =
4699 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc);
4700 /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */
4701 phba->fc_linkspeed =
4702 lpfc_async_link_speed_to_read_top(
4703 phba,
4704 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
4705
4706 if (bf_get(lpfc_acqe_fc_la_trunk_config_port0, acqe_fc)) {
4707 phba->trunk_link.link0.state =
4708 bf_get(lpfc_acqe_fc_la_trunk_link_status_port0, acqe_fc)
4709 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
4710 if (port_fault & 0x1)
4711 phba->trunk_link.link0.fault = err;
4712 }
4713 if (bf_get(lpfc_acqe_fc_la_trunk_config_port1, acqe_fc)) {
4714 phba->trunk_link.link1.state =
4715 bf_get(lpfc_acqe_fc_la_trunk_link_status_port1, acqe_fc)
4716 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
4717 if (port_fault & 0x2)
4718 phba->trunk_link.link1.fault = err;
4719 }
4720 if (bf_get(lpfc_acqe_fc_la_trunk_config_port2, acqe_fc)) {
4721 phba->trunk_link.link2.state =
4722 bf_get(lpfc_acqe_fc_la_trunk_link_status_port2, acqe_fc)
4723 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
4724 if (port_fault & 0x4)
4725 phba->trunk_link.link2.fault = err;
4726 }
4727 if (bf_get(lpfc_acqe_fc_la_trunk_config_port3, acqe_fc)) {
4728 phba->trunk_link.link3.state =
4729 bf_get(lpfc_acqe_fc_la_trunk_link_status_port3, acqe_fc)
4730 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
4731 if (port_fault & 0x8)
4732 phba->trunk_link.link3.fault = err;
4733 }
4734
4735 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4736 "2910 Async FC Trunking Event - Speed:%d\n"
4737 "\tLogical speed:%d "
4738 "port0: %s port1: %s port2: %s port3: %s\n",
4739 phba->sli4_hba.link_state.speed,
4740 phba->sli4_hba.link_state.logical_speed,
4741 trunk_link_status(0), trunk_link_status(1),
4742 trunk_link_status(2), trunk_link_status(3));
4743
4744 if (port_fault)
4745 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4746 "3202 trunk error:0x%x (%s) seen on port0:%s "
4747 /*
4748 * SLI-4: We have only 0xA error codes
4749 * defined as of now. print an appropriate
4750 * message in case driver needs to be updated.
4751 */
4752 "port1:%s port2:%s port3:%s\n", err, err > 0xA ?
4753 "UNDEFINED. update driver." : trunk_errmsg[err],
4754 trunk_port_fault(0), trunk_port_fault(1),
4755 trunk_port_fault(2), trunk_port_fault(3));
4756}
4757
4758
4759/**
James Smart70f3c072010-12-15 17:57:33 -05004760 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
4761 * @phba: pointer to lpfc hba data structure.
4762 * @acqe_fc: pointer to the async fc completion queue entry.
4763 *
4764 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
4765 * that the event was received and then issue a read_topology mailbox command so
4766 * that the rest of the driver will treat it the same as SLI3.
4767 **/
4768static void
4769lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
4770{
4771 struct lpfc_dmabuf *mp;
4772 LPFC_MBOXQ_t *pmb;
James Smart7bdedb32016-07-06 12:36:00 -07004773 MAILBOX_t *mb;
4774 struct lpfc_mbx_read_top *la;
James Smart70f3c072010-12-15 17:57:33 -05004775 int rc;
4776
4777 if (bf_get(lpfc_trailer_type, acqe_fc) !=
4778 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
4779 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4780 "2895 Non FC link Event detected.(%d)\n",
4781 bf_get(lpfc_trailer_type, acqe_fc));
4782 return;
4783 }
James Smart1dc5ec22018-10-23 13:41:11 -07004784
4785 if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) ==
4786 LPFC_FC_LA_TYPE_TRUNKING_EVENT) {
4787 lpfc_update_trunk_link_status(phba, acqe_fc);
4788 return;
4789 }
4790
James Smart70f3c072010-12-15 17:57:33 -05004791 /* Keep the link status for extra SLI4 state machine reference */
4792 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004793 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
4794 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05004795 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
4796 phba->sli4_hba.link_state.topology =
4797 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
4798 phba->sli4_hba.link_state.status =
4799 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
4800 phba->sli4_hba.link_state.type =
4801 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
4802 phba->sli4_hba.link_state.number =
4803 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
4804 phba->sli4_hba.link_state.fault =
4805 bf_get(lpfc_acqe_link_fault, acqe_fc);
4806 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004807 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart70f3c072010-12-15 17:57:33 -05004808 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4809 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4810 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4811 "%dMbps Fault:%d\n",
4812 phba->sli4_hba.link_state.speed,
4813 phba->sli4_hba.link_state.topology,
4814 phba->sli4_hba.link_state.status,
4815 phba->sli4_hba.link_state.type,
4816 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004817 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004818 phba->sli4_hba.link_state.fault);
4819 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4820 if (!pmb) {
4821 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4822 "2897 The mboxq allocation failed\n");
4823 return;
4824 }
4825 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4826 if (!mp) {
4827 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4828 "2898 The lpfc_dmabuf allocation failed\n");
4829 goto out_free_pmb;
4830 }
4831 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4832 if (!mp->virt) {
4833 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4834 "2899 The mbuf allocation failed\n");
4835 goto out_free_dmabuf;
4836 }
4837
4838 /* Cleanup any outstanding ELS commands */
4839 lpfc_els_flush_all_cmd(phba);
4840
4841 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004842 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smart70f3c072010-12-15 17:57:33 -05004843
4844 /* Update link event statistics */
4845 phba->sli.slistat.link_event++;
4846
4847 /* Create lpfc_handle_latt mailbox command from link ACQE */
4848 lpfc_read_topology(phba, pmb, mp);
4849 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4850 pmb->vport = phba->pport;
4851
James Smart7bdedb32016-07-06 12:36:00 -07004852 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
James Smartae9e28f2017-05-15 15:20:51 -07004853 phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK);
4854
4855 switch (phba->sli4_hba.link_state.status) {
4856 case LPFC_FC_LA_TYPE_MDS_LINK_DOWN:
4857 phba->link_flag |= LS_MDS_LINK_DOWN;
4858 break;
4859 case LPFC_FC_LA_TYPE_MDS_LOOPBACK:
4860 phba->link_flag |= LS_MDS_LOOPBACK;
4861 break;
4862 default:
4863 break;
4864 }
4865
James Smart23288b72018-05-04 20:37:53 -07004866 /* Initialize completion status */
James Smart7bdedb32016-07-06 12:36:00 -07004867 mb = &pmb->u.mb;
James Smart23288b72018-05-04 20:37:53 -07004868 mb->mbxStatus = MBX_SUCCESS;
4869
4870 /* Parse port fault information field */
4871 lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc);
James Smart7bdedb32016-07-06 12:36:00 -07004872
4873 /* Parse and translate link attention fields */
4874 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
4875 la->eventTag = acqe_fc->event_tag;
James Smart7bdedb32016-07-06 12:36:00 -07004876
James Smartaeb3c812017-04-21 16:05:02 -07004877 if (phba->sli4_hba.link_state.status ==
4878 LPFC_FC_LA_TYPE_UNEXP_WWPN) {
4879 bf_set(lpfc_mbx_read_top_att_type, la,
4880 LPFC_FC_LA_TYPE_UNEXP_WWPN);
4881 } else {
4882 bf_set(lpfc_mbx_read_top_att_type, la,
4883 LPFC_FC_LA_TYPE_LINK_DOWN);
4884 }
James Smart7bdedb32016-07-06 12:36:00 -07004885 /* Invoke the mailbox command callback function */
4886 lpfc_mbx_cmpl_read_topology(phba, pmb);
4887
4888 return;
4889 }
4890
James Smart70f3c072010-12-15 17:57:33 -05004891 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4892 if (rc == MBX_NOT_FINISHED)
4893 goto out_free_dmabuf;
4894 return;
4895
4896out_free_dmabuf:
4897 kfree(mp);
4898out_free_pmb:
4899 mempool_free(pmb, phba->mbox_mem_pool);
4900}
4901
4902/**
4903 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4904 * @phba: pointer to lpfc hba data structure.
4905 * @acqe_fc: pointer to the async SLI completion queue entry.
4906 *
4907 * This routine is to handle the SLI4 asynchronous SLI events.
4908 **/
4909static void
4910lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
4911{
James Smart4b8bae02012-06-12 13:55:07 -04004912 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04004913 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04004914 uint8_t status;
James Smart946727d2015-04-07 15:07:09 -04004915 uint8_t evt_type;
James Smart448193b2015-12-16 18:12:05 -05004916 uint8_t operational = 0;
James Smart946727d2015-04-07 15:07:09 -04004917 struct temp_event temp_event_data;
James Smart4b8bae02012-06-12 13:55:07 -04004918 struct lpfc_acqe_misconfigured_event *misconfigured;
James Smart946727d2015-04-07 15:07:09 -04004919 struct Scsi_Host *shost;
James Smartcd713482018-10-23 13:41:01 -07004920 struct lpfc_vport **vports;
4921 int rc, i;
James Smart4b8bae02012-06-12 13:55:07 -04004922
James Smart946727d2015-04-07 15:07:09 -04004923 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
4924
James Smart448193b2015-12-16 18:12:05 -05004925 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4926 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4927 "x%08x SLI Event Type:%d\n",
4928 acqe_sli->event_data1, acqe_sli->event_data2,
4929 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004930
4931 port_name = phba->Port[0];
4932 if (port_name == 0x00)
4933 port_name = '?'; /* get port name is empty */
4934
James Smart946727d2015-04-07 15:07:09 -04004935 switch (evt_type) {
4936 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
4937 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4938 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
4939 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4940
4941 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4942 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4943 acqe_sli->event_data1, port_name);
4944
James Smart310429e2016-07-06 12:35:54 -07004945 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04004946 shost = lpfc_shost_from_vport(phba->pport);
4947 fc_host_post_vendor_event(shost, fc_get_event_number(),
4948 sizeof(temp_event_data),
4949 (char *)&temp_event_data,
4950 SCSI_NL_VID_TYPE_PCI
4951 | PCI_VENDOR_ID_EMULEX);
4952 break;
4953 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
4954 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4955 temp_event_data.event_code = LPFC_NORMAL_TEMP;
4956 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4957
4958 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4959 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4960 acqe_sli->event_data1, port_name);
4961
4962 shost = lpfc_shost_from_vport(phba->pport);
4963 fc_host_post_vendor_event(shost, fc_get_event_number(),
4964 sizeof(temp_event_data),
4965 (char *)&temp_event_data,
4966 SCSI_NL_VID_TYPE_PCI
4967 | PCI_VENDOR_ID_EMULEX);
4968 break;
4969 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
4970 misconfigured = (struct lpfc_acqe_misconfigured_event *)
James Smart4b8bae02012-06-12 13:55:07 -04004971 &acqe_sli->event_data1;
4972
James Smart946727d2015-04-07 15:07:09 -04004973 /* fetch the status for this port */
4974 switch (phba->sli4_hba.lnk_info.lnk_no) {
4975 case LPFC_LINK_NUMBER_0:
James Smart448193b2015-12-16 18:12:05 -05004976 status = bf_get(lpfc_sli_misconfigured_port0_state,
4977 &misconfigured->theEvent);
4978 operational = bf_get(lpfc_sli_misconfigured_port0_op,
James Smart4b8bae02012-06-12 13:55:07 -04004979 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004980 break;
4981 case LPFC_LINK_NUMBER_1:
James Smart448193b2015-12-16 18:12:05 -05004982 status = bf_get(lpfc_sli_misconfigured_port1_state,
4983 &misconfigured->theEvent);
4984 operational = bf_get(lpfc_sli_misconfigured_port1_op,
James Smart4b8bae02012-06-12 13:55:07 -04004985 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004986 break;
4987 case LPFC_LINK_NUMBER_2:
James Smart448193b2015-12-16 18:12:05 -05004988 status = bf_get(lpfc_sli_misconfigured_port2_state,
4989 &misconfigured->theEvent);
4990 operational = bf_get(lpfc_sli_misconfigured_port2_op,
James Smart4b8bae02012-06-12 13:55:07 -04004991 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004992 break;
4993 case LPFC_LINK_NUMBER_3:
James Smart448193b2015-12-16 18:12:05 -05004994 status = bf_get(lpfc_sli_misconfigured_port3_state,
4995 &misconfigured->theEvent);
4996 operational = bf_get(lpfc_sli_misconfigured_port3_op,
James Smart4b8bae02012-06-12 13:55:07 -04004997 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004998 break;
4999 default:
James Smart448193b2015-12-16 18:12:05 -05005000 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5001 "3296 "
5002 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
5003 "event: Invalid link %d",
5004 phba->sli4_hba.lnk_info.lnk_no);
5005 return;
James Smart946727d2015-04-07 15:07:09 -04005006 }
James Smart4b8bae02012-06-12 13:55:07 -04005007
James Smart448193b2015-12-16 18:12:05 -05005008 /* Skip if optic state unchanged */
5009 if (phba->sli4_hba.lnk_info.optic_state == status)
5010 return;
5011
James Smart946727d2015-04-07 15:07:09 -04005012 switch (status) {
5013 case LPFC_SLI_EVENT_STATUS_VALID:
James Smart448193b2015-12-16 18:12:05 -05005014 sprintf(message, "Physical Link is functional");
5015 break;
James Smart946727d2015-04-07 15:07:09 -04005016 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
5017 sprintf(message, "Optics faulted/incorrectly "
5018 "installed/not installed - Reseat optics, "
5019 "if issue not resolved, replace.");
5020 break;
5021 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
5022 sprintf(message,
5023 "Optics of two types installed - Remove one "
5024 "optic or install matching pair of optics.");
5025 break;
5026 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
5027 sprintf(message, "Incompatible optics - Replace with "
James Smart292098b2012-09-29 11:31:41 -04005028 "compatible optics for card to function.");
James Smart946727d2015-04-07 15:07:09 -04005029 break;
James Smart448193b2015-12-16 18:12:05 -05005030 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
5031 sprintf(message, "Unqualified optics - Replace with "
5032 "Avago optics for Warranty and Technical "
5033 "Support - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08005034 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05005035 break;
5036 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
5037 sprintf(message, "Uncertified optics - Replace with "
5038 "Avago-certified optics to enable link "
5039 "operation - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08005040 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05005041 break;
James Smart946727d2015-04-07 15:07:09 -04005042 default:
5043 /* firmware is reporting a status we don't know about */
5044 sprintf(message, "Unknown event status x%02x", status);
5045 break;
5046 }
James Smartcd713482018-10-23 13:41:01 -07005047
5048 /* Issue READ_CONFIG mbox command to refresh supported speeds */
5049 rc = lpfc_sli4_read_config(phba);
James Smart3952e912018-10-23 13:41:02 -07005050 if (rc) {
James Smartcd713482018-10-23 13:41:01 -07005051 phba->lmt = 0;
5052 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5053 "3194 Unable to retrieve supported "
James Smart3952e912018-10-23 13:41:02 -07005054 "speeds, rc = 0x%x\n", rc);
James Smartcd713482018-10-23 13:41:01 -07005055 }
5056 vports = lpfc_create_vport_work_array(phba);
5057 if (vports != NULL) {
5058 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
5059 i++) {
5060 shost = lpfc_shost_from_vport(vports[i]);
5061 lpfc_host_supported_speeds_set(shost);
5062 }
5063 }
5064 lpfc_destroy_vport_work_array(phba, vports);
5065
James Smart448193b2015-12-16 18:12:05 -05005066 phba->sli4_hba.lnk_info.optic_state = status;
James Smart946727d2015-04-07 15:07:09 -04005067 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart448193b2015-12-16 18:12:05 -05005068 "3176 Port Name %c %s\n", port_name, message);
James Smart946727d2015-04-07 15:07:09 -04005069 break;
5070 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
5071 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5072 "3192 Remote DPort Test Initiated - "
5073 "Event Data1:x%08x Event Data2: x%08x\n",
5074 acqe_sli->event_data1, acqe_sli->event_data2);
James Smart4b8bae02012-06-12 13:55:07 -04005075 break;
5076 default:
James Smart946727d2015-04-07 15:07:09 -04005077 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5078 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
5079 "x%08x SLI Event Type:%d\n",
5080 acqe_sli->event_data1, acqe_sli->event_data2,
5081 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04005082 break;
5083 }
James Smart70f3c072010-12-15 17:57:33 -05005084}
5085
5086/**
James Smartfc2b9892010-02-26 14:15:29 -05005087 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
5088 * @vport: pointer to vport data structure.
5089 *
5090 * This routine is to perform Clear Virtual Link (CVL) on a vport in
5091 * response to a CVL event.
5092 *
5093 * Return the pointer to the ndlp with the vport if successful, otherwise
5094 * return NULL.
5095 **/
5096static struct lpfc_nodelist *
5097lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
5098{
5099 struct lpfc_nodelist *ndlp;
5100 struct Scsi_Host *shost;
5101 struct lpfc_hba *phba;
5102
5103 if (!vport)
5104 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05005105 phba = vport->phba;
5106 if (!phba)
5107 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04005108 ndlp = lpfc_findnode_did(vport, Fabric_DID);
5109 if (!ndlp) {
5110 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07005111 ndlp = lpfc_nlp_init(vport, Fabric_DID);
James Smart78730cf2010-04-06 15:06:30 -04005112 if (!ndlp)
5113 return 0;
James Smart78730cf2010-04-06 15:06:30 -04005114 /* Set the node type */
5115 ndlp->nlp_type |= NLP_FABRIC;
5116 /* Put ndlp onto node list */
5117 lpfc_enqueue_node(vport, ndlp);
5118 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5119 /* re-setup ndlp without removing from node list */
5120 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
5121 if (!ndlp)
5122 return 0;
5123 }
James Smart63e801c2010-11-20 23:14:19 -05005124 if ((phba->pport->port_state < LPFC_FLOGI) &&
5125 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05005126 return NULL;
5127 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05005128 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
5129 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05005130 return NULL;
5131 shost = lpfc_shost_from_vport(vport);
5132 if (!shost)
5133 return NULL;
5134 lpfc_linkdown_port(vport);
5135 lpfc_cleanup_pending_mbox(vport);
5136 spin_lock_irq(shost->host_lock);
5137 vport->fc_flag |= FC_VPORT_CVL_RCVD;
5138 spin_unlock_irq(shost->host_lock);
5139
5140 return ndlp;
5141}
5142
5143/**
5144 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
5145 * @vport: pointer to lpfc hba data structure.
5146 *
5147 * This routine is to perform Clear Virtual Link (CVL) on all vports in
5148 * response to a FCF dead event.
5149 **/
5150static void
5151lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
5152{
5153 struct lpfc_vport **vports;
5154 int i;
5155
5156 vports = lpfc_create_vport_work_array(phba);
5157 if (vports)
5158 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
5159 lpfc_sli4_perform_vport_cvl(vports[i]);
5160 lpfc_destroy_vport_work_array(phba, vports);
5161}
5162
5163/**
James Smart76a95d72010-11-20 23:11:48 -05005164 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04005165 * @phba: pointer to lpfc hba data structure.
5166 * @acqe_link: pointer to the async fcoe completion queue entry.
5167 *
5168 * This routine is to handle the SLI4 asynchronous fcoe event.
5169 **/
5170static void
James Smart76a95d72010-11-20 23:11:48 -05005171lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05005172 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04005173{
James Smart70f3c072010-12-15 17:57:33 -05005174 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04005175 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04005176 struct lpfc_vport *vport;
5177 struct lpfc_nodelist *ndlp;
5178 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05005179 int active_vlink_present;
5180 struct lpfc_vport **vports;
5181 int i;
James Smartda0436e2009-05-22 14:51:39 -04005182
James Smart70f3c072010-12-15 17:57:33 -05005183 phba->fc_eventTag = acqe_fip->event_tag;
5184 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04005185 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05005186 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
5187 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
5188 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04005189 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5190 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005191 "2546 New FCF event, evt_tag:x%x, "
5192 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005193 acqe_fip->event_tag,
5194 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04005195 else
5196 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
5197 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005198 "2788 FCF param modified event, "
5199 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005200 acqe_fip->event_tag,
5201 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04005202 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05005203 /*
5204 * During period of FCF discovery, read the FCF
5205 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04005206 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05005207 */
5208 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5209 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005210 "2779 Read FCF (x%x) for updating "
5211 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05005212 acqe_fip->index);
5213 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05005214 }
James Smart38b92ef2010-08-04 16:11:39 -04005215
5216 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04005217 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04005218 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04005219 spin_unlock_irq(&phba->hbalock);
5220 break;
5221 }
5222 /* If fast FCF failover rescan event is pending, do nothing */
James Smart036cad12018-10-23 13:41:06 -07005223 if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) {
James Smart38b92ef2010-08-04 16:11:39 -04005224 spin_unlock_irq(&phba->hbalock);
5225 break;
5226 }
5227
James Smartc2b97122013-05-31 17:05:36 -04005228 /* If the FCF has been in discovered state, do nothing. */
5229 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
James Smart3804dc82010-07-14 15:31:37 -04005230 spin_unlock_irq(&phba->hbalock);
5231 break;
5232 }
5233 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04005234
James Smart0c9ab6f2010-02-26 14:15:57 -05005235 /* Otherwise, scan the entire FCF table and re-discover SAN */
5236 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005237 "2770 Start FCF table scan per async FCF "
5238 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005239 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05005240 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
5241 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04005242 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05005243 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5244 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04005245 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04005246 break;
5247
James Smart70f3c072010-12-15 17:57:33 -05005248 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04005249 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04005250 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005251 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
5252 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04005253 break;
5254
James Smart70f3c072010-12-15 17:57:33 -05005255 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05005256 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05005257 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005258 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05005259 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04005260 /*
5261 * If we are in the middle of FCF failover process, clear
5262 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04005263 */
James Smartfc2b9892010-02-26 14:15:29 -05005264 spin_lock_irq(&phba->hbalock);
James Smarta1cadfe2016-07-06 12:36:02 -07005265 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
5266 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
James Smartfc2b9892010-02-26 14:15:29 -05005267 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005268 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05005269 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05005270 break;
5271 }
James Smart38b92ef2010-08-04 16:11:39 -04005272 spin_unlock_irq(&phba->hbalock);
5273
5274 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05005275 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04005276 break;
5277
5278 /*
5279 * Otherwise, request the port to rediscover the entire FCF
5280 * table for a fast recovery from case that the current FCF
5281 * is no longer valid as we are not in the middle of FCF
5282 * failover process already.
5283 */
James Smartc2b97122013-05-31 17:05:36 -04005284 spin_lock_irq(&phba->hbalock);
5285 /* Mark the fast failover process in progress */
5286 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
5287 spin_unlock_irq(&phba->hbalock);
5288
5289 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
5290 "2771 Start FCF fast failover process due to "
5291 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
5292 "\n", acqe_fip->event_tag, acqe_fip->index);
5293 rc = lpfc_sli4_redisc_fcf_table(phba);
5294 if (rc) {
5295 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5296 LOG_DISCOVERY,
Colin Ian King7afc0ce2018-05-03 10:26:12 +01005297 "2772 Issue FCF rediscover mailbox "
James Smartc2b97122013-05-31 17:05:36 -04005298 "command failed, fail through to FCF "
5299 "dead event\n");
5300 spin_lock_irq(&phba->hbalock);
5301 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
5302 spin_unlock_irq(&phba->hbalock);
5303 /*
5304 * Last resort will fail over by treating this
5305 * as a link down to FCF registration.
5306 */
5307 lpfc_sli4_fcf_dead_failthrough(phba);
5308 } else {
5309 /* Reset FCF roundrobin bmask for new discovery */
5310 lpfc_sli4_clear_fcf_rr_bmask(phba);
5311 /*
5312 * Handling fast FCF failover to a DEAD FCF event is
5313 * considered equalivant to receiving CVL to all vports.
5314 */
5315 lpfc_sli4_perform_all_vport_cvl(phba);
5316 }
James Smartda0436e2009-05-22 14:51:39 -04005317 break;
James Smart70f3c072010-12-15 17:57:33 -05005318 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05005319 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05005320 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04005321 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05005322 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04005323
James Smart6669f9b2009-10-02 15:16:45 -04005324 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04005325 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05005326 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04005327 if (!ndlp)
5328 break;
James Smart695a8142010-01-26 23:08:03 -05005329 active_vlink_present = 0;
5330
5331 vports = lpfc_create_vport_work_array(phba);
5332 if (vports) {
5333 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
5334 i++) {
5335 if ((!(vports[i]->fc_flag &
5336 FC_VPORT_CVL_RCVD)) &&
5337 (vports[i]->port_state > LPFC_FDISC)) {
5338 active_vlink_present = 1;
5339 break;
5340 }
5341 }
5342 lpfc_destroy_vport_work_array(phba, vports);
5343 }
5344
James Smartcc823552015-05-21 13:55:26 -04005345 /*
5346 * Don't re-instantiate if vport is marked for deletion.
5347 * If we are here first then vport_delete is going to wait
5348 * for discovery to complete.
5349 */
5350 if (!(vport->load_flag & FC_UNLOADING) &&
5351 active_vlink_present) {
James Smart695a8142010-01-26 23:08:03 -05005352 /*
5353 * If there are other active VLinks present,
5354 * re-instantiate the Vlink using FDISC.
5355 */
James Smart256ec0d2013-04-17 20:14:58 -04005356 mod_timer(&ndlp->nlp_delayfunc,
5357 jiffies + msecs_to_jiffies(1000));
James Smartfc2b9892010-02-26 14:15:29 -05005358 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04005359 spin_lock_irq(shost->host_lock);
5360 ndlp->nlp_flag |= NLP_DELAY_TMO;
5361 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05005362 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
5363 vport->port_state = LPFC_FDISC;
5364 } else {
James Smartecfd03c2010-02-12 14:41:27 -05005365 /*
5366 * Otherwise, we request port to rediscover
5367 * the entire FCF table for a fast recovery
5368 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05005369 * is no longer valid if we are not already
5370 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05005371 */
James Smartfc2b9892010-02-26 14:15:29 -05005372 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005373 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05005374 spin_unlock_irq(&phba->hbalock);
5375 break;
5376 }
5377 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05005378 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05005379 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005380 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5381 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005382 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05005383 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05005384 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05005385 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05005386 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5387 LOG_DISCOVERY,
5388 "2774 Issue FCF rediscover "
Colin Ian King7afc0ce2018-05-03 10:26:12 +01005389 "mailbox command failed, "
James Smart0c9ab6f2010-02-26 14:15:57 -05005390 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05005391 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005392 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05005393 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05005394 /*
5395 * Last resort will be re-try on the
5396 * the current registered FCF entry.
5397 */
5398 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04005399 } else
5400 /*
5401 * Reset FCF roundrobin bmask for new
5402 * discovery.
5403 */
James Smart7d791df2011-07-22 18:37:52 -04005404 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04005405 }
5406 break;
James Smartda0436e2009-05-22 14:51:39 -04005407 default:
5408 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5409 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05005410 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04005411 break;
5412 }
5413}
5414
5415/**
5416 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
5417 * @phba: pointer to lpfc hba data structure.
5418 * @acqe_link: pointer to the async dcbx completion queue entry.
5419 *
5420 * This routine is to handle the SLI4 asynchronous dcbx event.
5421 **/
5422static void
5423lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
5424 struct lpfc_acqe_dcbx *acqe_dcbx)
5425{
James Smart4d9ab992009-10-02 15:16:39 -04005426 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04005427 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5428 "0290 The SLI4 DCBX asynchronous event is not "
5429 "handled yet\n");
5430}
5431
5432/**
James Smartb19a0612010-04-06 14:48:51 -04005433 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
5434 * @phba: pointer to lpfc hba data structure.
5435 * @acqe_link: pointer to the async grp5 completion queue entry.
5436 *
5437 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
5438 * is an asynchronous notified of a logical link speed change. The Port
5439 * reports the logical link speed in units of 10Mbps.
5440 **/
5441static void
5442lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
5443 struct lpfc_acqe_grp5 *acqe_grp5)
5444{
5445 uint16_t prev_ll_spd;
5446
5447 phba->fc_eventTag = acqe_grp5->event_tag;
5448 phba->fcoe_eventtag = acqe_grp5->event_tag;
5449 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
5450 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04005451 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04005452 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5453 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04005454 "from %dMbps to %dMbps\n", prev_ll_spd,
5455 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04005456}
5457
5458/**
James Smartda0436e2009-05-22 14:51:39 -04005459 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
5460 * @phba: pointer to lpfc hba data structure.
5461 *
5462 * This routine is invoked by the worker thread to process all the pending
5463 * SLI4 asynchronous events.
5464 **/
5465void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
5466{
5467 struct lpfc_cq_event *cq_event;
5468
5469 /* First, declare the async event has been handled */
5470 spin_lock_irq(&phba->hbalock);
5471 phba->hba_flag &= ~ASYNC_EVENT;
5472 spin_unlock_irq(&phba->hbalock);
5473 /* Now, handle all the async events */
5474 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
5475 /* Get the first event from the head of the event queue */
5476 spin_lock_irq(&phba->hbalock);
5477 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
5478 cq_event, struct lpfc_cq_event, list);
5479 spin_unlock_irq(&phba->hbalock);
5480 /* Process the asynchronous event */
5481 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
5482 case LPFC_TRAILER_CODE_LINK:
5483 lpfc_sli4_async_link_evt(phba,
5484 &cq_event->cqe.acqe_link);
5485 break;
5486 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05005487 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04005488 break;
5489 case LPFC_TRAILER_CODE_DCBX:
5490 lpfc_sli4_async_dcbx_evt(phba,
5491 &cq_event->cqe.acqe_dcbx);
5492 break;
James Smartb19a0612010-04-06 14:48:51 -04005493 case LPFC_TRAILER_CODE_GRP5:
5494 lpfc_sli4_async_grp5_evt(phba,
5495 &cq_event->cqe.acqe_grp5);
5496 break;
James Smart70f3c072010-12-15 17:57:33 -05005497 case LPFC_TRAILER_CODE_FC:
5498 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
5499 break;
5500 case LPFC_TRAILER_CODE_SLI:
5501 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
5502 break;
James Smartda0436e2009-05-22 14:51:39 -04005503 default:
5504 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5505 "1804 Invalid asynchrous event code: "
5506 "x%x\n", bf_get(lpfc_trailer_code,
5507 &cq_event->cqe.mcqe_cmpl));
5508 break;
5509 }
5510 /* Free the completion event processed to the free pool */
5511 lpfc_sli4_cq_event_release(phba, cq_event);
5512 }
5513}
5514
5515/**
James Smartecfd03c2010-02-12 14:41:27 -05005516 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
5517 * @phba: pointer to lpfc hba data structure.
5518 *
5519 * This routine is invoked by the worker thread to process FCF table
5520 * rediscovery pending completion event.
5521 **/
5522void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
5523{
5524 int rc;
5525
5526 spin_lock_irq(&phba->hbalock);
5527 /* Clear FCF rediscovery timeout event */
5528 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
5529 /* Clear driver fast failover FCF record flag */
5530 phba->fcf.failover_rec.flag = 0;
5531 /* Set state for FCF fast failover */
5532 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
5533 spin_unlock_irq(&phba->hbalock);
5534
5535 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05005536 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005537 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05005538 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05005539 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05005540 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5541 "2747 Issue FCF scan read FCF mailbox "
5542 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05005543}
5544
5545/**
James Smartda0436e2009-05-22 14:51:39 -04005546 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
5547 * @phba: pointer to lpfc hba data structure.
5548 * @dev_grp: The HBA PCI-Device group number.
5549 *
5550 * This routine is invoked to set up the per HBA PCI-Device group function
5551 * API jump table entries.
5552 *
5553 * Return: 0 if success, otherwise -ENODEV
5554 **/
5555int
5556lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05005557{
5558 int rc;
5559
James Smartda0436e2009-05-22 14:51:39 -04005560 /* Set up lpfc PCI-device group */
5561 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05005562
James Smartda0436e2009-05-22 14:51:39 -04005563 /* The LPFC_PCI_DEV_OC uses SLI4 */
5564 if (dev_grp == LPFC_PCI_DEV_OC)
5565 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05005566
James Smartda0436e2009-05-22 14:51:39 -04005567 /* Set up device INIT API function jump table */
5568 rc = lpfc_init_api_table_setup(phba, dev_grp);
5569 if (rc)
5570 return -ENODEV;
5571 /* Set up SCSI API function jump table */
5572 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
5573 if (rc)
5574 return -ENODEV;
5575 /* Set up SLI API function jump table */
5576 rc = lpfc_sli_api_table_setup(phba, dev_grp);
5577 if (rc)
5578 return -ENODEV;
5579 /* Set up MBOX API function jump table */
5580 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
5581 if (rc)
5582 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05005583
James Smartda0436e2009-05-22 14:51:39 -04005584 return 0;
James Smart5b75da22008-12-04 22:39:35 -05005585}
5586
5587/**
James Smart3621a712009-04-06 18:47:14 -04005588 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05005589 * @phba: pointer to lpfc hba data structure.
5590 * @intr_mode: active interrupt mode adopted.
5591 *
5592 * This routine it invoked to log the currently used active interrupt mode
5593 * to the device.
James Smart3772a992009-05-22 14:50:54 -04005594 **/
5595static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05005596{
5597 switch (intr_mode) {
5598 case 0:
5599 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5600 "0470 Enable INTx interrupt mode.\n");
5601 break;
5602 case 1:
5603 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5604 "0481 Enabled MSI interrupt mode.\n");
5605 break;
5606 case 2:
5607 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5608 "0480 Enabled MSI-X interrupt mode.\n");
5609 break;
5610 default:
5611 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5612 "0482 Illegal interrupt mode.\n");
5613 break;
5614 }
5615 return;
5616}
5617
James Smart5b75da22008-12-04 22:39:35 -05005618/**
James Smart3772a992009-05-22 14:50:54 -04005619 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05005620 * @phba: pointer to lpfc hba data structure.
5621 *
James Smart3772a992009-05-22 14:50:54 -04005622 * This routine is invoked to enable the PCI device that is common to all
5623 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05005624 *
5625 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005626 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005627 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05005628 **/
James Smart3772a992009-05-22 14:50:54 -04005629static int
5630lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05005631{
James Smart3772a992009-05-22 14:50:54 -04005632 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05005633
James Smart3772a992009-05-22 14:50:54 -04005634 /* Obtain PCI device reference */
5635 if (!phba->pcidev)
5636 goto out_error;
5637 else
5638 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04005639 /* Enable PCI device */
5640 if (pci_enable_device_mem(pdev))
5641 goto out_error;
5642 /* Request PCI resource for the device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005643 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
James Smart3772a992009-05-22 14:50:54 -04005644 goto out_disable_device;
5645 /* Set up device as PCI master and save state for EEH */
5646 pci_set_master(pdev);
5647 pci_try_set_mwi(pdev);
5648 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05005649
James Smart05580562011-05-24 11:40:48 -04005650 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
Jon Mason453193e2013-09-11 15:38:13 -07005651 if (pci_is_pcie(pdev))
James Smart05580562011-05-24 11:40:48 -04005652 pdev->needs_freset = 1;
5653
James Smart3772a992009-05-22 14:50:54 -04005654 return 0;
James Smart5b75da22008-12-04 22:39:35 -05005655
James Smart3772a992009-05-22 14:50:54 -04005656out_disable_device:
5657 pci_disable_device(pdev);
5658out_error:
James Smart079b5c92011-08-21 21:48:49 -04005659 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005660 "1401 Failed to enable pci device\n");
James Smart3772a992009-05-22 14:50:54 -04005661 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05005662}
5663
5664/**
James Smart3772a992009-05-22 14:50:54 -04005665 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05005666 * @phba: pointer to lpfc hba data structure.
5667 *
James Smart3772a992009-05-22 14:50:54 -04005668 * This routine is invoked to disable the PCI device that is common to all
5669 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05005670 **/
5671static void
James Smart3772a992009-05-22 14:50:54 -04005672lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05005673{
James Smart3772a992009-05-22 14:50:54 -04005674 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05005675
James Smart3772a992009-05-22 14:50:54 -04005676 /* Obtain PCI device reference */
5677 if (!phba->pcidev)
5678 return;
5679 else
5680 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04005681 /* Release PCI resource and disable PCI device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005682 pci_release_mem_regions(pdev);
James Smart3772a992009-05-22 14:50:54 -04005683 pci_disable_device(pdev);
James Smart5b75da22008-12-04 22:39:35 -05005684
5685 return;
5686}
5687
5688/**
James Smart3772a992009-05-22 14:50:54 -04005689 * lpfc_reset_hba - Reset a hba
5690 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04005691 *
James Smart3772a992009-05-22 14:50:54 -04005692 * This routine is invoked to reset a hba device. It brings the HBA
5693 * offline, performs a board restart, and then brings the board back
5694 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
5695 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04005696 **/
James Smart3772a992009-05-22 14:50:54 -04005697void
5698lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05005699{
James Smart3772a992009-05-22 14:50:54 -04005700 /* If resets are disabled then set error state and return. */
5701 if (!phba->cfg_enable_hba_reset) {
5702 phba->link_state = LPFC_HBA_ERROR;
5703 return;
5704 }
James Smartee620212014-04-04 13:51:53 -04005705 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
5706 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
5707 else
5708 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart3772a992009-05-22 14:50:54 -04005709 lpfc_offline(phba);
5710 lpfc_sli_brdrestart(phba);
5711 lpfc_online(phba);
5712 lpfc_unblock_mgmt_io(phba);
5713}
dea31012005-04-17 16:05:31 -05005714
James Smart3772a992009-05-22 14:50:54 -04005715/**
James Smart0a96e972011-07-22 18:37:28 -04005716 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
5717 * @phba: pointer to lpfc hba data structure.
5718 *
5719 * This function enables the PCI SR-IOV virtual functions to a physical
5720 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5721 * enable the number of virtual functions to the physical function. As
5722 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5723 * API call does not considered as an error condition for most of the device.
5724 **/
5725uint16_t
5726lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
5727{
5728 struct pci_dev *pdev = phba->pcidev;
5729 uint16_t nr_virtfn;
5730 int pos;
5731
James Smart0a96e972011-07-22 18:37:28 -04005732 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
5733 if (pos == 0)
5734 return 0;
5735
5736 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
5737 return nr_virtfn;
5738}
5739
5740/**
James Smart912e3ac2011-05-24 11:42:11 -04005741 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
5742 * @phba: pointer to lpfc hba data structure.
5743 * @nr_vfn: number of virtual functions to be enabled.
5744 *
5745 * This function enables the PCI SR-IOV virtual functions to a physical
5746 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5747 * enable the number of virtual functions to the physical function. As
5748 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5749 * API call does not considered as an error condition for most of the device.
5750 **/
5751int
5752lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
5753{
5754 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04005755 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04005756 int rc;
5757
James Smart0a96e972011-07-22 18:37:28 -04005758 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
5759 if (nr_vfn > max_nr_vfn) {
5760 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5761 "3057 Requested vfs (%d) greater than "
5762 "supported vfs (%d)", nr_vfn, max_nr_vfn);
5763 return -EINVAL;
5764 }
5765
James Smart912e3ac2011-05-24 11:42:11 -04005766 rc = pci_enable_sriov(pdev, nr_vfn);
5767 if (rc) {
5768 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5769 "2806 Failed to enable sriov on this device "
5770 "with vfn number nr_vf:%d, rc:%d\n",
5771 nr_vfn, rc);
5772 } else
5773 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5774 "2807 Successful enable sriov on this device "
5775 "with vfn number nr_vf:%d\n", nr_vfn);
5776 return rc;
5777}
5778
5779/**
James Smart895427b2017-02-12 13:52:30 -08005780 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
James Smart3772a992009-05-22 14:50:54 -04005781 * @phba: pointer to lpfc hba data structure.
5782 *
James Smart895427b2017-02-12 13:52:30 -08005783 * This routine is invoked to set up the driver internal resources before the
5784 * device specific resource setup to support the HBA device it attached to.
James Smart3772a992009-05-22 14:50:54 -04005785 *
5786 * Return codes
James Smart895427b2017-02-12 13:52:30 -08005787 * 0 - successful
5788 * other values - error
James Smart3772a992009-05-22 14:50:54 -04005789 **/
5790static int
James Smart895427b2017-02-12 13:52:30 -08005791lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
James Smart3772a992009-05-22 14:50:54 -04005792{
James Smart895427b2017-02-12 13:52:30 -08005793 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05005794
James Smart3772a992009-05-22 14:50:54 -04005795 /*
James Smart895427b2017-02-12 13:52:30 -08005796 * Driver resources common to all SLI revisions
James Smart3772a992009-05-22 14:50:54 -04005797 */
James Smart895427b2017-02-12 13:52:30 -08005798 atomic_set(&phba->fast_event_count, 0);
5799 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005800
James Smart895427b2017-02-12 13:52:30 -08005801 /* Initialize ndlp management spinlock */
5802 spin_lock_init(&phba->ndlp_lock);
James Smart3772a992009-05-22 14:50:54 -04005803
James Smart523128e2018-09-10 10:30:46 -07005804 /* Initialize port_list spinlock */
5805 spin_lock_init(&phba->port_list_lock);
James Smart895427b2017-02-12 13:52:30 -08005806 INIT_LIST_HEAD(&phba->port_list);
James Smart523128e2018-09-10 10:30:46 -07005807
James Smart895427b2017-02-12 13:52:30 -08005808 INIT_LIST_HEAD(&phba->work_list);
5809 init_waitqueue_head(&phba->wait_4_mlo_m_q);
5810
5811 /* Initialize the wait queue head for the kernel thread */
5812 init_waitqueue_head(&phba->work_waitq);
5813
5814 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartf358dd02017-02-12 13:52:34 -08005815 "1403 Protocols supported %s %s %s\n",
James Smart895427b2017-02-12 13:52:30 -08005816 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
5817 "SCSI" : " "),
5818 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
James Smartf358dd02017-02-12 13:52:34 -08005819 "NVME" : " "),
5820 (phba->nvmet_support ? "NVMET" : " "));
James Smart895427b2017-02-12 13:52:30 -08005821
5822 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5823 /* Initialize the scsi buffer list used by driver for scsi IO */
5824 spin_lock_init(&phba->scsi_buf_list_get_lock);
5825 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5826 spin_lock_init(&phba->scsi_buf_list_put_lock);
5827 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
5828 }
5829
5830 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
5831 (phba->nvmet_support == 0)) {
5832 /* Initialize the NVME buffer list used by driver for NVME IO */
5833 spin_lock_init(&phba->nvme_buf_list_get_lock);
5834 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_get);
James Smartcf1a1d32017-12-08 17:18:03 -08005835 phba->get_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08005836 spin_lock_init(&phba->nvme_buf_list_put_lock);
5837 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
James Smartcf1a1d32017-12-08 17:18:03 -08005838 phba->put_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08005839 }
5840
5841 /* Initialize the fabric iocb list */
5842 INIT_LIST_HEAD(&phba->fabric_iocb_list);
5843
5844 /* Initialize list to save ELS buffers */
5845 INIT_LIST_HEAD(&phba->elsbuf);
5846
5847 /* Initialize FCF connection rec list */
5848 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
5849
5850 /* Initialize OAS configuration list */
5851 spin_lock_init(&phba->devicelock);
5852 INIT_LIST_HEAD(&phba->luns);
5853
James Smart3772a992009-05-22 14:50:54 -04005854 /* MBOX heartbeat timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005855 timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04005856 /* Fabric block timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005857 timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04005858 /* EA polling mode timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005859 timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0);
James Smart895427b2017-02-12 13:52:30 -08005860 /* Heartbeat timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005861 timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0);
James Smart895427b2017-02-12 13:52:30 -08005862
5863 return 0;
5864}
5865
5866/**
5867 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
5868 * @phba: pointer to lpfc hba data structure.
5869 *
5870 * This routine is invoked to set up the driver internal resources specific to
5871 * support the SLI-3 HBA device it attached to.
5872 *
5873 * Return codes
5874 * 0 - successful
5875 * other values - error
5876 **/
5877static int
5878lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
5879{
5880 int rc;
5881
5882 /*
5883 * Initialize timers used by driver
5884 */
5885
5886 /* FCP polling mode timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005887 timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04005888
5889 /* Host attention work mask setup */
5890 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
5891 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
5892
5893 /* Get all the module params for configuring this host */
5894 lpfc_get_cfgparam(phba);
James Smart895427b2017-02-12 13:52:30 -08005895 /* Set up phase-1 common device driver resources */
5896
5897 rc = lpfc_setup_driver_resource_phase1(phba);
5898 if (rc)
5899 return -ENODEV;
5900
James Smart49198b32010-04-06 15:04:33 -04005901 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
5902 phba->menlo_flag |= HBA_MENLO_SUPPORT;
5903 /* check for menlo minimum sg count */
5904 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
5905 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
5906 }
5907
James Smart895427b2017-02-12 13:52:30 -08005908 if (!phba->sli.sli3_ring)
Kees Cook6396bb22018-06-12 14:03:40 -07005909 phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING,
5910 sizeof(struct lpfc_sli_ring),
5911 GFP_KERNEL);
James Smart895427b2017-02-12 13:52:30 -08005912 if (!phba->sli.sli3_ring)
James Smart2a76a282012-08-03 12:35:54 -04005913 return -ENOMEM;
5914
James Smart3772a992009-05-22 14:50:54 -04005915 /*
James Smart96f70772013-04-17 20:16:15 -04005916 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smart3772a992009-05-22 14:50:54 -04005917 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart3772a992009-05-22 14:50:54 -04005918 */
James Smart3772a992009-05-22 14:50:54 -04005919
James Smart96f70772013-04-17 20:16:15 -04005920 /* Initialize the host templates the configured values. */
James Smart3772a992009-05-22 14:50:54 -04005921 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart96418b52017-03-04 09:30:31 -08005922 lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt;
5923 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart3772a992009-05-22 14:50:54 -04005924
James Smart96f70772013-04-17 20:16:15 -04005925 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
5926 if (phba->cfg_enable_bg) {
5927 /*
5928 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5929 * the FCP rsp, and a BDE for each. Sice we have no control
5930 * over how many protection data segments the SCSI Layer
5931 * will hand us (ie: there could be one for every block
5932 * in the IO), we just allocate enough BDEs to accomidate
5933 * our max amount and we need to limit lpfc_sg_seg_cnt to
5934 * minimize the risk of running out.
5935 */
5936 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5937 sizeof(struct fcp_rsp) +
5938 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
5939
5940 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
5941 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
5942
5943 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
5944 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
5945 } else {
5946 /*
5947 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5948 * the FCP rsp, a BDE for each, and a BDE for up to
5949 * cfg_sg_seg_cnt data segments.
5950 */
5951 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5952 sizeof(struct fcp_rsp) +
5953 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
5954
5955 /* Total BDEs in BPL for scsi_sg_list */
5956 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5957 }
5958
5959 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5960 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
5961 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5962 phba->cfg_total_seg_cnt);
5963
James Smart3772a992009-05-22 14:50:54 -04005964 phba->max_vpi = LPFC_MAX_VPI;
5965 /* This will be set to correct value after config_port mbox */
5966 phba->max_vports = 0;
5967
5968 /*
5969 * Initialize the SLI Layer to run with lpfc HBAs.
5970 */
5971 lpfc_sli_setup(phba);
James Smart895427b2017-02-12 13:52:30 -08005972 lpfc_sli_queue_init(phba);
James Smart3772a992009-05-22 14:50:54 -04005973
5974 /* Allocate device driver memory */
5975 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
5976 return -ENOMEM;
5977
James Smart912e3ac2011-05-24 11:42:11 -04005978 /*
5979 * Enable sr-iov virtual functions if supported and configured
5980 * through the module parameter.
5981 */
5982 if (phba->cfg_sriov_nr_virtfn > 0) {
5983 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5984 phba->cfg_sriov_nr_virtfn);
5985 if (rc) {
5986 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5987 "2808 Requested number of SR-IOV "
5988 "virtual functions (%d) is not "
5989 "supported\n",
5990 phba->cfg_sriov_nr_virtfn);
5991 phba->cfg_sriov_nr_virtfn = 0;
5992 }
5993 }
5994
James Smart3772a992009-05-22 14:50:54 -04005995 return 0;
5996}
5997
5998/**
5999 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
6000 * @phba: pointer to lpfc hba data structure.
6001 *
6002 * This routine is invoked to unset the driver internal resources set up
6003 * specific for supporting the SLI-3 HBA device it attached to.
6004 **/
6005static void
6006lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
6007{
6008 /* Free device driver memory allocated */
6009 lpfc_mem_free_all(phba);
6010
6011 return;
6012}
6013
6014/**
James Smartda0436e2009-05-22 14:51:39 -04006015 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
6016 * @phba: pointer to lpfc hba data structure.
6017 *
6018 * This routine is invoked to set up the driver internal resources specific to
6019 * support the SLI-4 HBA device it attached to.
6020 *
6021 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006022 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04006023 * other values - error
6024 **/
6025static int
6026lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
6027{
James Smart28baac72010-02-12 14:42:03 -05006028 LPFC_MBOXQ_t *mboxq;
James Smartf358dd02017-02-12 13:52:34 -08006029 MAILBOX_t *mb;
James Smart895427b2017-02-12 13:52:30 -08006030 int rc, i, max_buf_size;
James Smart28baac72010-02-12 14:42:03 -05006031 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
6032 struct lpfc_mqe *mqe;
James Smart09294d42013-04-17 20:16:05 -04006033 int longs;
James Smart1ba981f2014-02-20 09:56:45 -05006034 int fof_vectors = 0;
James Smart81e6a632017-11-20 16:00:43 -08006035 int extra;
James Smartf358dd02017-02-12 13:52:34 -08006036 uint64_t wwn;
James Smartb92dc722018-05-24 21:09:01 -07006037 u32 if_type;
6038 u32 if_fam;
James Smartda0436e2009-05-22 14:51:39 -04006039
James Smart895427b2017-02-12 13:52:30 -08006040 phba->sli4_hba.num_online_cpu = num_online_cpus();
6041 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
6042 phba->sli4_hba.curr_disp_cpu = 0;
6043
James Smart716d3bc2013-09-06 12:18:28 -04006044 /* Get all the module params for configuring this host */
6045 lpfc_get_cfgparam(phba);
6046
James Smart895427b2017-02-12 13:52:30 -08006047 /* Set up phase-1 common device driver resources */
6048 rc = lpfc_setup_driver_resource_phase1(phba);
6049 if (rc)
6050 return -ENODEV;
6051
James Smartda0436e2009-05-22 14:51:39 -04006052 /* Before proceed, wait for POST done and device ready */
6053 rc = lpfc_sli4_post_status_check(phba);
6054 if (rc)
6055 return -ENODEV;
6056
6057 /*
6058 * Initialize timers used by driver
6059 */
6060
Kees Cookf22eb4d2017-09-06 20:24:26 -07006061 timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0);
James Smartda0436e2009-05-22 14:51:39 -04006062
James Smartecfd03c2010-02-12 14:41:27 -05006063 /* FCF rediscover timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07006064 timer_setup(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo, 0);
James Smartecfd03c2010-02-12 14:41:27 -05006065
James Smartda0436e2009-05-22 14:51:39 -04006066 /*
James Smart7ad20aa2011-05-24 11:44:28 -04006067 * Control structure for handling external multi-buffer mailbox
6068 * command pass-through.
6069 */
6070 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
6071 sizeof(struct lpfc_mbox_ext_buf_ctx));
6072 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
6073
James Smartda0436e2009-05-22 14:51:39 -04006074 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04006075
James Smartda0436e2009-05-22 14:51:39 -04006076 /* This will be set to correct value after the read_config mbox */
6077 phba->max_vports = 0;
6078
6079 /* Program the default value of vlan_id and fc_map */
6080 phba->valid_vlan = 0;
6081 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
6082 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
6083 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
6084
6085 /*
James Smart2a76a282012-08-03 12:35:54 -04006086 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
James Smart895427b2017-02-12 13:52:30 -08006087 * we will associate a new ring, for each EQ/CQ/WQ tuple.
6088 * The WQ create will allocate the ring.
James Smart2a76a282012-08-03 12:35:54 -04006089 */
James Smart085c6472010-11-20 23:11:37 -05006090
James Smart09294d42013-04-17 20:16:05 -04006091 /*
James Smart81e6a632017-11-20 16:00:43 -08006092 * 1 for cmd, 1 for rsp, NVME adds an extra one
6093 * for boundary conditions in its max_sgl_segment template.
6094 */
6095 extra = 2;
6096 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
6097 extra++;
6098
6099 /*
James Smart09294d42013-04-17 20:16:05 -04006100 * It doesn't matter what family our adapter is in, we are
6101 * limited to 2 Pages, 512 SGEs, for our SGL.
6102 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
6103 */
6104 max_buf_size = (2 * SLI4_PAGE_SIZE);
James Smart09294d42013-04-17 20:16:05 -04006105
James Smartda0436e2009-05-22 14:51:39 -04006106 /*
James Smart895427b2017-02-12 13:52:30 -08006107 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
6108 * used to create the sg_dma_buf_pool must be calculated.
James Smart28baac72010-02-12 14:42:03 -05006109 */
James Smartf44ac122018-03-05 12:04:08 -08006110 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
James Smart96f70772013-04-17 20:16:15 -04006111 /*
James Smart895427b2017-02-12 13:52:30 -08006112 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
6113 * the FCP rsp, and a SGE. Sice we have no control
6114 * over how many protection segments the SCSI Layer
James Smart96f70772013-04-17 20:16:15 -04006115 * will hand us (ie: there could be one for every block
James Smart895427b2017-02-12 13:52:30 -08006116 * in the IO), just allocate enough SGEs to accomidate
6117 * our max amount and we need to limit lpfc_sg_seg_cnt
6118 * to minimize the risk of running out.
James Smart96f70772013-04-17 20:16:15 -04006119 */
6120 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08006121 sizeof(struct fcp_rsp) + max_buf_size;
James Smart96f70772013-04-17 20:16:15 -04006122
6123 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
6124 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
6125
James Smart5b9e70b2018-09-10 10:30:42 -07006126 /*
6127 * If supporting DIF, reduce the seg count for scsi to
6128 * allow room for the DIF sges.
6129 */
6130 if (phba->cfg_enable_bg &&
6131 phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF)
6132 phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF;
6133 else
6134 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
6135
James Smart96f70772013-04-17 20:16:15 -04006136 } else {
6137 /*
James Smart895427b2017-02-12 13:52:30 -08006138 * The scsi_buf for a regular I/O holds the FCP cmnd,
James Smart96f70772013-04-17 20:16:15 -04006139 * the FCP rsp, a SGE for each, and a SGE for up to
6140 * cfg_sg_seg_cnt data segments.
6141 */
6142 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08006143 sizeof(struct fcp_rsp) +
James Smart81e6a632017-11-20 16:00:43 -08006144 ((phba->cfg_sg_seg_cnt + extra) *
James Smart895427b2017-02-12 13:52:30 -08006145 sizeof(struct sli4_sge));
James Smart96f70772013-04-17 20:16:15 -04006146
6147 /* Total SGEs for scsi_sg_list */
James Smart81e6a632017-11-20 16:00:43 -08006148 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra;
James Smart5b9e70b2018-09-10 10:30:42 -07006149 phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt;
James Smart895427b2017-02-12 13:52:30 -08006150
James Smart96f70772013-04-17 20:16:15 -04006151 /*
James Smart81e6a632017-11-20 16:00:43 -08006152 * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only
James Smart895427b2017-02-12 13:52:30 -08006153 * need to post 1 page for the SGL.
James Smart96f70772013-04-17 20:16:15 -04006154 */
James Smart085c6472010-11-20 23:11:37 -05006155 }
James Smartacd68592012-01-18 16:25:09 -05006156
James Smart5b9e70b2018-09-10 10:30:42 -07006157 /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */
6158 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
6159 if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) {
6160 lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT,
6161 "6300 Reducing NVME sg segment "
6162 "cnt to %d\n",
6163 LPFC_MAX_NVME_SEG_CNT);
6164 phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT;
6165 } else
6166 phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt;
6167 }
6168
James Smart96f70772013-04-17 20:16:15 -04006169 /* Initialize the host templates with the updated values. */
James Smart5b9e70b2018-09-10 10:30:42 -07006170 lpfc_vport_template.sg_tablesize = phba->cfg_scsi_seg_cnt;
6171 lpfc_template.sg_tablesize = phba->cfg_scsi_seg_cnt;
6172 lpfc_template_no_hr.sg_tablesize = phba->cfg_scsi_seg_cnt;
James Smart96f70772013-04-17 20:16:15 -04006173
6174 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
6175 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
6176 else
6177 phba->cfg_sg_dma_buf_size =
6178 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
6179
6180 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
James Smart5b9e70b2018-09-10 10:30:42 -07006181 "9087 sg_seg_cnt:%d dmabuf_size:%d "
6182 "total:%d scsi:%d nvme:%d\n",
James Smart96f70772013-04-17 20:16:15 -04006183 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
James Smart5b9e70b2018-09-10 10:30:42 -07006184 phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt,
6185 phba->cfg_nvme_seg_cnt);
James Smartda0436e2009-05-22 14:51:39 -04006186
6187 /* Initialize buffer queue management fields */
James Smart895427b2017-02-12 13:52:30 -08006188 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
James Smartda0436e2009-05-22 14:51:39 -04006189 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
6190 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
6191
6192 /*
6193 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
6194 */
James Smart895427b2017-02-12 13:52:30 -08006195 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
6196 /* Initialize the Abort scsi buffer list used by driver */
6197 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
6198 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
6199 }
6200
6201 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
6202 /* Initialize the Abort nvme buffer list used by driver */
6203 spin_lock_init(&phba->sli4_hba.abts_nvme_buf_list_lock);
6204 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
James Smart86c67372017-04-21 16:05:04 -07006205 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
James Smarta8cf5df2017-05-15 15:20:46 -07006206 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list);
James Smart895427b2017-02-12 13:52:30 -08006207 }
6208
James Smartda0436e2009-05-22 14:51:39 -04006209 /* This abort list used by worker thread */
James Smart895427b2017-02-12 13:52:30 -08006210 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
James Smarta8cf5df2017-05-15 15:20:46 -07006211 spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock);
James Smartda0436e2009-05-22 14:51:39 -04006212
6213 /*
James Smart6d368e52011-05-24 11:44:12 -04006214 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04006215 */
6216
6217 /* Driver internel slow-path CQ Event pool */
6218 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
6219 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04006220 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04006221 /* Asynchronous event CQ Event work queue list */
6222 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
6223 /* Fast-path XRI aborted CQ Event work queue list */
6224 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
6225 /* Slow-path XRI aborted CQ Event work queue list */
6226 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
6227 /* Receive queue CQ Event work queue list */
6228 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
6229
James Smart6d368e52011-05-24 11:44:12 -04006230 /* Initialize extent block lists. */
6231 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
6232 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
6233 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
6234 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
6235
James Smartd1f525a2017-04-21 16:04:55 -07006236 /* Initialize mboxq lists. If the early init routines fail
6237 * these lists need to be correctly initialized.
6238 */
6239 INIT_LIST_HEAD(&phba->sli.mboxq);
6240 INIT_LIST_HEAD(&phba->sli.mboxq_cmpl);
6241
James Smart448193b2015-12-16 18:12:05 -05006242 /* initialize optic_state to 0xFF */
6243 phba->sli4_hba.lnk_info.optic_state = 0xff;
6244
James Smartda0436e2009-05-22 14:51:39 -04006245 /* Allocate device driver memory */
6246 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
6247 if (rc)
6248 return -ENOMEM;
6249
James Smart2fcee4b2010-12-15 17:57:46 -05006250 /* IF Type 2 ports get initialized now. */
James Smart27d6ac02018-02-22 08:18:42 -08006251 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
James Smart2fcee4b2010-12-15 17:57:46 -05006252 LPFC_SLI_INTF_IF_TYPE_2) {
6253 rc = lpfc_pci_function_reset(phba);
James Smart895427b2017-02-12 13:52:30 -08006254 if (unlikely(rc)) {
6255 rc = -ENODEV;
6256 goto out_free_mem;
6257 }
James Smart946727d2015-04-07 15:07:09 -04006258 phba->temp_sensor_support = 1;
James Smart2fcee4b2010-12-15 17:57:46 -05006259 }
6260
James Smartda0436e2009-05-22 14:51:39 -04006261 /* Create the bootstrap mailbox command */
6262 rc = lpfc_create_bootstrap_mbox(phba);
6263 if (unlikely(rc))
6264 goto out_free_mem;
6265
6266 /* Set up the host's endian order with the device. */
6267 rc = lpfc_setup_endian_order(phba);
6268 if (unlikely(rc))
6269 goto out_free_bsmbx;
6270
6271 /* Set up the hba's configuration parameters. */
6272 rc = lpfc_sli4_read_config(phba);
6273 if (unlikely(rc))
6274 goto out_free_bsmbx;
James Smartcff261f2013-12-17 20:29:47 -05006275 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
6276 if (unlikely(rc))
6277 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04006278
James Smart2fcee4b2010-12-15 17:57:46 -05006279 /* IF Type 0 ports get initialized now. */
6280 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
6281 LPFC_SLI_INTF_IF_TYPE_0) {
6282 rc = lpfc_pci_function_reset(phba);
6283 if (unlikely(rc))
6284 goto out_free_bsmbx;
6285 }
James Smartda0436e2009-05-22 14:51:39 -04006286
James Smartcb5172e2010-03-15 11:25:07 -04006287 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
6288 GFP_KERNEL);
6289 if (!mboxq) {
6290 rc = -ENOMEM;
6291 goto out_free_bsmbx;
6292 }
6293
James Smartf358dd02017-02-12 13:52:34 -08006294 /* Check for NVMET being configured */
James Smart895427b2017-02-12 13:52:30 -08006295 phba->nvmet_support = 0;
James Smartf358dd02017-02-12 13:52:34 -08006296 if (lpfc_enable_nvmet_cnt) {
6297
6298 /* First get WWN of HBA instance */
6299 lpfc_read_nv(phba, mboxq);
6300 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6301 if (rc != MBX_SUCCESS) {
6302 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6303 "6016 Mailbox failed , mbxCmd x%x "
6304 "READ_NV, mbxStatus x%x\n",
6305 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
6306 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
James Smartd1f525a2017-04-21 16:04:55 -07006307 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartf358dd02017-02-12 13:52:34 -08006308 rc = -EIO;
6309 goto out_free_bsmbx;
6310 }
6311 mb = &mboxq->u.mb;
6312 memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
6313 sizeof(uint64_t));
6314 wwn = cpu_to_be64(wwn);
6315 phba->sli4_hba.wwnn.u.name = wwn;
6316 memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
6317 sizeof(uint64_t));
6318 /* wwn is WWPN of HBA instance */
6319 wwn = cpu_to_be64(wwn);
6320 phba->sli4_hba.wwpn.u.name = wwn;
6321
6322 /* Check to see if it matches any module parameter */
6323 for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
6324 if (wwn == lpfc_enable_nvmet[i]) {
James Smart7d708032017-03-08 14:36:01 -08006325#if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
James Smart3c603be2017-05-15 15:20:44 -07006326 if (lpfc_nvmet_mem_alloc(phba))
6327 break;
6328
6329 phba->nvmet_support = 1; /* a match */
6330
James Smartf358dd02017-02-12 13:52:34 -08006331 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6332 "6017 NVME Target %016llx\n",
6333 wwn);
James Smart7d708032017-03-08 14:36:01 -08006334#else
6335 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6336 "6021 Can't enable NVME Target."
6337 " NVME_TARGET_FC infrastructure"
6338 " is not in kernel\n");
6339#endif
James Smart3c603be2017-05-15 15:20:44 -07006340 break;
James Smartf358dd02017-02-12 13:52:34 -08006341 }
6342 }
6343 }
James Smart895427b2017-02-12 13:52:30 -08006344
6345 lpfc_nvme_mod_param_dep(phba);
6346
James Smartfedd3b72011-02-16 12:39:24 -05006347 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04006348 lpfc_supported_pages(mboxq);
6349 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05006350 if (!rc) {
6351 mqe = &mboxq->u.mqe;
6352 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
6353 LPFC_MAX_SUPPORTED_PAGES);
6354 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
6355 switch (pn_page[i]) {
6356 case LPFC_SLI4_PARAMETERS:
6357 phba->sli4_hba.pc_sli4_params.supported = 1;
6358 break;
6359 default:
6360 break;
6361 }
6362 }
6363 /* Read the port's SLI4 Parameters capabilities if supported. */
6364 if (phba->sli4_hba.pc_sli4_params.supported)
6365 rc = lpfc_pc_sli4_params_get(phba, mboxq);
6366 if (rc) {
6367 mempool_free(mboxq, phba->mbox_mem_pool);
6368 rc = -EIO;
6369 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04006370 }
6371 }
James Smart65791f12016-07-06 12:35:56 -07006372
James Smartfedd3b72011-02-16 12:39:24 -05006373 /*
6374 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04006375 * If this call fails, it isn't critical unless the SLI4 parameters come
6376 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05006377 */
James Smart6d368e52011-05-24 11:44:12 -04006378 rc = lpfc_get_sli4_parameters(phba, mboxq);
6379 if (rc) {
James Smartb92dc722018-05-24 21:09:01 -07006380 if_type = bf_get(lpfc_sli_intf_if_type,
6381 &phba->sli4_hba.sli_intf);
6382 if_fam = bf_get(lpfc_sli_intf_sli_family,
6383 &phba->sli4_hba.sli_intf);
James Smart6d368e52011-05-24 11:44:12 -04006384 if (phba->sli4_hba.extents_in_use &&
6385 phba->sli4_hba.rpi_hdrs_in_use) {
6386 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6387 "2999 Unsupported SLI4 Parameters "
6388 "Extents and RPI headers enabled.\n");
James Smartb92dc722018-05-24 21:09:01 -07006389 if (if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
6390 if_fam == LPFC_SLI_INTF_FAMILY_BE2) {
6391 mempool_free(mboxq, phba->mbox_mem_pool);
6392 rc = -EIO;
6393 goto out_free_bsmbx;
6394 }
James Smart6d368e52011-05-24 11:44:12 -04006395 }
James Smartb92dc722018-05-24 21:09:01 -07006396 if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 &&
6397 if_fam == LPFC_SLI_INTF_FAMILY_BE2)) {
6398 mempool_free(mboxq, phba->mbox_mem_pool);
6399 rc = -EIO;
6400 goto out_free_bsmbx;
6401 }
James Smart6d368e52011-05-24 11:44:12 -04006402 }
James Smart895427b2017-02-12 13:52:30 -08006403
James Smartcb5172e2010-03-15 11:25:07 -04006404 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -05006405
6406 /* Verify OAS is supported */
6407 lpfc_sli4_oas_verify(phba);
6408 if (phba->cfg_fof)
6409 fof_vectors = 1;
6410
James Smartd2cc9bc2018-09-10 10:30:50 -07006411 /* Verify RAS support on adapter */
6412 lpfc_sli4_ras_init(phba);
6413
James Smart5350d872011-10-10 21:33:49 -04006414 /* Verify all the SLI4 queues */
6415 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04006416 if (rc)
6417 goto out_free_bsmbx;
6418
6419 /* Create driver internal CQE event pool */
6420 rc = lpfc_sli4_cq_event_pool_create(phba);
6421 if (rc)
James Smart5350d872011-10-10 21:33:49 -04006422 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04006423
James Smart8a9d2e82012-05-09 21:16:12 -04006424 /* Initialize sgl lists per host */
6425 lpfc_init_sgl_list(phba);
6426
6427 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04006428 rc = lpfc_init_active_sgl_array(phba);
6429 if (rc) {
6430 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6431 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04006432 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04006433 }
James Smartda0436e2009-05-22 14:51:39 -04006434 rc = lpfc_sli4_init_rpi_hdrs(phba);
6435 if (rc) {
6436 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6437 "1432 Failed to initialize rpi headers.\n");
6438 goto out_free_active_sgl;
6439 }
6440
James Smarta93ff372010-10-22 11:06:08 -04006441 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05006442 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
Kees Cook6396bb22018-06-12 14:03:40 -07006443 phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long),
James Smart0c9ab6f2010-02-26 14:15:57 -05006444 GFP_KERNEL);
6445 if (!phba->fcf.fcf_rr_bmask) {
6446 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6447 "2759 Failed allocate memory for FCF round "
6448 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04006449 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05006450 goto out_remove_rpi_hdrs;
6451 }
6452
James Smart895427b2017-02-12 13:52:30 -08006453 phba->sli4_hba.hba_eq_hdl = kcalloc(fof_vectors + phba->io_channel_irqs,
6454 sizeof(struct lpfc_hba_eq_hdl),
6455 GFP_KERNEL);
6456 if (!phba->sli4_hba.hba_eq_hdl) {
James Smart67d12732012-08-03 12:36:13 -04006457 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6458 "2572 Failed allocate memory for "
6459 "fast-path per-EQ handle array\n");
6460 rc = -ENOMEM;
6461 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04006462 }
6463
James Smart895427b2017-02-12 13:52:30 -08006464 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_present_cpu,
6465 sizeof(struct lpfc_vector_map_info),
6466 GFP_KERNEL);
James Smart7bb03bb2013-04-17 20:19:16 -04006467 if (!phba->sli4_hba.cpu_map) {
6468 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6469 "3327 Failed allocate memory for msi-x "
6470 "interrupt vector mapping\n");
6471 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08006472 goto out_free_hba_eq_hdl;
James Smart7bb03bb2013-04-17 20:19:16 -04006473 }
James Smartb246de12013-05-31 17:03:07 -04006474 if (lpfc_used_cpu == NULL) {
James Smart895427b2017-02-12 13:52:30 -08006475 lpfc_used_cpu = kcalloc(lpfc_present_cpu, sizeof(uint16_t),
6476 GFP_KERNEL);
James Smartb246de12013-05-31 17:03:07 -04006477 if (!lpfc_used_cpu) {
6478 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6479 "3335 Failed allocate memory for msi-x "
6480 "interrupt vector mapping\n");
6481 kfree(phba->sli4_hba.cpu_map);
6482 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08006483 goto out_free_hba_eq_hdl;
James Smartb246de12013-05-31 17:03:07 -04006484 }
6485 for (i = 0; i < lpfc_present_cpu; i++)
6486 lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
6487 }
6488
James Smart912e3ac2011-05-24 11:42:11 -04006489 /*
6490 * Enable sr-iov virtual functions if supported and configured
6491 * through the module parameter.
6492 */
6493 if (phba->cfg_sriov_nr_virtfn > 0) {
6494 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
6495 phba->cfg_sriov_nr_virtfn);
6496 if (rc) {
6497 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6498 "3020 Requested number of SR-IOV "
6499 "virtual functions (%d) is not "
6500 "supported\n",
6501 phba->cfg_sriov_nr_virtfn);
6502 phba->cfg_sriov_nr_virtfn = 0;
6503 }
6504 }
6505
James Smart5248a742011-07-22 18:37:06 -04006506 return 0;
James Smartda0436e2009-05-22 14:51:39 -04006507
James Smart895427b2017-02-12 13:52:30 -08006508out_free_hba_eq_hdl:
6509 kfree(phba->sli4_hba.hba_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05006510out_free_fcf_rr_bmask:
6511 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04006512out_remove_rpi_hdrs:
6513 lpfc_sli4_remove_rpi_hdrs(phba);
6514out_free_active_sgl:
6515 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04006516out_destroy_cq_event_pool:
6517 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04006518out_free_bsmbx:
6519 lpfc_destroy_bootstrap_mbox(phba);
6520out_free_mem:
6521 lpfc_mem_free(phba);
6522 return rc;
6523}
6524
6525/**
6526 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
6527 * @phba: pointer to lpfc hba data structure.
6528 *
6529 * This routine is invoked to unset the driver internal resources set up
6530 * specific for supporting the SLI-4 HBA device it attached to.
6531 **/
6532static void
6533lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
6534{
6535 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6536
James Smart7bb03bb2013-04-17 20:19:16 -04006537 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
6538 kfree(phba->sli4_hba.cpu_map);
6539 phba->sli4_hba.num_present_cpu = 0;
6540 phba->sli4_hba.num_online_cpu = 0;
James Smart76fd07a2014-02-20 09:57:18 -05006541 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04006542
James Smartda0436e2009-05-22 14:51:39 -04006543 /* Free memory allocated for fast-path work queue handles */
James Smart895427b2017-02-12 13:52:30 -08006544 kfree(phba->sli4_hba.hba_eq_hdl);
James Smartda0436e2009-05-22 14:51:39 -04006545
6546 /* Free the allocated rpi headers. */
6547 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04006548 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04006549
James Smart0c9ab6f2010-02-26 14:15:57 -05006550 /* Free eligible FCF index bmask */
6551 kfree(phba->fcf.fcf_rr_bmask);
6552
James Smartda0436e2009-05-22 14:51:39 -04006553 /* Free the ELS sgl list */
6554 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04006555 lpfc_free_els_sgl_list(phba);
James Smartf358dd02017-02-12 13:52:34 -08006556 lpfc_free_nvmet_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04006557
James Smartda0436e2009-05-22 14:51:39 -04006558 /* Free the completion queue EQ event pool */
6559 lpfc_sli4_cq_event_release_all(phba);
6560 lpfc_sli4_cq_event_pool_destroy(phba);
6561
James Smart6d368e52011-05-24 11:44:12 -04006562 /* Release resource identifiers. */
6563 lpfc_sli4_dealloc_resource_identifiers(phba);
6564
James Smartda0436e2009-05-22 14:51:39 -04006565 /* Free the bsmbx region. */
6566 lpfc_destroy_bootstrap_mbox(phba);
6567
6568 /* Free the SLI Layer memory with SLI4 HBAs */
6569 lpfc_mem_free_all(phba);
6570
6571 /* Free the current connect table */
6572 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04006573 &phba->fcf_conn_rec_list, list) {
6574 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04006575 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04006576 }
James Smartda0436e2009-05-22 14:51:39 -04006577
6578 return;
6579}
6580
6581/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006582 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04006583 * @phba: The hba struct for which this call is being executed.
6584 * @dev_grp: The HBA PCI-Device group number.
6585 *
6586 * This routine sets up the device INIT interface API function jump table
6587 * in @phba struct.
6588 *
6589 * Returns: 0 - success, -ENODEV - failure.
6590 **/
6591int
6592lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
6593{
James Smart84d1b002010-02-12 14:42:33 -05006594 phba->lpfc_hba_init_link = lpfc_hba_init_link;
6595 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05006596 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04006597 switch (dev_grp) {
6598 case LPFC_PCI_DEV_LP:
6599 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
6600 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
6601 phba->lpfc_stop_port = lpfc_stop_port_s3;
6602 break;
James Smartda0436e2009-05-22 14:51:39 -04006603 case LPFC_PCI_DEV_OC:
6604 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
6605 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
6606 phba->lpfc_stop_port = lpfc_stop_port_s4;
6607 break;
James Smart3772a992009-05-22 14:50:54 -04006608 default:
6609 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6610 "1431 Invalid HBA PCI-device group: 0x%x\n",
6611 dev_grp);
6612 return -ENODEV;
6613 break;
6614 }
6615 return 0;
6616}
6617
6618/**
James Smart3772a992009-05-22 14:50:54 -04006619 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
6620 * @phba: pointer to lpfc hba data structure.
6621 *
6622 * This routine is invoked to set up the driver internal resources after the
6623 * device specific resource setup to support the HBA device it attached to.
6624 *
6625 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006626 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006627 * other values - error
6628 **/
6629static int
6630lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
6631{
6632 int error;
6633
6634 /* Startup the kernel thread for this host adapter. */
6635 phba->worker_thread = kthread_run(lpfc_do_work, phba,
6636 "lpfc_worker_%d", phba->brd_no);
6637 if (IS_ERR(phba->worker_thread)) {
6638 error = PTR_ERR(phba->worker_thread);
6639 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006640 }
6641
James Smart0cdb84e2018-04-09 14:24:26 -07006642 /* The lpfc_wq workqueue for deferred irq use, is only used for SLI4 */
6643 if (phba->sli_rev == LPFC_SLI_REV4)
6644 phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0);
6645 else
6646 phba->wq = NULL;
Dick Kennedyf485c182017-09-29 17:34:34 -07006647
James Smart3772a992009-05-22 14:50:54 -04006648 return 0;
6649}
6650
6651/**
6652 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
6653 * @phba: pointer to lpfc hba data structure.
6654 *
6655 * This routine is invoked to unset the driver internal resources set up after
6656 * the device specific resource setup for supporting the HBA device it
6657 * attached to.
6658 **/
6659static void
6660lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
6661{
Dick Kennedyf485c182017-09-29 17:34:34 -07006662 if (phba->wq) {
6663 flush_workqueue(phba->wq);
6664 destroy_workqueue(phba->wq);
6665 phba->wq = NULL;
6666 }
6667
James Smart3772a992009-05-22 14:50:54 -04006668 /* Stop kernel worker thread */
James Smart0cdb84e2018-04-09 14:24:26 -07006669 if (phba->worker_thread)
6670 kthread_stop(phba->worker_thread);
James Smart3772a992009-05-22 14:50:54 -04006671}
6672
6673/**
6674 * lpfc_free_iocb_list - Free iocb list.
6675 * @phba: pointer to lpfc hba data structure.
6676 *
6677 * This routine is invoked to free the driver's IOCB list and memory.
6678 **/
James Smart6c621a22017-05-15 15:20:45 -07006679void
James Smart3772a992009-05-22 14:50:54 -04006680lpfc_free_iocb_list(struct lpfc_hba *phba)
6681{
6682 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
6683
6684 spin_lock_irq(&phba->hbalock);
6685 list_for_each_entry_safe(iocbq_entry, iocbq_next,
6686 &phba->lpfc_iocb_list, list) {
6687 list_del(&iocbq_entry->list);
6688 kfree(iocbq_entry);
6689 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006690 }
James Smart3772a992009-05-22 14:50:54 -04006691 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006692
James Smart3772a992009-05-22 14:50:54 -04006693 return;
6694}
dea31012005-04-17 16:05:31 -05006695
James Smart3772a992009-05-22 14:50:54 -04006696/**
6697 * lpfc_init_iocb_list - Allocate and initialize iocb list.
6698 * @phba: pointer to lpfc hba data structure.
6699 *
6700 * This routine is invoked to allocate and initizlize the driver's IOCB
6701 * list and set up the IOCB tag array accordingly.
6702 *
6703 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006704 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006705 * other values - error
6706 **/
James Smart6c621a22017-05-15 15:20:45 -07006707int
James Smart3772a992009-05-22 14:50:54 -04006708lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
6709{
6710 struct lpfc_iocbq *iocbq_entry = NULL;
6711 uint16_t iotag;
6712 int i;
dea31012005-04-17 16:05:31 -05006713
6714 /* Initialize and populate the iocb list per host. */
6715 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04006716 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07006717 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05006718 if (iocbq_entry == NULL) {
6719 printk(KERN_ERR "%s: only allocated %d iocbs of "
6720 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07006721 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05006722 goto out_free_iocbq;
6723 }
6724
James Bottomley604a3e32005-10-29 10:28:33 -05006725 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
6726 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04006727 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05006728 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04006729 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05006730 goto out_free_iocbq;
6731 }
James Smart6d368e52011-05-24 11:44:12 -04006732 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04006733 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05006734
6735 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006736 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
6737 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05006738 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006739 }
6740
James Smart3772a992009-05-22 14:50:54 -04006741 return 0;
6742
6743out_free_iocbq:
6744 lpfc_free_iocb_list(phba);
6745
6746 return -ENOMEM;
6747}
6748
6749/**
James Smart8a9d2e82012-05-09 21:16:12 -04006750 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04006751 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04006752 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04006753 *
James Smart8a9d2e82012-05-09 21:16:12 -04006754 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04006755 **/
James Smart8a9d2e82012-05-09 21:16:12 -04006756void
6757lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04006758{
6759 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04006760
6761 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
6762 list_del(&sglq_entry->list);
6763 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
6764 kfree(sglq_entry);
6765 }
6766}
6767
6768/**
6769 * lpfc_free_els_sgl_list - Free els sgl list.
6770 * @phba: pointer to lpfc hba data structure.
6771 *
6772 * This routine is invoked to free the driver's els sgl list and memory.
6773 **/
6774static void
6775lpfc_free_els_sgl_list(struct lpfc_hba *phba)
6776{
James Smartda0436e2009-05-22 14:51:39 -04006777 LIST_HEAD(sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04006778
James Smart8a9d2e82012-05-09 21:16:12 -04006779 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04006780 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08006781 spin_lock(&phba->sli4_hba.sgl_list_lock);
6782 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
6783 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04006784 spin_unlock_irq(&phba->hbalock);
6785
James Smart8a9d2e82012-05-09 21:16:12 -04006786 /* Now free the sgl list */
6787 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04006788}
6789
6790/**
James Smartf358dd02017-02-12 13:52:34 -08006791 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
6792 * @phba: pointer to lpfc hba data structure.
6793 *
6794 * This routine is invoked to free the driver's nvmet sgl list and memory.
6795 **/
6796static void
6797lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
6798{
6799 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6800 LIST_HEAD(sglq_list);
6801
6802 /* Retrieve all nvmet sgls from driver list */
6803 spin_lock_irq(&phba->hbalock);
6804 spin_lock(&phba->sli4_hba.sgl_list_lock);
6805 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
6806 spin_unlock(&phba->sli4_hba.sgl_list_lock);
6807 spin_unlock_irq(&phba->hbalock);
6808
6809 /* Now free the sgl list */
6810 list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
6811 list_del(&sglq_entry->list);
6812 lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
6813 kfree(sglq_entry);
6814 }
Dick Kennedy4b40d022017-08-23 16:55:38 -07006815
6816 /* Update the nvmet_xri_cnt to reflect no current sgls.
6817 * The next initialization cycle sets the count and allocates
6818 * the sgls over again.
6819 */
6820 phba->sli4_hba.nvmet_xri_cnt = 0;
James Smartf358dd02017-02-12 13:52:34 -08006821}
6822
6823/**
James Smartda0436e2009-05-22 14:51:39 -04006824 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
6825 * @phba: pointer to lpfc hba data structure.
6826 *
6827 * This routine is invoked to allocate the driver's active sgl memory.
6828 * This array will hold the sglq_entry's for active IOs.
6829 **/
6830static int
6831lpfc_init_active_sgl_array(struct lpfc_hba *phba)
6832{
6833 int size;
6834 size = sizeof(struct lpfc_sglq *);
6835 size *= phba->sli4_hba.max_cfg_param.max_xri;
6836
6837 phba->sli4_hba.lpfc_sglq_active_list =
6838 kzalloc(size, GFP_KERNEL);
6839 if (!phba->sli4_hba.lpfc_sglq_active_list)
6840 return -ENOMEM;
6841 return 0;
6842}
6843
6844/**
6845 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
6846 * @phba: pointer to lpfc hba data structure.
6847 *
6848 * This routine is invoked to walk through the array of active sglq entries
6849 * and free all of the resources.
6850 * This is just a place holder for now.
6851 **/
6852static void
6853lpfc_free_active_sgl(struct lpfc_hba *phba)
6854{
6855 kfree(phba->sli4_hba.lpfc_sglq_active_list);
6856}
6857
6858/**
6859 * lpfc_init_sgl_list - Allocate and initialize sgl list.
6860 * @phba: pointer to lpfc hba data structure.
6861 *
6862 * This routine is invoked to allocate and initizlize the driver's sgl
6863 * list and set up the sgl xritag tag array accordingly.
6864 *
James Smartda0436e2009-05-22 14:51:39 -04006865 **/
James Smart8a9d2e82012-05-09 21:16:12 -04006866static void
James Smartda0436e2009-05-22 14:51:39 -04006867lpfc_init_sgl_list(struct lpfc_hba *phba)
6868{
James Smartda0436e2009-05-22 14:51:39 -04006869 /* Initialize and populate the sglq list per host/VF. */
James Smart895427b2017-02-12 13:52:30 -08006870 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
James Smartda0436e2009-05-22 14:51:39 -04006871 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -08006872 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
James Smart86c67372017-04-21 16:05:04 -07006873 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
James Smartda0436e2009-05-22 14:51:39 -04006874
James Smart8a9d2e82012-05-09 21:16:12 -04006875 /* els xri-sgl book keeping */
6876 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04006877
James Smart8a9d2e82012-05-09 21:16:12 -04006878 /* scsi xri-buffer book keeping */
James Smartda0436e2009-05-22 14:51:39 -04006879 phba->sli4_hba.scsi_xri_cnt = 0;
James Smart895427b2017-02-12 13:52:30 -08006880
6881 /* nvme xri-buffer book keeping */
6882 phba->sli4_hba.nvme_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04006883}
6884
6885/**
6886 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
6887 * @phba: pointer to lpfc hba data structure.
6888 *
6889 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04006890 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04006891 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04006892 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
6893 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04006894 *
6895 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006896 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04006897 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04006898 **/
6899int
6900lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
6901{
6902 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04006903 struct lpfc_rpi_hdr *rpi_hdr;
6904
6905 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05006906 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04006907 return rc;
James Smart6d368e52011-05-24 11:44:12 -04006908 if (phba->sli4_hba.extents_in_use)
6909 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04006910
6911 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
6912 if (!rpi_hdr) {
6913 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6914 "0391 Error during rpi post operation\n");
6915 lpfc_sli4_remove_rpis(phba);
6916 rc = -ENODEV;
6917 }
6918
6919 return rc;
6920}
6921
6922/**
6923 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
6924 * @phba: pointer to lpfc hba data structure.
6925 *
6926 * This routine is invoked to allocate a single 4KB memory region to
6927 * support rpis and stores them in the phba. This single region
6928 * provides support for up to 64 rpis. The region is used globally
6929 * by the device.
6930 *
6931 * Returns:
6932 * A valid rpi hdr on success.
6933 * A NULL pointer on any failure.
6934 **/
6935struct lpfc_rpi_hdr *
6936lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
6937{
6938 uint16_t rpi_limit, curr_rpi_range;
6939 struct lpfc_dmabuf *dmabuf;
6940 struct lpfc_rpi_hdr *rpi_hdr;
6941
James Smart6d368e52011-05-24 11:44:12 -04006942 /*
6943 * If the SLI4 port supports extents, posting the rpi header isn't
6944 * required. Set the expected maximum count and let the actual value
6945 * get set when extents are fully allocated.
6946 */
6947 if (!phba->sli4_hba.rpi_hdrs_in_use)
6948 return NULL;
6949 if (phba->sli4_hba.extents_in_use)
6950 return NULL;
6951
6952 /* The limit on the logical index is just the max_rpi count. */
James Smart845d9e82017-05-15 15:20:38 -07006953 rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi;
James Smartda0436e2009-05-22 14:51:39 -04006954
6955 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006956 /*
6957 * Establish the starting RPI in this header block. The starting
6958 * rpi is normalized to a zero base because the physical rpi is
6959 * port based.
6960 */
James Smart97f2ecf2012-03-01 22:35:23 -05006961 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04006962 spin_unlock_irq(&phba->hbalock);
6963
James Smart845d9e82017-05-15 15:20:38 -07006964 /* Reached full RPI range */
6965 if (curr_rpi_range == rpi_limit)
James Smart6d368e52011-05-24 11:44:12 -04006966 return NULL;
James Smart845d9e82017-05-15 15:20:38 -07006967
James Smartda0436e2009-05-22 14:51:39 -04006968 /*
6969 * First allocate the protocol header region for the port. The
6970 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
6971 */
6972 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6973 if (!dmabuf)
6974 return NULL;
6975
Joe Perches1aee3832014-09-03 12:56:12 -04006976 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
6977 LPFC_HDR_TEMPLATE_SIZE,
6978 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04006979 if (!dmabuf->virt) {
6980 rpi_hdr = NULL;
6981 goto err_free_dmabuf;
6982 }
6983
James Smartda0436e2009-05-22 14:51:39 -04006984 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
6985 rpi_hdr = NULL;
6986 goto err_free_coherent;
6987 }
6988
6989 /* Save the rpi header data for cleanup later. */
6990 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
6991 if (!rpi_hdr)
6992 goto err_free_coherent;
6993
6994 rpi_hdr->dmabuf = dmabuf;
6995 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
6996 rpi_hdr->page_count = 1;
6997 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006998
6999 /* The rpi_hdr stores the logical index only. */
7000 rpi_hdr->start_rpi = curr_rpi_range;
James Smart845d9e82017-05-15 15:20:38 -07007001 rpi_hdr->next_rpi = phba->sli4_hba.next_rpi + LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04007002 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
7003
James Smartda0436e2009-05-22 14:51:39 -04007004 spin_unlock_irq(&phba->hbalock);
7005 return rpi_hdr;
7006
7007 err_free_coherent:
7008 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
7009 dmabuf->virt, dmabuf->phys);
7010 err_free_dmabuf:
7011 kfree(dmabuf);
7012 return NULL;
7013}
7014
7015/**
7016 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
7017 * @phba: pointer to lpfc hba data structure.
7018 *
7019 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04007020 * to support rpis for SLI4 ports not supporting extents. This routine
7021 * presumes the caller has released all rpis consumed by fabric or port
7022 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04007023 **/
7024void
7025lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
7026{
7027 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
7028
James Smart6d368e52011-05-24 11:44:12 -04007029 if (!phba->sli4_hba.rpi_hdrs_in_use)
7030 goto exit;
7031
James Smartda0436e2009-05-22 14:51:39 -04007032 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
7033 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
7034 list_del(&rpi_hdr->list);
7035 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
7036 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
7037 kfree(rpi_hdr->dmabuf);
7038 kfree(rpi_hdr);
7039 }
James Smart6d368e52011-05-24 11:44:12 -04007040 exit:
7041 /* There are no rpis available to the port now. */
7042 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04007043}
7044
7045/**
James Smart3772a992009-05-22 14:50:54 -04007046 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
7047 * @pdev: pointer to pci device data structure.
7048 *
7049 * This routine is invoked to allocate the driver hba data structure for an
7050 * HBA device. If the allocation is successful, the phba reference to the
7051 * PCI device data structure is set.
7052 *
7053 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007054 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04007055 * NULL - error
7056 **/
7057static struct lpfc_hba *
7058lpfc_hba_alloc(struct pci_dev *pdev)
7059{
7060 struct lpfc_hba *phba;
7061
7062 /* Allocate memory for HBA structure */
7063 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
7064 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02007065 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04007066 return NULL;
7067 }
7068
7069 /* Set reference to PCI device in HBA structure */
7070 phba->pcidev = pdev;
7071
7072 /* Assign an unused board number */
7073 phba->brd_no = lpfc_get_instance();
7074 if (phba->brd_no < 0) {
7075 kfree(phba);
7076 return NULL;
7077 }
James Smart65791f12016-07-06 12:35:56 -07007078 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
James Smart3772a992009-05-22 14:50:54 -04007079
James Smart4fede782010-01-26 23:08:55 -05007080 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04007081 INIT_LIST_HEAD(&phba->ct_ev_waiters);
7082
James Smart3772a992009-05-22 14:50:54 -04007083 return phba;
7084}
7085
7086/**
7087 * lpfc_hba_free - Free driver hba data structure with a device.
7088 * @phba: pointer to lpfc hba data structure.
7089 *
7090 * This routine is invoked to free the driver hba data structure with an
7091 * HBA device.
7092 **/
7093static void
7094lpfc_hba_free(struct lpfc_hba *phba)
7095{
7096 /* Release the driver assigned board number */
7097 idr_remove(&lpfc_hba_index, phba->brd_no);
7098
James Smart895427b2017-02-12 13:52:30 -08007099 /* Free memory allocated with sli3 rings */
7100 kfree(phba->sli.sli3_ring);
7101 phba->sli.sli3_ring = NULL;
James Smart2a76a282012-08-03 12:35:54 -04007102
James Smart3772a992009-05-22 14:50:54 -04007103 kfree(phba);
7104 return;
7105}
7106
7107/**
7108 * lpfc_create_shost - Create hba physical port with associated scsi host.
7109 * @phba: pointer to lpfc hba data structure.
7110 *
7111 * This routine is invoked to create HBA physical port and associate a SCSI
7112 * host with it.
7113 *
7114 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007115 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007116 * other values - error
7117 **/
7118static int
7119lpfc_create_shost(struct lpfc_hba *phba)
7120{
7121 struct lpfc_vport *vport;
7122 struct Scsi_Host *shost;
7123
7124 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05007125 phba->fc_edtov = FF_DEF_EDTOV;
7126 phba->fc_ratov = FF_DEF_RATOV;
7127 phba->fc_altov = FF_DEF_ALTOV;
7128 phba->fc_arbtov = FF_DEF_ARBTOV;
7129
James Smartd7c47992010-06-08 18:31:54 -04007130 atomic_set(&phba->sdev_cnt, 0);
James Smart2cee7802017-06-01 21:07:02 -07007131 atomic_set(&phba->fc4ScsiInputRequests, 0);
7132 atomic_set(&phba->fc4ScsiOutputRequests, 0);
7133 atomic_set(&phba->fc4ScsiControlRequests, 0);
7134 atomic_set(&phba->fc4ScsiIoCmpls, 0);
James Smart3de2a652007-08-02 11:09:59 -04007135 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05007136 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04007137 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05007138
7139 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05007140 phba->pport = vport;
James Smart2ea259e2017-02-12 13:52:27 -08007141
James Smartf358dd02017-02-12 13:52:34 -08007142 if (phba->nvmet_support) {
7143 /* Only 1 vport (pport) will support NVME target */
7144 if (phba->txrdy_payload_pool == NULL) {
Romain Perier771db5c2017-07-06 10:13:05 +02007145 phba->txrdy_payload_pool = dma_pool_create(
7146 "txrdy_pool", &phba->pcidev->dev,
James Smartf358dd02017-02-12 13:52:34 -08007147 TXRDY_PAYLOAD_LEN, 16, 0);
7148 if (phba->txrdy_payload_pool) {
7149 phba->targetport = NULL;
7150 phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
7151 lpfc_printf_log(phba, KERN_INFO,
7152 LOG_INIT | LOG_NVME_DISC,
7153 "6076 NVME Target Found\n");
7154 }
7155 }
7156 }
7157
James Smart858c9f62007-06-17 19:56:39 -05007158 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04007159 /* Put reference to SCSI host to driver's device private data */
7160 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05007161
James Smart4258e982015-12-16 18:11:58 -05007162 /*
7163 * At this point we are fully registered with PSA. In addition,
7164 * any initial discovery should be completed.
7165 */
7166 vport->load_flag |= FC_ALLOW_FDMI;
James Smart8663cbb2016-03-31 14:12:33 -07007167 if (phba->cfg_enable_SmartSAN ||
7168 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -05007169
7170 /* Setup appropriate attribute masks */
7171 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -07007172 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -05007173 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
7174 else
7175 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
7176 }
James Smart3772a992009-05-22 14:50:54 -04007177 return 0;
7178}
dea31012005-04-17 16:05:31 -05007179
James Smart3772a992009-05-22 14:50:54 -04007180/**
7181 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
7182 * @phba: pointer to lpfc hba data structure.
7183 *
7184 * This routine is invoked to destroy HBA physical port and the associated
7185 * SCSI host.
7186 **/
7187static void
7188lpfc_destroy_shost(struct lpfc_hba *phba)
7189{
7190 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04007191
James Smart3772a992009-05-22 14:50:54 -04007192 /* Destroy physical port that associated with the SCSI host */
7193 destroy_port(vport);
7194
7195 return;
7196}
7197
7198/**
7199 * lpfc_setup_bg - Setup Block guard structures and debug areas.
7200 * @phba: pointer to lpfc hba data structure.
7201 * @shost: the shost to be used to detect Block guard settings.
7202 *
7203 * This routine sets up the local Block guard protocol settings for @shost.
7204 * This routine also allocates memory for debugging bg buffers.
7205 **/
7206static void
7207lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
7208{
James Smartbbeb79b2012-06-12 13:54:27 -04007209 uint32_t old_mask;
7210 uint32_t old_guard;
7211
James Smart3772a992009-05-22 14:50:54 -04007212 int pagecnt = 10;
James Smartb3b98b72016-10-13 15:06:06 -07007213 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
James Smart3772a992009-05-22 14:50:54 -04007214 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7215 "1478 Registering BlockGuard with the "
7216 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04007217
James Smartb3b98b72016-10-13 15:06:06 -07007218 old_mask = phba->cfg_prot_mask;
7219 old_guard = phba->cfg_prot_guard;
James Smartbbeb79b2012-06-12 13:54:27 -04007220
7221 /* Only allow supported values */
James Smartb3b98b72016-10-13 15:06:06 -07007222 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
James Smartbbeb79b2012-06-12 13:54:27 -04007223 SHOST_DIX_TYPE0_PROTECTION |
7224 SHOST_DIX_TYPE1_PROTECTION);
James Smartb3b98b72016-10-13 15:06:06 -07007225 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
7226 SHOST_DIX_GUARD_CRC);
James Smartbbeb79b2012-06-12 13:54:27 -04007227
7228 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
James Smartb3b98b72016-10-13 15:06:06 -07007229 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
7230 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
James Smartbbeb79b2012-06-12 13:54:27 -04007231
James Smartb3b98b72016-10-13 15:06:06 -07007232 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
7233 if ((old_mask != phba->cfg_prot_mask) ||
7234 (old_guard != phba->cfg_prot_guard))
James Smartbbeb79b2012-06-12 13:54:27 -04007235 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7236 "1475 Registering BlockGuard with the "
7237 "SCSI layer: mask %d guard %d\n",
James Smartb3b98b72016-10-13 15:06:06 -07007238 phba->cfg_prot_mask,
7239 phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04007240
James Smartb3b98b72016-10-13 15:06:06 -07007241 scsi_host_set_prot(shost, phba->cfg_prot_mask);
7242 scsi_host_set_guard(shost, phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04007243 } else
7244 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7245 "1479 Not Registering BlockGuard with the SCSI "
7246 "layer, Bad protection parameters: %d %d\n",
7247 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04007248 }
James Smartbbeb79b2012-06-12 13:54:27 -04007249
James Smart81301a92008-12-04 22:39:46 -05007250 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05007251 while (pagecnt) {
7252 spin_lock_init(&_dump_buf_lock);
7253 _dump_buf_data =
7254 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
7255 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04007256 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7257 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04007258 "_dump_buf_data at 0x%p\n",
7259 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05007260 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04007261 memset(_dump_buf_data, 0,
7262 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05007263 break;
James Smart3772a992009-05-22 14:50:54 -04007264 } else
James Smart81301a92008-12-04 22:39:46 -05007265 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05007266 }
James Smart81301a92008-12-04 22:39:46 -05007267 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04007268 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7269 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04007270 "memory for hexdump\n");
7271 } else
James Smart6a9c52c2009-10-02 15:16:51 -04007272 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7273 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05007274 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05007275 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05007276 while (pagecnt) {
7277 _dump_buf_dif =
7278 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
7279 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04007280 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7281 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04007282 "_dump_buf_dif at 0x%p\n",
7283 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05007284 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04007285 memset(_dump_buf_dif, 0,
7286 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05007287 break;
James Smart3772a992009-05-22 14:50:54 -04007288 } else
James Smart81301a92008-12-04 22:39:46 -05007289 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05007290 }
James Smart81301a92008-12-04 22:39:46 -05007291 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04007292 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7293 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04007294 "memory for hexdump\n");
7295 } else
James Smart6a9c52c2009-10-02 15:16:51 -04007296 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7297 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04007298 _dump_buf_dif);
7299}
7300
7301/**
7302 * lpfc_post_init_setup - Perform necessary device post initialization setup.
7303 * @phba: pointer to lpfc hba data structure.
7304 *
7305 * This routine is invoked to perform all the necessary post initialization
7306 * setup for the device.
7307 **/
7308static void
7309lpfc_post_init_setup(struct lpfc_hba *phba)
7310{
7311 struct Scsi_Host *shost;
7312 struct lpfc_adapter_event_header adapter_event;
7313
7314 /* Get the default values for Model Name and Description */
7315 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
7316
7317 /*
7318 * hba setup may have changed the hba_queue_depth so we need to
7319 * adjust the value of can_queue.
7320 */
7321 shost = pci_get_drvdata(phba->pcidev);
7322 shost->can_queue = phba->cfg_hba_queue_depth - 10;
7323 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
7324 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05007325
7326 lpfc_host_attrib_init(shost);
7327
James Smart2e0fef82007-06-17 19:56:36 -05007328 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
7329 spin_lock_irq(shost->host_lock);
7330 lpfc_poll_start_timer(phba);
7331 spin_unlock_irq(shost->host_lock);
7332 }
James Smart8f6d98d2006-08-01 07:34:00 -04007333
James Smart93996272008-08-24 21:50:30 -04007334 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7335 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04007336 /* Send board arrival event to upper layer */
7337 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
7338 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
7339 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04007340 sizeof(adapter_event),
7341 (char *) &adapter_event,
7342 LPFC_NL_VENDOR_ID);
7343 return;
7344}
7345
7346/**
7347 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
7348 * @phba: pointer to lpfc hba data structure.
7349 *
7350 * This routine is invoked to set up the PCI device memory space for device
7351 * with SLI-3 interface spec.
7352 *
7353 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007354 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007355 * other values - error
7356 **/
7357static int
7358lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
7359{
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02007360 struct pci_dev *pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04007361 unsigned long bar0map_len, bar2map_len;
7362 int i, hbq_count;
7363 void *ptr;
7364 int error = -ENODEV;
7365
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02007366 if (!pdev)
James Smart3772a992009-05-22 14:50:54 -04007367 return error;
James Smart3772a992009-05-22 14:50:54 -04007368
7369 /* Set the device DMA mask size */
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02007370 if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) ||
7371 dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)))
7372 return error;
James Smart3772a992009-05-22 14:50:54 -04007373
7374 /* Get the bus address of Bar0 and Bar2 and the number of bytes
7375 * required by each mapping.
7376 */
7377 phba->pci_bar0_map = pci_resource_start(pdev, 0);
7378 bar0map_len = pci_resource_len(pdev, 0);
7379
7380 phba->pci_bar2_map = pci_resource_start(pdev, 2);
7381 bar2map_len = pci_resource_len(pdev, 2);
7382
7383 /* Map HBA SLIM to a kernel virtual address. */
7384 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
7385 if (!phba->slim_memmap_p) {
7386 dev_printk(KERN_ERR, &pdev->dev,
7387 "ioremap failed for SLIM memory.\n");
7388 goto out;
7389 }
7390
7391 /* Map HBA Control Registers to a kernel virtual address. */
7392 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
7393 if (!phba->ctrl_regs_memmap_p) {
7394 dev_printk(KERN_ERR, &pdev->dev,
7395 "ioremap failed for HBA control registers.\n");
7396 goto out_iounmap_slim;
7397 }
7398
7399 /* Allocate memory for SLI-2 structures */
Joe Perches1aee3832014-09-03 12:56:12 -04007400 phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7401 &phba->slim2p.phys, GFP_KERNEL);
James Smart3772a992009-05-22 14:50:54 -04007402 if (!phba->slim2p.virt)
7403 goto out_iounmap;
7404
James Smart3772a992009-05-22 14:50:54 -04007405 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04007406 phba->mbox_ext = (phba->slim2p.virt +
7407 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04007408 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
7409 phba->IOCBs = (phba->slim2p.virt +
7410 offsetof(struct lpfc_sli2_slim, IOCBs));
7411
7412 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
7413 lpfc_sli_hbq_size(),
7414 &phba->hbqslimp.phys,
7415 GFP_KERNEL);
7416 if (!phba->hbqslimp.virt)
7417 goto out_free_slim;
7418
7419 hbq_count = lpfc_sli_hbq_count();
7420 ptr = phba->hbqslimp.virt;
7421 for (i = 0; i < hbq_count; ++i) {
7422 phba->hbqs[i].hbq_virt = ptr;
7423 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
7424 ptr += (lpfc_hbq_defs[i]->entry_count *
7425 sizeof(struct lpfc_hbq_entry));
7426 }
7427 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
7428 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
7429
7430 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
7431
James Smart3772a992009-05-22 14:50:54 -04007432 phba->MBslimaddr = phba->slim_memmap_p;
7433 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
7434 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
7435 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
7436 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04007437
dea31012005-04-17 16:05:31 -05007438 return 0;
7439
dea31012005-04-17 16:05:31 -05007440out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04007441 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7442 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05007443out_iounmap:
7444 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05007445out_iounmap_slim:
dea31012005-04-17 16:05:31 -05007446 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05007447out:
7448 return error;
7449}
7450
James Smarte59058c2008-08-24 21:49:00 -04007451/**
James Smart3772a992009-05-22 14:50:54 -04007452 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
7453 * @phba: pointer to lpfc hba data structure.
7454 *
7455 * This routine is invoked to unset the PCI device memory space for device
7456 * with SLI-3 interface spec.
7457 **/
7458static void
7459lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
7460{
7461 struct pci_dev *pdev;
7462
7463 /* Obtain PCI device reference */
7464 if (!phba->pcidev)
7465 return;
7466 else
7467 pdev = phba->pcidev;
7468
7469 /* Free coherent DMA memory allocated */
7470 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
7471 phba->hbqslimp.virt, phba->hbqslimp.phys);
7472 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7473 phba->slim2p.virt, phba->slim2p.phys);
7474
7475 /* I/O memory unmap */
7476 iounmap(phba->ctrl_regs_memmap_p);
7477 iounmap(phba->slim_memmap_p);
7478
7479 return;
7480}
7481
7482/**
James Smartda0436e2009-05-22 14:51:39 -04007483 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
7484 * @phba: pointer to lpfc hba data structure.
7485 *
7486 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
7487 * done and check status.
7488 *
7489 * Return 0 if successful, otherwise -ENODEV.
7490 **/
7491int
7492lpfc_sli4_post_status_check(struct lpfc_hba *phba)
7493{
James Smart2fcee4b2010-12-15 17:57:46 -05007494 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
7495 struct lpfc_register reg_data;
7496 int i, port_error = 0;
7497 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04007498
James Smart9940b972011-03-11 16:06:12 -05007499 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
7500 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05007501 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04007502 return -ENODEV;
7503
James Smartda0436e2009-05-22 14:51:39 -04007504 /* Wait up to 30 seconds for the SLI Port POST done and ready */
7505 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05007506 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
7507 &portsmphr_reg.word0) ||
7508 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007509 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04007510 port_error = -ENODEV;
7511 break;
7512 }
James Smart2fcee4b2010-12-15 17:57:46 -05007513 if (LPFC_POST_STAGE_PORT_READY ==
7514 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04007515 break;
James Smartda0436e2009-05-22 14:51:39 -04007516 msleep(10);
7517 }
7518
James Smart2fcee4b2010-12-15 17:57:46 -05007519 /*
7520 * If there was a port error during POST, then don't proceed with
7521 * other register reads as the data may not be valid. Just exit.
7522 */
7523 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04007524 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05007525 "1408 Port Failed POST - portsmphr=0x%x, "
7526 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
7527 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
7528 portsmphr_reg.word0,
7529 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
7530 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
7531 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
7532 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
7533 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
7534 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
7535 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
7536 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
7537 } else {
James Smart28baac72010-02-12 14:42:03 -05007538 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05007539 "2534 Device Info: SLIFamily=0x%x, "
7540 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
7541 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05007542 bf_get(lpfc_sli_intf_sli_family,
7543 &phba->sli4_hba.sli_intf),
7544 bf_get(lpfc_sli_intf_slirev,
7545 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05007546 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05007547 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05007548 bf_get(lpfc_sli_intf_sli_hint1,
7549 &phba->sli4_hba.sli_intf),
7550 bf_get(lpfc_sli_intf_sli_hint2,
7551 &phba->sli4_hba.sli_intf),
7552 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05007553 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05007554 /*
7555 * Check for other Port errors during the initialization
7556 * process. Fail the load if the port did not come up
7557 * correctly.
7558 */
7559 if_type = bf_get(lpfc_sli_intf_if_type,
7560 &phba->sli4_hba.sli_intf);
7561 switch (if_type) {
7562 case LPFC_SLI_INTF_IF_TYPE_0:
7563 phba->sli4_hba.ue_mask_lo =
7564 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
7565 phba->sli4_hba.ue_mask_hi =
7566 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
7567 uerrlo_reg.word0 =
7568 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
7569 uerrhi_reg.word0 =
7570 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
7571 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
7572 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
7573 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7574 "1422 Unrecoverable Error "
7575 "Detected during POST "
7576 "uerr_lo_reg=0x%x, "
7577 "uerr_hi_reg=0x%x, "
7578 "ue_mask_lo_reg=0x%x, "
7579 "ue_mask_hi_reg=0x%x\n",
7580 uerrlo_reg.word0,
7581 uerrhi_reg.word0,
7582 phba->sli4_hba.ue_mask_lo,
7583 phba->sli4_hba.ue_mask_hi);
7584 port_error = -ENODEV;
7585 }
7586 break;
7587 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08007588 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2fcee4b2010-12-15 17:57:46 -05007589 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05007590 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
7591 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04007592 (bf_get(lpfc_sliport_status_err, &reg_data) &&
7593 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007594 phba->work_status[0] =
7595 readl(phba->sli4_hba.u.if_type2.
7596 ERR1regaddr);
7597 phba->work_status[1] =
7598 readl(phba->sli4_hba.u.if_type2.
7599 ERR2regaddr);
7600 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05007601 "2888 Unrecoverable port error "
7602 "following POST: port status reg "
7603 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05007604 "error 1=0x%x, error 2=0x%x\n",
7605 reg_data.word0,
7606 portsmphr_reg.word0,
7607 phba->work_status[0],
7608 phba->work_status[1]);
7609 port_error = -ENODEV;
7610 }
7611 break;
7612 case LPFC_SLI_INTF_IF_TYPE_1:
7613 default:
7614 break;
7615 }
James Smart28baac72010-02-12 14:42:03 -05007616 }
James Smartda0436e2009-05-22 14:51:39 -04007617 return port_error;
7618}
7619
7620/**
7621 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
7622 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05007623 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04007624 *
7625 * This routine is invoked to set up SLI4 BAR0 PCI config space register
7626 * memory map.
7627 **/
7628static void
James Smart2fcee4b2010-12-15 17:57:46 -05007629lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04007630{
James Smart2fcee4b2010-12-15 17:57:46 -05007631 switch (if_type) {
7632 case LPFC_SLI_INTF_IF_TYPE_0:
7633 phba->sli4_hba.u.if_type0.UERRLOregaddr =
7634 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
7635 phba->sli4_hba.u.if_type0.UERRHIregaddr =
7636 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
7637 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
7638 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
7639 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
7640 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
7641 phba->sli4_hba.SLIINTFregaddr =
7642 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7643 break;
7644 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart0cf07f842017-06-01 21:07:10 -07007645 phba->sli4_hba.u.if_type2.EQDregaddr =
7646 phba->sli4_hba.conf_regs_memmap_p +
7647 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007648 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007649 phba->sli4_hba.conf_regs_memmap_p +
7650 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007651 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007652 phba->sli4_hba.conf_regs_memmap_p +
7653 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007654 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007655 phba->sli4_hba.conf_regs_memmap_p +
7656 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007657 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007658 phba->sli4_hba.conf_regs_memmap_p +
7659 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007660 phba->sli4_hba.SLIINTFregaddr =
7661 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7662 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007663 phba->sli4_hba.conf_regs_memmap_p +
7664 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007665 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05007666 phba->sli4_hba.conf_regs_memmap_p +
7667 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05007668 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05007669 phba->sli4_hba.conf_regs_memmap_p +
7670 LPFC_ULP0_WQ_DOORBELL;
James Smart9dd35422018-02-22 08:18:41 -08007671 phba->sli4_hba.CQDBregaddr =
James Smart2fcee4b2010-12-15 17:57:46 -05007672 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
James Smart9dd35422018-02-22 08:18:41 -08007673 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
James Smart2fcee4b2010-12-15 17:57:46 -05007674 phba->sli4_hba.MQDBregaddr =
7675 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
7676 phba->sli4_hba.BMBXregaddr =
7677 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
7678 break;
James Smart27d6ac02018-02-22 08:18:42 -08007679 case LPFC_SLI_INTF_IF_TYPE_6:
7680 phba->sli4_hba.u.if_type2.EQDregaddr =
7681 phba->sli4_hba.conf_regs_memmap_p +
7682 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
7683 phba->sli4_hba.u.if_type2.ERR1regaddr =
7684 phba->sli4_hba.conf_regs_memmap_p +
7685 LPFC_CTL_PORT_ER1_OFFSET;
7686 phba->sli4_hba.u.if_type2.ERR2regaddr =
7687 phba->sli4_hba.conf_regs_memmap_p +
7688 LPFC_CTL_PORT_ER2_OFFSET;
7689 phba->sli4_hba.u.if_type2.CTRLregaddr =
7690 phba->sli4_hba.conf_regs_memmap_p +
7691 LPFC_CTL_PORT_CTL_OFFSET;
7692 phba->sli4_hba.u.if_type2.STATUSregaddr =
7693 phba->sli4_hba.conf_regs_memmap_p +
7694 LPFC_CTL_PORT_STA_OFFSET;
7695 phba->sli4_hba.PSMPHRregaddr =
7696 phba->sli4_hba.conf_regs_memmap_p +
7697 LPFC_CTL_PORT_SEM_OFFSET;
7698 phba->sli4_hba.BMBXregaddr =
7699 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
7700 break;
James Smart2fcee4b2010-12-15 17:57:46 -05007701 case LPFC_SLI_INTF_IF_TYPE_1:
7702 default:
7703 dev_printk(KERN_ERR, &phba->pcidev->dev,
7704 "FATAL - unsupported SLI4 interface type - %d\n",
7705 if_type);
7706 break;
7707 }
James Smartda0436e2009-05-22 14:51:39 -04007708}
7709
7710/**
7711 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
7712 * @phba: pointer to lpfc hba data structure.
7713 *
James Smart27d6ac02018-02-22 08:18:42 -08007714 * This routine is invoked to set up SLI4 BAR1 register memory map.
James Smartda0436e2009-05-22 14:51:39 -04007715 **/
7716static void
James Smart27d6ac02018-02-22 08:18:42 -08007717lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04007718{
James Smart27d6ac02018-02-22 08:18:42 -08007719 switch (if_type) {
7720 case LPFC_SLI_INTF_IF_TYPE_0:
7721 phba->sli4_hba.PSMPHRregaddr =
7722 phba->sli4_hba.ctrl_regs_memmap_p +
7723 LPFC_SLIPORT_IF0_SMPHR;
7724 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7725 LPFC_HST_ISR0;
7726 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7727 LPFC_HST_IMR0;
7728 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7729 LPFC_HST_ISCR0;
7730 break;
7731 case LPFC_SLI_INTF_IF_TYPE_6:
7732 phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7733 LPFC_IF6_RQ_DOORBELL;
7734 phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7735 LPFC_IF6_WQ_DOORBELL;
7736 phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7737 LPFC_IF6_CQ_DOORBELL;
7738 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7739 LPFC_IF6_EQ_DOORBELL;
7740 phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7741 LPFC_IF6_MQ_DOORBELL;
7742 break;
7743 case LPFC_SLI_INTF_IF_TYPE_2:
7744 case LPFC_SLI_INTF_IF_TYPE_1:
7745 default:
7746 dev_err(&phba->pcidev->dev,
7747 "FATAL - unsupported SLI4 interface type - %d\n",
7748 if_type);
7749 break;
7750 }
James Smartda0436e2009-05-22 14:51:39 -04007751}
7752
7753/**
7754 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
7755 * @phba: pointer to lpfc hba data structure.
7756 * @vf: virtual function number
7757 *
7758 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
7759 * based on the given viftual function number, @vf.
7760 *
7761 * Return 0 if successful, otherwise -ENODEV.
7762 **/
7763static int
7764lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
7765{
7766 if (vf > LPFC_VIR_FUNC_MAX)
7767 return -ENODEV;
7768
7769 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05007770 vf * LPFC_VFR_PAGE_SIZE +
7771 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04007772 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05007773 vf * LPFC_VFR_PAGE_SIZE +
7774 LPFC_ULP0_WQ_DOORBELL);
James Smart9dd35422018-02-22 08:18:41 -08007775 phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7776 vf * LPFC_VFR_PAGE_SIZE +
7777 LPFC_EQCQ_DOORBELL);
7778 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
James Smartda0436e2009-05-22 14:51:39 -04007779 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7780 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
7781 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7782 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
7783 return 0;
7784}
7785
7786/**
7787 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
7788 * @phba: pointer to lpfc hba data structure.
7789 *
7790 * This routine is invoked to create the bootstrap mailbox
7791 * region consistent with the SLI-4 interface spec. This
7792 * routine allocates all memory necessary to communicate
7793 * mailbox commands to the port and sets up all alignment
7794 * needs. No locks are expected to be held when calling
7795 * this routine.
7796 *
7797 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007798 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04007799 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04007800 **/
7801static int
7802lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
7803{
7804 uint32_t bmbx_size;
7805 struct lpfc_dmabuf *dmabuf;
7806 struct dma_address *dma_address;
7807 uint32_t pa_addr;
7808 uint64_t phys_addr;
7809
7810 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
7811 if (!dmabuf)
7812 return -ENOMEM;
7813
7814 /*
7815 * The bootstrap mailbox region is comprised of 2 parts
7816 * plus an alignment restriction of 16 bytes.
7817 */
7818 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
Joe Perches1aee3832014-09-03 12:56:12 -04007819 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
7820 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04007821 if (!dmabuf->virt) {
7822 kfree(dmabuf);
7823 return -ENOMEM;
7824 }
James Smartda0436e2009-05-22 14:51:39 -04007825
7826 /*
7827 * Initialize the bootstrap mailbox pointers now so that the register
7828 * operations are simple later. The mailbox dma address is required
7829 * to be 16-byte aligned. Also align the virtual memory as each
7830 * maibox is copied into the bmbx mailbox region before issuing the
7831 * command to the port.
7832 */
7833 phba->sli4_hba.bmbx.dmabuf = dmabuf;
7834 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
7835
7836 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
7837 LPFC_ALIGN_16_BYTE);
7838 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
7839 LPFC_ALIGN_16_BYTE);
7840
7841 /*
7842 * Set the high and low physical addresses now. The SLI4 alignment
7843 * requirement is 16 bytes and the mailbox is posted to the port
7844 * as two 30-bit addresses. The other data is a bit marking whether
7845 * the 30-bit address is the high or low address.
7846 * Upcast bmbx aphys to 64bits so shift instruction compiles
7847 * clean on 32 bit machines.
7848 */
7849 dma_address = &phba->sli4_hba.bmbx.dma_address;
7850 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
7851 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
7852 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
7853 LPFC_BMBX_BIT1_ADDR_HI);
7854
7855 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
7856 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
7857 LPFC_BMBX_BIT1_ADDR_LO);
7858 return 0;
7859}
7860
7861/**
7862 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
7863 * @phba: pointer to lpfc hba data structure.
7864 *
7865 * This routine is invoked to teardown the bootstrap mailbox
7866 * region and release all host resources. This routine requires
7867 * the caller to ensure all mailbox commands recovered, no
7868 * additional mailbox comands are sent, and interrupts are disabled
7869 * before calling this routine.
7870 *
7871 **/
7872static void
7873lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
7874{
7875 dma_free_coherent(&phba->pcidev->dev,
7876 phba->sli4_hba.bmbx.bmbx_size,
7877 phba->sli4_hba.bmbx.dmabuf->virt,
7878 phba->sli4_hba.bmbx.dmabuf->phys);
7879
7880 kfree(phba->sli4_hba.bmbx.dmabuf);
7881 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
7882}
7883
7884/**
7885 * lpfc_sli4_read_config - Get the config parameters.
7886 * @phba: pointer to lpfc hba data structure.
7887 *
7888 * This routine is invoked to read the configuration parameters from the HBA.
7889 * The configuration parameters are used to set the base and maximum values
7890 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
7891 * allocation for the port.
7892 *
7893 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007894 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007895 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007896 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007897 **/
James Smartff78d8f2011-12-13 13:21:35 -05007898int
James Smartda0436e2009-05-22 14:51:39 -04007899lpfc_sli4_read_config(struct lpfc_hba *phba)
7900{
7901 LPFC_MBOXQ_t *pmb;
7902 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04007903 union lpfc_sli4_cfg_shdr *shdr;
7904 uint32_t shdr_status, shdr_add_status;
7905 struct lpfc_mbx_get_func_cfg *get_func_cfg;
7906 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04007907 char *pdesc_0;
James Smartc6918162016-10-13 15:06:16 -07007908 uint16_t forced_link_speed;
7909 uint32_t if_type;
James Smart8aa134a2012-08-14 14:25:29 -04007910 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04007911
7912 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7913 if (!pmb) {
7914 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7915 "2011 Unable to allocate memory for issuing "
7916 "SLI_CONFIG_SPECIAL mailbox command\n");
7917 return -ENOMEM;
7918 }
7919
7920 lpfc_read_config(phba, pmb);
7921
7922 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
7923 if (rc != MBX_SUCCESS) {
7924 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7925 "2012 Mailbox failed , mbxCmd x%x "
7926 "READ_CONFIG, mbxStatus x%x\n",
7927 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7928 bf_get(lpfc_mqe_status, &pmb->u.mqe));
7929 rc = -EIO;
7930 } else {
7931 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05007932 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
7933 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
7934 phba->sli4_hba.lnk_info.lnk_tp =
7935 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
7936 phba->sli4_hba.lnk_info.lnk_no =
7937 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
7938 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7939 "3081 lnk_type:%d, lnk_numb:%d\n",
7940 phba->sli4_hba.lnk_info.lnk_tp,
7941 phba->sli4_hba.lnk_info.lnk_no);
7942 } else
7943 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
7944 "3082 Mailbox (x%x) returned ldv:x0\n",
7945 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart44fd7fe2017-08-23 16:55:47 -07007946 if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) {
7947 phba->bbcredit_support = 1;
7948 phba->sli4_hba.bbscn_params.word0 = rd_config->word8;
7949 }
7950
James Smart1dc5ec22018-10-23 13:41:11 -07007951 phba->sli4_hba.conf_trunk =
7952 bf_get(lpfc_mbx_rd_conf_trunk, rd_config);
James Smart6d368e52011-05-24 11:44:12 -04007953 phba->sli4_hba.extents_in_use =
7954 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04007955 phba->sli4_hba.max_cfg_param.max_xri =
7956 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
7957 phba->sli4_hba.max_cfg_param.xri_base =
7958 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
7959 phba->sli4_hba.max_cfg_param.max_vpi =
7960 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
James Smart8b47ae62018-11-29 16:09:33 -08007961 /* Limit the max we support */
7962 if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS)
7963 phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS;
James Smartda0436e2009-05-22 14:51:39 -04007964 phba->sli4_hba.max_cfg_param.vpi_base =
7965 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
7966 phba->sli4_hba.max_cfg_param.max_rpi =
7967 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
7968 phba->sli4_hba.max_cfg_param.rpi_base =
7969 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
7970 phba->sli4_hba.max_cfg_param.max_vfi =
7971 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
7972 phba->sli4_hba.max_cfg_param.vfi_base =
7973 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
7974 phba->sli4_hba.max_cfg_param.max_fcfi =
7975 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04007976 phba->sli4_hba.max_cfg_param.max_eq =
7977 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
7978 phba->sli4_hba.max_cfg_param.max_rq =
7979 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
7980 phba->sli4_hba.max_cfg_param.max_wq =
7981 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
7982 phba->sli4_hba.max_cfg_param.max_cq =
7983 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
7984 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
7985 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
7986 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
7987 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05007988 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
7989 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04007990 phba->max_vports = phba->max_vpi;
7991 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04007992 "2003 cfg params Extents? %d "
7993 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04007994 "VPI(B:%d M:%d) "
7995 "VFI(B:%d M:%d) "
7996 "RPI(B:%d M:%d) "
James Smart2ea259e2017-02-12 13:52:27 -08007997 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n",
James Smart6d368e52011-05-24 11:44:12 -04007998 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04007999 phba->sli4_hba.max_cfg_param.xri_base,
8000 phba->sli4_hba.max_cfg_param.max_xri,
8001 phba->sli4_hba.max_cfg_param.vpi_base,
8002 phba->sli4_hba.max_cfg_param.max_vpi,
8003 phba->sli4_hba.max_cfg_param.vfi_base,
8004 phba->sli4_hba.max_cfg_param.max_vfi,
8005 phba->sli4_hba.max_cfg_param.rpi_base,
8006 phba->sli4_hba.max_cfg_param.max_rpi,
James Smart2ea259e2017-02-12 13:52:27 -08008007 phba->sli4_hba.max_cfg_param.max_fcfi,
8008 phba->sli4_hba.max_cfg_param.max_eq,
8009 phba->sli4_hba.max_cfg_param.max_cq,
8010 phba->sli4_hba.max_cfg_param.max_wq,
8011 phba->sli4_hba.max_cfg_param.max_rq);
8012
James Smartd38f33b2018-05-04 20:37:54 -07008013 /*
8014 * Calculate NVME queue resources based on how
8015 * many WQ/CQs are available.
8016 */
8017 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8018 length = phba->sli4_hba.max_cfg_param.max_wq;
8019 if (phba->sli4_hba.max_cfg_param.max_cq <
8020 phba->sli4_hba.max_cfg_param.max_wq)
8021 length = phba->sli4_hba.max_cfg_param.max_cq;
8022
8023 /*
8024 * Whats left after this can go toward NVME.
8025 * The minus 6 accounts for ELS, NVME LS, MBOX
8026 * fof plus a couple extra. When configured for
8027 * NVMET, FCP io channel WQs are not created.
8028 */
8029 length -= 6;
8030 if (!phba->nvmet_support)
8031 length -= phba->cfg_fcp_io_channel;
8032
8033 if (phba->cfg_nvme_io_channel > length) {
8034 lpfc_printf_log(
8035 phba, KERN_ERR, LOG_SLI,
8036 "2005 Reducing NVME IO channel to %d: "
8037 "WQ %d CQ %d NVMEIO %d FCPIO %d\n",
8038 length,
8039 phba->sli4_hba.max_cfg_param.max_wq,
8040 phba->sli4_hba.max_cfg_param.max_cq,
8041 phba->cfg_nvme_io_channel,
8042 phba->cfg_fcp_io_channel);
8043
8044 phba->cfg_nvme_io_channel = length;
8045 }
8046 }
James Smartda0436e2009-05-22 14:51:39 -04008047 }
James Smart912e3ac2011-05-24 11:42:11 -04008048
8049 if (rc)
8050 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04008051
James Smartc6918162016-10-13 15:06:16 -07008052 /* Update link speed if forced link speed is supported */
8053 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smart27d6ac02018-02-22 08:18:42 -08008054 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
James Smartc6918162016-10-13 15:06:16 -07008055 forced_link_speed =
8056 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
8057 if (forced_link_speed) {
8058 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
8059
8060 switch (forced_link_speed) {
8061 case LINK_SPEED_1G:
8062 phba->cfg_link_speed =
8063 LPFC_USER_LINK_SPEED_1G;
8064 break;
8065 case LINK_SPEED_2G:
8066 phba->cfg_link_speed =
8067 LPFC_USER_LINK_SPEED_2G;
8068 break;
8069 case LINK_SPEED_4G:
8070 phba->cfg_link_speed =
8071 LPFC_USER_LINK_SPEED_4G;
8072 break;
8073 case LINK_SPEED_8G:
8074 phba->cfg_link_speed =
8075 LPFC_USER_LINK_SPEED_8G;
8076 break;
8077 case LINK_SPEED_10G:
8078 phba->cfg_link_speed =
8079 LPFC_USER_LINK_SPEED_10G;
8080 break;
8081 case LINK_SPEED_16G:
8082 phba->cfg_link_speed =
8083 LPFC_USER_LINK_SPEED_16G;
8084 break;
8085 case LINK_SPEED_32G:
8086 phba->cfg_link_speed =
8087 LPFC_USER_LINK_SPEED_32G;
8088 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08008089 case LINK_SPEED_64G:
8090 phba->cfg_link_speed =
8091 LPFC_USER_LINK_SPEED_64G;
8092 break;
James Smartc6918162016-10-13 15:06:16 -07008093 case 0xffff:
8094 phba->cfg_link_speed =
8095 LPFC_USER_LINK_SPEED_AUTO;
8096 break;
8097 default:
8098 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8099 "0047 Unrecognized link "
8100 "speed : %d\n",
8101 forced_link_speed);
8102 phba->cfg_link_speed =
8103 LPFC_USER_LINK_SPEED_AUTO;
8104 }
8105 }
8106 }
8107
James Smartda0436e2009-05-22 14:51:39 -04008108 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -04008109 length = phba->sli4_hba.max_cfg_param.max_xri -
8110 lpfc_sli4_get_els_iocb_cnt(phba);
8111 if (phba->cfg_hba_queue_depth > length) {
8112 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8113 "3361 HBA queue depth changed from %d to %d\n",
8114 phba->cfg_hba_queue_depth, length);
8115 phba->cfg_hba_queue_depth = length;
8116 }
James Smart912e3ac2011-05-24 11:42:11 -04008117
James Smart27d6ac02018-02-22 08:18:42 -08008118 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smart912e3ac2011-05-24 11:42:11 -04008119 LPFC_SLI_INTF_IF_TYPE_2)
8120 goto read_cfg_out;
8121
8122 /* get the pf# and vf# for SLI4 if_type 2 port */
8123 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
8124 sizeof(struct lpfc_sli4_cfg_mhdr));
8125 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
8126 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
8127 length, LPFC_SLI4_MBX_EMBED);
8128
James Smart8aa134a2012-08-14 14:25:29 -04008129 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04008130 shdr = (union lpfc_sli4_cfg_shdr *)
8131 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
8132 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8133 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04008134 if (rc2 || shdr_status || shdr_add_status) {
James Smart912e3ac2011-05-24 11:42:11 -04008135 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8136 "3026 Mailbox failed , mbxCmd x%x "
8137 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
8138 bf_get(lpfc_mqe_command, &pmb->u.mqe),
8139 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04008140 goto read_cfg_out;
8141 }
8142
8143 /* search for fc_fcoe resrouce descriptor */
8144 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
James Smart912e3ac2011-05-24 11:42:11 -04008145
James Smart8aa134a2012-08-14 14:25:29 -04008146 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
8147 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
8148 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
8149 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
8150 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
8151 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
8152 goto read_cfg_out;
8153
James Smart912e3ac2011-05-24 11:42:11 -04008154 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04008155 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04008156 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04008157 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04008158 phba->sli4_hba.iov.pf_number =
8159 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
8160 phba->sli4_hba.iov.vf_number =
8161 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
8162 break;
8163 }
8164 }
8165
8166 if (i < LPFC_RSRC_DESC_MAX_NUM)
8167 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8168 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
8169 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
8170 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04008171 else
James Smart912e3ac2011-05-24 11:42:11 -04008172 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8173 "3028 GET_FUNCTION_CONFIG: failed to find "
Colin Ian Kingc4dba182018-10-16 18:28:53 +01008174 "Resource Descriptor:x%x\n",
James Smart912e3ac2011-05-24 11:42:11 -04008175 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04008176
8177read_cfg_out:
8178 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04008179 return rc;
8180}
8181
8182/**
James Smart2fcee4b2010-12-15 17:57:46 -05008183 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04008184 * @phba: pointer to lpfc hba data structure.
8185 *
James Smart2fcee4b2010-12-15 17:57:46 -05008186 * This routine is invoked to setup the port-side endian order when
8187 * the port if_type is 0. This routine has no function for other
8188 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04008189 *
8190 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008191 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008192 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008193 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008194 **/
8195static int
8196lpfc_setup_endian_order(struct lpfc_hba *phba)
8197{
8198 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05008199 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04008200 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
8201 HOST_ENDIAN_HIGH_WORD1};
8202
James Smart2fcee4b2010-12-15 17:57:46 -05008203 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8204 switch (if_type) {
8205 case LPFC_SLI_INTF_IF_TYPE_0:
8206 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8207 GFP_KERNEL);
8208 if (!mboxq) {
8209 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8210 "0492 Unable to allocate memory for "
8211 "issuing SLI_CONFIG_SPECIAL mailbox "
8212 "command\n");
8213 return -ENOMEM;
8214 }
James Smartda0436e2009-05-22 14:51:39 -04008215
James Smart2fcee4b2010-12-15 17:57:46 -05008216 /*
8217 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
8218 * two words to contain special data values and no other data.
8219 */
8220 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
8221 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
8222 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8223 if (rc != MBX_SUCCESS) {
8224 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8225 "0493 SLI_CONFIG_SPECIAL mailbox "
8226 "failed with status x%x\n",
8227 rc);
8228 rc = -EIO;
8229 }
8230 mempool_free(mboxq, phba->mbox_mem_pool);
8231 break;
James Smart27d6ac02018-02-22 08:18:42 -08008232 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2fcee4b2010-12-15 17:57:46 -05008233 case LPFC_SLI_INTF_IF_TYPE_2:
8234 case LPFC_SLI_INTF_IF_TYPE_1:
8235 default:
8236 break;
James Smartda0436e2009-05-22 14:51:39 -04008237 }
James Smartda0436e2009-05-22 14:51:39 -04008238 return rc;
8239}
8240
8241/**
James Smart895427b2017-02-12 13:52:30 -08008242 * lpfc_sli4_queue_verify - Verify and update EQ counts
James Smartda0436e2009-05-22 14:51:39 -04008243 * @phba: pointer to lpfc hba data structure.
8244 *
James Smart895427b2017-02-12 13:52:30 -08008245 * This routine is invoked to check the user settable queue counts for EQs.
8246 * After this routine is called the counts will be set to valid values that
James Smart5350d872011-10-10 21:33:49 -04008247 * adhere to the constraints of the system's interrupt vectors and the port's
8248 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04008249 *
8250 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008251 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008252 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04008253 **/
8254static int
James Smart5350d872011-10-10 21:33:49 -04008255lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04008256{
James Smart895427b2017-02-12 13:52:30 -08008257 int io_channel;
James Smart1ba981f2014-02-20 09:56:45 -05008258 int fof_vectors = phba->cfg_fof ? 1 : 0;
James Smartda0436e2009-05-22 14:51:39 -04008259
8260 /*
James Smart67d12732012-08-03 12:36:13 -04008261 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04008262 * device parameters
8263 */
8264
James Smart67d12732012-08-03 12:36:13 -04008265 /* Sanity check on HBA EQ parameters */
James Smart895427b2017-02-12 13:52:30 -08008266 io_channel = phba->io_channel_irqs;
James Smartda0436e2009-05-22 14:51:39 -04008267
James Smart895427b2017-02-12 13:52:30 -08008268 if (phba->sli4_hba.num_online_cpu < io_channel) {
James Smart82c3e9b2012-09-29 11:29:50 -04008269 lpfc_printf_log(phba,
8270 KERN_ERR, LOG_INIT,
James Smart90695ee2012-08-14 14:25:36 -04008271 "3188 Reducing IO channels to match number of "
James Smart7bb03bb2013-04-17 20:19:16 -04008272 "online CPUs: from %d to %d\n",
James Smart895427b2017-02-12 13:52:30 -08008273 io_channel, phba->sli4_hba.num_online_cpu);
8274 io_channel = phba->sli4_hba.num_online_cpu;
James Smart90695ee2012-08-14 14:25:36 -04008275 }
8276
James Smart895427b2017-02-12 13:52:30 -08008277 if (io_channel + fof_vectors > phba->sli4_hba.max_cfg_param.max_eq) {
James Smart82c3e9b2012-09-29 11:29:50 -04008278 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8279 "2575 Reducing IO channels to match number of "
8280 "available EQs: from %d to %d\n",
James Smart895427b2017-02-12 13:52:30 -08008281 io_channel,
James Smart82c3e9b2012-09-29 11:29:50 -04008282 phba->sli4_hba.max_cfg_param.max_eq);
James Smart895427b2017-02-12 13:52:30 -08008283 io_channel = phba->sli4_hba.max_cfg_param.max_eq - fof_vectors;
James Smartda0436e2009-05-22 14:51:39 -04008284 }
James Smart67d12732012-08-03 12:36:13 -04008285
James Smart895427b2017-02-12 13:52:30 -08008286 /* The actual number of FCP / NVME event queues adopted */
8287 if (io_channel != phba->io_channel_irqs)
8288 phba->io_channel_irqs = io_channel;
8289 if (phba->cfg_fcp_io_channel > io_channel)
8290 phba->cfg_fcp_io_channel = io_channel;
8291 if (phba->cfg_nvme_io_channel > io_channel)
8292 phba->cfg_nvme_io_channel = io_channel;
James Smartbcb24f62017-11-20 16:00:36 -08008293 if (phba->nvmet_support) {
8294 if (phba->cfg_nvme_io_channel < phba->cfg_nvmet_mrq)
8295 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
8296 }
8297 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
8298 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
James Smart895427b2017-02-12 13:52:30 -08008299
8300 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2d7dbc42017-02-12 13:52:35 -08008301 "2574 IO channels: irqs %d fcp %d nvme %d MRQ: %d\n",
James Smart895427b2017-02-12 13:52:30 -08008302 phba->io_channel_irqs, phba->cfg_fcp_io_channel,
James Smart2d7dbc42017-02-12 13:52:35 -08008303 phba->cfg_nvme_io_channel, phba->cfg_nvmet_mrq);
James Smartda0436e2009-05-22 14:51:39 -04008304
James Smartda0436e2009-05-22 14:51:39 -04008305 /* Get EQ depth from module parameter, fake the default for now */
8306 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8307 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8308
James Smart5350d872011-10-10 21:33:49 -04008309 /* Get CQ depth from module parameter, fake the default for now */
8310 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8311 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart5350d872011-10-10 21:33:49 -04008312 return 0;
James Smart895427b2017-02-12 13:52:30 -08008313}
8314
8315static int
8316lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx)
8317{
8318 struct lpfc_queue *qdesc;
James Smart895427b2017-02-12 13:52:30 -08008319
James Smarta51e41b2017-12-08 17:18:06 -08008320 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
James Smart81b96ed2017-11-20 16:00:29 -08008321 phba->sli4_hba.cq_esize,
James Smarta51e41b2017-12-08 17:18:06 -08008322 LPFC_CQE_EXP_COUNT);
James Smart895427b2017-02-12 13:52:30 -08008323 if (!qdesc) {
8324 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8325 "0508 Failed allocate fast-path NVME CQ (%d)\n",
8326 wqidx);
8327 return 1;
8328 }
James Smart7365f6f2018-02-22 08:18:46 -08008329 qdesc->qe_valid = 1;
James Smart895427b2017-02-12 13:52:30 -08008330 phba->sli4_hba.nvme_cq[wqidx] = qdesc;
8331
James Smarta51e41b2017-12-08 17:18:06 -08008332 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8333 LPFC_WQE128_SIZE, LPFC_WQE_EXP_COUNT);
James Smart895427b2017-02-12 13:52:30 -08008334 if (!qdesc) {
8335 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8336 "0509 Failed allocate fast-path NVME WQ (%d)\n",
8337 wqidx);
8338 return 1;
8339 }
8340 phba->sli4_hba.nvme_wq[wqidx] = qdesc;
8341 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8342 return 0;
8343}
8344
8345static int
8346lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx)
8347{
8348 struct lpfc_queue *qdesc;
James Smartc176ffa2018-01-30 15:58:46 -08008349 uint32_t wqesize;
James Smart895427b2017-02-12 13:52:30 -08008350
8351 /* Create Fast Path FCP CQs */
James Smartc176ffa2018-01-30 15:58:46 -08008352 if (phba->enab_exp_wqcq_pages)
James Smarta51e41b2017-12-08 17:18:06 -08008353 /* Increase the CQ size when WQEs contain an embedded cdb */
8354 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8355 phba->sli4_hba.cq_esize,
8356 LPFC_CQE_EXP_COUNT);
8357
8358 else
8359 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8360 phba->sli4_hba.cq_esize,
8361 phba->sli4_hba.cq_ecount);
James Smart895427b2017-02-12 13:52:30 -08008362 if (!qdesc) {
8363 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8364 "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx);
8365 return 1;
8366 }
James Smart7365f6f2018-02-22 08:18:46 -08008367 qdesc->qe_valid = 1;
James Smart895427b2017-02-12 13:52:30 -08008368 phba->sli4_hba.fcp_cq[wqidx] = qdesc;
8369
8370 /* Create Fast Path FCP WQs */
James Smartc176ffa2018-01-30 15:58:46 -08008371 if (phba->enab_exp_wqcq_pages) {
James Smarta51e41b2017-12-08 17:18:06 -08008372 /* Increase the WQ size when WQEs contain an embedded cdb */
James Smartc176ffa2018-01-30 15:58:46 -08008373 wqesize = (phba->fcp_embed_io) ?
8374 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
James Smarta51e41b2017-12-08 17:18:06 -08008375 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
James Smartc176ffa2018-01-30 15:58:46 -08008376 wqesize,
James Smarta51e41b2017-12-08 17:18:06 -08008377 LPFC_WQE_EXP_COUNT);
James Smartc176ffa2018-01-30 15:58:46 -08008378 } else
James Smarta51e41b2017-12-08 17:18:06 -08008379 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8380 phba->sli4_hba.wq_esize,
8381 phba->sli4_hba.wq_ecount);
James Smartc176ffa2018-01-30 15:58:46 -08008382
James Smart895427b2017-02-12 13:52:30 -08008383 if (!qdesc) {
8384 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8385 "0503 Failed allocate fast-path FCP WQ (%d)\n",
8386 wqidx);
8387 return 1;
8388 }
8389 phba->sli4_hba.fcp_wq[wqidx] = qdesc;
8390 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8391 return 0;
James Smart5350d872011-10-10 21:33:49 -04008392}
8393
8394/**
8395 * lpfc_sli4_queue_create - Create all the SLI4 queues
8396 * @phba: pointer to lpfc hba data structure.
8397 *
8398 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
8399 * operation. For each SLI4 queue type, the parameters such as queue entry
8400 * count (queue depth) shall be taken from the module parameter. For now,
8401 * we just use some constant number as place holder.
8402 *
8403 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07008404 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04008405 * -ENOMEM - No availble memory
8406 * -EIO - The mailbox failed to complete successfully.
8407 **/
8408int
8409lpfc_sli4_queue_create(struct lpfc_hba *phba)
8410{
8411 struct lpfc_queue *qdesc;
James Smartd1f525a2017-04-21 16:04:55 -07008412 int idx, io_channel;
James Smart5350d872011-10-10 21:33:49 -04008413
8414 /*
James Smart67d12732012-08-03 12:36:13 -04008415 * Create HBA Record arrays.
James Smart895427b2017-02-12 13:52:30 -08008416 * Both NVME and FCP will share that same vectors / EQs
James Smart5350d872011-10-10 21:33:49 -04008417 */
James Smart895427b2017-02-12 13:52:30 -08008418 io_channel = phba->io_channel_irqs;
8419 if (!io_channel)
James Smart67d12732012-08-03 12:36:13 -04008420 return -ERANGE;
James Smart5350d872011-10-10 21:33:49 -04008421
James Smart67d12732012-08-03 12:36:13 -04008422 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
8423 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
8424 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
8425 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
8426 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
8427 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
James Smart895427b2017-02-12 13:52:30 -08008428 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8429 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8430 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8431 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart67d12732012-08-03 12:36:13 -04008432
James Smart895427b2017-02-12 13:52:30 -08008433 phba->sli4_hba.hba_eq = kcalloc(io_channel,
8434 sizeof(struct lpfc_queue *),
8435 GFP_KERNEL);
James Smart67d12732012-08-03 12:36:13 -04008436 if (!phba->sli4_hba.hba_eq) {
James Smartda0436e2009-05-22 14:51:39 -04008437 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04008438 "2576 Failed allocate memory for "
8439 "fast-path EQ record array\n");
James Smartda0436e2009-05-22 14:51:39 -04008440 goto out_error;
8441 }
James Smart67d12732012-08-03 12:36:13 -04008442
James Smart895427b2017-02-12 13:52:30 -08008443 if (phba->cfg_fcp_io_channel) {
8444 phba->sli4_hba.fcp_cq = kcalloc(phba->cfg_fcp_io_channel,
8445 sizeof(struct lpfc_queue *),
8446 GFP_KERNEL);
8447 if (!phba->sli4_hba.fcp_cq) {
8448 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8449 "2577 Failed allocate memory for "
8450 "fast-path CQ record array\n");
8451 goto out_error;
8452 }
8453 phba->sli4_hba.fcp_wq = kcalloc(phba->cfg_fcp_io_channel,
8454 sizeof(struct lpfc_queue *),
8455 GFP_KERNEL);
8456 if (!phba->sli4_hba.fcp_wq) {
8457 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8458 "2578 Failed allocate memory for "
8459 "fast-path FCP WQ record array\n");
8460 goto out_error;
8461 }
8462 /*
8463 * Since the first EQ can have multiple CQs associated with it,
8464 * this array is used to quickly see if we have a FCP fast-path
8465 * CQ match.
8466 */
8467 phba->sli4_hba.fcp_cq_map = kcalloc(phba->cfg_fcp_io_channel,
8468 sizeof(uint16_t),
8469 GFP_KERNEL);
8470 if (!phba->sli4_hba.fcp_cq_map) {
8471 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8472 "2545 Failed allocate memory for "
8473 "fast-path CQ map\n");
8474 goto out_error;
8475 }
James Smart67d12732012-08-03 12:36:13 -04008476 }
8477
James Smart895427b2017-02-12 13:52:30 -08008478 if (phba->cfg_nvme_io_channel) {
8479 phba->sli4_hba.nvme_cq = kcalloc(phba->cfg_nvme_io_channel,
8480 sizeof(struct lpfc_queue *),
8481 GFP_KERNEL);
8482 if (!phba->sli4_hba.nvme_cq) {
8483 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8484 "6077 Failed allocate memory for "
8485 "fast-path CQ record array\n");
8486 goto out_error;
8487 }
8488
James Smart895427b2017-02-12 13:52:30 -08008489 phba->sli4_hba.nvme_wq = kcalloc(phba->cfg_nvme_io_channel,
8490 sizeof(struct lpfc_queue *),
8491 GFP_KERNEL);
8492 if (!phba->sli4_hba.nvme_wq) {
8493 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8494 "2581 Failed allocate memory for "
8495 "fast-path NVME WQ record array\n");
8496 goto out_error;
8497 }
8498
8499 /*
8500 * Since the first EQ can have multiple CQs associated with it,
8501 * this array is used to quickly see if we have a NVME fast-path
8502 * CQ match.
8503 */
8504 phba->sli4_hba.nvme_cq_map = kcalloc(phba->cfg_nvme_io_channel,
8505 sizeof(uint16_t),
8506 GFP_KERNEL);
8507 if (!phba->sli4_hba.nvme_cq_map) {
8508 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8509 "6078 Failed allocate memory for "
8510 "fast-path CQ map\n");
8511 goto out_error;
8512 }
James Smart2d7dbc42017-02-12 13:52:35 -08008513
8514 if (phba->nvmet_support) {
8515 phba->sli4_hba.nvmet_cqset = kcalloc(
8516 phba->cfg_nvmet_mrq,
8517 sizeof(struct lpfc_queue *),
8518 GFP_KERNEL);
8519 if (!phba->sli4_hba.nvmet_cqset) {
8520 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8521 "3121 Fail allocate memory for "
8522 "fast-path CQ set array\n");
8523 goto out_error;
8524 }
8525 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
8526 phba->cfg_nvmet_mrq,
8527 sizeof(struct lpfc_queue *),
8528 GFP_KERNEL);
8529 if (!phba->sli4_hba.nvmet_mrq_hdr) {
8530 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8531 "3122 Fail allocate memory for "
8532 "fast-path RQ set hdr array\n");
8533 goto out_error;
8534 }
8535 phba->sli4_hba.nvmet_mrq_data = kcalloc(
8536 phba->cfg_nvmet_mrq,
8537 sizeof(struct lpfc_queue *),
8538 GFP_KERNEL);
8539 if (!phba->sli4_hba.nvmet_mrq_data) {
8540 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8541 "3124 Fail allocate memory for "
8542 "fast-path RQ set data array\n");
8543 goto out_error;
8544 }
8545 }
James Smart67d12732012-08-03 12:36:13 -04008546 }
James Smartda0436e2009-05-22 14:51:39 -04008547
James Smart895427b2017-02-12 13:52:30 -08008548 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
James Smart67d12732012-08-03 12:36:13 -04008549
James Smart895427b2017-02-12 13:52:30 -08008550 /* Create HBA Event Queues (EQs) */
8551 for (idx = 0; idx < io_channel; idx++) {
James Smart67d12732012-08-03 12:36:13 -04008552 /* Create EQs */
James Smart81b96ed2017-11-20 16:00:29 -08008553 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8554 phba->sli4_hba.eq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008555 phba->sli4_hba.eq_ecount);
8556 if (!qdesc) {
8557 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04008558 "0497 Failed allocate EQ (%d)\n", idx);
8559 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008560 }
James Smart7365f6f2018-02-22 08:18:46 -08008561 qdesc->qe_valid = 1;
James Smart67d12732012-08-03 12:36:13 -04008562 phba->sli4_hba.hba_eq[idx] = qdesc;
James Smartda0436e2009-05-22 14:51:39 -04008563 }
8564
James Smart895427b2017-02-12 13:52:30 -08008565 /* FCP and NVME io channels are not required to be balanced */
8566
8567 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
8568 if (lpfc_alloc_fcp_wq_cq(phba, idx))
8569 goto out_error;
8570
8571 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
8572 if (lpfc_alloc_nvme_wq_cq(phba, idx))
8573 goto out_error;
James Smart67d12732012-08-03 12:36:13 -04008574
James Smart2d7dbc42017-02-12 13:52:35 -08008575 if (phba->nvmet_support) {
8576 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8577 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08008578 LPFC_DEFAULT_PAGE_SIZE,
8579 phba->sli4_hba.cq_esize,
8580 phba->sli4_hba.cq_ecount);
James Smart2d7dbc42017-02-12 13:52:35 -08008581 if (!qdesc) {
8582 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8583 "3142 Failed allocate NVME "
8584 "CQ Set (%d)\n", idx);
8585 goto out_error;
8586 }
James Smart7365f6f2018-02-22 08:18:46 -08008587 qdesc->qe_valid = 1;
James Smart2d7dbc42017-02-12 13:52:35 -08008588 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
8589 }
8590 }
8591
James Smartda0436e2009-05-22 14:51:39 -04008592 /*
James Smart67d12732012-08-03 12:36:13 -04008593 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04008594 */
8595
James Smartda0436e2009-05-22 14:51:39 -04008596 /* Create slow-path Mailbox Command Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008597 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8598 phba->sli4_hba.cq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008599 phba->sli4_hba.cq_ecount);
8600 if (!qdesc) {
8601 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8602 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04008603 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008604 }
James Smart7365f6f2018-02-22 08:18:46 -08008605 qdesc->qe_valid = 1;
James Smartda0436e2009-05-22 14:51:39 -04008606 phba->sli4_hba.mbx_cq = qdesc;
8607
8608 /* Create slow-path ELS Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008609 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8610 phba->sli4_hba.cq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008611 phba->sli4_hba.cq_ecount);
8612 if (!qdesc) {
8613 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8614 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -04008615 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008616 }
James Smart7365f6f2018-02-22 08:18:46 -08008617 qdesc->qe_valid = 1;
James Smartda0436e2009-05-22 14:51:39 -04008618 phba->sli4_hba.els_cq = qdesc;
8619
James Smartda0436e2009-05-22 14:51:39 -04008620
James Smart5350d872011-10-10 21:33:49 -04008621 /*
James Smart67d12732012-08-03 12:36:13 -04008622 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04008623 */
James Smartda0436e2009-05-22 14:51:39 -04008624
8625 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04008626
James Smart81b96ed2017-11-20 16:00:29 -08008627 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8628 phba->sli4_hba.mq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008629 phba->sli4_hba.mq_ecount);
8630 if (!qdesc) {
8631 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8632 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04008633 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008634 }
8635 phba->sli4_hba.mbx_wq = qdesc;
8636
8637 /*
James Smart67d12732012-08-03 12:36:13 -04008638 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04008639 */
James Smartda0436e2009-05-22 14:51:39 -04008640
8641 /* Create slow-path ELS Work Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008642 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8643 phba->sli4_hba.wq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008644 phba->sli4_hba.wq_ecount);
8645 if (!qdesc) {
8646 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8647 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04008648 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008649 }
8650 phba->sli4_hba.els_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08008651 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8652
8653 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8654 /* Create NVME LS Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008655 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8656 phba->sli4_hba.cq_esize,
James Smart895427b2017-02-12 13:52:30 -08008657 phba->sli4_hba.cq_ecount);
8658 if (!qdesc) {
8659 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8660 "6079 Failed allocate NVME LS CQ\n");
8661 goto out_error;
8662 }
James Smart7365f6f2018-02-22 08:18:46 -08008663 qdesc->qe_valid = 1;
James Smart895427b2017-02-12 13:52:30 -08008664 phba->sli4_hba.nvmels_cq = qdesc;
8665
8666 /* Create NVME LS Work Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008667 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8668 phba->sli4_hba.wq_esize,
James Smart895427b2017-02-12 13:52:30 -08008669 phba->sli4_hba.wq_ecount);
8670 if (!qdesc) {
8671 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8672 "6080 Failed allocate NVME LS WQ\n");
8673 goto out_error;
8674 }
8675 phba->sli4_hba.nvmels_wq = qdesc;
8676 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8677 }
James Smartda0436e2009-05-22 14:51:39 -04008678
James Smartda0436e2009-05-22 14:51:39 -04008679 /*
8680 * Create Receive Queue (RQ)
8681 */
James Smartda0436e2009-05-22 14:51:39 -04008682
8683 /* Create Receive Queue for header */
James Smart81b96ed2017-11-20 16:00:29 -08008684 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8685 phba->sli4_hba.rq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008686 phba->sli4_hba.rq_ecount);
8687 if (!qdesc) {
8688 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8689 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04008690 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008691 }
8692 phba->sli4_hba.hdr_rq = qdesc;
8693
8694 /* Create Receive Queue for data */
James Smart81b96ed2017-11-20 16:00:29 -08008695 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8696 phba->sli4_hba.rq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008697 phba->sli4_hba.rq_ecount);
8698 if (!qdesc) {
8699 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8700 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04008701 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008702 }
8703 phba->sli4_hba.dat_rq = qdesc;
8704
James Smart2d7dbc42017-02-12 13:52:35 -08008705 if (phba->nvmet_support) {
8706 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8707 /* Create NVMET Receive Queue for header */
8708 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08008709 LPFC_DEFAULT_PAGE_SIZE,
James Smart2d7dbc42017-02-12 13:52:35 -08008710 phba->sli4_hba.rq_esize,
James Smart61f3d4b2017-05-15 15:20:41 -07008711 LPFC_NVMET_RQE_DEF_COUNT);
James Smart2d7dbc42017-02-12 13:52:35 -08008712 if (!qdesc) {
8713 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8714 "3146 Failed allocate "
8715 "receive HRQ\n");
8716 goto out_error;
8717 }
8718 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
8719
8720 /* Only needed for header of RQ pair */
8721 qdesc->rqbp = kzalloc(sizeof(struct lpfc_rqb),
8722 GFP_KERNEL);
8723 if (qdesc->rqbp == NULL) {
8724 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8725 "6131 Failed allocate "
8726 "Header RQBP\n");
8727 goto out_error;
8728 }
8729
Dick Kennedy4b40d022017-08-23 16:55:38 -07008730 /* Put list in known state in case driver load fails. */
8731 INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list);
8732
James Smart2d7dbc42017-02-12 13:52:35 -08008733 /* Create NVMET Receive Queue for data */
8734 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08008735 LPFC_DEFAULT_PAGE_SIZE,
James Smart2d7dbc42017-02-12 13:52:35 -08008736 phba->sli4_hba.rq_esize,
James Smart61f3d4b2017-05-15 15:20:41 -07008737 LPFC_NVMET_RQE_DEF_COUNT);
James Smart2d7dbc42017-02-12 13:52:35 -08008738 if (!qdesc) {
8739 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8740 "3156 Failed allocate "
8741 "receive DRQ\n");
8742 goto out_error;
8743 }
8744 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
8745 }
8746 }
8747
James Smart1ba981f2014-02-20 09:56:45 -05008748 /* Create the Queues needed for Flash Optimized Fabric operations */
8749 if (phba->cfg_fof)
8750 lpfc_fof_queue_create(phba);
James Smartda0436e2009-05-22 14:51:39 -04008751 return 0;
8752
James Smartda0436e2009-05-22 14:51:39 -04008753out_error:
James Smart67d12732012-08-03 12:36:13 -04008754 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04008755 return -ENOMEM;
8756}
8757
James Smart895427b2017-02-12 13:52:30 -08008758static inline void
8759__lpfc_sli4_release_queue(struct lpfc_queue **qp)
8760{
8761 if (*qp != NULL) {
8762 lpfc_sli4_queue_free(*qp);
8763 *qp = NULL;
8764 }
8765}
8766
8767static inline void
8768lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
8769{
8770 int idx;
8771
8772 if (*qs == NULL)
8773 return;
8774
8775 for (idx = 0; idx < max; idx++)
8776 __lpfc_sli4_release_queue(&(*qs)[idx]);
8777
8778 kfree(*qs);
8779 *qs = NULL;
8780}
8781
8782static inline void
8783lpfc_sli4_release_queue_map(uint16_t **qmap)
8784{
8785 if (*qmap != NULL) {
8786 kfree(*qmap);
8787 *qmap = NULL;
8788 }
8789}
8790
James Smartda0436e2009-05-22 14:51:39 -04008791/**
8792 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
8793 * @phba: pointer to lpfc hba data structure.
8794 *
8795 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
8796 * operation.
8797 *
8798 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008799 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008800 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008801 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008802 **/
James Smart5350d872011-10-10 21:33:49 -04008803void
James Smartda0436e2009-05-22 14:51:39 -04008804lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
8805{
James Smart1ba981f2014-02-20 09:56:45 -05008806 if (phba->cfg_fof)
8807 lpfc_fof_queue_destroy(phba);
8808
James Smart895427b2017-02-12 13:52:30 -08008809 /* Release HBA eqs */
8810 lpfc_sli4_release_queues(&phba->sli4_hba.hba_eq, phba->io_channel_irqs);
James Smart67d12732012-08-03 12:36:13 -04008811
James Smart895427b2017-02-12 13:52:30 -08008812 /* Release FCP cqs */
8813 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_cq,
James Smartd1f525a2017-04-21 16:04:55 -07008814 phba->cfg_fcp_io_channel);
James Smart67d12732012-08-03 12:36:13 -04008815
James Smart895427b2017-02-12 13:52:30 -08008816 /* Release FCP wqs */
8817 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_wq,
James Smartd1f525a2017-04-21 16:04:55 -07008818 phba->cfg_fcp_io_channel);
James Smart67d12732012-08-03 12:36:13 -04008819
8820 /* Release FCP CQ mapping array */
James Smart895427b2017-02-12 13:52:30 -08008821 lpfc_sli4_release_queue_map(&phba->sli4_hba.fcp_cq_map);
8822
8823 /* Release NVME cqs */
8824 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_cq,
8825 phba->cfg_nvme_io_channel);
8826
8827 /* Release NVME wqs */
8828 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_wq,
8829 phba->cfg_nvme_io_channel);
8830
8831 /* Release NVME CQ mapping array */
8832 lpfc_sli4_release_queue_map(&phba->sli4_hba.nvme_cq_map);
James Smartda0436e2009-05-22 14:51:39 -04008833
James Smartbcb24f62017-11-20 16:00:36 -08008834 if (phba->nvmet_support) {
8835 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
8836 phba->cfg_nvmet_mrq);
James Smart2d7dbc42017-02-12 13:52:35 -08008837
James Smartbcb24f62017-11-20 16:00:36 -08008838 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
8839 phba->cfg_nvmet_mrq);
8840 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
8841 phba->cfg_nvmet_mrq);
8842 }
James Smart2d7dbc42017-02-12 13:52:35 -08008843
James Smartda0436e2009-05-22 14:51:39 -04008844 /* Release mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08008845 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
James Smartda0436e2009-05-22 14:51:39 -04008846
8847 /* Release ELS work queue */
James Smart895427b2017-02-12 13:52:30 -08008848 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
8849
8850 /* Release ELS work queue */
8851 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
James Smartda0436e2009-05-22 14:51:39 -04008852
8853 /* Release unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08008854 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
8855 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
James Smartda0436e2009-05-22 14:51:39 -04008856
James Smartda0436e2009-05-22 14:51:39 -04008857 /* Release ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08008858 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
8859
8860 /* Release NVME LS complete queue */
8861 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
James Smartda0436e2009-05-22 14:51:39 -04008862
8863 /* Release mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08008864 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
8865
8866 /* Everything on this list has been freed */
8867 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
8868}
8869
8870int
James Smart895427b2017-02-12 13:52:30 -08008871lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
8872{
8873 struct lpfc_rqb *rqbp;
8874 struct lpfc_dmabuf *h_buf;
8875 struct rqb_dmabuf *rqb_buffer;
8876
8877 rqbp = rq->rqbp;
8878 while (!list_empty(&rqbp->rqb_buffer_list)) {
8879 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
8880 struct lpfc_dmabuf, list);
8881
8882 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
8883 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
8884 rqbp->buffer_count--;
8885 }
8886 return 1;
8887}
8888
8889static int
8890lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
8891 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
8892 int qidx, uint32_t qtype)
8893{
8894 struct lpfc_sli_ring *pring;
8895 int rc;
8896
8897 if (!eq || !cq || !wq) {
8898 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8899 "6085 Fast-path %s (%d) not allocated\n",
8900 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
8901 return -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04008902 }
James Smartda0436e2009-05-22 14:51:39 -04008903
James Smart895427b2017-02-12 13:52:30 -08008904 /* create the Cq first */
8905 rc = lpfc_cq_create(phba, cq, eq,
8906 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
8907 if (rc) {
8908 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8909 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
8910 qidx, (uint32_t)rc);
8911 return rc;
8912 }
James Smart81b96ed2017-11-20 16:00:29 -08008913 cq->chann = qidx;
James Smart895427b2017-02-12 13:52:30 -08008914
8915 if (qtype != LPFC_MBOX) {
8916 /* Setup nvme_cq_map for fast lookup */
8917 if (cq_map)
8918 *cq_map = cq->queue_id;
8919
8920 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8921 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
8922 qidx, cq->queue_id, qidx, eq->queue_id);
8923
8924 /* create the wq */
8925 rc = lpfc_wq_create(phba, wq, cq, qtype);
8926 if (rc) {
8927 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8928 "6123 Fail setup fastpath WQ (%d), rc = 0x%x\n",
8929 qidx, (uint32_t)rc);
8930 /* no need to tear down cq - caller will do so */
8931 return rc;
8932 }
James Smart81b96ed2017-11-20 16:00:29 -08008933 wq->chann = qidx;
James Smart895427b2017-02-12 13:52:30 -08008934
8935 /* Bind this CQ/WQ to the NVME ring */
8936 pring = wq->pring;
8937 pring->sli.sli4.wqp = (void *)wq;
8938 cq->pring = pring;
8939
8940 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8941 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
8942 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
8943 } else {
8944 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
8945 if (rc) {
8946 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8947 "0539 Failed setup of slow-path MQ: "
8948 "rc = 0x%x\n", rc);
8949 /* no need to tear down cq - caller will do so */
8950 return rc;
8951 }
8952
8953 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8954 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
8955 phba->sli4_hba.mbx_wq->queue_id,
8956 phba->sli4_hba.mbx_cq->queue_id);
8957 }
8958
8959 return 0;
James Smartda0436e2009-05-22 14:51:39 -04008960}
8961
8962/**
8963 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
8964 * @phba: pointer to lpfc hba data structure.
8965 *
8966 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
8967 * operation.
8968 *
8969 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008970 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008971 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008972 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008973 **/
8974int
8975lpfc_sli4_queue_setup(struct lpfc_hba *phba)
8976{
James Smart962bc512013-01-03 15:44:00 -05008977 uint32_t shdr_status, shdr_add_status;
8978 union lpfc_sli4_cfg_shdr *shdr;
8979 LPFC_MBOXQ_t *mboxq;
James Smart895427b2017-02-12 13:52:30 -08008980 int qidx;
8981 uint32_t length, io_channel;
8982 int rc = -ENOMEM;
James Smart962bc512013-01-03 15:44:00 -05008983
8984 /* Check for dual-ULP support */
8985 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8986 if (!mboxq) {
8987 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8988 "3249 Unable to allocate memory for "
8989 "QUERY_FW_CFG mailbox command\n");
8990 return -ENOMEM;
8991 }
8992 length = (sizeof(struct lpfc_mbx_query_fw_config) -
8993 sizeof(struct lpfc_sli4_cfg_mhdr));
8994 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8995 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
8996 length, LPFC_SLI4_MBX_EMBED);
8997
8998 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8999
9000 shdr = (union lpfc_sli4_cfg_shdr *)
9001 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
9002 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9003 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9004 if (shdr_status || shdr_add_status || rc) {
9005 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9006 "3250 QUERY_FW_CFG mailbox failed with status "
9007 "x%x add_status x%x, mbx status x%x\n",
9008 shdr_status, shdr_add_status, rc);
9009 if (rc != MBX_TIMEOUT)
9010 mempool_free(mboxq, phba->mbox_mem_pool);
9011 rc = -ENXIO;
9012 goto out_error;
9013 }
9014
9015 phba->sli4_hba.fw_func_mode =
9016 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
9017 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
9018 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
James Smart8b017a32015-05-21 13:55:18 -04009019 phba->sli4_hba.physical_port =
9020 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
James Smart962bc512013-01-03 15:44:00 -05009021 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9022 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
9023 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
9024 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
9025
9026 if (rc != MBX_TIMEOUT)
9027 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04009028
9029 /*
James Smart67d12732012-08-03 12:36:13 -04009030 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04009031 */
James Smart895427b2017-02-12 13:52:30 -08009032 io_channel = phba->io_channel_irqs;
James Smartda0436e2009-05-22 14:51:39 -04009033
James Smart67d12732012-08-03 12:36:13 -04009034 /* Set up HBA event queue */
James Smart895427b2017-02-12 13:52:30 -08009035 if (io_channel && !phba->sli4_hba.hba_eq) {
James Smart2e90f4b2011-12-13 13:22:37 -05009036 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9037 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05009038 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04009039 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05009040 }
James Smart895427b2017-02-12 13:52:30 -08009041 for (qidx = 0; qidx < io_channel; qidx++) {
9042 if (!phba->sli4_hba.hba_eq[qidx]) {
James Smartda0436e2009-05-22 14:51:39 -04009043 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9044 "0522 Fast-path EQ (%d) not "
James Smart895427b2017-02-12 13:52:30 -08009045 "allocated\n", qidx);
James Smart1b511972011-12-13 13:23:09 -05009046 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009047 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009048 }
James Smart895427b2017-02-12 13:52:30 -08009049 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[qidx],
9050 phba->cfg_fcp_imax);
James Smartda0436e2009-05-22 14:51:39 -04009051 if (rc) {
9052 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9053 "0523 Failed setup of fast-path EQ "
James Smart895427b2017-02-12 13:52:30 -08009054 "(%d), rc = 0x%x\n", qidx,
James Smarta2fc4aef2014-09-03 12:57:55 -04009055 (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08009056 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009057 }
9058 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009059 "2584 HBA EQ setup: queue[%d]-id=%d\n",
9060 qidx, phba->sli4_hba.hba_eq[qidx]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04009061 }
9062
James Smart895427b2017-02-12 13:52:30 -08009063 if (phba->cfg_nvme_io_channel) {
9064 if (!phba->sli4_hba.nvme_cq || !phba->sli4_hba.nvme_wq) {
James Smart67d12732012-08-03 12:36:13 -04009065 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009066 "6084 Fast-path NVME %s array not allocated\n",
9067 (phba->sli4_hba.nvme_cq) ? "CQ" : "WQ");
James Smart67d12732012-08-03 12:36:13 -04009068 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009069 goto out_destroy;
James Smart67d12732012-08-03 12:36:13 -04009070 }
9071
James Smart895427b2017-02-12 13:52:30 -08009072 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
9073 rc = lpfc_create_wq_cq(phba,
9074 phba->sli4_hba.hba_eq[
9075 qidx % io_channel],
9076 phba->sli4_hba.nvme_cq[qidx],
9077 phba->sli4_hba.nvme_wq[qidx],
9078 &phba->sli4_hba.nvme_cq_map[qidx],
9079 qidx, LPFC_NVME);
9080 if (rc) {
9081 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9082 "6123 Failed to setup fastpath "
9083 "NVME WQ/CQ (%d), rc = 0x%x\n",
9084 qidx, (uint32_t)rc);
9085 goto out_destroy;
9086 }
9087 }
James Smart67d12732012-08-03 12:36:13 -04009088 }
9089
James Smart895427b2017-02-12 13:52:30 -08009090 if (phba->cfg_fcp_io_channel) {
9091 /* Set up fast-path FCP Response Complete Queue */
9092 if (!phba->sli4_hba.fcp_cq || !phba->sli4_hba.fcp_wq) {
James Smart67d12732012-08-03 12:36:13 -04009093 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009094 "3148 Fast-path FCP %s array not allocated\n",
9095 phba->sli4_hba.fcp_cq ? "WQ" : "CQ");
James Smart67d12732012-08-03 12:36:13 -04009096 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009097 goto out_destroy;
James Smart67d12732012-08-03 12:36:13 -04009098 }
9099
James Smart895427b2017-02-12 13:52:30 -08009100 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
9101 rc = lpfc_create_wq_cq(phba,
9102 phba->sli4_hba.hba_eq[
9103 qidx % io_channel],
9104 phba->sli4_hba.fcp_cq[qidx],
9105 phba->sli4_hba.fcp_wq[qidx],
9106 &phba->sli4_hba.fcp_cq_map[qidx],
9107 qidx, LPFC_FCP);
9108 if (rc) {
9109 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9110 "0535 Failed to setup fastpath "
9111 "FCP WQ/CQ (%d), rc = 0x%x\n",
9112 qidx, (uint32_t)rc);
9113 goto out_destroy;
9114 }
9115 }
James Smart67d12732012-08-03 12:36:13 -04009116 }
James Smartda0436e2009-05-22 14:51:39 -04009117
9118 /*
James Smart895427b2017-02-12 13:52:30 -08009119 * Set up Slow Path Complete Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04009120 */
9121
James Smart895427b2017-02-12 13:52:30 -08009122 /* Set up slow-path MBOX CQ/MQ */
9123
9124 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
James Smartda0436e2009-05-22 14:51:39 -04009125 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009126 "0528 %s not allocated\n",
9127 phba->sli4_hba.mbx_cq ?
James Smartd1f525a2017-04-21 16:04:55 -07009128 "Mailbox WQ" : "Mailbox CQ");
James Smart1b511972011-12-13 13:23:09 -05009129 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009130 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009131 }
James Smart895427b2017-02-12 13:52:30 -08009132
9133 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
James Smartd1f525a2017-04-21 16:04:55 -07009134 phba->sli4_hba.mbx_cq,
9135 phba->sli4_hba.mbx_wq,
9136 NULL, 0, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04009137 if (rc) {
9138 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009139 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
9140 (uint32_t)rc);
9141 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009142 }
James Smart2d7dbc42017-02-12 13:52:35 -08009143 if (phba->nvmet_support) {
9144 if (!phba->sli4_hba.nvmet_cqset) {
9145 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9146 "3165 Fast-path NVME CQ Set "
9147 "array not allocated\n");
9148 rc = -ENOMEM;
9149 goto out_destroy;
9150 }
9151 if (phba->cfg_nvmet_mrq > 1) {
9152 rc = lpfc_cq_create_set(phba,
9153 phba->sli4_hba.nvmet_cqset,
9154 phba->sli4_hba.hba_eq,
9155 LPFC_WCQ, LPFC_NVMET);
9156 if (rc) {
9157 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9158 "3164 Failed setup of NVME CQ "
9159 "Set, rc = 0x%x\n",
9160 (uint32_t)rc);
9161 goto out_destroy;
9162 }
9163 } else {
9164 /* Set up NVMET Receive Complete Queue */
9165 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
9166 phba->sli4_hba.hba_eq[0],
9167 LPFC_WCQ, LPFC_NVMET);
9168 if (rc) {
9169 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9170 "6089 Failed setup NVMET CQ: "
9171 "rc = 0x%x\n", (uint32_t)rc);
9172 goto out_destroy;
9173 }
James Smart81b96ed2017-11-20 16:00:29 -08009174 phba->sli4_hba.nvmet_cqset[0]->chann = 0;
9175
James Smart2d7dbc42017-02-12 13:52:35 -08009176 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9177 "6090 NVMET CQ setup: cq-id=%d, "
9178 "parent eq-id=%d\n",
9179 phba->sli4_hba.nvmet_cqset[0]->queue_id,
9180 phba->sli4_hba.hba_eq[0]->queue_id);
9181 }
9182 }
James Smartda0436e2009-05-22 14:51:39 -04009183
James Smart895427b2017-02-12 13:52:30 -08009184 /* Set up slow-path ELS WQ/CQ */
9185 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
James Smartda0436e2009-05-22 14:51:39 -04009186 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009187 "0530 ELS %s not allocated\n",
9188 phba->sli4_hba.els_cq ? "WQ" : "CQ");
James Smart1b511972011-12-13 13:23:09 -05009189 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009190 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009191 }
James Smart895427b2017-02-12 13:52:30 -08009192 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
9193 phba->sli4_hba.els_cq,
9194 phba->sli4_hba.els_wq,
9195 NULL, 0, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04009196 if (rc) {
9197 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009198 "0529 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
9199 (uint32_t)rc);
9200 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009201 }
9202 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9203 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
9204 phba->sli4_hba.els_wq->queue_id,
9205 phba->sli4_hba.els_cq->queue_id);
9206
James Smart895427b2017-02-12 13:52:30 -08009207 if (phba->cfg_nvme_io_channel) {
9208 /* Set up NVME LS Complete Queue */
9209 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
9210 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9211 "6091 LS %s not allocated\n",
9212 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
9213 rc = -ENOMEM;
9214 goto out_destroy;
9215 }
9216 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
9217 phba->sli4_hba.nvmels_cq,
9218 phba->sli4_hba.nvmels_wq,
9219 NULL, 0, LPFC_NVME_LS);
9220 if (rc) {
9221 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9222 "0529 Failed setup of NVVME LS WQ/CQ: "
9223 "rc = 0x%x\n", (uint32_t)rc);
9224 goto out_destroy;
9225 }
9226
9227 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9228 "6096 ELS WQ setup: wq-id=%d, "
9229 "parent cq-id=%d\n",
9230 phba->sli4_hba.nvmels_wq->queue_id,
9231 phba->sli4_hba.nvmels_cq->queue_id);
9232 }
9233
James Smart2d7dbc42017-02-12 13:52:35 -08009234 /*
9235 * Create NVMET Receive Queue (RQ)
9236 */
9237 if (phba->nvmet_support) {
9238 if ((!phba->sli4_hba.nvmet_cqset) ||
9239 (!phba->sli4_hba.nvmet_mrq_hdr) ||
9240 (!phba->sli4_hba.nvmet_mrq_data)) {
9241 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9242 "6130 MRQ CQ Queues not "
9243 "allocated\n");
9244 rc = -ENOMEM;
9245 goto out_destroy;
9246 }
9247 if (phba->cfg_nvmet_mrq > 1) {
9248 rc = lpfc_mrq_create(phba,
9249 phba->sli4_hba.nvmet_mrq_hdr,
9250 phba->sli4_hba.nvmet_mrq_data,
9251 phba->sli4_hba.nvmet_cqset,
9252 LPFC_NVMET);
9253 if (rc) {
9254 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9255 "6098 Failed setup of NVMET "
9256 "MRQ: rc = 0x%x\n",
9257 (uint32_t)rc);
9258 goto out_destroy;
9259 }
9260
9261 } else {
9262 rc = lpfc_rq_create(phba,
9263 phba->sli4_hba.nvmet_mrq_hdr[0],
9264 phba->sli4_hba.nvmet_mrq_data[0],
9265 phba->sli4_hba.nvmet_cqset[0],
9266 LPFC_NVMET);
9267 if (rc) {
9268 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9269 "6057 Failed setup of NVMET "
9270 "Receive Queue: rc = 0x%x\n",
9271 (uint32_t)rc);
9272 goto out_destroy;
9273 }
9274
9275 lpfc_printf_log(
9276 phba, KERN_INFO, LOG_INIT,
9277 "6099 NVMET RQ setup: hdr-rq-id=%d, "
9278 "dat-rq-id=%d parent cq-id=%d\n",
9279 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
9280 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
9281 phba->sli4_hba.nvmet_cqset[0]->queue_id);
9282
9283 }
9284 }
9285
James Smartda0436e2009-05-22 14:51:39 -04009286 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
9287 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9288 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05009289 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009290 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009291 }
James Smart73d91e52011-10-10 21:32:10 -04009292
James Smartda0436e2009-05-22 14:51:39 -04009293 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04009294 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04009295 if (rc) {
9296 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9297 "0541 Failed setup of Receive Queue: "
James Smarta2fc4aef2014-09-03 12:57:55 -04009298 "rc = 0x%x\n", (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08009299 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009300 }
James Smart73d91e52011-10-10 21:32:10 -04009301
James Smartda0436e2009-05-22 14:51:39 -04009302 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9303 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
9304 "parent cq-id=%d\n",
9305 phba->sli4_hba.hdr_rq->queue_id,
9306 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04009307 phba->sli4_hba.els_cq->queue_id);
James Smart1ba981f2014-02-20 09:56:45 -05009308
9309 if (phba->cfg_fof) {
9310 rc = lpfc_fof_queue_setup(phba);
9311 if (rc) {
9312 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9313 "0549 Failed setup of FOF Queues: "
9314 "rc = 0x%x\n", rc);
James Smart895427b2017-02-12 13:52:30 -08009315 goto out_destroy;
James Smart1ba981f2014-02-20 09:56:45 -05009316 }
9317 }
James Smart2c9c5a02015-04-07 15:07:15 -04009318
James Smart43140ca2017-03-04 09:30:34 -08009319 for (qidx = 0; qidx < io_channel; qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
James Smart0cf07f842017-06-01 21:07:10 -07009320 lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT,
9321 phba->cfg_fcp_imax);
James Smart43140ca2017-03-04 09:30:34 -08009322
James Smartda0436e2009-05-22 14:51:39 -04009323 return 0;
9324
James Smart895427b2017-02-12 13:52:30 -08009325out_destroy:
9326 lpfc_sli4_queue_unset(phba);
James Smartda0436e2009-05-22 14:51:39 -04009327out_error:
9328 return rc;
9329}
9330
9331/**
9332 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
9333 * @phba: pointer to lpfc hba data structure.
9334 *
9335 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
9336 * operation.
9337 *
9338 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009339 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009340 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009341 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009342 **/
9343void
9344lpfc_sli4_queue_unset(struct lpfc_hba *phba)
9345{
James Smart895427b2017-02-12 13:52:30 -08009346 int qidx;
James Smartda0436e2009-05-22 14:51:39 -04009347
James Smart1ba981f2014-02-20 09:56:45 -05009348 /* Unset the queues created for Flash Optimized Fabric operations */
9349 if (phba->cfg_fof)
9350 lpfc_fof_queue_destroy(phba);
James Smart895427b2017-02-12 13:52:30 -08009351
James Smartda0436e2009-05-22 14:51:39 -04009352 /* Unset mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08009353 if (phba->sli4_hba.mbx_wq)
9354 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
9355
9356 /* Unset NVME LS work queue */
9357 if (phba->sli4_hba.nvmels_wq)
9358 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
9359
James Smartda0436e2009-05-22 14:51:39 -04009360 /* Unset ELS work queue */
Colin Ian King019c0d62017-05-06 23:13:55 +01009361 if (phba->sli4_hba.els_wq)
James Smart895427b2017-02-12 13:52:30 -08009362 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
9363
James Smartda0436e2009-05-22 14:51:39 -04009364 /* Unset unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08009365 if (phba->sli4_hba.hdr_rq)
9366 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
9367 phba->sli4_hba.dat_rq);
9368
James Smartda0436e2009-05-22 14:51:39 -04009369 /* Unset FCP work queue */
James Smart895427b2017-02-12 13:52:30 -08009370 if (phba->sli4_hba.fcp_wq)
9371 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
9372 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[qidx]);
9373
9374 /* Unset NVME work queue */
9375 if (phba->sli4_hba.nvme_wq) {
9376 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
9377 lpfc_wq_destroy(phba, phba->sli4_hba.nvme_wq[qidx]);
James Smart67d12732012-08-03 12:36:13 -04009378 }
James Smart895427b2017-02-12 13:52:30 -08009379
James Smartda0436e2009-05-22 14:51:39 -04009380 /* Unset mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08009381 if (phba->sli4_hba.mbx_cq)
9382 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
9383
James Smartda0436e2009-05-22 14:51:39 -04009384 /* Unset ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08009385 if (phba->sli4_hba.els_cq)
9386 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
9387
9388 /* Unset NVME LS complete queue */
9389 if (phba->sli4_hba.nvmels_cq)
9390 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
9391
9392 /* Unset NVME response complete queue */
9393 if (phba->sli4_hba.nvme_cq)
9394 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
9395 lpfc_cq_destroy(phba, phba->sli4_hba.nvme_cq[qidx]);
9396
James Smartbcb24f62017-11-20 16:00:36 -08009397 if (phba->nvmet_support) {
9398 /* Unset NVMET MRQ queue */
9399 if (phba->sli4_hba.nvmet_mrq_hdr) {
9400 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9401 lpfc_rq_destroy(
9402 phba,
James Smart2d7dbc42017-02-12 13:52:35 -08009403 phba->sli4_hba.nvmet_mrq_hdr[qidx],
9404 phba->sli4_hba.nvmet_mrq_data[qidx]);
James Smartbcb24f62017-11-20 16:00:36 -08009405 }
James Smart2d7dbc42017-02-12 13:52:35 -08009406
James Smartbcb24f62017-11-20 16:00:36 -08009407 /* Unset NVMET CQ Set complete queue */
9408 if (phba->sli4_hba.nvmet_cqset) {
9409 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9410 lpfc_cq_destroy(
9411 phba, phba->sli4_hba.nvmet_cqset[qidx]);
9412 }
James Smart2d7dbc42017-02-12 13:52:35 -08009413 }
9414
James Smartda0436e2009-05-22 14:51:39 -04009415 /* Unset FCP response complete queue */
James Smart895427b2017-02-12 13:52:30 -08009416 if (phba->sli4_hba.fcp_cq)
9417 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
9418 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[qidx]);
9419
James Smartda0436e2009-05-22 14:51:39 -04009420 /* Unset fast-path event queue */
James Smart895427b2017-02-12 13:52:30 -08009421 if (phba->sli4_hba.hba_eq)
9422 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++)
9423 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[qidx]);
James Smartda0436e2009-05-22 14:51:39 -04009424}
9425
9426/**
9427 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
9428 * @phba: pointer to lpfc hba data structure.
9429 *
9430 * This routine is invoked to allocate and set up a pool of completion queue
9431 * events. The body of the completion queue event is a completion queue entry
9432 * CQE. For now, this pool is used for the interrupt service routine to queue
9433 * the following HBA completion queue events for the worker thread to process:
9434 * - Mailbox asynchronous events
9435 * - Receive queue completion unsolicited events
9436 * Later, this can be used for all the slow-path events.
9437 *
9438 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009439 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009440 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04009441 **/
9442static int
9443lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
9444{
9445 struct lpfc_cq_event *cq_event;
9446 int i;
9447
9448 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
9449 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
9450 if (!cq_event)
9451 goto out_pool_create_fail;
9452 list_add_tail(&cq_event->list,
9453 &phba->sli4_hba.sp_cqe_event_pool);
9454 }
9455 return 0;
9456
9457out_pool_create_fail:
9458 lpfc_sli4_cq_event_pool_destroy(phba);
9459 return -ENOMEM;
9460}
9461
9462/**
9463 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
9464 * @phba: pointer to lpfc hba data structure.
9465 *
9466 * This routine is invoked to free the pool of completion queue events at
9467 * driver unload time. Note that, it is the responsibility of the driver
9468 * cleanup routine to free all the outstanding completion-queue events
9469 * allocated from this pool back into the pool before invoking this routine
9470 * to destroy the pool.
9471 **/
9472static void
9473lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
9474{
9475 struct lpfc_cq_event *cq_event, *next_cq_event;
9476
9477 list_for_each_entry_safe(cq_event, next_cq_event,
9478 &phba->sli4_hba.sp_cqe_event_pool, list) {
9479 list_del(&cq_event->list);
9480 kfree(cq_event);
9481 }
9482}
9483
9484/**
9485 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9486 * @phba: pointer to lpfc hba data structure.
9487 *
9488 * This routine is the lock free version of the API invoked to allocate a
9489 * completion-queue event from the free pool.
9490 *
9491 * Return: Pointer to the newly allocated completion-queue event if successful
9492 * NULL otherwise.
9493 **/
9494struct lpfc_cq_event *
9495__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9496{
9497 struct lpfc_cq_event *cq_event = NULL;
9498
9499 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
9500 struct lpfc_cq_event, list);
9501 return cq_event;
9502}
9503
9504/**
9505 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9506 * @phba: pointer to lpfc hba data structure.
9507 *
9508 * This routine is the lock version of the API invoked to allocate a
9509 * completion-queue event from the free pool.
9510 *
9511 * Return: Pointer to the newly allocated completion-queue event if successful
9512 * NULL otherwise.
9513 **/
9514struct lpfc_cq_event *
9515lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9516{
9517 struct lpfc_cq_event *cq_event;
9518 unsigned long iflags;
9519
9520 spin_lock_irqsave(&phba->hbalock, iflags);
9521 cq_event = __lpfc_sli4_cq_event_alloc(phba);
9522 spin_unlock_irqrestore(&phba->hbalock, iflags);
9523 return cq_event;
9524}
9525
9526/**
9527 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9528 * @phba: pointer to lpfc hba data structure.
9529 * @cq_event: pointer to the completion queue event to be freed.
9530 *
9531 * This routine is the lock free version of the API invoked to release a
9532 * completion-queue event back into the free pool.
9533 **/
9534void
9535__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9536 struct lpfc_cq_event *cq_event)
9537{
9538 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
9539}
9540
9541/**
9542 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9543 * @phba: pointer to lpfc hba data structure.
9544 * @cq_event: pointer to the completion queue event to be freed.
9545 *
9546 * This routine is the lock version of the API invoked to release a
9547 * completion-queue event back into the free pool.
9548 **/
9549void
9550lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9551 struct lpfc_cq_event *cq_event)
9552{
9553 unsigned long iflags;
9554 spin_lock_irqsave(&phba->hbalock, iflags);
9555 __lpfc_sli4_cq_event_release(phba, cq_event);
9556 spin_unlock_irqrestore(&phba->hbalock, iflags);
9557}
9558
9559/**
9560 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
9561 * @phba: pointer to lpfc hba data structure.
9562 *
9563 * This routine is to free all the pending completion-queue events to the
9564 * back into the free pool for device reset.
9565 **/
9566static void
9567lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
9568{
9569 LIST_HEAD(cqelist);
9570 struct lpfc_cq_event *cqe;
9571 unsigned long iflags;
9572
9573 /* Retrieve all the pending WCQEs from pending WCQE lists */
9574 spin_lock_irqsave(&phba->hbalock, iflags);
9575 /* Pending FCP XRI abort events */
9576 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
9577 &cqelist);
9578 /* Pending ELS XRI abort events */
9579 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
9580 &cqelist);
9581 /* Pending asynnc events */
9582 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
9583 &cqelist);
9584 spin_unlock_irqrestore(&phba->hbalock, iflags);
9585
9586 while (!list_empty(&cqelist)) {
9587 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
9588 lpfc_sli4_cq_event_release(phba, cqe);
9589 }
9590}
9591
9592/**
9593 * lpfc_pci_function_reset - Reset pci function.
9594 * @phba: pointer to lpfc hba data structure.
9595 *
9596 * This routine is invoked to request a PCI function reset. It will destroys
9597 * all resources assigned to the PCI function which originates this request.
9598 *
9599 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009600 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009601 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009602 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009603 **/
9604int
9605lpfc_pci_function_reset(struct lpfc_hba *phba)
9606{
9607 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05009608 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04009609 uint32_t shdr_status, shdr_add_status;
James Smart2f6fa2c2014-09-03 12:57:08 -04009610 uint32_t rdy_chk;
9611 uint32_t port_reset = 0;
James Smartda0436e2009-05-22 14:51:39 -04009612 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05009613 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -05009614 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -04009615
James Smart2fcee4b2010-12-15 17:57:46 -05009616 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9617 switch (if_type) {
9618 case LPFC_SLI_INTF_IF_TYPE_0:
9619 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
9620 GFP_KERNEL);
9621 if (!mboxq) {
9622 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9623 "0494 Unable to allocate memory for "
9624 "issuing SLI_FUNCTION_RESET mailbox "
9625 "command\n");
9626 return -ENOMEM;
9627 }
9628
9629 /* Setup PCI function reset mailbox-ioctl command */
9630 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9631 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
9632 LPFC_SLI4_MBX_EMBED);
9633 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9634 shdr = (union lpfc_sli4_cfg_shdr *)
9635 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
9636 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9637 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
9638 &shdr->response);
9639 if (rc != MBX_TIMEOUT)
9640 mempool_free(mboxq, phba->mbox_mem_pool);
9641 if (shdr_status || shdr_add_status || rc) {
9642 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9643 "0495 SLI_FUNCTION_RESET mailbox "
9644 "failed with status x%x add_status x%x,"
9645 " mbx status x%x\n",
9646 shdr_status, shdr_add_status, rc);
9647 rc = -ENXIO;
9648 }
9649 break;
9650 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08009651 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2f6fa2c2014-09-03 12:57:08 -04009652wait:
9653 /*
9654 * Poll the Port Status Register and wait for RDY for
9655 * up to 30 seconds. If the port doesn't respond, treat
9656 * it as an error.
9657 */
James Smart77d093f2015-04-07 15:07:08 -04009658 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
James Smart2f6fa2c2014-09-03 12:57:08 -04009659 if (lpfc_readl(phba->sli4_hba.u.if_type2.
9660 STATUSregaddr, &reg_data.word0)) {
9661 rc = -ENODEV;
9662 goto out;
9663 }
9664 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
9665 break;
9666 msleep(20);
9667 }
9668
9669 if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
9670 phba->work_status[0] = readl(
9671 phba->sli4_hba.u.if_type2.ERR1regaddr);
9672 phba->work_status[1] = readl(
9673 phba->sli4_hba.u.if_type2.ERR2regaddr);
9674 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9675 "2890 Port not ready, port status reg "
9676 "0x%x error 1=0x%x, error 2=0x%x\n",
9677 reg_data.word0,
9678 phba->work_status[0],
9679 phba->work_status[1]);
9680 rc = -ENODEV;
9681 goto out;
9682 }
9683
9684 if (!port_reset) {
9685 /*
9686 * Reset the port now
9687 */
James Smart2fcee4b2010-12-15 17:57:46 -05009688 reg_data.word0 = 0;
9689 bf_set(lpfc_sliport_ctrl_end, &reg_data,
9690 LPFC_SLIPORT_LITTLE_ENDIAN);
9691 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
9692 LPFC_SLIPORT_INIT_PORT);
9693 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
9694 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -05009695 /* flush */
James Smart2b81f942012-03-01 22:37:18 -05009696 pci_read_config_word(phba->pcidev,
9697 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -05009698
James Smart2f6fa2c2014-09-03 12:57:08 -04009699 port_reset = 1;
9700 msleep(20);
9701 goto wait;
9702 } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
9703 rc = -ENODEV;
9704 goto out;
James Smart2fcee4b2010-12-15 17:57:46 -05009705 }
9706 break;
James Smart2f6fa2c2014-09-03 12:57:08 -04009707
James Smart2fcee4b2010-12-15 17:57:46 -05009708 case LPFC_SLI_INTF_IF_TYPE_1:
9709 default:
9710 break;
James Smartda0436e2009-05-22 14:51:39 -04009711 }
9712
James Smart73d91e52011-10-10 21:32:10 -04009713out:
James Smart2fcee4b2010-12-15 17:57:46 -05009714 /* Catch the not-ready port failure after a port reset. */
James Smart2f6fa2c2014-09-03 12:57:08 -04009715 if (rc) {
James Smart229adb02013-04-17 20:16:51 -04009716 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9717 "3317 HBA not functional: IP Reset Failed "
James Smart2f6fa2c2014-09-03 12:57:08 -04009718 "try: echo fw_reset > board_mode\n");
James Smart2fcee4b2010-12-15 17:57:46 -05009719 rc = -ENODEV;
James Smart229adb02013-04-17 20:16:51 -04009720 }
James Smart2fcee4b2010-12-15 17:57:46 -05009721
James Smartda0436e2009-05-22 14:51:39 -04009722 return rc;
9723}
9724
9725/**
James Smartda0436e2009-05-22 14:51:39 -04009726 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
9727 * @phba: pointer to lpfc hba data structure.
9728 *
9729 * This routine is invoked to set up the PCI device memory space for device
9730 * with SLI-4 interface spec.
9731 *
9732 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009733 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009734 * other values - error
9735 **/
9736static int
9737lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
9738{
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02009739 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -04009740 unsigned long bar0map_len, bar1map_len, bar2map_len;
9741 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05009742 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04009743
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02009744 if (!pdev)
James Smartda0436e2009-05-22 14:51:39 -04009745 return error;
James Smartda0436e2009-05-22 14:51:39 -04009746
9747 /* Set the device DMA mask size */
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02009748 if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) ||
9749 dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)))
9750 return error;
James Smartda0436e2009-05-22 14:51:39 -04009751
James Smart2fcee4b2010-12-15 17:57:46 -05009752 /*
9753 * The BARs and register set definitions and offset locations are
9754 * dependent on the if_type.
9755 */
9756 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
9757 &phba->sli4_hba.sli_intf.word0)) {
9758 return error;
9759 }
9760
9761 /* There is no SLI3 failback for SLI4 devices. */
9762 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
9763 LPFC_SLI_INTF_VALID) {
9764 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9765 "2894 SLI_INTF reg contents invalid "
9766 "sli_intf reg 0x%x\n",
9767 phba->sli4_hba.sli_intf.word0);
9768 return error;
9769 }
9770
9771 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9772 /*
9773 * Get the bus address of SLI4 device Bar regions and the
9774 * number of bytes required by each mapping. The mapping of the
9775 * particular PCI BARs regions is dependent on the type of
9776 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04009777 */
James Smartf5ca6f22013-09-06 12:21:09 -04009778 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
9779 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
9780 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
James Smart2fcee4b2010-12-15 17:57:46 -05009781
9782 /*
9783 * Map SLI4 PCI Config Space Register base to a kernel virtual
9784 * addr
9785 */
9786 phba->sli4_hba.conf_regs_memmap_p =
9787 ioremap(phba->pci_bar0_map, bar0map_len);
9788 if (!phba->sli4_hba.conf_regs_memmap_p) {
9789 dev_printk(KERN_ERR, &pdev->dev,
9790 "ioremap failed for SLI4 PCI config "
9791 "registers.\n");
9792 goto out;
9793 }
James Smartf5ca6f22013-09-06 12:21:09 -04009794 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05009795 /* Set up BAR0 PCI config space register memory map */
9796 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05009797 } else {
9798 phba->pci_bar0_map = pci_resource_start(pdev, 1);
9799 bar0map_len = pci_resource_len(pdev, 1);
James Smart27d6ac02018-02-22 08:18:42 -08009800 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
James Smart2fcee4b2010-12-15 17:57:46 -05009801 dev_printk(KERN_ERR, &pdev->dev,
9802 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
9803 goto out;
9804 }
9805 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04009806 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05009807 if (!phba->sli4_hba.conf_regs_memmap_p) {
9808 dev_printk(KERN_ERR, &pdev->dev,
9809 "ioremap failed for SLI4 PCI config "
9810 "registers.\n");
9811 goto out;
9812 }
9813 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04009814 }
9815
James Smarte4b97942017-11-20 16:00:31 -08009816 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
9817 if (pci_resource_start(pdev, PCI_64BIT_BAR2)) {
9818 /*
9819 * Map SLI4 if type 0 HBA Control Register base to a
9820 * kernel virtual address and setup the registers.
9821 */
9822 phba->pci_bar1_map = pci_resource_start(pdev,
9823 PCI_64BIT_BAR2);
9824 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
9825 phba->sli4_hba.ctrl_regs_memmap_p =
9826 ioremap(phba->pci_bar1_map,
9827 bar1map_len);
9828 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
9829 dev_err(&pdev->dev,
9830 "ioremap failed for SLI4 HBA "
9831 "control registers.\n");
9832 error = -ENOMEM;
9833 goto out_iounmap_conf;
9834 }
9835 phba->pci_bar2_memmap_p =
9836 phba->sli4_hba.ctrl_regs_memmap_p;
James Smart27d6ac02018-02-22 08:18:42 -08009837 lpfc_sli4_bar1_register_memmap(phba, if_type);
James Smarte4b97942017-11-20 16:00:31 -08009838 } else {
9839 error = -ENOMEM;
James Smart2fcee4b2010-12-15 17:57:46 -05009840 goto out_iounmap_conf;
9841 }
James Smartda0436e2009-05-22 14:51:39 -04009842 }
9843
James Smart27d6ac02018-02-22 08:18:42 -08009844 if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) &&
9845 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
9846 /*
9847 * Map SLI4 if type 6 HBA Doorbell Register base to a kernel
9848 * virtual address and setup the registers.
9849 */
9850 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
9851 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
9852 phba->sli4_hba.drbl_regs_memmap_p =
9853 ioremap(phba->pci_bar1_map, bar1map_len);
9854 if (!phba->sli4_hba.drbl_regs_memmap_p) {
9855 dev_err(&pdev->dev,
9856 "ioremap failed for SLI4 HBA doorbell registers.\n");
9857 goto out_iounmap_conf;
9858 }
9859 phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
9860 lpfc_sli4_bar1_register_memmap(phba, if_type);
9861 }
9862
James Smarte4b97942017-11-20 16:00:31 -08009863 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
9864 if (pci_resource_start(pdev, PCI_64BIT_BAR4)) {
9865 /*
9866 * Map SLI4 if type 0 HBA Doorbell Register base to
9867 * a kernel virtual address and setup the registers.
9868 */
9869 phba->pci_bar2_map = pci_resource_start(pdev,
9870 PCI_64BIT_BAR4);
9871 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
9872 phba->sli4_hba.drbl_regs_memmap_p =
9873 ioremap(phba->pci_bar2_map,
9874 bar2map_len);
9875 if (!phba->sli4_hba.drbl_regs_memmap_p) {
9876 dev_err(&pdev->dev,
9877 "ioremap failed for SLI4 HBA"
9878 " doorbell registers.\n");
9879 error = -ENOMEM;
9880 goto out_iounmap_ctrl;
9881 }
9882 phba->pci_bar4_memmap_p =
9883 phba->sli4_hba.drbl_regs_memmap_p;
9884 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
9885 if (error)
9886 goto out_iounmap_all;
9887 } else {
9888 error = -ENOMEM;
James Smart2fcee4b2010-12-15 17:57:46 -05009889 goto out_iounmap_all;
James Smarte4b97942017-11-20 16:00:31 -08009890 }
James Smartda0436e2009-05-22 14:51:39 -04009891 }
9892
James Smart1351e692018-02-22 08:18:43 -08009893 if (if_type == LPFC_SLI_INTF_IF_TYPE_6 &&
9894 pci_resource_start(pdev, PCI_64BIT_BAR4)) {
9895 /*
9896 * Map SLI4 if type 6 HBA DPP Register base to a kernel
9897 * virtual address and setup the registers.
9898 */
9899 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
9900 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
9901 phba->sli4_hba.dpp_regs_memmap_p =
9902 ioremap(phba->pci_bar2_map, bar2map_len);
9903 if (!phba->sli4_hba.dpp_regs_memmap_p) {
9904 dev_err(&pdev->dev,
9905 "ioremap failed for SLI4 HBA dpp registers.\n");
9906 goto out_iounmap_ctrl;
9907 }
9908 phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
9909 }
9910
James Smartb71413d2018-02-22 08:18:40 -08009911 /* Set up the EQ/CQ register handeling functions now */
James Smart27d6ac02018-02-22 08:18:42 -08009912 switch (if_type) {
9913 case LPFC_SLI_INTF_IF_TYPE_0:
9914 case LPFC_SLI_INTF_IF_TYPE_2:
James Smartb71413d2018-02-22 08:18:40 -08009915 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr;
9916 phba->sli4_hba.sli4_eq_release = lpfc_sli4_eq_release;
9917 phba->sli4_hba.sli4_cq_release = lpfc_sli4_cq_release;
James Smart27d6ac02018-02-22 08:18:42 -08009918 break;
9919 case LPFC_SLI_INTF_IF_TYPE_6:
9920 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_if6_eq_clr_intr;
9921 phba->sli4_hba.sli4_eq_release = lpfc_sli4_if6_eq_release;
9922 phba->sli4_hba.sli4_cq_release = lpfc_sli4_if6_cq_release;
9923 break;
9924 default:
9925 break;
James Smartb71413d2018-02-22 08:18:40 -08009926 }
9927
James Smartda0436e2009-05-22 14:51:39 -04009928 return 0;
9929
9930out_iounmap_all:
9931 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9932out_iounmap_ctrl:
9933 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9934out_iounmap_conf:
9935 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9936out:
9937 return error;
9938}
9939
9940/**
9941 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
9942 * @phba: pointer to lpfc hba data structure.
9943 *
9944 * This routine is invoked to unset the PCI device memory space for device
9945 * with SLI-4 interface spec.
9946 **/
9947static void
9948lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
9949{
James Smart2e90f4b2011-12-13 13:22:37 -05009950 uint32_t if_type;
9951 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -04009952
James Smart2e90f4b2011-12-13 13:22:37 -05009953 switch (if_type) {
9954 case LPFC_SLI_INTF_IF_TYPE_0:
9955 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9956 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9957 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9958 break;
9959 case LPFC_SLI_INTF_IF_TYPE_2:
9960 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9961 break;
James Smart27d6ac02018-02-22 08:18:42 -08009962 case LPFC_SLI_INTF_IF_TYPE_6:
9963 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9964 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9965 break;
James Smart2e90f4b2011-12-13 13:22:37 -05009966 case LPFC_SLI_INTF_IF_TYPE_1:
9967 default:
9968 dev_printk(KERN_ERR, &phba->pcidev->dev,
9969 "FATAL - unsupported SLI4 interface type - %d\n",
9970 if_type);
9971 break;
9972 }
James Smartda0436e2009-05-22 14:51:39 -04009973}
9974
9975/**
James Smart3772a992009-05-22 14:50:54 -04009976 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
9977 * @phba: pointer to lpfc hba data structure.
9978 *
9979 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009980 * with SLI-3 interface specs.
James Smart3772a992009-05-22 14:50:54 -04009981 *
9982 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009983 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009984 * other values - error
9985 **/
9986static int
9987lpfc_sli_enable_msix(struct lpfc_hba *phba)
9988{
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009989 int rc;
James Smart3772a992009-05-22 14:50:54 -04009990 LPFC_MBOXQ_t *pmb;
9991
9992 /* Set up MSI-X multi-message vectors */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009993 rc = pci_alloc_irq_vectors(phba->pcidev,
9994 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
9995 if (rc < 0) {
James Smart3772a992009-05-22 14:50:54 -04009996 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9997 "0420 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009998 goto vec_fail_out;
James Smart3772a992009-05-22 14:50:54 -04009999 }
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010000
James Smart3772a992009-05-22 14:50:54 -040010001 /*
10002 * Assign MSI-X vectors to interrupt handlers
10003 */
10004
10005 /* vector-0 is associated to slow-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010006 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
James Smarted243d32015-05-21 13:55:25 -040010007 &lpfc_sli_sp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -040010008 LPFC_SP_DRIVER_HANDLER_NAME, phba);
10009 if (rc) {
10010 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10011 "0421 MSI-X slow-path request_irq failed "
10012 "(%d)\n", rc);
10013 goto msi_fail_out;
10014 }
10015
10016 /* vector-1 is associated to fast-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010017 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
James Smarted243d32015-05-21 13:55:25 -040010018 &lpfc_sli_fp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -040010019 LPFC_FP_DRIVER_HANDLER_NAME, phba);
10020
10021 if (rc) {
10022 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10023 "0429 MSI-X fast-path request_irq failed "
10024 "(%d)\n", rc);
10025 goto irq_fail_out;
10026 }
10027
10028 /*
10029 * Configure HBA MSI-X attention conditions to messages
10030 */
10031 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10032
10033 if (!pmb) {
10034 rc = -ENOMEM;
10035 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10036 "0474 Unable to allocate memory for issuing "
10037 "MBOX_CONFIG_MSI command\n");
10038 goto mem_fail_out;
10039 }
10040 rc = lpfc_config_msi(phba, pmb);
10041 if (rc)
10042 goto mbx_fail_out;
10043 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
10044 if (rc != MBX_SUCCESS) {
10045 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
10046 "0351 Config MSI mailbox command failed, "
10047 "mbxCmd x%x, mbxStatus x%x\n",
10048 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
10049 goto mbx_fail_out;
10050 }
10051
10052 /* Free memory allocated for mailbox command */
10053 mempool_free(pmb, phba->mbox_mem_pool);
10054 return rc;
10055
10056mbx_fail_out:
10057 /* Free memory allocated for mailbox command */
10058 mempool_free(pmb, phba->mbox_mem_pool);
10059
10060mem_fail_out:
10061 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010062 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
James Smart3772a992009-05-22 14:50:54 -040010063
10064irq_fail_out:
10065 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010066 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
James Smart3772a992009-05-22 14:50:54 -040010067
10068msi_fail_out:
10069 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010070 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +020010071
10072vec_fail_out:
James Smart3772a992009-05-22 14:50:54 -040010073 return rc;
10074}
10075
10076/**
James Smart3772a992009-05-22 14:50:54 -040010077 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
10078 * @phba: pointer to lpfc hba data structure.
10079 *
10080 * This routine is invoked to enable the MSI interrupt mode to device with
10081 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
10082 * enable the MSI vector. The device driver is responsible for calling the
10083 * request_irq() to register MSI vector with a interrupt the handler, which
10084 * is done in this function.
10085 *
10086 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010087 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -040010088 * other values - error
10089 */
10090static int
10091lpfc_sli_enable_msi(struct lpfc_hba *phba)
10092{
10093 int rc;
10094
10095 rc = pci_enable_msi(phba->pcidev);
10096 if (!rc)
10097 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10098 "0462 PCI enable MSI mode success.\n");
10099 else {
10100 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10101 "0471 PCI enable MSI mode failed (%d)\n", rc);
10102 return rc;
10103 }
10104
10105 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
James Smarted243d32015-05-21 13:55:25 -040010106 0, LPFC_DRIVER_NAME, phba);
James Smart3772a992009-05-22 14:50:54 -040010107 if (rc) {
10108 pci_disable_msi(phba->pcidev);
10109 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10110 "0478 MSI request_irq failed (%d)\n", rc);
10111 }
10112 return rc;
10113}
10114
10115/**
James Smart3772a992009-05-22 14:50:54 -040010116 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
10117 * @phba: pointer to lpfc hba data structure.
10118 *
10119 * This routine is invoked to enable device interrupt and associate driver's
10120 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
10121 * spec. Depends on the interrupt mode configured to the driver, the driver
10122 * will try to fallback from the configured interrupt mode to an interrupt
10123 * mode which is supported by the platform, kernel, and device in the order
10124 * of:
10125 * MSI-X -> MSI -> IRQ.
10126 *
10127 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010128 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -040010129 * other values - error
10130 **/
10131static uint32_t
10132lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
10133{
10134 uint32_t intr_mode = LPFC_INTR_ERROR;
10135 int retval;
10136
10137 if (cfg_mode == 2) {
10138 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
10139 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
10140 if (!retval) {
10141 /* Now, try to enable MSI-X interrupt mode */
10142 retval = lpfc_sli_enable_msix(phba);
10143 if (!retval) {
10144 /* Indicate initialization to MSI-X mode */
10145 phba->intr_type = MSIX;
10146 intr_mode = 2;
10147 }
10148 }
10149 }
10150
10151 /* Fallback to MSI if MSI-X initialization failed */
10152 if (cfg_mode >= 1 && phba->intr_type == NONE) {
10153 retval = lpfc_sli_enable_msi(phba);
10154 if (!retval) {
10155 /* Indicate initialization to MSI mode */
10156 phba->intr_type = MSI;
10157 intr_mode = 1;
10158 }
10159 }
10160
10161 /* Fallback to INTx if both MSI-X/MSI initalization failed */
10162 if (phba->intr_type == NONE) {
10163 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
10164 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
10165 if (!retval) {
10166 /* Indicate initialization to INTx mode */
10167 phba->intr_type = INTx;
10168 intr_mode = 0;
10169 }
10170 }
10171 return intr_mode;
10172}
10173
10174/**
10175 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
10176 * @phba: pointer to lpfc hba data structure.
10177 *
10178 * This routine is invoked to disable device interrupt and disassociate the
10179 * driver's interrupt handler(s) from interrupt vector(s) to device with
10180 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
10181 * release the interrupt vector(s) for the message signaled interrupt.
10182 **/
10183static void
10184lpfc_sli_disable_intr(struct lpfc_hba *phba)
10185{
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010186 int nr_irqs, i;
10187
James Smart3772a992009-05-22 14:50:54 -040010188 if (phba->intr_type == MSIX)
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010189 nr_irqs = LPFC_MSIX_VECTORS;
10190 else
10191 nr_irqs = 1;
10192
10193 for (i = 0; i < nr_irqs; i++)
10194 free_irq(pci_irq_vector(phba->pcidev, i), phba);
10195 pci_free_irq_vectors(phba->pcidev);
James Smart3772a992009-05-22 14:50:54 -040010196
10197 /* Reset interrupt management states */
10198 phba->intr_type = NONE;
10199 phba->sli.slistat.sli_intr = 0;
James Smart3772a992009-05-22 14:50:54 -040010200}
10201
10202/**
James Smart895427b2017-02-12 13:52:30 -080010203 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
James Smart7bb03bb2013-04-17 20:19:16 -040010204 * @phba: pointer to lpfc hba data structure.
James Smart895427b2017-02-12 13:52:30 -080010205 * @vectors: number of msix vectors allocated.
James Smart7bb03bb2013-04-17 20:19:16 -040010206 *
James Smart895427b2017-02-12 13:52:30 -080010207 * The routine will figure out the CPU affinity assignment for every
10208 * MSI-X vector allocated for the HBA. The hba_eq_hdl will be updated
10209 * with a pointer to the CPU mask that defines ALL the CPUs this vector
10210 * can be associated with. If the vector can be unquely associated with
10211 * a single CPU, that CPU will be recorded in hba_eq_hdl[index].cpu.
10212 * In addition, the CPU to IO channel mapping will be calculated
10213 * and the phba->sli4_hba.cpu_map array will reflect this.
James Smart7bb03bb2013-04-17 20:19:16 -040010214 */
James Smart895427b2017-02-12 13:52:30 -080010215static void
10216lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
James Smart7bb03bb2013-04-17 20:19:16 -040010217{
10218 struct lpfc_vector_map_info *cpup;
James Smart895427b2017-02-12 13:52:30 -080010219 int index = 0;
10220 int vec = 0;
James Smart7bb03bb2013-04-17 20:19:16 -040010221 int cpu;
James Smart7bb03bb2013-04-17 20:19:16 -040010222#ifdef CONFIG_X86
10223 struct cpuinfo_x86 *cpuinfo;
10224#endif
James Smart7bb03bb2013-04-17 20:19:16 -040010225
10226 /* Init cpu_map array */
10227 memset(phba->sli4_hba.cpu_map, 0xff,
10228 (sizeof(struct lpfc_vector_map_info) *
James Smart895427b2017-02-12 13:52:30 -080010229 phba->sli4_hba.num_present_cpu));
James Smart7bb03bb2013-04-17 20:19:16 -040010230
10231 /* Update CPU map with physical id and core id of each CPU */
10232 cpup = phba->sli4_hba.cpu_map;
10233 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
10234#ifdef CONFIG_X86
10235 cpuinfo = &cpu_data(cpu);
10236 cpup->phys_id = cpuinfo->phys_proc_id;
10237 cpup->core_id = cpuinfo->cpu_core_id;
10238#else
10239 /* No distinction between CPUs for other platforms */
10240 cpup->phys_id = 0;
10241 cpup->core_id = 0;
10242#endif
James Smart895427b2017-02-12 13:52:30 -080010243 cpup->channel_id = index; /* For now round robin */
10244 cpup->irq = pci_irq_vector(phba->pcidev, vec);
10245 vec++;
10246 if (vec >= vectors)
10247 vec = 0;
10248 index++;
10249 if (index >= phba->cfg_fcp_io_channel)
10250 index = 0;
James Smart7bb03bb2013-04-17 20:19:16 -040010251 cpup++;
10252 }
James Smart7bb03bb2013-04-17 20:19:16 -040010253}
10254
10255
10256/**
James Smartda0436e2009-05-22 14:51:39 -040010257 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
10258 * @phba: pointer to lpfc hba data structure.
10259 *
10260 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010261 * with SLI-4 interface spec.
James Smartda0436e2009-05-22 14:51:39 -040010262 *
10263 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010264 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040010265 * other values - error
10266 **/
10267static int
10268lpfc_sli4_enable_msix(struct lpfc_hba *phba)
10269{
James Smart75baf692010-06-08 18:31:21 -040010270 int vectors, rc, index;
James Smartb83d0052017-06-01 21:07:05 -070010271 char *name;
James Smartda0436e2009-05-22 14:51:39 -040010272
10273 /* Set up MSI-X multi-message vectors */
James Smart895427b2017-02-12 13:52:30 -080010274 vectors = phba->io_channel_irqs;
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010275 if (phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -050010276 vectors++;
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010277
James Smartf358dd02017-02-12 13:52:34 -080010278 rc = pci_alloc_irq_vectors(phba->pcidev,
10279 (phba->nvmet_support) ? 1 : 2,
10280 vectors, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY);
Alexander Gordeev4f871e12014-09-03 12:56:29 -040010281 if (rc < 0) {
James Smartda0436e2009-05-22 14:51:39 -040010282 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10283 "0484 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +020010284 goto vec_fail_out;
James Smartda0436e2009-05-22 14:51:39 -040010285 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -040010286 vectors = rc;
James Smart75baf692010-06-08 18:31:21 -040010287
James Smart7bb03bb2013-04-17 20:19:16 -040010288 /* Assign MSI-X vectors to interrupt handlers */
James Smart67d12732012-08-03 12:36:13 -040010289 for (index = 0; index < vectors; index++) {
James Smartb83d0052017-06-01 21:07:05 -070010290 name = phba->sli4_hba.hba_eq_hdl[index].handler_name;
10291 memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ);
10292 snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ,
James Smart4305f182012-08-03 12:36:33 -040010293 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -040010294
James Smart895427b2017-02-12 13:52:30 -080010295 phba->sli4_hba.hba_eq_hdl[index].idx = index;
10296 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
10297 atomic_set(&phba->sli4_hba.hba_eq_hdl[index].hba_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -050010298 if (phba->cfg_fof && (index == (vectors - 1)))
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010299 rc = request_irq(pci_irq_vector(phba->pcidev, index),
James Smarted243d32015-05-21 13:55:25 -040010300 &lpfc_sli4_fof_intr_handler, 0,
James Smartb83d0052017-06-01 21:07:05 -070010301 name,
James Smart895427b2017-02-12 13:52:30 -080010302 &phba->sli4_hba.hba_eq_hdl[index]);
James Smart1ba981f2014-02-20 09:56:45 -050010303 else
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010304 rc = request_irq(pci_irq_vector(phba->pcidev, index),
James Smarted243d32015-05-21 13:55:25 -040010305 &lpfc_sli4_hba_intr_handler, 0,
James Smartb83d0052017-06-01 21:07:05 -070010306 name,
James Smart895427b2017-02-12 13:52:30 -080010307 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -040010308 if (rc) {
10309 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10310 "0486 MSI-X fast-path (%d) "
10311 "request_irq failed (%d)\n", index, rc);
10312 goto cfg_fail_out;
10313 }
10314 }
10315
James Smart1ba981f2014-02-20 09:56:45 -050010316 if (phba->cfg_fof)
10317 vectors--;
10318
James Smart895427b2017-02-12 13:52:30 -080010319 if (vectors != phba->io_channel_irqs) {
James Smart82c3e9b2012-09-29 11:29:50 -040010320 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10321 "3238 Reducing IO channels to match number of "
10322 "MSI-X vectors, requested %d got %d\n",
James Smart895427b2017-02-12 13:52:30 -080010323 phba->io_channel_irqs, vectors);
10324 if (phba->cfg_fcp_io_channel > vectors)
10325 phba->cfg_fcp_io_channel = vectors;
10326 if (phba->cfg_nvme_io_channel > vectors)
10327 phba->cfg_nvme_io_channel = vectors;
10328 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
10329 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
10330 else
10331 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
James Smart82c3e9b2012-09-29 11:29:50 -040010332 }
James Smart895427b2017-02-12 13:52:30 -080010333 lpfc_cpu_affinity_check(phba, vectors);
James Smart7bb03bb2013-04-17 20:19:16 -040010334
James Smartda0436e2009-05-22 14:51:39 -040010335 return rc;
10336
10337cfg_fail_out:
10338 /* free the irq already requested */
James Smart895427b2017-02-12 13:52:30 -080010339 for (--index; index >= 0; index--)
10340 free_irq(pci_irq_vector(phba->pcidev, index),
10341 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -040010342
James Smartda0436e2009-05-22 14:51:39 -040010343 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010344 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +020010345
10346vec_fail_out:
James Smartda0436e2009-05-22 14:51:39 -040010347 return rc;
10348}
10349
10350/**
James Smartda0436e2009-05-22 14:51:39 -040010351 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
10352 * @phba: pointer to lpfc hba data structure.
10353 *
10354 * This routine is invoked to enable the MSI interrupt mode to device with
10355 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
10356 * to enable the MSI vector. The device driver is responsible for calling
10357 * the request_irq() to register MSI vector with a interrupt the handler,
10358 * which is done in this function.
10359 *
10360 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010361 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040010362 * other values - error
10363 **/
10364static int
10365lpfc_sli4_enable_msi(struct lpfc_hba *phba)
10366{
10367 int rc, index;
10368
10369 rc = pci_enable_msi(phba->pcidev);
10370 if (!rc)
10371 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10372 "0487 PCI enable MSI mode success.\n");
10373 else {
10374 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10375 "0488 PCI enable MSI mode failed (%d)\n", rc);
10376 return rc;
10377 }
10378
10379 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
James Smarted243d32015-05-21 13:55:25 -040010380 0, LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -040010381 if (rc) {
10382 pci_disable_msi(phba->pcidev);
10383 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10384 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -040010385 return rc;
James Smartda0436e2009-05-22 14:51:39 -040010386 }
10387
James Smart895427b2017-02-12 13:52:30 -080010388 for (index = 0; index < phba->io_channel_irqs; index++) {
10389 phba->sli4_hba.hba_eq_hdl[index].idx = index;
10390 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smartda0436e2009-05-22 14:51:39 -040010391 }
10392
James Smart1ba981f2014-02-20 09:56:45 -050010393 if (phba->cfg_fof) {
James Smart895427b2017-02-12 13:52:30 -080010394 phba->sli4_hba.hba_eq_hdl[index].idx = index;
10395 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smart1ba981f2014-02-20 09:56:45 -050010396 }
James Smart75baf692010-06-08 18:31:21 -040010397 return 0;
James Smartda0436e2009-05-22 14:51:39 -040010398}
10399
10400/**
James Smartda0436e2009-05-22 14:51:39 -040010401 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
10402 * @phba: pointer to lpfc hba data structure.
10403 *
10404 * This routine is invoked to enable device interrupt and associate driver's
10405 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
10406 * interface spec. Depends on the interrupt mode configured to the driver,
10407 * the driver will try to fallback from the configured interrupt mode to an
10408 * interrupt mode which is supported by the platform, kernel, and device in
10409 * the order of:
10410 * MSI-X -> MSI -> IRQ.
10411 *
10412 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010413 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040010414 * other values - error
10415 **/
10416static uint32_t
10417lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
10418{
10419 uint32_t intr_mode = LPFC_INTR_ERROR;
James Smart895427b2017-02-12 13:52:30 -080010420 int retval, idx;
James Smartda0436e2009-05-22 14:51:39 -040010421
10422 if (cfg_mode == 2) {
10423 /* Preparation before conf_msi mbox cmd */
10424 retval = 0;
10425 if (!retval) {
10426 /* Now, try to enable MSI-X interrupt mode */
10427 retval = lpfc_sli4_enable_msix(phba);
10428 if (!retval) {
10429 /* Indicate initialization to MSI-X mode */
10430 phba->intr_type = MSIX;
10431 intr_mode = 2;
10432 }
10433 }
10434 }
10435
10436 /* Fallback to MSI if MSI-X initialization failed */
10437 if (cfg_mode >= 1 && phba->intr_type == NONE) {
10438 retval = lpfc_sli4_enable_msi(phba);
10439 if (!retval) {
10440 /* Indicate initialization to MSI mode */
10441 phba->intr_type = MSI;
10442 intr_mode = 1;
10443 }
10444 }
10445
10446 /* Fallback to INTx if both MSI-X/MSI initalization failed */
10447 if (phba->intr_type == NONE) {
10448 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
10449 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
10450 if (!retval) {
James Smart895427b2017-02-12 13:52:30 -080010451 struct lpfc_hba_eq_hdl *eqhdl;
10452
James Smartda0436e2009-05-22 14:51:39 -040010453 /* Indicate initialization to INTx mode */
10454 phba->intr_type = INTx;
10455 intr_mode = 0;
James Smart895427b2017-02-12 13:52:30 -080010456
10457 for (idx = 0; idx < phba->io_channel_irqs; idx++) {
10458 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
10459 eqhdl->idx = idx;
10460 eqhdl->phba = phba;
10461 atomic_set(&eqhdl->hba_eq_in_use, 1);
James Smartda0436e2009-05-22 14:51:39 -040010462 }
James Smart1ba981f2014-02-20 09:56:45 -050010463 if (phba->cfg_fof) {
James Smart895427b2017-02-12 13:52:30 -080010464 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
10465 eqhdl->idx = idx;
10466 eqhdl->phba = phba;
10467 atomic_set(&eqhdl->hba_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -050010468 }
James Smartda0436e2009-05-22 14:51:39 -040010469 }
10470 }
10471 return intr_mode;
10472}
10473
10474/**
10475 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
10476 * @phba: pointer to lpfc hba data structure.
10477 *
10478 * This routine is invoked to disable device interrupt and disassociate
10479 * the driver's interrupt handler(s) from interrupt vector(s) to device
10480 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
10481 * will release the interrupt vector(s) for the message signaled interrupt.
10482 **/
10483static void
10484lpfc_sli4_disable_intr(struct lpfc_hba *phba)
10485{
10486 /* Disable the currently initialized interrupt mode */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010487 if (phba->intr_type == MSIX) {
10488 int index;
10489
10490 /* Free up MSI-X multi-message vectors */
James Smart895427b2017-02-12 13:52:30 -080010491 for (index = 0; index < phba->io_channel_irqs; index++)
10492 free_irq(pci_irq_vector(phba->pcidev, index),
10493 &phba->sli4_hba.hba_eq_hdl[index]);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010494
10495 if (phba->cfg_fof)
James Smart895427b2017-02-12 13:52:30 -080010496 free_irq(pci_irq_vector(phba->pcidev, index),
10497 &phba->sli4_hba.hba_eq_hdl[index]);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010498 } else {
James Smartda0436e2009-05-22 14:51:39 -040010499 free_irq(phba->pcidev->irq, phba);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010500 }
10501
10502 pci_free_irq_vectors(phba->pcidev);
James Smartda0436e2009-05-22 14:51:39 -040010503
10504 /* Reset interrupt management states */
10505 phba->intr_type = NONE;
10506 phba->sli.slistat.sli_intr = 0;
James Smartda0436e2009-05-22 14:51:39 -040010507}
10508
10509/**
James Smart3772a992009-05-22 14:50:54 -040010510 * lpfc_unset_hba - Unset SLI3 hba device initialization
10511 * @phba: pointer to lpfc hba data structure.
10512 *
10513 * This routine is invoked to unset the HBA device initialization steps to
10514 * a device with SLI-3 interface spec.
10515 **/
10516static void
10517lpfc_unset_hba(struct lpfc_hba *phba)
10518{
10519 struct lpfc_vport *vport = phba->pport;
10520 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
10521
10522 spin_lock_irq(shost->host_lock);
10523 vport->load_flag |= FC_UNLOADING;
10524 spin_unlock_irq(shost->host_lock);
10525
James Smart72859902012-01-18 16:25:38 -050010526 kfree(phba->vpi_bmask);
10527 kfree(phba->vpi_ids);
10528
James Smart3772a992009-05-22 14:50:54 -040010529 lpfc_stop_hba_timers(phba);
10530
10531 phba->pport->work_port_events = 0;
10532
10533 lpfc_sli_hba_down(phba);
10534
10535 lpfc_sli_brdrestart(phba);
10536
10537 lpfc_sli_disable_intr(phba);
10538
10539 return;
10540}
10541
10542/**
James Smart5af5eee2010-10-22 11:06:38 -040010543 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
10544 * @phba: Pointer to HBA context object.
10545 *
10546 * This function is called in the SLI4 code path to wait for completion
10547 * of device's XRIs exchange busy. It will check the XRI exchange busy
10548 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
10549 * that, it will check the XRI exchange busy on outstanding FCP and ELS
10550 * I/Os every 30 seconds, log error message, and wait forever. Only when
10551 * all XRI exchange busy complete, the driver unload shall proceed with
10552 * invoking the function reset ioctl mailbox command to the CNA and the
10553 * the rest of the driver unload resource release.
10554 **/
10555static void
10556lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
10557{
10558 int wait_time = 0;
James Smart895427b2017-02-12 13:52:30 -080010559 int nvme_xri_cmpl = 1;
James Smart86c67372017-04-21 16:05:04 -070010560 int nvmet_xri_cmpl = 1;
James Smart895427b2017-02-12 13:52:30 -080010561 int fcp_xri_cmpl = 1;
James Smart5af5eee2010-10-22 11:06:38 -040010562 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
10563
James Smartc3725bd2017-11-20 16:00:42 -080010564 /* Driver just aborted IOs during the hba_unset process. Pause
10565 * here to give the HBA time to complete the IO and get entries
10566 * into the abts lists.
10567 */
10568 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5);
10569
10570 /* Wait for NVME pending IO to flush back to transport. */
10571 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
10572 lpfc_nvme_wait_for_io_drain(phba);
10573
James Smart895427b2017-02-12 13:52:30 -080010574 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
10575 fcp_xri_cmpl =
10576 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
James Smart86c67372017-04-21 16:05:04 -070010577 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -080010578 nvme_xri_cmpl =
10579 list_empty(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
James Smart86c67372017-04-21 16:05:04 -070010580 nvmet_xri_cmpl =
10581 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
10582 }
James Smart895427b2017-02-12 13:52:30 -080010583
James Smartf358dd02017-02-12 13:52:34 -080010584 while (!fcp_xri_cmpl || !els_xri_cmpl || !nvme_xri_cmpl ||
10585 !nvmet_xri_cmpl) {
James Smart5af5eee2010-10-22 11:06:38 -040010586 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
James Smart68c9b552018-06-26 08:24:25 -070010587 if (!nvmet_xri_cmpl)
10588 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10589 "6424 NVMET XRI exchange busy "
10590 "wait time: %d seconds.\n",
10591 wait_time/1000);
James Smart895427b2017-02-12 13:52:30 -080010592 if (!nvme_xri_cmpl)
10593 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10594 "6100 NVME XRI exchange busy "
10595 "wait time: %d seconds.\n",
10596 wait_time/1000);
James Smart5af5eee2010-10-22 11:06:38 -040010597 if (!fcp_xri_cmpl)
10598 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10599 "2877 FCP XRI exchange busy "
10600 "wait time: %d seconds.\n",
10601 wait_time/1000);
10602 if (!els_xri_cmpl)
10603 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10604 "2878 ELS XRI exchange busy "
10605 "wait time: %d seconds.\n",
10606 wait_time/1000);
10607 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
10608 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
10609 } else {
10610 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
10611 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
10612 }
James Smart86c67372017-04-21 16:05:04 -070010613 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -080010614 nvme_xri_cmpl = list_empty(
10615 &phba->sli4_hba.lpfc_abts_nvme_buf_list);
James Smart86c67372017-04-21 16:05:04 -070010616 nvmet_xri_cmpl = list_empty(
10617 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
10618 }
James Smart895427b2017-02-12 13:52:30 -080010619
10620 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
10621 fcp_xri_cmpl = list_empty(
10622 &phba->sli4_hba.lpfc_abts_scsi_buf_list);
10623
James Smart5af5eee2010-10-22 11:06:38 -040010624 els_xri_cmpl =
10625 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -080010626
James Smart5af5eee2010-10-22 11:06:38 -040010627 }
10628}
10629
10630/**
James Smartda0436e2009-05-22 14:51:39 -040010631 * lpfc_sli4_hba_unset - Unset the fcoe hba
10632 * @phba: Pointer to HBA context object.
10633 *
10634 * This function is called in the SLI4 code path to reset the HBA's FCoE
10635 * function. The caller is not required to hold any lock. This routine
10636 * issues PCI function reset mailbox command to reset the FCoE function.
10637 * At the end of the function, it calls lpfc_hba_down_post function to
10638 * free any pending commands.
10639 **/
10640static void
10641lpfc_sli4_hba_unset(struct lpfc_hba *phba)
10642{
10643 int wait_cnt = 0;
10644 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -040010645 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -040010646
10647 lpfc_stop_hba_timers(phba);
10648 phba->sli4_hba.intr_enable = 0;
10649
10650 /*
10651 * Gracefully wait out the potential current outstanding asynchronous
10652 * mailbox command.
10653 */
10654
10655 /* First, block any pending async mailbox command from posted */
10656 spin_lock_irq(&phba->hbalock);
10657 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
10658 spin_unlock_irq(&phba->hbalock);
10659 /* Now, trying to wait it out if we can */
10660 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
10661 msleep(10);
10662 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
10663 break;
10664 }
10665 /* Forcefully release the outstanding mailbox command if timed out */
10666 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
10667 spin_lock_irq(&phba->hbalock);
10668 mboxq = phba->sli.mbox_active;
10669 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
10670 __lpfc_mbox_cmpl_put(phba, mboxq);
10671 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
10672 phba->sli.mbox_active = NULL;
10673 spin_unlock_irq(&phba->hbalock);
10674 }
10675
James Smart5af5eee2010-10-22 11:06:38 -040010676 /* Abort all iocbs associated with the hba */
10677 lpfc_sli_hba_iocb_abort(phba);
10678
10679 /* Wait for completion of device XRI exchange busy */
10680 lpfc_sli4_xri_exchange_busy_wait(phba);
10681
James Smartda0436e2009-05-22 14:51:39 -040010682 /* Disable PCI subsystem interrupt */
10683 lpfc_sli4_disable_intr(phba);
10684
James Smart912e3ac2011-05-24 11:42:11 -040010685 /* Disable SR-IOV if enabled */
10686 if (phba->cfg_sriov_nr_virtfn)
10687 pci_disable_sriov(pdev);
10688
James Smartda0436e2009-05-22 14:51:39 -040010689 /* Stop kthread signal shall trigger work_done one more time */
10690 kthread_stop(phba->worker_thread);
10691
James Smartd2cc9bc2018-09-10 10:30:50 -070010692 /* Disable FW logging to host memory */
10693 writel(LPFC_CTL_PDEV_CTL_DDL_RAS,
10694 phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
10695
10696 /* Free RAS DMA memory */
10697 if (phba->ras_fwlog.ras_enabled == true)
10698 lpfc_sli4_ras_dma_free(phba);
10699
James Smartd1f525a2017-04-21 16:04:55 -070010700 /* Unset the queues shared with the hardware then release all
10701 * allocated resources.
10702 */
10703 lpfc_sli4_queue_unset(phba);
10704 lpfc_sli4_queue_destroy(phba);
10705
James Smart3677a3a2010-09-29 11:19:14 -040010706 /* Reset SLI4 HBA FCoE function */
10707 lpfc_pci_function_reset(phba);
10708
James Smartda0436e2009-05-22 14:51:39 -040010709 /* Stop the SLI4 device port */
10710 phba->pport->work_port_events = 0;
10711}
10712
James Smart28baac72010-02-12 14:42:03 -050010713 /**
10714 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
10715 * @phba: Pointer to HBA context object.
10716 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10717 *
10718 * This function is called in the SLI4 code path to read the port's
10719 * sli4 capabilities.
10720 *
10721 * This function may be be called from any context that can block-wait
10722 * for the completion. The expectation is that this routine is called
10723 * typically from probe_one or from the online routine.
10724 **/
10725int
10726lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10727{
10728 int rc;
10729 struct lpfc_mqe *mqe;
10730 struct lpfc_pc_sli4_params *sli4_params;
10731 uint32_t mbox_tmo;
10732
10733 rc = 0;
10734 mqe = &mboxq->u.mqe;
10735
10736 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -050010737 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -050010738 if (!phba->sli4_hba.intr_enable)
10739 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10740 else {
James Smarta183a152011-10-10 21:32:43 -040010741 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -050010742 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10743 }
10744
10745 if (unlikely(rc))
10746 return 1;
10747
10748 sli4_params = &phba->sli4_hba.pc_sli4_params;
10749 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
10750 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
10751 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
10752 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
10753 &mqe->un.sli4_params);
10754 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
10755 &mqe->un.sli4_params);
10756 sli4_params->proto_types = mqe->un.sli4_params.word3;
10757 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
10758 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
10759 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
10760 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
10761 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
10762 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
10763 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
10764 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
10765 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
10766 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
10767 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
10768 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
10769 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
10770 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
10771 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
10772 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
10773 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
10774 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
10775 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
10776 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -040010777
10778 /* Make sure that sge_supp_len can be handled by the driver */
10779 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10780 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10781
James Smart28baac72010-02-12 14:42:03 -050010782 return rc;
10783}
10784
James Smartda0436e2009-05-22 14:51:39 -040010785/**
James Smartfedd3b72011-02-16 12:39:24 -050010786 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
10787 * @phba: Pointer to HBA context object.
10788 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10789 *
10790 * This function is called in the SLI4 code path to read the port's
10791 * sli4 capabilities.
10792 *
10793 * This function may be be called from any context that can block-wait
10794 * for the completion. The expectation is that this routine is called
10795 * typically from probe_one or from the online routine.
10796 **/
10797int
10798lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10799{
10800 int rc;
10801 struct lpfc_mqe *mqe = &mboxq->u.mqe;
10802 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -040010803 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -050010804 int length;
James Smartbf316c72018-04-09 14:24:28 -070010805 bool exp_wqcq_pages = true;
James Smartfedd3b72011-02-16 12:39:24 -050010806 struct lpfc_sli4_parameters *mbx_sli4_parameters;
10807
James Smart6d368e52011-05-24 11:44:12 -040010808 /*
10809 * By default, the driver assumes the SLI4 port requires RPI
10810 * header postings. The SLI4_PARAM response will correct this
10811 * assumption.
10812 */
10813 phba->sli4_hba.rpi_hdrs_in_use = 1;
10814
James Smartfedd3b72011-02-16 12:39:24 -050010815 /* Read the port's SLI4 Config Parameters */
10816 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
10817 sizeof(struct lpfc_sli4_cfg_mhdr));
10818 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
10819 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
10820 length, LPFC_SLI4_MBX_EMBED);
10821 if (!phba->sli4_hba.intr_enable)
10822 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -040010823 else {
10824 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
10825 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10826 }
James Smartfedd3b72011-02-16 12:39:24 -050010827 if (unlikely(rc))
10828 return rc;
10829 sli4_params = &phba->sli4_hba.pc_sli4_params;
10830 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
10831 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
10832 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
10833 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
10834 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
10835 mbx_sli4_parameters);
10836 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
10837 mbx_sli4_parameters);
10838 if (bf_get(cfg_phwq, mbx_sli4_parameters))
10839 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
10840 else
10841 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
10842 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
10843 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
James Smart1ba981f2014-02-20 09:56:45 -050010844 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010845 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
10846 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
10847 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
10848 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
James Smart7365f6f2018-02-22 08:18:46 -080010849 sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters);
10850 sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters);
James Smart0c651872013-07-15 18:33:23 -040010851 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
James Smart66e9e6b2018-06-26 08:24:27 -070010852 sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010853 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
10854 mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080010855 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010856 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
10857 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -040010858 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
10859 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080010860 phba->nvme_support = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
10861 bf_get(cfg_xib, mbx_sli4_parameters));
10862
10863 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) ||
10864 !phba->nvme_support) {
10865 phba->nvme_support = 0;
10866 phba->nvmet_support = 0;
James Smartbcb24f62017-11-20 16:00:36 -080010867 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_OFF;
James Smart895427b2017-02-12 13:52:30 -080010868 phba->cfg_nvme_io_channel = 0;
10869 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
10870 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
10871 "6101 Disabling NVME support: "
10872 "Not supported by firmware: %d %d\n",
10873 bf_get(cfg_nvme, mbx_sli4_parameters),
10874 bf_get(cfg_xib, mbx_sli4_parameters));
10875
10876 /* If firmware doesn't support NVME, just use SCSI support */
10877 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
10878 return -ENODEV;
10879 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
10880 }
James Smart05580562011-05-24 11:40:48 -040010881
James Smart414abe02018-06-26 08:24:26 -070010882 /* Only embed PBDE for if_type 6, PBDE support requires xib be set */
10883 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
10884 LPFC_SLI_INTF_IF_TYPE_6) || (!bf_get(cfg_xib, mbx_sli4_parameters)))
10885 phba->cfg_enable_pbde = 0;
James Smart0bc2b7c2018-02-22 08:18:48 -080010886
James Smart20aefac2018-01-30 15:58:58 -080010887 /*
10888 * To support Suppress Response feature we must satisfy 3 conditions.
10889 * lpfc_suppress_rsp module parameter must be set (default).
10890 * In SLI4-Parameters Descriptor:
10891 * Extended Inline Buffers (XIB) must be supported.
10892 * Suppress Response IU Not Supported (SRIUNS) must NOT be supported
10893 * (double negative).
10894 */
10895 if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) &&
10896 !(bf_get(cfg_nosr, mbx_sli4_parameters)))
James Smartf358dd02017-02-12 13:52:34 -080010897 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
James Smart20aefac2018-01-30 15:58:58 -080010898 else
10899 phba->cfg_suppress_rsp = 0;
James Smartf358dd02017-02-12 13:52:34 -080010900
James Smart0cf07f842017-06-01 21:07:10 -070010901 if (bf_get(cfg_eqdr, mbx_sli4_parameters))
10902 phba->sli.sli_flag |= LPFC_SLI_USE_EQDR;
10903
James Smart05580562011-05-24 11:40:48 -040010904 /* Make sure that sge_supp_len can be handled by the driver */
10905 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10906 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10907
James Smartb5c53952016-03-31 14:12:30 -070010908 /*
James Smartc176ffa2018-01-30 15:58:46 -080010909 * Check whether the adapter supports an embedded copy of the
10910 * FCP CMD IU within the WQE for FCP_Ixxx commands. In order
10911 * to use this option, 128-byte WQEs must be used.
James Smartb5c53952016-03-31 14:12:30 -070010912 */
10913 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
10914 phba->fcp_embed_io = 1;
10915 else
10916 phba->fcp_embed_io = 0;
James Smart7bdedb32016-07-06 12:36:00 -070010917
James Smart0bc2b7c2018-02-22 08:18:48 -080010918 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
James Smart414abe02018-06-26 08:24:26 -070010919 "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n",
James Smart0bc2b7c2018-02-22 08:18:48 -080010920 bf_get(cfg_xib, mbx_sli4_parameters),
James Smart414abe02018-06-26 08:24:26 -070010921 phba->cfg_enable_pbde,
10922 phba->fcp_embed_io, phba->nvme_support,
James Smart4e565cf2018-02-22 08:18:50 -080010923 phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp);
James Smart0bc2b7c2018-02-22 08:18:48 -080010924
James Smartbf316c72018-04-09 14:24:28 -070010925 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
10926 LPFC_SLI_INTF_IF_TYPE_2) &&
10927 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
James Smartc2217682018-05-24 21:09:00 -070010928 LPFC_SLI_INTF_FAMILY_LNCR_A0))
James Smartbf316c72018-04-09 14:24:28 -070010929 exp_wqcq_pages = false;
10930
James Smartc176ffa2018-01-30 15:58:46 -080010931 if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) &&
10932 (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) &&
James Smartbf316c72018-04-09 14:24:28 -070010933 exp_wqcq_pages &&
James Smartc176ffa2018-01-30 15:58:46 -080010934 (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT))
10935 phba->enab_exp_wqcq_pages = 1;
10936 else
10937 phba->enab_exp_wqcq_pages = 0;
James Smart7bdedb32016-07-06 12:36:00 -070010938 /*
10939 * Check if the SLI port supports MDS Diagnostics
10940 */
10941 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
10942 phba->mds_diags_support = 1;
10943 else
10944 phba->mds_diags_support = 0;
James Smartd2cc9bc2018-09-10 10:30:50 -070010945
James Smartfedd3b72011-02-16 12:39:24 -050010946 return 0;
10947}
10948
10949/**
James Smart3772a992009-05-22 14:50:54 -040010950 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
10951 * @pdev: pointer to PCI device
10952 * @pid: pointer to PCI device identifier
10953 *
10954 * This routine is to be called to attach a device with SLI-3 interface spec
10955 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10956 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10957 * information of the device and driver to see if the driver state that it can
10958 * support this kind of device. If the match is successful, the driver core
10959 * invokes this routine. If this routine determines it can claim the HBA, it
10960 * does all the initialization that it needs to do to handle the HBA properly.
10961 *
10962 * Return code
10963 * 0 - driver can claim the device
10964 * negative value - driver can not claim the device
10965 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010966static int
James Smart3772a992009-05-22 14:50:54 -040010967lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
10968{
10969 struct lpfc_hba *phba;
10970 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040010971 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -040010972 int error;
10973 uint32_t cfg_mode, intr_mode;
10974
10975 /* Allocate memory for HBA structure */
10976 phba = lpfc_hba_alloc(pdev);
10977 if (!phba)
10978 return -ENOMEM;
10979
10980 /* Perform generic PCI device enabling operation */
10981 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040010982 if (error)
James Smart3772a992009-05-22 14:50:54 -040010983 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -040010984
10985 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
10986 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
10987 if (error)
10988 goto out_disable_pci_dev;
10989
10990 /* Set up SLI-3 specific device PCI memory space */
10991 error = lpfc_sli_pci_mem_setup(phba);
10992 if (error) {
10993 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10994 "1402 Failed to set up pci memory space.\n");
10995 goto out_disable_pci_dev;
10996 }
10997
James Smart3772a992009-05-22 14:50:54 -040010998 /* Set up SLI-3 specific device driver resources */
10999 error = lpfc_sli_driver_resource_setup(phba);
11000 if (error) {
11001 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11002 "1404 Failed to set up driver resource.\n");
11003 goto out_unset_pci_mem_s3;
11004 }
11005
11006 /* Initialize and populate the iocb list per host */
James Smartd1f525a2017-04-21 16:04:55 -070011007
James Smart3772a992009-05-22 14:50:54 -040011008 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
11009 if (error) {
11010 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11011 "1405 Failed to initialize iocb list.\n");
11012 goto out_unset_driver_resource_s3;
11013 }
11014
11015 /* Set up common device driver resources */
11016 error = lpfc_setup_driver_resource_phase2(phba);
11017 if (error) {
11018 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11019 "1406 Failed to set up driver resource.\n");
11020 goto out_free_iocb_list;
11021 }
11022
James Smart079b5c92011-08-21 21:48:49 -040011023 /* Get the default values for Model Name and Description */
11024 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
11025
James Smart3772a992009-05-22 14:50:54 -040011026 /* Create SCSI host to the physical port */
11027 error = lpfc_create_shost(phba);
11028 if (error) {
11029 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11030 "1407 Failed to create scsi host.\n");
11031 goto out_unset_driver_resource;
11032 }
11033
11034 /* Configure sysfs attributes */
11035 vport = phba->pport;
11036 error = lpfc_alloc_sysfs_attr(vport);
11037 if (error) {
11038 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11039 "1476 Failed to allocate sysfs attr\n");
11040 goto out_destroy_shost;
11041 }
11042
James Smart6669f9b2009-10-02 15:16:45 -040011043 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -040011044 /* Now, trying to enable interrupt and bring up the device */
11045 cfg_mode = phba->cfg_use_msi;
11046 while (true) {
11047 /* Put device to a known state before enabling interrupt */
11048 lpfc_stop_port(phba);
11049 /* Configure and enable interrupt */
11050 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
11051 if (intr_mode == LPFC_INTR_ERROR) {
11052 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11053 "0431 Failed to enable interrupt.\n");
11054 error = -ENODEV;
11055 goto out_free_sysfs_attr;
11056 }
11057 /* SLI-3 HBA setup */
11058 if (lpfc_sli_hba_setup(phba)) {
11059 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11060 "1477 Failed to set up hba\n");
11061 error = -ENODEV;
11062 goto out_remove_device;
11063 }
11064
11065 /* Wait 50ms for the interrupts of previous mailbox commands */
11066 msleep(50);
11067 /* Check active interrupts on message signaled interrupts */
11068 if (intr_mode == 0 ||
11069 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
11070 /* Log the current active interrupt mode */
11071 phba->intr_mode = intr_mode;
11072 lpfc_log_intr_mode(phba, intr_mode);
11073 break;
11074 } else {
11075 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11076 "0447 Configure interrupt mode (%d) "
11077 "failed active interrupt test.\n",
11078 intr_mode);
11079 /* Disable the current interrupt mode */
11080 lpfc_sli_disable_intr(phba);
11081 /* Try next level of interrupt mode */
11082 cfg_mode = --intr_mode;
11083 }
11084 }
11085
11086 /* Perform post initialization setup */
11087 lpfc_post_init_setup(phba);
11088
11089 /* Check if there are static vports to be created. */
11090 lpfc_create_static_vport(phba);
11091
11092 return 0;
11093
11094out_remove_device:
11095 lpfc_unset_hba(phba);
11096out_free_sysfs_attr:
11097 lpfc_free_sysfs_attr(vport);
11098out_destroy_shost:
11099 lpfc_destroy_shost(phba);
11100out_unset_driver_resource:
11101 lpfc_unset_driver_resource_phase2(phba);
11102out_free_iocb_list:
11103 lpfc_free_iocb_list(phba);
11104out_unset_driver_resource_s3:
11105 lpfc_sli_driver_resource_unset(phba);
11106out_unset_pci_mem_s3:
11107 lpfc_sli_pci_mem_unset(phba);
11108out_disable_pci_dev:
11109 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040011110 if (shost)
11111 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -040011112out_free_phba:
11113 lpfc_hba_free(phba);
11114 return error;
11115}
11116
11117/**
11118 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -040011119 * @pdev: pointer to PCI device
11120 *
James Smart3772a992009-05-22 14:50:54 -040011121 * This routine is to be called to disattach a device with SLI-3 interface
11122 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
11123 * removed from PCI bus, it performs all the necessary cleanup for the HBA
11124 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -040011125 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011126static void
James Smart3772a992009-05-22 14:50:54 -040011127lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -050011128{
James Smart2e0fef82007-06-17 19:56:36 -050011129 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11130 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -050011131 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -050011132 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -050011133 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -050011134
James Smart549e55c2007-08-02 11:09:51 -040011135 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -040011136 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -040011137 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -050011138
James Smart858c9f62007-06-17 19:56:39 -050011139 lpfc_free_sysfs_attr(vport);
11140
James Smarteada2722008-12-04 22:39:13 -050011141 /* Release all the vports against this physical port */
11142 vports = lpfc_create_vport_work_array(phba);
11143 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040011144 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
11145 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
11146 continue;
James Smarteada2722008-12-04 22:39:13 -050011147 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040011148 }
James Smarteada2722008-12-04 22:39:13 -050011149 lpfc_destroy_vport_work_array(phba, vports);
11150
11151 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -050011152 fc_remove_host(shost);
11153 scsi_remove_host(shost);
James Smartd613b6a2017-02-12 13:52:37 -080011154
James Smart87af33f2007-10-27 13:37:43 -040011155 lpfc_cleanup(vport);
11156
James Smart2e0fef82007-06-17 19:56:36 -050011157 /*
11158 * Bring down the SLI Layer. This step disable all interrupts,
11159 * clears the rings, discards all mailbox commands, and resets
11160 * the HBA.
11161 */
James Smarta257bf92009-04-06 18:48:10 -040011162
Justin P. Mattock48e34d02010-12-30 15:07:58 -080011163 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -050011164 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -040011165 /* Stop kthread signal shall trigger work_done one more time */
11166 kthread_stop(phba->worker_thread);
11167 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -050011168 lpfc_sli_brdrestart(phba);
11169
James Smart72859902012-01-18 16:25:38 -050011170 kfree(phba->vpi_bmask);
11171 kfree(phba->vpi_ids);
11172
James Smart3772a992009-05-22 14:50:54 -040011173 lpfc_stop_hba_timers(phba);
James Smart523128e2018-09-10 10:30:46 -070011174 spin_lock_irq(&phba->port_list_lock);
James Smart858c9f62007-06-17 19:56:39 -050011175 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -070011176 spin_unlock_irq(&phba->port_list_lock);
James Smart858c9f62007-06-17 19:56:39 -050011177
James Smart858c9f62007-06-17 19:56:39 -050011178 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -050011179
James Smart912e3ac2011-05-24 11:42:11 -040011180 /* Disable SR-IOV if enabled */
11181 if (phba->cfg_sriov_nr_virtfn)
11182 pci_disable_sriov(pdev);
11183
James Smart5b75da22008-12-04 22:39:35 -050011184 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -040011185 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -050011186
James Smart858c9f62007-06-17 19:56:39 -050011187 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -050011188
11189 /*
11190 * Call scsi_free before mem_free since scsi bufs are released to their
11191 * corresponding pools here.
11192 */
11193 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -040011194 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -050011195
James Smart34b02dc2008-08-24 21:49:55 -040011196 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
11197 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -050011198
James Smart2e0fef82007-06-17 19:56:36 -050011199 /* Free resources associated with SLI2 interface */
11200 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -040011201 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -050011202
11203 /* unmap adapter SLIM and Control Registers */
11204 iounmap(phba->ctrl_regs_memmap_p);
11205 iounmap(phba->slim_memmap_p);
11206
James Smart3772a992009-05-22 14:50:54 -040011207 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -050011208
Johannes Thumshirne0c04832016-06-07 09:44:03 +020011209 pci_release_mem_regions(pdev);
James Smart2e0fef82007-06-17 19:56:36 -050011210 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -050011211}
11212
Linas Vepstas8d63f372007-02-14 14:28:36 -060011213/**
James Smart3772a992009-05-22 14:50:54 -040011214 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050011215 * @pdev: pointer to PCI device
11216 * @msg: power management message
11217 *
James Smart3772a992009-05-22 14:50:54 -040011218 * This routine is to be called from the kernel's PCI subsystem to support
11219 * system Power Management (PM) to device with SLI-3 interface spec. When
11220 * PM invokes this method, it quiesces the device by stopping the driver's
11221 * worker thread for the device, turning off device's interrupt and DMA,
11222 * and bring the device offline. Note that as the driver implements the
11223 * minimum PM requirements to a power-aware driver's PM support for the
11224 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
11225 * to the suspend() method call will be treated as SUSPEND and the driver will
11226 * fully reinitialize its device during resume() method call, the driver will
11227 * set device to PCI_D3hot state in PCI config space instead of setting it
11228 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -050011229 *
11230 * Return code
James Smart3772a992009-05-22 14:50:54 -040011231 * 0 - driver suspended the device
11232 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050011233 **/
11234static int
James Smart3772a992009-05-22 14:50:54 -040011235lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -050011236{
11237 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11238 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11239
11240 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11241 "0473 PCI device Power Management suspend.\n");
11242
11243 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040011244 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -050011245 lpfc_offline(phba);
11246 kthread_stop(phba->worker_thread);
11247
11248 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -040011249 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -050011250
11251 /* Save device state to PCI config space */
11252 pci_save_state(pdev);
11253 pci_set_power_state(pdev, PCI_D3hot);
11254
11255 return 0;
11256}
11257
11258/**
James Smart3772a992009-05-22 14:50:54 -040011259 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050011260 * @pdev: pointer to PCI device
11261 *
James Smart3772a992009-05-22 14:50:54 -040011262 * This routine is to be called from the kernel's PCI subsystem to support
11263 * system Power Management (PM) to device with SLI-3 interface spec. When PM
11264 * invokes this method, it restores the device's PCI config space state and
11265 * fully reinitializes the device and brings it online. Note that as the
11266 * driver implements the minimum PM requirements to a power-aware driver's
11267 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
11268 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
11269 * driver will fully reinitialize its device during resume() method call,
11270 * the device will be set to PCI_D0 directly in PCI config space before
11271 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -050011272 *
11273 * Return code
James Smart3772a992009-05-22 14:50:54 -040011274 * 0 - driver suspended the device
11275 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050011276 **/
11277static int
James Smart3772a992009-05-22 14:50:54 -040011278lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -050011279{
11280 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11281 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -050011282 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050011283 int error;
11284
11285 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11286 "0452 PCI device Power Management resume.\n");
11287
11288 /* Restore device state from PCI config space */
11289 pci_set_power_state(pdev, PCI_D0);
11290 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -040011291
James Smart1dfb5a42010-02-12 14:40:50 -050011292 /*
11293 * As the new kernel behavior of pci_restore_state() API call clears
11294 * device saved_state flag, need to save the restored state again.
11295 */
11296 pci_save_state(pdev);
11297
James Smart3a55b532008-12-04 22:38:54 -050011298 if (pdev->is_busmaster)
11299 pci_set_master(pdev);
11300
11301 /* Startup the kernel thread for this host adapter. */
11302 phba->worker_thread = kthread_run(lpfc_do_work, phba,
11303 "lpfc_worker_%d", phba->brd_no);
11304 if (IS_ERR(phba->worker_thread)) {
11305 error = PTR_ERR(phba->worker_thread);
11306 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11307 "0434 PM resume failed to start worker "
11308 "thread: error=x%x.\n", error);
11309 return error;
11310 }
11311
James Smart5b75da22008-12-04 22:39:35 -050011312 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040011313 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050011314 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -050011315 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -050011316 "0430 PM resume Failed to enable interrupt\n");
11317 return -EIO;
11318 } else
11319 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050011320
11321 /* Restart HBA and bring it online */
11322 lpfc_sli_brdrestart(phba);
11323 lpfc_online(phba);
11324
James Smart5b75da22008-12-04 22:39:35 -050011325 /* Log the current active interrupt mode */
11326 lpfc_log_intr_mode(phba, phba->intr_mode);
11327
James Smart3a55b532008-12-04 22:38:54 -050011328 return 0;
11329}
11330
11331/**
James Smart891478a2009-11-18 15:40:23 -050011332 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
11333 * @phba: pointer to lpfc hba data structure.
11334 *
11335 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -040011336 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -050011337 **/
11338static void
11339lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
11340{
11341 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11342 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -040011343
11344 /*
11345 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
11346 * and let the SCSI mid-layer to retry them to recover.
11347 */
James Smartdb55fba2014-04-04 13:52:02 -040011348 lpfc_sli_abort_fcp_rings(phba);
James Smart891478a2009-11-18 15:40:23 -050011349}
11350
11351/**
James Smart0d878412009-10-02 15:16:56 -040011352 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
11353 * @phba: pointer to lpfc hba data structure.
11354 *
11355 * This routine is called to prepare the SLI3 device for PCI slot reset. It
11356 * disables the device interrupt and pci device, and aborts the internal FCP
11357 * pending I/Os.
11358 **/
11359static void
11360lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
11361{
James Smart0d878412009-10-02 15:16:56 -040011362 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050011363 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -040011364
James Smart75baf692010-06-08 18:31:21 -040011365 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040011366 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040011367
James Smarte2af0d22010-03-15 11:25:32 -040011368 /* Block all SCSI devices' I/Os on the host */
11369 lpfc_scsi_dev_block(phba);
11370
James Smartea714f32013-04-17 20:18:47 -040011371 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
11372 lpfc_sli_flush_fcp_rings(phba);
11373
James Smarte2af0d22010-03-15 11:25:32 -040011374 /* stop all timers */
11375 lpfc_stop_hba_timers(phba);
11376
James Smart0d878412009-10-02 15:16:56 -040011377 /* Disable interrupt and pci device */
11378 lpfc_sli_disable_intr(phba);
11379 pci_disable_device(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -040011380}
11381
11382/**
11383 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
11384 * @phba: pointer to lpfc hba data structure.
11385 *
11386 * This routine is called to prepare the SLI3 device for PCI slot permanently
11387 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
11388 * pending I/Os.
11389 **/
11390static void
James Smart75baf692010-06-08 18:31:21 -040011391lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -040011392{
11393 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050011394 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -040011395 /* Block all SCSI devices' I/Os on the host */
11396 lpfc_scsi_dev_block(phba);
11397
11398 /* stop all timers */
11399 lpfc_stop_hba_timers(phba);
11400
James Smart0d878412009-10-02 15:16:56 -040011401 /* Clean up all driver's outstanding SCSI I/Os */
11402 lpfc_sli_flush_fcp_rings(phba);
11403}
11404
11405/**
James Smart3772a992009-05-22 14:50:54 -040011406 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -040011407 * @pdev: pointer to PCI device.
11408 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -060011409 *
James Smart3772a992009-05-22 14:50:54 -040011410 * This routine is called from the PCI subsystem for I/O error handling to
11411 * device with SLI-3 interface spec. This function is called by the PCI
11412 * subsystem after a PCI bus error affecting this device has been detected.
11413 * When this function is invoked, it will need to stop all the I/Os and
11414 * interrupt(s) to the device. Once that is done, it will return
11415 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
11416 * as desired.
James Smarte59058c2008-08-24 21:49:00 -040011417 *
11418 * Return codes
James Smart0d878412009-10-02 15:16:56 -040011419 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -040011420 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11421 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -040011422 **/
James Smart3772a992009-05-22 14:50:54 -040011423static pci_ers_result_t
11424lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -060011425{
James Smart51ef4c22007-08-02 11:10:31 -040011426 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11427 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011428
James Smart0d878412009-10-02 15:16:56 -040011429 switch (state) {
11430 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -050011431 /* Non-fatal error, prepare for recovery */
11432 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -040011433 return PCI_ERS_RESULT_CAN_RECOVER;
11434 case pci_channel_io_frozen:
11435 /* Fatal error, prepare for slot reset */
11436 lpfc_sli_prep_dev_for_reset(phba);
11437 return PCI_ERS_RESULT_NEED_RESET;
11438 case pci_channel_io_perm_failure:
11439 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -040011440 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011441 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -040011442 default:
11443 /* Unknown state, prepare and request slot reset */
11444 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11445 "0472 Unknown PCI error state: x%x\n", state);
11446 lpfc_sli_prep_dev_for_reset(phba);
11447 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -040011448 }
Linas Vepstas8d63f372007-02-14 14:28:36 -060011449}
11450
11451/**
James Smart3772a992009-05-22 14:50:54 -040011452 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -040011453 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -060011454 *
James Smart3772a992009-05-22 14:50:54 -040011455 * This routine is called from the PCI subsystem for error handling to
11456 * device with SLI-3 interface spec. This is called after PCI bus has been
11457 * reset to restart the PCI card from scratch, as if from a cold-boot.
11458 * During the PCI subsystem error recovery, after driver returns
11459 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
11460 * recovery and then call this routine before calling the .resume method
11461 * to recover the device. This function will initialize the HBA device,
11462 * enable the interrupt, but it will just put the HBA to offline state
11463 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -040011464 *
11465 * Return codes
James Smart3772a992009-05-22 14:50:54 -040011466 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11467 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -060011468 */
James Smart3772a992009-05-22 14:50:54 -040011469static pci_ers_result_t
11470lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060011471{
James Smart51ef4c22007-08-02 11:10:31 -040011472 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11473 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011474 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -050011475 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011476
11477 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +110011478 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -060011479 printk(KERN_ERR "lpfc: Cannot re-enable "
11480 "PCI device after reset.\n");
11481 return PCI_ERS_RESULT_DISCONNECT;
11482 }
11483
James Smart97207482008-12-04 22:39:19 -050011484 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050011485
11486 /*
11487 * As the new kernel behavior of pci_restore_state() API call clears
11488 * device saved_state flag, need to save the restored state again.
11489 */
11490 pci_save_state(pdev);
11491
James Smart97207482008-12-04 22:39:19 -050011492 if (pdev->is_busmaster)
11493 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011494
James Smart92d7f7b2007-06-17 19:56:38 -050011495 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040011496 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -050011497 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011498
James Smart5b75da22008-12-04 22:39:35 -050011499 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040011500 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050011501 if (intr_mode == LPFC_INTR_ERROR) {
11502 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11503 "0427 Cannot re-enable interrupt after "
11504 "slot reset.\n");
11505 return PCI_ERS_RESULT_DISCONNECT;
11506 } else
11507 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011508
James Smart75baf692010-06-08 18:31:21 -040011509 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -040011510 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011511 lpfc_offline(phba);
11512 lpfc_sli_brdrestart(phba);
11513
James Smart5b75da22008-12-04 22:39:35 -050011514 /* Log the current active interrupt mode */
11515 lpfc_log_intr_mode(phba, phba->intr_mode);
11516
Linas Vepstas8d63f372007-02-14 14:28:36 -060011517 return PCI_ERS_RESULT_RECOVERED;
11518}
11519
11520/**
James Smart3772a992009-05-22 14:50:54 -040011521 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -040011522 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -060011523 *
James Smart3772a992009-05-22 14:50:54 -040011524 * This routine is called from the PCI subsystem for error handling to device
11525 * with SLI-3 interface spec. It is called when kernel error recovery tells
11526 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
11527 * error recovery. After this call, traffic can start to flow from this device
11528 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -060011529 */
James Smart3772a992009-05-22 14:50:54 -040011530static void
11531lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060011532{
James Smart51ef4c22007-08-02 11:10:31 -040011533 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11534 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011535
James Smarte2af0d22010-03-15 11:25:32 -040011536 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -040011537 lpfc_online(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011538}
11539
James Smart3772a992009-05-22 14:50:54 -040011540/**
James Smartda0436e2009-05-22 14:51:39 -040011541 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
11542 * @phba: pointer to lpfc hba data structure.
11543 *
11544 * returns the number of ELS/CT IOCBs to reserve
11545 **/
11546int
11547lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
11548{
11549 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
11550
James Smartf1126682009-06-10 17:22:44 -040011551 if (phba->sli_rev == LPFC_SLI_REV4) {
11552 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -040011553 return 10;
James Smartf1126682009-06-10 17:22:44 -040011554 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -040011555 return 25;
James Smartf1126682009-06-10 17:22:44 -040011556 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -040011557 return 50;
James Smartf1126682009-06-10 17:22:44 -040011558 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -040011559 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -040011560 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -040011561 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -040011562 else if (max_xri <= 2048)
11563 return 200;
11564 else
11565 return 250;
James Smartf1126682009-06-10 17:22:44 -040011566 } else
11567 return 0;
James Smartda0436e2009-05-22 14:51:39 -040011568}
11569
11570/**
James Smart895427b2017-02-12 13:52:30 -080011571 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
11572 * @phba: pointer to lpfc hba data structure.
11573 *
James Smartf358dd02017-02-12 13:52:34 -080011574 * returns the number of ELS/CT + NVMET IOCBs to reserve
James Smart895427b2017-02-12 13:52:30 -080011575 **/
11576int
11577lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
11578{
11579 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
11580
James Smartf358dd02017-02-12 13:52:34 -080011581 if (phba->nvmet_support)
11582 max_xri += LPFC_NVMET_BUF_POST;
James Smart895427b2017-02-12 13:52:30 -080011583 return max_xri;
11584}
11585
11586
James Smart1feb8202018-02-22 08:18:47 -080011587static void
11588lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset,
11589 uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize,
11590 const struct firmware *fw)
11591{
James Smarta72d56b2018-05-04 20:37:52 -070011592 if ((offset == ADD_STATUS_FW_NOT_SUPPORTED) ||
11593 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
11594 magic_number != MAGIC_NUMER_G6) ||
11595 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC &&
11596 magic_number != MAGIC_NUMER_G7))
James Smart1feb8202018-02-22 08:18:47 -080011597 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11598 "3030 This firmware version is not supported on "
11599 "this HBA model. Device:%x Magic:%x Type:%x "
11600 "ID:%x Size %d %zd\n",
11601 phba->pcidev->device, magic_number, ftype, fid,
11602 fsize, fw->size);
11603 else
11604 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11605 "3022 FW Download failed. Device:%x Magic:%x Type:%x "
11606 "ID:%x Size %d %zd\n",
11607 phba->pcidev->device, magic_number, ftype, fid,
11608 fsize, fw->size);
11609}
11610
11611
James Smart895427b2017-02-12 13:52:30 -080011612/**
James Smart52d52442011-05-24 11:42:45 -040011613 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -040011614 * @fw: pointer to firmware image returned from request_firmware.
James Smartce396282012-09-29 11:30:56 -040011615 * @phba: pointer to lpfc hba data structure.
James Smart52d52442011-05-24 11:42:45 -040011616 *
James Smart52d52442011-05-24 11:42:45 -040011617 **/
James Smartce396282012-09-29 11:30:56 -040011618static void
11619lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -040011620{
James Smartce396282012-09-29 11:30:56 -040011621 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -050011622 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -040011623 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -040011624 struct list_head dma_buffer_list;
11625 int i, rc = 0;
11626 struct lpfc_dmabuf *dmabuf, *next;
11627 uint32_t offset = 0, temp_offset = 0;
James Smart6b6ef5d2016-10-13 15:06:17 -070011628 uint32_t magic_number, ftype, fid, fsize;
James Smart52d52442011-05-24 11:42:45 -040011629
James Smartc71ab862012-10-31 14:44:33 -040011630 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -040011631 if (!fw) {
11632 rc = -ENXIO;
11633 goto out;
11634 }
11635 image = (struct lpfc_grp_hdr *)fw->data;
11636
James Smart6b6ef5d2016-10-13 15:06:17 -070011637 magic_number = be32_to_cpu(image->magic_number);
11638 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
James Smart1feb8202018-02-22 08:18:47 -080011639 fid = bf_get_be32(lpfc_grp_hdr_id, image);
James Smart6b6ef5d2016-10-13 15:06:17 -070011640 fsize = be32_to_cpu(image->size);
11641
James Smart52d52442011-05-24 11:42:45 -040011642 INIT_LIST_HEAD(&dma_buffer_list);
James Smart52d52442011-05-24 11:42:45 -040011643 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -040011644 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -040011645 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartce396282012-09-29 11:30:56 -040011646 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -040011647 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -040011648 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -040011649 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
11650 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
11651 GFP_KERNEL);
11652 if (!dmabuf) {
11653 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040011654 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040011655 }
11656 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
11657 SLI4_PAGE_SIZE,
11658 &dmabuf->phys,
11659 GFP_KERNEL);
11660 if (!dmabuf->virt) {
11661 kfree(dmabuf);
11662 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040011663 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040011664 }
11665 list_add_tail(&dmabuf->list, &dma_buffer_list);
11666 }
11667 while (offset < fw->size) {
11668 temp_offset = offset;
11669 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -040011670 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -040011671 memcpy(dmabuf->virt,
11672 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -040011673 fw->size - temp_offset);
11674 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -040011675 break;
11676 }
James Smart52d52442011-05-24 11:42:45 -040011677 memcpy(dmabuf->virt, fw->data + temp_offset,
11678 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -040011679 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -040011680 }
11681 rc = lpfc_wr_object(phba, &dma_buffer_list,
11682 (fw->size - offset), &offset);
James Smart1feb8202018-02-22 08:18:47 -080011683 if (rc) {
11684 lpfc_log_write_firmware_error(phba, offset,
11685 magic_number, ftype, fid, fsize, fw);
James Smartce396282012-09-29 11:30:56 -040011686 goto release_out;
James Smart1feb8202018-02-22 08:18:47 -080011687 }
James Smart52d52442011-05-24 11:42:45 -040011688 }
11689 rc = offset;
James Smart1feb8202018-02-22 08:18:47 -080011690 } else
11691 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11692 "3029 Skipped Firmware update, Current "
11693 "Version:%s New Version:%s\n",
11694 fwrev, image->revision);
James Smartce396282012-09-29 11:30:56 -040011695
11696release_out:
James Smart52d52442011-05-24 11:42:45 -040011697 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
11698 list_del(&dmabuf->list);
11699 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
11700 dmabuf->virt, dmabuf->phys);
11701 kfree(dmabuf);
11702 }
James Smartce396282012-09-29 11:30:56 -040011703 release_firmware(fw);
11704out:
11705 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc71ab862012-10-31 14:44:33 -040011706 "3024 Firmware update done: %d.\n", rc);
James Smartce396282012-09-29 11:30:56 -040011707 return;
James Smart52d52442011-05-24 11:42:45 -040011708}
11709
11710/**
James Smartc71ab862012-10-31 14:44:33 -040011711 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
11712 * @phba: pointer to lpfc hba data structure.
11713 *
11714 * This routine is called to perform Linux generic firmware upgrade on device
11715 * that supports such feature.
11716 **/
11717int
11718lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
11719{
11720 uint8_t file_name[ELX_MODEL_NAME_SIZE];
11721 int ret;
11722 const struct firmware *fw;
11723
11724 /* Only supported on SLI4 interface type 2 for now */
James Smart27d6ac02018-02-22 08:18:42 -080011725 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smartc71ab862012-10-31 14:44:33 -040011726 LPFC_SLI_INTF_IF_TYPE_2)
11727 return -EPERM;
11728
11729 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
11730
11731 if (fw_upgrade == INT_FW_UPGRADE) {
11732 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
11733 file_name, &phba->pcidev->dev,
11734 GFP_KERNEL, (void *)phba,
11735 lpfc_write_firmware);
11736 } else if (fw_upgrade == RUN_FW_UPGRADE) {
11737 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
11738 if (!ret)
11739 lpfc_write_firmware(fw, (void *)phba);
11740 } else {
11741 ret = -EINVAL;
11742 }
11743
11744 return ret;
11745}
11746
11747/**
James Smartda0436e2009-05-22 14:51:39 -040011748 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
11749 * @pdev: pointer to PCI device
11750 * @pid: pointer to PCI device identifier
11751 *
11752 * This routine is called from the kernel's PCI subsystem to device with
11753 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11754 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
11755 * information of the device and driver to see if the driver state that it
11756 * can support this kind of device. If the match is successful, the driver
11757 * core invokes this routine. If this routine determines it can claim the HBA,
11758 * it does all the initialization that it needs to do to handle the HBA
11759 * properly.
11760 *
11761 * Return code
11762 * 0 - driver can claim the device
11763 * negative value - driver can not claim the device
11764 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011765static int
James Smartda0436e2009-05-22 14:51:39 -040011766lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
11767{
11768 struct lpfc_hba *phba;
11769 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040011770 struct Scsi_Host *shost = NULL;
James Smart6c621a22017-05-15 15:20:45 -070011771 int error;
James Smartda0436e2009-05-22 14:51:39 -040011772 uint32_t cfg_mode, intr_mode;
James Smartda0436e2009-05-22 14:51:39 -040011773
11774 /* Allocate memory for HBA structure */
11775 phba = lpfc_hba_alloc(pdev);
11776 if (!phba)
11777 return -ENOMEM;
11778
11779 /* Perform generic PCI device enabling operation */
11780 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040011781 if (error)
James Smartda0436e2009-05-22 14:51:39 -040011782 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -040011783
11784 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
11785 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
11786 if (error)
11787 goto out_disable_pci_dev;
11788
11789 /* Set up SLI-4 specific device PCI memory space */
11790 error = lpfc_sli4_pci_mem_setup(phba);
11791 if (error) {
11792 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11793 "1410 Failed to set up pci memory space.\n");
11794 goto out_disable_pci_dev;
11795 }
11796
James Smartda0436e2009-05-22 14:51:39 -040011797 /* Set up SLI-4 Specific device driver resources */
11798 error = lpfc_sli4_driver_resource_setup(phba);
11799 if (error) {
11800 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11801 "1412 Failed to set up driver resource.\n");
11802 goto out_unset_pci_mem_s4;
11803 }
11804
James Smart19ca7602010-11-20 23:11:55 -050011805 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -040011806 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -050011807
James Smartda0436e2009-05-22 14:51:39 -040011808 /* Set up common device driver resources */
11809 error = lpfc_setup_driver_resource_phase2(phba);
11810 if (error) {
11811 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11812 "1414 Failed to set up driver resource.\n");
James Smart6c621a22017-05-15 15:20:45 -070011813 goto out_unset_driver_resource_s4;
James Smartda0436e2009-05-22 14:51:39 -040011814 }
11815
James Smart079b5c92011-08-21 21:48:49 -040011816 /* Get the default values for Model Name and Description */
11817 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
11818
James Smartda0436e2009-05-22 14:51:39 -040011819 /* Create SCSI host to the physical port */
11820 error = lpfc_create_shost(phba);
11821 if (error) {
11822 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11823 "1415 Failed to create scsi host.\n");
11824 goto out_unset_driver_resource;
11825 }
11826
11827 /* Configure sysfs attributes */
11828 vport = phba->pport;
11829 error = lpfc_alloc_sysfs_attr(vport);
11830 if (error) {
11831 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11832 "1416 Failed to allocate sysfs attr\n");
11833 goto out_destroy_shost;
11834 }
11835
James Smart6669f9b2009-10-02 15:16:45 -040011836 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -040011837 /* Now, trying to enable interrupt and bring up the device */
11838 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -040011839
James Smart7b15db32013-01-03 15:43:29 -050011840 /* Put device to a known state before enabling interrupt */
11841 lpfc_stop_port(phba);
James Smart895427b2017-02-12 13:52:30 -080011842
James Smart7b15db32013-01-03 15:43:29 -050011843 /* Configure and enable interrupt */
11844 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
11845 if (intr_mode == LPFC_INTR_ERROR) {
11846 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11847 "0426 Failed to enable interrupt.\n");
11848 error = -ENODEV;
11849 goto out_free_sysfs_attr;
James Smartda0436e2009-05-22 14:51:39 -040011850 }
James Smart7b15db32013-01-03 15:43:29 -050011851 /* Default to single EQ for non-MSI-X */
James Smart895427b2017-02-12 13:52:30 -080011852 if (phba->intr_type != MSIX) {
11853 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
11854 phba->cfg_fcp_io_channel = 1;
James Smart2d7dbc42017-02-12 13:52:35 -080011855 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -080011856 phba->cfg_nvme_io_channel = 1;
James Smart2d7dbc42017-02-12 13:52:35 -080011857 if (phba->nvmet_support)
11858 phba->cfg_nvmet_mrq = 1;
11859 }
James Smart895427b2017-02-12 13:52:30 -080011860 phba->io_channel_irqs = 1;
11861 }
11862
James Smart7b15db32013-01-03 15:43:29 -050011863 /* Set up SLI-4 HBA */
11864 if (lpfc_sli4_hba_setup(phba)) {
11865 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11866 "1421 Failed to set up hba\n");
11867 error = -ENODEV;
11868 goto out_disable_intr;
11869 }
11870
11871 /* Log the current active interrupt mode */
11872 phba->intr_mode = intr_mode;
11873 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -040011874
11875 /* Perform post initialization setup */
11876 lpfc_post_init_setup(phba);
11877
James Smart01649562017-02-12 13:52:32 -080011878 /* NVME support in FW earlier in the driver load corrects the
11879 * FC4 type making a check for nvme_support unnecessary.
11880 */
11881 if ((phba->nvmet_support == 0) &&
11882 (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
11883 /* Create NVME binding with nvme_fc_transport. This
James Smartd1f525a2017-04-21 16:04:55 -070011884 * ensures the vport is initialized. If the localport
11885 * create fails, it should not unload the driver to
11886 * support field issues.
James Smart01649562017-02-12 13:52:32 -080011887 */
11888 error = lpfc_nvme_create_localport(vport);
11889 if (error) {
11890 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11891 "6004 NVME registration failed, "
11892 "error x%x\n",
11893 error);
James Smart01649562017-02-12 13:52:32 -080011894 }
11895 }
James Smart895427b2017-02-12 13:52:30 -080011896
James Smartc71ab862012-10-31 14:44:33 -040011897 /* check for firmware upgrade or downgrade */
11898 if (phba->cfg_request_firmware_upgrade)
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040011899 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -040011900
James Smart1c6834a2009-07-19 10:01:26 -040011901 /* Check if there are static vports to be created. */
11902 lpfc_create_static_vport(phba);
James Smartd2cc9bc2018-09-10 10:30:50 -070011903
11904 /* Enable RAS FW log support */
11905 lpfc_sli4_ras_setup(phba);
11906
James Smartda0436e2009-05-22 14:51:39 -040011907 return 0;
11908
11909out_disable_intr:
11910 lpfc_sli4_disable_intr(phba);
11911out_free_sysfs_attr:
11912 lpfc_free_sysfs_attr(vport);
11913out_destroy_shost:
11914 lpfc_destroy_shost(phba);
11915out_unset_driver_resource:
11916 lpfc_unset_driver_resource_phase2(phba);
James Smartda0436e2009-05-22 14:51:39 -040011917out_unset_driver_resource_s4:
11918 lpfc_sli4_driver_resource_unset(phba);
11919out_unset_pci_mem_s4:
11920 lpfc_sli4_pci_mem_unset(phba);
11921out_disable_pci_dev:
11922 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040011923 if (shost)
11924 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -040011925out_free_phba:
11926 lpfc_hba_free(phba);
11927 return error;
11928}
11929
11930/**
11931 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
11932 * @pdev: pointer to PCI device
11933 *
11934 * This routine is called from the kernel's PCI subsystem to device with
11935 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11936 * removed from PCI bus, it performs all the necessary cleanup for the HBA
11937 * device to be removed from the PCI subsystem properly.
11938 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011939static void
James Smartda0436e2009-05-22 14:51:39 -040011940lpfc_pci_remove_one_s4(struct pci_dev *pdev)
11941{
11942 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11943 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
11944 struct lpfc_vport **vports;
11945 struct lpfc_hba *phba = vport->phba;
11946 int i;
11947
11948 /* Mark the device unloading flag */
11949 spin_lock_irq(&phba->hbalock);
11950 vport->load_flag |= FC_UNLOADING;
11951 spin_unlock_irq(&phba->hbalock);
11952
11953 /* Free the HBA sysfs attributes */
11954 lpfc_free_sysfs_attr(vport);
11955
11956 /* Release all the vports against this physical port */
11957 vports = lpfc_create_vport_work_array(phba);
11958 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040011959 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
11960 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
11961 continue;
James Smartda0436e2009-05-22 14:51:39 -040011962 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040011963 }
James Smartda0436e2009-05-22 14:51:39 -040011964 lpfc_destroy_vport_work_array(phba, vports);
11965
11966 /* Remove FC host and then SCSI host with the physical port */
11967 fc_remove_host(shost);
11968 scsi_remove_host(shost);
James Smartda0436e2009-05-22 14:51:39 -040011969
James Smartda0436e2009-05-22 14:51:39 -040011970 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
11971 * localports are destroyed after to cleanup all transport memory.
11972 */
11973 lpfc_cleanup(vport);
11974 lpfc_nvmet_destroy_targetport(phba);
11975 lpfc_nvme_destroy_localport(vport);
11976
James Smart281d6192018-01-30 15:58:47 -080011977 /*
11978 * Bring down the SLI Layer. This step disables all interrupts,
11979 * clears the rings, discards all mailbox commands, and resets
11980 * the HBA FCoE function.
11981 */
11982 lpfc_debugfs_terminate(vport);
11983 lpfc_sli4_hba_unset(phba);
James Smartda0436e2009-05-22 14:51:39 -040011984
Dick Kennedy19017622017-09-29 17:34:27 -070011985 lpfc_stop_hba_timers(phba);
James Smart523128e2018-09-10 10:30:46 -070011986 spin_lock_irq(&phba->port_list_lock);
James Smartda0436e2009-05-22 14:51:39 -040011987 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -070011988 spin_unlock_irq(&phba->port_list_lock);
James Smartda0436e2009-05-22 14:51:39 -040011989
James Smart3677a3a2010-09-29 11:19:14 -040011990 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -040011991 * buffers are released to their corresponding pools here.
11992 */
11993 lpfc_scsi_free(phba);
James Smart895427b2017-02-12 13:52:30 -080011994 lpfc_nvme_free(phba);
James Smart01649562017-02-12 13:52:32 -080011995 lpfc_free_iocb_list(phba);
James Smart67d12732012-08-03 12:36:13 -040011996
James Smart0cdb84e2018-04-09 14:24:26 -070011997 lpfc_unset_driver_resource_phase2(phba);
James Smartda0436e2009-05-22 14:51:39 -040011998 lpfc_sli4_driver_resource_unset(phba);
11999
12000 /* Unmap adapter Control and Doorbell registers */
12001 lpfc_sli4_pci_mem_unset(phba);
12002
12003 /* Release PCI resources and disable device's PCI function */
12004 scsi_host_put(shost);
12005 lpfc_disable_pci_dev(phba);
12006
12007 /* Finally, free the driver's device data structure */
12008 lpfc_hba_free(phba);
12009
12010 return;
12011}
12012
12013/**
12014 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
12015 * @pdev: pointer to PCI device
12016 * @msg: power management message
12017 *
12018 * This routine is called from the kernel's PCI subsystem to support system
12019 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
12020 * this method, it quiesces the device by stopping the driver's worker
12021 * thread for the device, turning off device's interrupt and DMA, and bring
12022 * the device offline. Note that as the driver implements the minimum PM
12023 * requirements to a power-aware driver's PM support for suspend/resume -- all
12024 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
12025 * method call will be treated as SUSPEND and the driver will fully
12026 * reinitialize its device during resume() method call, the driver will set
12027 * device to PCI_D3hot state in PCI config space instead of setting it
12028 * according to the @msg provided by the PM.
12029 *
12030 * Return code
12031 * 0 - driver suspended the device
12032 * Error otherwise
12033 **/
12034static int
12035lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
12036{
12037 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12038 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12039
12040 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -040012041 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -040012042
12043 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040012044 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -040012045 lpfc_offline(phba);
12046 kthread_stop(phba->worker_thread);
12047
12048 /* Disable interrupt from device */
12049 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040012050 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040012051
12052 /* Save device state to PCI config space */
12053 pci_save_state(pdev);
12054 pci_set_power_state(pdev, PCI_D3hot);
12055
12056 return 0;
12057}
12058
12059/**
12060 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
12061 * @pdev: pointer to PCI device
12062 *
12063 * This routine is called from the kernel's PCI subsystem to support system
12064 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
12065 * this method, it restores the device's PCI config space state and fully
12066 * reinitializes the device and brings it online. Note that as the driver
12067 * implements the minimum PM requirements to a power-aware driver's PM for
12068 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
12069 * to the suspend() method call will be treated as SUSPEND and the driver
12070 * will fully reinitialize its device during resume() method call, the device
12071 * will be set to PCI_D0 directly in PCI config space before restoring the
12072 * state.
12073 *
12074 * Return code
12075 * 0 - driver suspended the device
12076 * Error otherwise
12077 **/
12078static int
12079lpfc_pci_resume_one_s4(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 uint32_t intr_mode;
12084 int error;
12085
12086 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12087 "0292 PCI device Power Management resume.\n");
12088
12089 /* Restore device state from PCI config space */
12090 pci_set_power_state(pdev, PCI_D0);
12091 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050012092
12093 /*
12094 * As the new kernel behavior of pci_restore_state() API call clears
12095 * device saved_state flag, need to save the restored state again.
12096 */
12097 pci_save_state(pdev);
12098
James Smartda0436e2009-05-22 14:51:39 -040012099 if (pdev->is_busmaster)
12100 pci_set_master(pdev);
12101
12102 /* Startup the kernel thread for this host adapter. */
12103 phba->worker_thread = kthread_run(lpfc_do_work, phba,
12104 "lpfc_worker_%d", phba->brd_no);
12105 if (IS_ERR(phba->worker_thread)) {
12106 error = PTR_ERR(phba->worker_thread);
12107 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12108 "0293 PM resume failed to start worker "
12109 "thread: error=x%x.\n", error);
12110 return error;
12111 }
12112
12113 /* Configure and enable interrupt */
12114 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
12115 if (intr_mode == LPFC_INTR_ERROR) {
12116 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12117 "0294 PM resume Failed to enable interrupt\n");
12118 return -EIO;
12119 } else
12120 phba->intr_mode = intr_mode;
12121
12122 /* Restart HBA and bring it online */
12123 lpfc_sli_brdrestart(phba);
12124 lpfc_online(phba);
12125
12126 /* Log the current active interrupt mode */
12127 lpfc_log_intr_mode(phba, phba->intr_mode);
12128
12129 return 0;
12130}
12131
12132/**
James Smart75baf692010-06-08 18:31:21 -040012133 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
12134 * @phba: pointer to lpfc hba data structure.
12135 *
12136 * This routine is called to prepare the SLI4 device for PCI slot recover. It
12137 * aborts all the outstanding SCSI I/Os to the pci device.
12138 **/
12139static void
12140lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
12141{
James Smart75baf692010-06-08 18:31:21 -040012142 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12143 "2828 PCI channel I/O abort preparing for recovery\n");
12144 /*
12145 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
12146 * and let the SCSI mid-layer to retry them to recover.
12147 */
James Smartdb55fba2014-04-04 13:52:02 -040012148 lpfc_sli_abort_fcp_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040012149}
12150
12151/**
12152 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
12153 * @phba: pointer to lpfc hba data structure.
12154 *
12155 * This routine is called to prepare the SLI4 device for PCI slot reset. It
12156 * disables the device interrupt and pci device, and aborts the internal FCP
12157 * pending I/Os.
12158 **/
12159static void
12160lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
12161{
12162 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12163 "2826 PCI channel disable preparing for reset\n");
12164
12165 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040012166 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -040012167
12168 /* Block all SCSI devices' I/Os on the host */
12169 lpfc_scsi_dev_block(phba);
12170
James Smartea714f32013-04-17 20:18:47 -040012171 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
12172 lpfc_sli_flush_fcp_rings(phba);
12173
James Smartc3725bd2017-11-20 16:00:42 -080012174 /* Flush the outstanding NVME IOs if fc4 type enabled. */
12175 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
12176 lpfc_sli_flush_nvme_rings(phba);
12177
James Smart75baf692010-06-08 18:31:21 -040012178 /* stop all timers */
12179 lpfc_stop_hba_timers(phba);
12180
12181 /* Disable interrupt and pci device */
12182 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040012183 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -040012184 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -040012185}
12186
12187/**
12188 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
12189 * @phba: pointer to lpfc hba data structure.
12190 *
12191 * This routine is called to prepare the SLI4 device for PCI slot permanently
12192 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
12193 * pending I/Os.
12194 **/
12195static void
12196lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
12197{
12198 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12199 "2827 PCI channel permanent disable for failure\n");
12200
12201 /* Block all SCSI devices' I/Os on the host */
12202 lpfc_scsi_dev_block(phba);
12203
12204 /* stop all timers */
12205 lpfc_stop_hba_timers(phba);
12206
12207 /* Clean up all driver's outstanding SCSI I/Os */
12208 lpfc_sli_flush_fcp_rings(phba);
James Smartc3725bd2017-11-20 16:00:42 -080012209
12210 /* Flush the outstanding NVME IOs if fc4 type enabled. */
12211 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
12212 lpfc_sli_flush_nvme_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040012213}
12214
12215/**
James Smartda0436e2009-05-22 14:51:39 -040012216 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
12217 * @pdev: pointer to PCI device.
12218 * @state: the current PCI connection state.
12219 *
12220 * This routine is called from the PCI subsystem for error handling to device
12221 * with SLI-4 interface spec. This function is called by the PCI subsystem
12222 * after a PCI bus error affecting this device has been detected. When this
12223 * function is invoked, it will need to stop all the I/Os and interrupt(s)
12224 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
12225 * for the PCI subsystem to perform proper recovery as desired.
12226 *
12227 * Return codes
12228 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
12229 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12230 **/
12231static pci_ers_result_t
12232lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
12233{
James Smart75baf692010-06-08 18:31:21 -040012234 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12235 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12236
12237 switch (state) {
12238 case pci_channel_io_normal:
12239 /* Non-fatal error, prepare for recovery */
12240 lpfc_sli4_prep_dev_for_recover(phba);
12241 return PCI_ERS_RESULT_CAN_RECOVER;
12242 case pci_channel_io_frozen:
12243 /* Fatal error, prepare for slot reset */
12244 lpfc_sli4_prep_dev_for_reset(phba);
12245 return PCI_ERS_RESULT_NEED_RESET;
12246 case pci_channel_io_perm_failure:
12247 /* Permanent failure, prepare for device down */
12248 lpfc_sli4_prep_dev_for_perm_failure(phba);
12249 return PCI_ERS_RESULT_DISCONNECT;
12250 default:
12251 /* Unknown state, prepare and request slot reset */
12252 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12253 "2825 Unknown PCI error state: x%x\n", state);
12254 lpfc_sli4_prep_dev_for_reset(phba);
12255 return PCI_ERS_RESULT_NEED_RESET;
12256 }
James Smartda0436e2009-05-22 14:51:39 -040012257}
12258
12259/**
12260 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
12261 * @pdev: pointer to PCI device.
12262 *
12263 * This routine is called from the PCI subsystem for error handling to device
12264 * with SLI-4 interface spec. It is called after PCI bus has been reset to
12265 * restart the PCI card from scratch, as if from a cold-boot. During the
12266 * PCI subsystem error recovery, after the driver returns
12267 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
12268 * recovery and then call this routine before calling the .resume method to
12269 * recover the device. This function will initialize the HBA device, enable
12270 * the interrupt, but it will just put the HBA to offline state without
12271 * passing any I/O traffic.
12272 *
12273 * Return codes
12274 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
12275 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12276 */
12277static pci_ers_result_t
12278lpfc_io_slot_reset_s4(struct pci_dev *pdev)
12279{
James Smart75baf692010-06-08 18:31:21 -040012280 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12281 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12282 struct lpfc_sli *psli = &phba->sli;
12283 uint32_t intr_mode;
12284
12285 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
12286 if (pci_enable_device_mem(pdev)) {
12287 printk(KERN_ERR "lpfc: Cannot re-enable "
12288 "PCI device after reset.\n");
12289 return PCI_ERS_RESULT_DISCONNECT;
12290 }
12291
12292 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040012293
12294 /*
12295 * As the new kernel behavior of pci_restore_state() API call clears
12296 * device saved_state flag, need to save the restored state again.
12297 */
12298 pci_save_state(pdev);
12299
James Smart75baf692010-06-08 18:31:21 -040012300 if (pdev->is_busmaster)
12301 pci_set_master(pdev);
12302
12303 spin_lock_irq(&phba->hbalock);
12304 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
12305 spin_unlock_irq(&phba->hbalock);
12306
12307 /* Configure and enable interrupt */
12308 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
12309 if (intr_mode == LPFC_INTR_ERROR) {
12310 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12311 "2824 Cannot re-enable interrupt after "
12312 "slot reset.\n");
12313 return PCI_ERS_RESULT_DISCONNECT;
12314 } else
12315 phba->intr_mode = intr_mode;
12316
12317 /* Log the current active interrupt mode */
12318 lpfc_log_intr_mode(phba, phba->intr_mode);
12319
James Smartda0436e2009-05-22 14:51:39 -040012320 return PCI_ERS_RESULT_RECOVERED;
12321}
12322
12323/**
12324 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
12325 * @pdev: pointer to PCI device
12326 *
12327 * This routine is called from the PCI subsystem for error handling to device
12328 * with SLI-4 interface spec. It is called when kernel error recovery tells
12329 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
12330 * error recovery. After this call, traffic can start to flow from this device
12331 * again.
12332 **/
12333static void
12334lpfc_io_resume_s4(struct pci_dev *pdev)
12335{
James Smart75baf692010-06-08 18:31:21 -040012336 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12337 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12338
12339 /*
12340 * In case of slot reset, as function reset is performed through
12341 * mailbox command which needs DMA to be enabled, this operation
12342 * has to be moved to the io resume phase. Taking device offline
12343 * will perform the necessary cleanup.
12344 */
12345 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
12346 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040012347 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040012348 lpfc_offline(phba);
12349 lpfc_sli_brdrestart(phba);
12350 /* Bring the device back online */
12351 lpfc_online(phba);
12352 }
James Smartda0436e2009-05-22 14:51:39 -040012353}
12354
12355/**
James Smart3772a992009-05-22 14:50:54 -040012356 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
12357 * @pdev: pointer to PCI device
12358 * @pid: pointer to PCI device identifier
12359 *
12360 * This routine is to be registered to the kernel's PCI subsystem. When an
12361 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
12362 * at PCI device-specific information of the device and driver to see if the
12363 * driver state that it can support this kind of device. If the match is
12364 * successful, the driver core invokes this routine. This routine dispatches
12365 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
12366 * do all the initialization that it needs to do to handle the HBA device
12367 * properly.
12368 *
12369 * Return code
12370 * 0 - driver can claim the device
12371 * negative value - driver can not claim the device
12372 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012373static int
James Smart3772a992009-05-22 14:50:54 -040012374lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
12375{
12376 int rc;
James Smart8fa38512009-07-19 10:01:03 -040012377 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040012378
James Smart28baac72010-02-12 14:42:03 -050012379 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040012380 return -ENODEV;
12381
James Smart8fa38512009-07-19 10:01:03 -040012382 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050012383 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040012384 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040012385 else
James Smart3772a992009-05-22 14:50:54 -040012386 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040012387
James Smart3772a992009-05-22 14:50:54 -040012388 return rc;
12389}
12390
12391/**
12392 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
12393 * @pdev: pointer to PCI device
12394 *
12395 * This routine is to be registered to the kernel's PCI subsystem. When an
12396 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
12397 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
12398 * remove routine, which will perform all the necessary cleanup for the
12399 * device to be removed from the PCI subsystem properly.
12400 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012401static void
James Smart3772a992009-05-22 14:50:54 -040012402lpfc_pci_remove_one(struct pci_dev *pdev)
12403{
12404 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12405 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12406
12407 switch (phba->pci_dev_grp) {
12408 case LPFC_PCI_DEV_LP:
12409 lpfc_pci_remove_one_s3(pdev);
12410 break;
James Smartda0436e2009-05-22 14:51:39 -040012411 case LPFC_PCI_DEV_OC:
12412 lpfc_pci_remove_one_s4(pdev);
12413 break;
James Smart3772a992009-05-22 14:50:54 -040012414 default:
12415 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12416 "1424 Invalid PCI device group: 0x%x\n",
12417 phba->pci_dev_grp);
12418 break;
12419 }
12420 return;
12421}
12422
12423/**
12424 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
12425 * @pdev: pointer to PCI device
12426 * @msg: power management message
12427 *
12428 * This routine is to be registered to the kernel's PCI subsystem to support
12429 * system Power Management (PM). When PM invokes this method, it dispatches
12430 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
12431 * suspend the device.
12432 *
12433 * Return code
12434 * 0 - driver suspended the device
12435 * Error otherwise
12436 **/
12437static int
12438lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
12439{
12440 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12441 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12442 int rc = -ENODEV;
12443
12444 switch (phba->pci_dev_grp) {
12445 case LPFC_PCI_DEV_LP:
12446 rc = lpfc_pci_suspend_one_s3(pdev, msg);
12447 break;
James Smartda0436e2009-05-22 14:51:39 -040012448 case LPFC_PCI_DEV_OC:
12449 rc = lpfc_pci_suspend_one_s4(pdev, msg);
12450 break;
James Smart3772a992009-05-22 14:50:54 -040012451 default:
12452 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12453 "1425 Invalid PCI device group: 0x%x\n",
12454 phba->pci_dev_grp);
12455 break;
12456 }
12457 return rc;
12458}
12459
12460/**
12461 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
12462 * @pdev: pointer to PCI device
12463 *
12464 * This routine is to be registered to the kernel's PCI subsystem to support
12465 * system Power Management (PM). When PM invokes this method, it dispatches
12466 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
12467 * resume the device.
12468 *
12469 * Return code
12470 * 0 - driver suspended the device
12471 * Error otherwise
12472 **/
12473static int
12474lpfc_pci_resume_one(struct pci_dev *pdev)
12475{
12476 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12477 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12478 int rc = -ENODEV;
12479
12480 switch (phba->pci_dev_grp) {
12481 case LPFC_PCI_DEV_LP:
12482 rc = lpfc_pci_resume_one_s3(pdev);
12483 break;
James Smartda0436e2009-05-22 14:51:39 -040012484 case LPFC_PCI_DEV_OC:
12485 rc = lpfc_pci_resume_one_s4(pdev);
12486 break;
James Smart3772a992009-05-22 14:50:54 -040012487 default:
12488 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12489 "1426 Invalid PCI device group: 0x%x\n",
12490 phba->pci_dev_grp);
12491 break;
12492 }
12493 return rc;
12494}
12495
12496/**
12497 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
12498 * @pdev: pointer to PCI device.
12499 * @state: the current PCI connection state.
12500 *
12501 * This routine is registered to the PCI subsystem for error handling. This
12502 * function is called by the PCI subsystem after a PCI bus error affecting
12503 * this device has been detected. When this routine is invoked, it dispatches
12504 * the action to the proper SLI-3 or SLI-4 device error detected handling
12505 * routine, which will perform the proper error detected operation.
12506 *
12507 * Return codes
12508 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
12509 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12510 **/
12511static pci_ers_result_t
12512lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
12513{
12514 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12515 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12516 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
12517
12518 switch (phba->pci_dev_grp) {
12519 case LPFC_PCI_DEV_LP:
12520 rc = lpfc_io_error_detected_s3(pdev, state);
12521 break;
James Smartda0436e2009-05-22 14:51:39 -040012522 case LPFC_PCI_DEV_OC:
12523 rc = lpfc_io_error_detected_s4(pdev, state);
12524 break;
James Smart3772a992009-05-22 14:50:54 -040012525 default:
12526 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12527 "1427 Invalid PCI device group: 0x%x\n",
12528 phba->pci_dev_grp);
12529 break;
12530 }
12531 return rc;
12532}
12533
12534/**
12535 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
12536 * @pdev: pointer to PCI device.
12537 *
12538 * This routine is registered to the PCI subsystem for error handling. This
12539 * function is called after PCI bus has been reset to restart the PCI card
12540 * from scratch, as if from a cold-boot. When this routine is invoked, it
12541 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
12542 * routine, which will perform the proper device reset.
12543 *
12544 * Return codes
12545 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
12546 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12547 **/
12548static pci_ers_result_t
12549lpfc_io_slot_reset(struct pci_dev *pdev)
12550{
12551 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12552 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12553 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
12554
12555 switch (phba->pci_dev_grp) {
12556 case LPFC_PCI_DEV_LP:
12557 rc = lpfc_io_slot_reset_s3(pdev);
12558 break;
James Smartda0436e2009-05-22 14:51:39 -040012559 case LPFC_PCI_DEV_OC:
12560 rc = lpfc_io_slot_reset_s4(pdev);
12561 break;
James Smart3772a992009-05-22 14:50:54 -040012562 default:
12563 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12564 "1428 Invalid PCI device group: 0x%x\n",
12565 phba->pci_dev_grp);
12566 break;
12567 }
12568 return rc;
12569}
12570
12571/**
12572 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
12573 * @pdev: pointer to PCI device
12574 *
12575 * This routine is registered to the PCI subsystem for error handling. It
12576 * is called when kernel error recovery tells the lpfc driver that it is
12577 * OK to resume normal PCI operation after PCI bus error recovery. When
12578 * this routine is invoked, it dispatches the action to the proper SLI-3
12579 * or SLI-4 device io_resume routine, which will resume the device operation.
12580 **/
12581static void
12582lpfc_io_resume(struct pci_dev *pdev)
12583{
12584 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12585 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12586
12587 switch (phba->pci_dev_grp) {
12588 case LPFC_PCI_DEV_LP:
12589 lpfc_io_resume_s3(pdev);
12590 break;
James Smartda0436e2009-05-22 14:51:39 -040012591 case LPFC_PCI_DEV_OC:
12592 lpfc_io_resume_s4(pdev);
12593 break;
James Smart3772a992009-05-22 14:50:54 -040012594 default:
12595 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12596 "1429 Invalid PCI device group: 0x%x\n",
12597 phba->pci_dev_grp);
12598 break;
12599 }
12600 return;
12601}
12602
James Smart1ba981f2014-02-20 09:56:45 -050012603/**
12604 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
12605 * @phba: pointer to lpfc hba data structure.
12606 *
12607 * This routine checks to see if OAS is supported for this adapter. If
12608 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
12609 * the enable oas flag is cleared and the pool created for OAS device data
12610 * is destroyed.
12611 *
12612 **/
12613void
12614lpfc_sli4_oas_verify(struct lpfc_hba *phba)
12615{
12616
12617 if (!phba->cfg_EnableXLane)
12618 return;
12619
12620 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
12621 phba->cfg_fof = 1;
12622 } else {
James Smartf38fa0b2014-04-04 13:52:21 -040012623 phba->cfg_fof = 0;
James Smart1ba981f2014-02-20 09:56:45 -050012624 if (phba->device_data_mem_pool)
12625 mempool_destroy(phba->device_data_mem_pool);
12626 phba->device_data_mem_pool = NULL;
12627 }
12628
12629 return;
12630}
12631
12632/**
James Smartd2cc9bc2018-09-10 10:30:50 -070012633 * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter
12634 * @phba: pointer to lpfc hba data structure.
12635 *
12636 * This routine checks to see if RAS is supported by the adapter. Check the
12637 * function through which RAS support enablement is to be done.
12638 **/
12639void
12640lpfc_sli4_ras_init(struct lpfc_hba *phba)
12641{
12642 switch (phba->pcidev->device) {
12643 case PCI_DEVICE_ID_LANCER_G6_FC:
12644 case PCI_DEVICE_ID_LANCER_G7_FC:
12645 phba->ras_fwlog.ras_hwsupport = true;
James Smartcb349902018-11-29 16:09:27 -080012646 if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn) &&
12647 phba->cfg_ras_fwlog_buffsize)
James Smartd2cc9bc2018-09-10 10:30:50 -070012648 phba->ras_fwlog.ras_enabled = true;
12649 else
12650 phba->ras_fwlog.ras_enabled = false;
12651 break;
12652 default:
12653 phba->ras_fwlog.ras_hwsupport = false;
12654 }
12655}
12656
12657/**
James Smart1ba981f2014-02-20 09:56:45 -050012658 * lpfc_fof_queue_setup - Set up all the fof queues
12659 * @phba: pointer to lpfc hba data structure.
12660 *
12661 * This routine is invoked to set up all the fof queues for the FC HBA
12662 * operation.
12663 *
12664 * Return codes
12665 * 0 - successful
12666 * -ENOMEM - No available memory
12667 **/
12668int
12669lpfc_fof_queue_setup(struct lpfc_hba *phba)
12670{
James Smart895427b2017-02-12 13:52:30 -080012671 struct lpfc_sli_ring *pring;
James Smart1ba981f2014-02-20 09:56:45 -050012672 int rc;
12673
12674 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
12675 if (rc)
12676 return -ENOMEM;
12677
James Smartf38fa0b2014-04-04 13:52:21 -040012678 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050012679
12680 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
12681 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
12682 if (rc)
12683 goto out_oas_cq;
12684
12685 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
12686 phba->sli4_hba.oas_cq, LPFC_FCP);
12687 if (rc)
12688 goto out_oas_wq;
12689
James Smart895427b2017-02-12 13:52:30 -080012690 /* Bind this CQ/WQ to the NVME ring */
12691 pring = phba->sli4_hba.oas_wq->pring;
12692 pring->sli.sli4.wqp =
12693 (void *)phba->sli4_hba.oas_wq;
12694 phba->sli4_hba.oas_cq->pring = pring;
James Smart1ba981f2014-02-20 09:56:45 -050012695 }
12696
12697 return 0;
12698
12699out_oas_wq:
James Smartf38fa0b2014-04-04 13:52:21 -040012700 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
James Smart1ba981f2014-02-20 09:56:45 -050012701out_oas_cq:
12702 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
12703 return rc;
12704
12705}
12706
12707/**
12708 * lpfc_fof_queue_create - Create all the fof queues
12709 * @phba: pointer to lpfc hba data structure.
12710 *
12711 * This routine is invoked to allocate all the fof queues for the FC HBA
12712 * operation. For each SLI4 queue type, the parameters such as queue entry
12713 * count (queue depth) shall be taken from the module parameter. For now,
12714 * we just use some constant number as place holder.
12715 *
12716 * Return codes
12717 * 0 - successful
12718 * -ENOMEM - No availble memory
12719 * -EIO - The mailbox failed to complete successfully.
12720 **/
12721int
12722lpfc_fof_queue_create(struct lpfc_hba *phba)
12723{
12724 struct lpfc_queue *qdesc;
James Smartc176ffa2018-01-30 15:58:46 -080012725 uint32_t wqesize;
James Smart1ba981f2014-02-20 09:56:45 -050012726
12727 /* Create FOF EQ */
James Smart81b96ed2017-11-20 16:00:29 -080012728 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
12729 phba->sli4_hba.eq_esize,
James Smart1ba981f2014-02-20 09:56:45 -050012730 phba->sli4_hba.eq_ecount);
12731 if (!qdesc)
12732 goto out_error;
12733
James Smart7365f6f2018-02-22 08:18:46 -080012734 qdesc->qe_valid = 1;
James Smart1ba981f2014-02-20 09:56:45 -050012735 phba->sli4_hba.fof_eq = qdesc;
12736
James Smartf38fa0b2014-04-04 13:52:21 -040012737 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050012738
12739 /* Create OAS CQ */
James Smartc176ffa2018-01-30 15:58:46 -080012740 if (phba->enab_exp_wqcq_pages)
James Smarta51e41b2017-12-08 17:18:06 -080012741 qdesc = lpfc_sli4_queue_alloc(phba,
12742 LPFC_EXPANDED_PAGE_SIZE,
12743 phba->sli4_hba.cq_esize,
12744 LPFC_CQE_EXP_COUNT);
12745 else
12746 qdesc = lpfc_sli4_queue_alloc(phba,
12747 LPFC_DEFAULT_PAGE_SIZE,
12748 phba->sli4_hba.cq_esize,
12749 phba->sli4_hba.cq_ecount);
James Smart1ba981f2014-02-20 09:56:45 -050012750 if (!qdesc)
12751 goto out_error;
12752
James Smart7365f6f2018-02-22 08:18:46 -080012753 qdesc->qe_valid = 1;
James Smart1ba981f2014-02-20 09:56:45 -050012754 phba->sli4_hba.oas_cq = qdesc;
12755
12756 /* Create OAS WQ */
James Smartc176ffa2018-01-30 15:58:46 -080012757 if (phba->enab_exp_wqcq_pages) {
12758 wqesize = (phba->fcp_embed_io) ?
12759 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
James Smarta51e41b2017-12-08 17:18:06 -080012760 qdesc = lpfc_sli4_queue_alloc(phba,
12761 LPFC_EXPANDED_PAGE_SIZE,
James Smartc176ffa2018-01-30 15:58:46 -080012762 wqesize,
James Smarta51e41b2017-12-08 17:18:06 -080012763 LPFC_WQE_EXP_COUNT);
James Smartc176ffa2018-01-30 15:58:46 -080012764 } else
James Smarta51e41b2017-12-08 17:18:06 -080012765 qdesc = lpfc_sli4_queue_alloc(phba,
12766 LPFC_DEFAULT_PAGE_SIZE,
12767 phba->sli4_hba.wq_esize,
12768 phba->sli4_hba.wq_ecount);
James Smartc176ffa2018-01-30 15:58:46 -080012769
James Smart1ba981f2014-02-20 09:56:45 -050012770 if (!qdesc)
12771 goto out_error;
12772
12773 phba->sli4_hba.oas_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -080012774 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
James Smart1ba981f2014-02-20 09:56:45 -050012775
12776 }
12777 return 0;
12778
12779out_error:
12780 lpfc_fof_queue_destroy(phba);
12781 return -ENOMEM;
12782}
12783
12784/**
12785 * lpfc_fof_queue_destroy - Destroy all the fof queues
12786 * @phba: pointer to lpfc hba data structure.
12787 *
12788 * This routine is invoked to release all the SLI4 queues with the FC HBA
12789 * operation.
12790 *
12791 * Return codes
12792 * 0 - successful
12793 **/
12794int
12795lpfc_fof_queue_destroy(struct lpfc_hba *phba)
12796{
12797 /* Release FOF Event queue */
12798 if (phba->sli4_hba.fof_eq != NULL) {
12799 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
12800 phba->sli4_hba.fof_eq = NULL;
12801 }
12802
12803 /* Release OAS Completion queue */
12804 if (phba->sli4_hba.oas_cq != NULL) {
12805 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
12806 phba->sli4_hba.oas_cq = NULL;
12807 }
12808
12809 /* Release OAS Work queue */
12810 if (phba->sli4_hba.oas_wq != NULL) {
12811 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
12812 phba->sli4_hba.oas_wq = NULL;
12813 }
12814 return 0;
12815}
12816
dea31012005-04-17 16:05:31 -050012817MODULE_DEVICE_TABLE(pci, lpfc_id_table);
12818
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070012819static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060012820 .error_detected = lpfc_io_error_detected,
12821 .slot_reset = lpfc_io_slot_reset,
12822 .resume = lpfc_io_resume,
12823};
12824
dea31012005-04-17 16:05:31 -050012825static struct pci_driver lpfc_driver = {
12826 .name = LPFC_DRIVER_NAME,
12827 .id_table = lpfc_id_table,
12828 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012829 .remove = lpfc_pci_remove_one,
Anton Blanchard85e8a232017-02-13 08:49:20 +110012830 .shutdown = lpfc_pci_remove_one,
James Smart3a55b532008-12-04 22:38:54 -050012831 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040012832 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050012833 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050012834};
12835
James Smart3ef6d242012-01-18 16:23:48 -050012836static const struct file_operations lpfc_mgmt_fop = {
Al Viro858feac2013-04-14 22:39:37 -040012837 .owner = THIS_MODULE,
James Smart3ef6d242012-01-18 16:23:48 -050012838};
12839
12840static struct miscdevice lpfc_mgmt_dev = {
12841 .minor = MISC_DYNAMIC_MINOR,
12842 .name = "lpfcmgmt",
12843 .fops = &lpfc_mgmt_fop,
12844};
12845
James Smarte59058c2008-08-24 21:49:00 -040012846/**
James Smart3621a712009-04-06 18:47:14 -040012847 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040012848 *
12849 * This routine is to be invoked when the lpfc module is loaded into the
12850 * kernel. The special kernel macro module_init() is used to indicate the
12851 * role of this routine to the kernel as lpfc module entry point.
12852 *
12853 * Return codes
12854 * 0 - successful
12855 * -ENOMEM - FC attach transport failed
12856 * all others - failed
12857 */
dea31012005-04-17 16:05:31 -050012858static int __init
12859lpfc_init(void)
12860{
12861 int error = 0;
12862
12863 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012864 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050012865
James Smart3ef6d242012-01-18 16:23:48 -050012866 error = misc_register(&lpfc_mgmt_dev);
12867 if (error)
12868 printk(KERN_ERR "Could not register lpfcmgmt device, "
12869 "misc_register returned with status %d", error);
12870
James Smart458c0832016-07-06 12:36:07 -070012871 lpfc_transport_functions.vport_create = lpfc_vport_create;
12872 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
dea31012005-04-17 16:05:31 -050012873 lpfc_transport_template =
12874 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040012875 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050012876 return -ENOMEM;
James Smart458c0832016-07-06 12:36:07 -070012877 lpfc_vport_transport_template =
12878 fc_attach_transport(&lpfc_vport_transport_functions);
12879 if (lpfc_vport_transport_template == NULL) {
12880 fc_release_transport(lpfc_transport_template);
12881 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040012882 }
James Smart5fd11082018-03-05 12:04:04 -080012883 lpfc_nvme_cmd_template();
James Smartbd3061b2018-03-05 12:04:05 -080012884 lpfc_nvmet_cmd_template();
James Smart7bb03bb2013-04-17 20:19:16 -040012885
12886 /* Initialize in case vector mapping is needed */
James Smartb246de12013-05-31 17:03:07 -040012887 lpfc_used_cpu = NULL;
James Smart2ea259e2017-02-12 13:52:27 -080012888 lpfc_present_cpu = num_present_cpus();
James Smart7bb03bb2013-04-17 20:19:16 -040012889
dea31012005-04-17 16:05:31 -050012890 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050012891 if (error) {
dea31012005-04-17 16:05:31 -050012892 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070012893 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050012894 }
dea31012005-04-17 16:05:31 -050012895
12896 return error;
12897}
12898
James Smarte59058c2008-08-24 21:49:00 -040012899/**
James Smart3621a712009-04-06 18:47:14 -040012900 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040012901 *
12902 * This routine is invoked when the lpfc module is removed from the kernel.
12903 * The special kernel macro module_exit() is used to indicate the role of
12904 * this routine to the kernel as lpfc module exit point.
12905 */
dea31012005-04-17 16:05:31 -050012906static void __exit
12907lpfc_exit(void)
12908{
James Smart3ef6d242012-01-18 16:23:48 -050012909 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050012910 pci_unregister_driver(&lpfc_driver);
12911 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070012912 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050012913 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040012914 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
12915 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050012916 (1L << _dump_buf_data_order), _dump_buf_data);
12917 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
12918 }
12919
12920 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040012921 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
12922 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050012923 (1L << _dump_buf_dif_order), _dump_buf_dif);
12924 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
12925 }
James Smartb246de12013-05-31 17:03:07 -040012926 kfree(lpfc_used_cpu);
Johannes Thumshirn79739672015-08-31 16:48:11 -040012927 idr_destroy(&lpfc_hba_index);
dea31012005-04-17 16:05:31 -050012928}
12929
12930module_init(lpfc_init);
12931module_exit(lpfc_exit);
12932MODULE_LICENSE("GPL");
12933MODULE_DESCRIPTION(LPFC_MODULE_DESC);
James Smartd080abe2017-02-12 13:52:39 -080012934MODULE_AUTHOR("Broadcom");
dea31012005-04-17 16:05:31 -050012935MODULE_VERSION("0:" LPFC_DRIVER_VERSION);