blob: a588dfad4b119fbe2d2a487e3d11763d6859feb2 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart128bdda2018-01-30 15:59:03 -08004 * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
James Smart3e21d1c2018-05-04 20:37:59 -07005 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
James Smart50611572016-03-31 14:12:34 -07006 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * EMULEX and SLI are trademarks of Emulex. *
James Smartd080abe2017-02-12 13:52:39 -08008 * www.broadcom.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04009 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -050010 * *
11 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
dea31012005-04-17 16:05:31 -050022 *******************************************************************/
23
dea31012005-04-17 16:05:31 -050024#include <linux/blkdev.h>
25#include <linux/delay.h>
26#include <linux/dma-mapping.h>
27#include <linux/idr.h>
28#include <linux/interrupt.h>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040029#include <linux/module.h>
dea31012005-04-17 16:05:31 -050030#include <linux/kthread.h>
31#include <linux/pci.h>
32#include <linux/spinlock.h>
James Smart92d7f7b2007-06-17 19:56:38 -050033#include <linux/ctype.h>
James Smart0d878412009-10-02 15:16:56 -040034#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
James Smart52d52442011-05-24 11:42:45 -040036#include <linux/firmware.h>
James Smart3ef6d242012-01-18 16:23:48 -050037#include <linux/miscdevice.h>
James Smart7bb03bb2013-04-17 20:19:16 -040038#include <linux/percpu.h>
James Smart895427b2017-02-12 13:52:30 -080039#include <linux/msi.h>
Maurizio Lombardi286871a2017-08-23 16:55:48 -070040#include <linux/bitops.h>
dea31012005-04-17 16:05:31 -050041
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040042#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050043#include <scsi/scsi_device.h>
44#include <scsi/scsi_host.h>
45#include <scsi/scsi_transport_fc.h>
James Smart86c67372017-04-21 16:05:04 -070046#include <scsi/scsi_tcq.h>
47#include <scsi/fc/fc_fs.h>
48
49#include <linux/nvme-fc-driver.h>
dea31012005-04-17 16:05:31 -050050
James Smartda0436e2009-05-22 14:51:39 -040051#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050052#include "lpfc_hw.h"
53#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040054#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040055#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050056#include "lpfc_disc.h"
dea31012005-04-17 16:05:31 -050057#include "lpfc.h"
James Smart895427b2017-02-12 13:52:30 -080058#include "lpfc_scsi.h"
59#include "lpfc_nvme.h"
James Smart86c67372017-04-21 16:05:04 -070060#include "lpfc_nvmet.h"
dea31012005-04-17 16:05:31 -050061#include "lpfc_logmsg.h"
62#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050063#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050064#include "lpfc_version.h"
James Smart12f44452016-07-06 12:36:03 -070065#include "lpfc_ids.h"
dea31012005-04-17 16:05:31 -050066
James Smart81301a92008-12-04 22:39:46 -050067char *_dump_buf_data;
68unsigned long _dump_buf_data_order;
69char *_dump_buf_dif;
70unsigned long _dump_buf_dif_order;
71spinlock_t _dump_buf_lock;
72
James Smart7bb03bb2013-04-17 20:19:16 -040073/* Used when mapping IRQ vectors in a driver centric manner */
James Smartb246de12013-05-31 17:03:07 -040074uint16_t *lpfc_used_cpu;
75uint32_t lpfc_present_cpu;
James Smart7bb03bb2013-04-17 20:19:16 -040076
dea31012005-04-17 16:05:31 -050077static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
78static int lpfc_post_rcv_buf(struct lpfc_hba *);
James Smart5350d872011-10-10 21:33:49 -040079static int lpfc_sli4_queue_verify(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040080static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
81static int lpfc_setup_endian_order(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040082static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040083static void lpfc_free_els_sgl_list(struct lpfc_hba *);
James Smartf358dd02017-02-12 13:52:34 -080084static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040085static void lpfc_init_sgl_list(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040086static int lpfc_init_active_sgl_array(struct lpfc_hba *);
87static void lpfc_free_active_sgl(struct lpfc_hba *);
88static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
89static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
90static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
91static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
92static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
James Smart618a5232012-06-12 13:54:36 -040093static void lpfc_sli4_disable_intr(struct lpfc_hba *);
94static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
James Smart1ba981f2014-02-20 09:56:45 -050095static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
dea31012005-04-17 16:05:31 -050096
97static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050098static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -050099static DEFINE_IDR(lpfc_hba_index);
James Smartf358dd02017-02-12 13:52:34 -0800100#define LPFC_NVMET_BUF_POST 254
dea31012005-04-17 16:05:31 -0500101
James Smarte59058c2008-08-24 21:49:00 -0400102/**
James Smart3621a712009-04-06 18:47:14 -0400103 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
James Smarte59058c2008-08-24 21:49:00 -0400104 * @phba: pointer to lpfc hba data structure.
105 *
106 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
107 * mailbox command. It retrieves the revision information from the HBA and
108 * collects the Vital Product Data (VPD) about the HBA for preparing the
109 * configuration of the HBA.
110 *
111 * Return codes:
112 * 0 - success.
113 * -ERESTART - requests the SLI layer to reset the HBA and try again.
114 * Any other value - indicates an error.
115 **/
dea31012005-04-17 16:05:31 -0500116int
James Smart2e0fef82007-06-17 19:56:36 -0500117lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500118{
119 lpfc_vpd_t *vp = &phba->vpd;
120 int i = 0, rc;
121 LPFC_MBOXQ_t *pmb;
122 MAILBOX_t *mb;
123 char *lpfc_vpd_data = NULL;
124 uint16_t offset = 0;
125 static char licensed[56] =
126 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -0400127 static int init_key = 1;
dea31012005-04-17 16:05:31 -0500128
129 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
130 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500131 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500132 return -ENOMEM;
133 }
134
James Smart04c68492009-05-22 14:52:52 -0400135 mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -0500136 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -0500137
138 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -0400139 if (init_key) {
140 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -0500141
James Smart65a29c12006-07-06 15:50:50 -0400142 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
143 *ptext = cpu_to_be32(*ptext);
144 init_key = 0;
145 }
dea31012005-04-17 16:05:31 -0500146
147 lpfc_read_nv(phba, pmb);
148 memset((char*)mb->un.varRDnvp.rsvd3, 0,
149 sizeof (mb->un.varRDnvp.rsvd3));
150 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
151 sizeof (licensed));
152
153 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
154
155 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500156 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400157 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500158 "error, mbxCmd x%x READ_NVPARM, "
159 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500160 mb->mbxCommand, mb->mbxStatus);
161 mempool_free(pmb, phba->mbox_mem_pool);
162 return -ERESTART;
163 }
164 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500165 sizeof(phba->wwnn));
166 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
167 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500168 }
169
Martin Wilckdfb75132018-11-12 09:58:37 +0100170 /*
171 * Clear all option bits except LPFC_SLI3_BG_ENABLED,
172 * which was already set in lpfc_get_cfgparam()
173 */
174 phba->sli3_options &= (uint32_t)LPFC_SLI3_BG_ENABLED;
James Smart92d7f7b2007-06-17 19:56:38 -0500175
dea31012005-04-17 16:05:31 -0500176 /* Setup and issue mailbox READ REV command */
177 lpfc_read_rev(phba, pmb);
178 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
179 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500180 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400181 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500182 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500183 mb->mbxCommand, mb->mbxStatus);
184 mempool_free( pmb, phba->mbox_mem_pool);
185 return -ERESTART;
186 }
187
James Smart92d7f7b2007-06-17 19:56:38 -0500188
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500189 /*
190 * The value of rr must be 1 since the driver set the cv field to 1.
191 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500192 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500193 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500194 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500195 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400196 "0440 Adapter failed to init, READ_REV has "
197 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500198 mempool_free(pmb, phba->mbox_mem_pool);
199 return -ERESTART;
dea31012005-04-17 16:05:31 -0500200 }
201
James Smart495a7142008-06-14 22:52:59 -0400202 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
203 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500204 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400205 }
James Smarted957682007-06-17 19:56:37 -0500206
dea31012005-04-17 16:05:31 -0500207 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500208 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500209 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500210 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
211 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
212 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
213 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500214 vp->rev.biuRev = mb->un.varRdRev.biuRev;
215 vp->rev.smRev = mb->un.varRdRev.smRev;
216 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
217 vp->rev.endecRev = mb->un.varRdRev.endecRev;
218 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
219 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
220 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
221 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
222 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
223 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
224
James Smart92d7f7b2007-06-17 19:56:38 -0500225 /* If the sli feature level is less then 9, we must
226 * tear down all RPIs and VPIs on link down if NPIV
227 * is enabled.
228 */
229 if (vp->rev.feaLevelHigh < 9)
230 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
231
dea31012005-04-17 16:05:31 -0500232 if (lpfc_is_LC_HBA(phba->pcidev->device))
233 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
234 sizeof (phba->RandomData));
235
dea31012005-04-17 16:05:31 -0500236 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500237 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
238 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400239 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500240 do {
James Smarta0c87cb2009-07-19 10:01:10 -0400241 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
dea31012005-04-17 16:05:31 -0500242 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
243
244 if (rc != MBX_SUCCESS) {
245 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400246 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500247 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500248 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500249 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500250 }
James Smart04c68492009-05-22 14:52:52 -0400251 /* dump mem may return a zero when finished or we got a
252 * mailbox error, either way we are done.
253 */
254 if (mb->un.varDmp.word_cnt == 0)
255 break;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500256 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
257 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400258 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
259 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500260 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500261 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500262 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
263 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500264
265 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500266out_free_mbox:
267 mempool_free(pmb, phba->mbox_mem_pool);
268 return 0;
269}
270
James Smarte59058c2008-08-24 21:49:00 -0400271/**
James Smart3621a712009-04-06 18:47:14 -0400272 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
James Smarte59058c2008-08-24 21:49:00 -0400273 * @phba: pointer to lpfc hba data structure.
274 * @pmboxq: pointer to the driver internal queue element for mailbox command.
275 *
276 * This is the completion handler for driver's configuring asynchronous event
277 * mailbox command to the device. If the mailbox command returns successfully,
278 * it will set internal async event support flag to 1; otherwise, it will
279 * set internal async event support flag to 0.
280 **/
James Smart57127f12007-10-27 13:37:05 -0400281static void
282lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
283{
James Smart04c68492009-05-22 14:52:52 -0400284 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
James Smart57127f12007-10-27 13:37:05 -0400285 phba->temp_sensor_support = 1;
286 else
287 phba->temp_sensor_support = 0;
288 mempool_free(pmboxq, phba->mbox_mem_pool);
289 return;
290}
291
James Smarte59058c2008-08-24 21:49:00 -0400292/**
James Smart3621a712009-04-06 18:47:14 -0400293 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
James Smart97207482008-12-04 22:39:19 -0500294 * @phba: pointer to lpfc hba data structure.
295 * @pmboxq: pointer to the driver internal queue element for mailbox command.
296 *
297 * This is the completion handler for dump mailbox command for getting
298 * wake up parameters. When this command complete, the response contain
299 * Option rom version of the HBA. This function translate the version number
300 * into a human readable string and store it in OptionROMVersion.
301 **/
302static void
303lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
304{
305 struct prog_id *prg;
306 uint32_t prog_id_word;
307 char dist = ' ';
308 /* character array used for decoding dist type. */
309 char dist_char[] = "nabx";
310
James Smart04c68492009-05-22 14:52:52 -0400311 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
James Smart9f1e1b52008-12-04 22:39:40 -0500312 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500313 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500314 }
James Smart97207482008-12-04 22:39:19 -0500315
316 prg = (struct prog_id *) &prog_id_word;
317
318 /* word 7 contain option rom version */
James Smart04c68492009-05-22 14:52:52 -0400319 prog_id_word = pmboxq->u.mb.un.varWords[7];
James Smart97207482008-12-04 22:39:19 -0500320
321 /* Decode the Option rom version word to a readable string */
322 if (prg->dist < 4)
323 dist = dist_char[prg->dist];
324
325 if ((prg->dist == 3) && (prg->num == 0))
James Smarta2fc4aef2014-09-03 12:57:55 -0400326 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
James Smart97207482008-12-04 22:39:19 -0500327 prg->ver, prg->rev, prg->lev);
328 else
James Smarta2fc4aef2014-09-03 12:57:55 -0400329 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
James Smart97207482008-12-04 22:39:19 -0500330 prg->ver, prg->rev, prg->lev,
331 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500332 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500333 return;
334}
335
336/**
James Smart05580562011-05-24 11:40:48 -0400337 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
338 * cfg_soft_wwnn, cfg_soft_wwpn
339 * @vport: pointer to lpfc vport data structure.
340 *
341 *
342 * Return codes
343 * None.
344 **/
345void
346lpfc_update_vport_wwn(struct lpfc_vport *vport)
347{
James Smartaeb3c812017-04-21 16:05:02 -0700348 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
349 u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0];
350
James Smart05580562011-05-24 11:40:48 -0400351 /* If the soft name exists then update it using the service params */
352 if (vport->phba->cfg_soft_wwnn)
353 u64_to_wwn(vport->phba->cfg_soft_wwnn,
354 vport->fc_sparam.nodeName.u.wwn);
355 if (vport->phba->cfg_soft_wwpn)
356 u64_to_wwn(vport->phba->cfg_soft_wwpn,
357 vport->fc_sparam.portName.u.wwn);
358
359 /*
360 * If the name is empty or there exists a soft name
361 * then copy the service params name, otherwise use the fc name
362 */
363 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
364 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
365 sizeof(struct lpfc_name));
366 else
367 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
368 sizeof(struct lpfc_name));
369
James Smartaeb3c812017-04-21 16:05:02 -0700370 /*
371 * If the port name has changed, then set the Param changes flag
372 * to unreg the login
373 */
374 if (vport->fc_portname.u.wwn[0] != 0 &&
375 memcmp(&vport->fc_portname, &vport->fc_sparam.portName,
376 sizeof(struct lpfc_name)))
377 vport->vport_flag |= FAWWPN_PARAM_CHG;
378
379 if (vport->fc_portname.u.wwn[0] == 0 ||
380 vport->phba->cfg_soft_wwpn ||
381 (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) ||
382 vport->vport_flag & FAWWPN_SET) {
James Smart05580562011-05-24 11:40:48 -0400383 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
384 sizeof(struct lpfc_name));
James Smartaeb3c812017-04-21 16:05:02 -0700385 vport->vport_flag &= ~FAWWPN_SET;
386 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR)
387 vport->vport_flag |= FAWWPN_SET;
388 }
James Smart05580562011-05-24 11:40:48 -0400389 else
390 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
391 sizeof(struct lpfc_name));
392}
393
394/**
James Smart3621a712009-04-06 18:47:14 -0400395 * lpfc_config_port_post - Perform lpfc initialization after config port
James Smarte59058c2008-08-24 21:49:00 -0400396 * @phba: pointer to lpfc hba data structure.
397 *
398 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
399 * command call. It performs all internal resource and state setups on the
400 * port: post IOCB buffers, enable appropriate host interrupt attentions,
401 * ELS ring timers, etc.
402 *
403 * Return codes
404 * 0 - success.
405 * Any other value - error.
406 **/
dea31012005-04-17 16:05:31 -0500407int
James Smart2e0fef82007-06-17 19:56:36 -0500408lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500409{
James Smart2e0fef82007-06-17 19:56:36 -0500410 struct lpfc_vport *vport = phba->pport;
James Smarta257bf92009-04-06 18:48:10 -0400411 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500412 LPFC_MBOXQ_t *pmb;
413 MAILBOX_t *mb;
414 struct lpfc_dmabuf *mp;
415 struct lpfc_sli *psli = &phba->sli;
416 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500417 int i, j;
418 int rc;
dea31012005-04-17 16:05:31 -0500419
James Smart7af67052007-10-27 13:38:11 -0400420 spin_lock_irq(&phba->hbalock);
421 /*
422 * If the Config port completed correctly the HBA is not
423 * over heated any more.
424 */
425 if (phba->over_temp_state == HBA_OVER_TEMP)
426 phba->over_temp_state = HBA_NORMAL_TEMP;
427 spin_unlock_irq(&phba->hbalock);
428
dea31012005-04-17 16:05:31 -0500429 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
430 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500431 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500432 return -ENOMEM;
433 }
James Smart04c68492009-05-22 14:52:52 -0400434 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500435
dea31012005-04-17 16:05:31 -0500436 /* Get login parameters for NID. */
James Smart9f1177a2010-02-26 14:12:57 -0500437 rc = lpfc_read_sparam(phba, pmb, 0);
438 if (rc) {
439 mempool_free(pmb, phba->mbox_mem_pool);
440 return -ENOMEM;
441 }
442
James Smarted957682007-06-17 19:56:37 -0500443 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500444 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500445 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400446 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500447 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500448 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500449 phba->link_state = LPFC_HBA_ERROR;
James Smart3e1f0712018-11-29 16:09:29 -0800450 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart9f1177a2010-02-26 14:12:57 -0500451 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500452 lpfc_mbuf_free(phba, mp->virt, mp->phys);
453 kfree(mp);
454 return -EIO;
455 }
456
James Smart3e1f0712018-11-29 16:09:29 -0800457 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
dea31012005-04-17 16:05:31 -0500458
James Smart2e0fef82007-06-17 19:56:36 -0500459 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500460 lpfc_mbuf_free(phba, mp->virt, mp->phys);
461 kfree(mp);
James Smart3e1f0712018-11-29 16:09:29 -0800462 pmb->ctx_buf = NULL;
James Smart05580562011-05-24 11:40:48 -0400463 lpfc_update_vport_wwn(vport);
James Smarta257bf92009-04-06 18:48:10 -0400464
465 /* Update the fc_host data structures with new wwn. */
466 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
467 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart21e9a0a2009-05-22 14:53:21 -0400468 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smarta257bf92009-04-06 18:48:10 -0400469
dea31012005-04-17 16:05:31 -0500470 /* If no serial number in VPD data, use low 6 bytes of WWNN */
471 /* This should be consolidated into parse_vpd ? - mr */
472 if (phba->SerialNumber[0] == 0) {
473 uint8_t *outptr;
474
James Smart2e0fef82007-06-17 19:56:36 -0500475 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500476 for (i = 0; i < 12; i++) {
477 status = *outptr++;
478 j = ((status & 0xf0) >> 4);
479 if (j <= 9)
480 phba->SerialNumber[i] =
481 (char)((uint8_t) 0x30 + (uint8_t) j);
482 else
483 phba->SerialNumber[i] =
484 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
485 i++;
486 j = (status & 0xf);
487 if (j <= 9)
488 phba->SerialNumber[i] =
489 (char)((uint8_t) 0x30 + (uint8_t) j);
490 else
491 phba->SerialNumber[i] =
492 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
493 }
494 }
495
dea31012005-04-17 16:05:31 -0500496 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500497 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500498 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500499 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400500 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500501 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500502 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500503 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500504 mempool_free( pmb, phba->mbox_mem_pool);
505 return -EIO;
506 }
507
James Smarta0c87cb2009-07-19 10:01:10 -0400508 /* Check if the port is disabled */
509 lpfc_sli_read_link_ste(phba);
510
dea31012005-04-17 16:05:31 -0500511 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -0400512 i = (mb->un.varRdConfig.max_xri + 1);
513 if (phba->cfg_hba_queue_depth > i) {
514 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
515 "3359 HBA queue depth changed from %d to %d\n",
516 phba->cfg_hba_queue_depth, i);
517 phba->cfg_hba_queue_depth = i;
518 }
519
520 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
521 i = (mb->un.varRdConfig.max_xri >> 3);
522 if (phba->pport->cfg_lun_queue_depth > i) {
523 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
524 "3360 LUN queue depth changed from %d to %d\n",
525 phba->pport->cfg_lun_queue_depth, i);
526 phba->pport->cfg_lun_queue_depth = i;
527 }
dea31012005-04-17 16:05:31 -0500528
529 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500530
531 /* Get the default values for Model Name and Description */
532 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
533
James Smart2e0fef82007-06-17 19:56:36 -0500534 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500535
James Smart0b727fe2007-10-27 13:37:25 -0400536 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smart895427b2017-02-12 13:52:30 -0800537 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
538 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
539 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
540 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500541
542 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500543 if (phba->sli_rev != 3)
544 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500545
James Smart93996272008-08-24 21:50:30 -0400546 /*
547 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
548 */
549 if (phba->intr_type == MSIX) {
550 rc = lpfc_config_msi(phba, pmb);
551 if (rc) {
552 mempool_free(pmb, phba->mbox_mem_pool);
553 return -EIO;
554 }
555 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
556 if (rc != MBX_SUCCESS) {
557 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
558 "0352 Config MSI mailbox command "
559 "failed, mbxCmd x%x, mbxStatus x%x\n",
James Smart04c68492009-05-22 14:52:52 -0400560 pmb->u.mb.mbxCommand,
561 pmb->u.mb.mbxStatus);
James Smart93996272008-08-24 21:50:30 -0400562 mempool_free(pmb, phba->mbox_mem_pool);
563 return -EIO;
564 }
565 }
566
James Smart04c68492009-05-22 14:52:52 -0400567 spin_lock_irq(&phba->hbalock);
James Smart93996272008-08-24 21:50:30 -0400568 /* Initialize ERATT handling flag */
569 phba->hba_flag &= ~HBA_ERATT_HANDLED;
570
dea31012005-04-17 16:05:31 -0500571 /* Enable appropriate host interrupts */
James Smart9940b972011-03-11 16:06:12 -0500572 if (lpfc_readl(phba->HCregaddr, &status)) {
573 spin_unlock_irq(&phba->hbalock);
574 return -EIO;
575 }
dea31012005-04-17 16:05:31 -0500576 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
577 if (psli->num_rings > 0)
578 status |= HC_R0INT_ENA;
579 if (psli->num_rings > 1)
580 status |= HC_R1INT_ENA;
581 if (psli->num_rings > 2)
582 status |= HC_R2INT_ENA;
583 if (psli->num_rings > 3)
584 status |= HC_R3INT_ENA;
585
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500586 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
587 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400588 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500589
dea31012005-04-17 16:05:31 -0500590 writel(status, phba->HCregaddr);
591 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500592 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500593
James Smart93996272008-08-24 21:50:30 -0400594 /* Set up ring-0 (ELS) timer */
595 timeout = phba->fc_ratov * 2;
James Smart256ec0d2013-04-17 20:14:58 -0400596 mod_timer(&vport->els_tmofunc,
597 jiffies + msecs_to_jiffies(1000 * timeout));
James Smart93996272008-08-24 21:50:30 -0400598 /* Set up heart beat (HB) timer */
James Smart256ec0d2013-04-17 20:14:58 -0400599 mod_timer(&phba->hb_tmofunc,
600 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -0500601 phba->hb_outstanding = 0;
602 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400603 /* Set up error attention (ERATT) polling timer */
James Smart256ec0d2013-04-17 20:14:58 -0400604 mod_timer(&phba->eratt_poll,
James Smart65791f12016-07-06 12:35:56 -0700605 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
dea31012005-04-17 16:05:31 -0500606
James Smarta0c87cb2009-07-19 10:01:10 -0400607 if (phba->hba_flag & LINK_DISABLED) {
608 lpfc_printf_log(phba,
609 KERN_ERR, LOG_INIT,
610 "2598 Adapter Link is disabled.\n");
611 lpfc_down_link(phba, pmb);
612 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
613 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
614 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
615 lpfc_printf_log(phba,
616 KERN_ERR, LOG_INIT,
617 "2599 Adapter failed to issue DOWN_LINK"
618 " mbox command rc 0x%x\n", rc);
619
620 mempool_free(pmb, phba->mbox_mem_pool);
621 return -EIO;
622 }
James Smarte40a02c2010-02-26 14:13:54 -0500623 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
James Smart026abb82011-12-13 13:20:45 -0500624 mempool_free(pmb, phba->mbox_mem_pool);
625 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
626 if (rc)
627 return rc;
dea31012005-04-17 16:05:31 -0500628 }
629 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400630 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500631 if (!pmb) {
632 phba->link_state = LPFC_HBA_ERROR;
633 return -ENOMEM;
634 }
635
James Smart57127f12007-10-27 13:37:05 -0400636 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
637 pmb->mbox_cmpl = lpfc_config_async_cmpl;
638 pmb->vport = phba->pport;
639 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500640
James Smart57127f12007-10-27 13:37:05 -0400641 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
642 lpfc_printf_log(phba,
643 KERN_ERR,
644 LOG_INIT,
645 "0456 Adapter failed to issue "
James Smarte4e74272009-07-19 10:01:38 -0400646 "ASYNCEVT_ENABLE mbox status x%x\n",
James Smart57127f12007-10-27 13:37:05 -0400647 rc);
648 mempool_free(pmb, phba->mbox_mem_pool);
649 }
James Smart97207482008-12-04 22:39:19 -0500650
651 /* Get Option rom version */
652 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500653 if (!pmb) {
654 phba->link_state = LPFC_HBA_ERROR;
655 return -ENOMEM;
656 }
657
James Smart97207482008-12-04 22:39:19 -0500658 lpfc_dump_wakeup_param(phba, pmb);
659 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
660 pmb->vport = phba->pport;
661 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
662
663 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
664 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
James Smarte4e74272009-07-19 10:01:38 -0400665 "to get Option ROM version status x%x\n", rc);
James Smart97207482008-12-04 22:39:19 -0500666 mempool_free(pmb, phba->mbox_mem_pool);
667 }
668
James Smartd7c255b2008-08-24 21:50:00 -0400669 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400670}
671
James Smarte59058c2008-08-24 21:49:00 -0400672/**
James Smart84d1b002010-02-12 14:42:33 -0500673 * lpfc_hba_init_link - Initialize the FC link
674 * @phba: pointer to lpfc hba data structure.
James Smart6e7288d2010-06-07 15:23:35 -0400675 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500676 *
677 * This routine will issue the INIT_LINK mailbox command call.
678 * It is available to other drivers through the lpfc_hba data
679 * structure for use as a delayed link up mechanism with the
680 * module parameter lpfc_suppress_link_up.
681 *
682 * Return code
683 * 0 - success
684 * Any other value - error
685 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400686static int
James Smart6e7288d2010-06-07 15:23:35 -0400687lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500688{
James Smart1b511972011-12-13 13:23:09 -0500689 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
690}
691
692/**
693 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
694 * @phba: pointer to lpfc hba data structure.
695 * @fc_topology: desired fc topology.
696 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
697 *
698 * This routine will issue the INIT_LINK mailbox command call.
699 * It is available to other drivers through the lpfc_hba data
700 * structure for use as a delayed link up mechanism with the
701 * module parameter lpfc_suppress_link_up.
702 *
703 * Return code
704 * 0 - success
705 * Any other value - error
706 **/
707int
708lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
709 uint32_t flag)
710{
James Smart84d1b002010-02-12 14:42:33 -0500711 struct lpfc_vport *vport = phba->pport;
712 LPFC_MBOXQ_t *pmb;
713 MAILBOX_t *mb;
714 int rc;
715
716 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
717 if (!pmb) {
718 phba->link_state = LPFC_HBA_ERROR;
719 return -ENOMEM;
720 }
721 mb = &pmb->u.mb;
722 pmb->vport = vport;
723
James Smart026abb82011-12-13 13:20:45 -0500724 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
725 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
726 !(phba->lmt & LMT_1Gb)) ||
727 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
728 !(phba->lmt & LMT_2Gb)) ||
729 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
730 !(phba->lmt & LMT_4Gb)) ||
731 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
732 !(phba->lmt & LMT_8Gb)) ||
733 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
734 !(phba->lmt & LMT_10Gb)) ||
735 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
James Smartd38dd522015-08-31 16:48:17 -0400736 !(phba->lmt & LMT_16Gb)) ||
737 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
James Smartfbd8a6b2018-02-22 08:18:45 -0800738 !(phba->lmt & LMT_32Gb)) ||
739 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) &&
740 !(phba->lmt & LMT_64Gb))) {
James Smart026abb82011-12-13 13:20:45 -0500741 /* Reset link speed to auto */
742 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
743 "1302 Invalid speed for this board:%d "
744 "Reset link speed to auto.\n",
745 phba->cfg_link_speed);
746 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
747 }
James Smart1b511972011-12-13 13:23:09 -0500748 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
James Smart84d1b002010-02-12 14:42:33 -0500749 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart1b511972011-12-13 13:23:09 -0500750 if (phba->sli_rev < LPFC_SLI_REV4)
751 lpfc_set_loopback_flag(phba);
James Smart6e7288d2010-06-07 15:23:35 -0400752 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart76a95d72010-11-20 23:11:48 -0500753 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
James Smart84d1b002010-02-12 14:42:33 -0500754 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
755 "0498 Adapter failed to init, mbxCmd x%x "
756 "INIT_LINK, mbxStatus x%x\n",
757 mb->mbxCommand, mb->mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -0500758 if (phba->sli_rev <= LPFC_SLI_REV3) {
759 /* Clear all interrupt enable conditions */
760 writel(0, phba->HCregaddr);
761 readl(phba->HCregaddr); /* flush */
762 /* Clear all pending interrupts */
763 writel(0xffffffff, phba->HAregaddr);
764 readl(phba->HAregaddr); /* flush */
765 }
James Smart84d1b002010-02-12 14:42:33 -0500766 phba->link_state = LPFC_HBA_ERROR;
James Smart6e7288d2010-06-07 15:23:35 -0400767 if (rc != MBX_BUSY || flag == MBX_POLL)
James Smart84d1b002010-02-12 14:42:33 -0500768 mempool_free(pmb, phba->mbox_mem_pool);
769 return -EIO;
770 }
James Smarte40a02c2010-02-26 14:13:54 -0500771 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
James Smart6e7288d2010-06-07 15:23:35 -0400772 if (flag == MBX_POLL)
773 mempool_free(pmb, phba->mbox_mem_pool);
James Smart84d1b002010-02-12 14:42:33 -0500774
775 return 0;
776}
777
778/**
779 * lpfc_hba_down_link - this routine downs the FC link
James Smart6e7288d2010-06-07 15:23:35 -0400780 * @phba: pointer to lpfc hba data structure.
781 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500782 *
783 * This routine will issue the DOWN_LINK mailbox command call.
784 * It is available to other drivers through the lpfc_hba data
785 * structure for use to stop the link.
786 *
787 * Return code
788 * 0 - success
789 * Any other value - error
790 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400791static int
James Smart6e7288d2010-06-07 15:23:35 -0400792lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500793{
794 LPFC_MBOXQ_t *pmb;
795 int rc;
796
797 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
798 if (!pmb) {
799 phba->link_state = LPFC_HBA_ERROR;
800 return -ENOMEM;
801 }
802
803 lpfc_printf_log(phba,
804 KERN_ERR, LOG_INIT,
805 "0491 Adapter Link is disabled.\n");
806 lpfc_down_link(phba, pmb);
807 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart6e7288d2010-06-07 15:23:35 -0400808 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart84d1b002010-02-12 14:42:33 -0500809 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
810 lpfc_printf_log(phba,
811 KERN_ERR, LOG_INIT,
812 "2522 Adapter failed to issue DOWN_LINK"
813 " mbox command rc 0x%x\n", rc);
814
815 mempool_free(pmb, phba->mbox_mem_pool);
816 return -EIO;
817 }
James Smart6e7288d2010-06-07 15:23:35 -0400818 if (flag == MBX_POLL)
819 mempool_free(pmb, phba->mbox_mem_pool);
820
James Smart84d1b002010-02-12 14:42:33 -0500821 return 0;
822}
823
824/**
James Smart3621a712009-04-06 18:47:14 -0400825 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400826 * @phba: pointer to lpfc HBA data structure.
827 *
828 * This routine will do LPFC uninitialization before the HBA is reset when
829 * bringing down the SLI Layer.
830 *
831 * Return codes
832 * 0 - success.
833 * Any other value - error.
834 **/
dea31012005-04-17 16:05:31 -0500835int
James Smart2e0fef82007-06-17 19:56:36 -0500836lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500837{
James Smart1b32f6a2008-02-08 18:49:39 -0500838 struct lpfc_vport **vports;
839 int i;
James Smart3772a992009-05-22 14:50:54 -0400840
841 if (phba->sli_rev <= LPFC_SLI_REV3) {
842 /* Disable interrupts */
843 writel(0, phba->HCregaddr);
844 readl(phba->HCregaddr); /* flush */
845 }
dea31012005-04-17 16:05:31 -0500846
James Smart1b32f6a2008-02-08 18:49:39 -0500847 if (phba->pport->load_flag & FC_UNLOADING)
848 lpfc_cleanup_discovery_resources(phba->pport);
849 else {
850 vports = lpfc_create_vport_work_array(phba);
851 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -0400852 for (i = 0; i <= phba->max_vports &&
853 vports[i] != NULL; i++)
James Smart1b32f6a2008-02-08 18:49:39 -0500854 lpfc_cleanup_discovery_resources(vports[i]);
855 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500856 }
857 return 0;
dea31012005-04-17 16:05:31 -0500858}
859
James Smarte59058c2008-08-24 21:49:00 -0400860/**
James Smart68e814f2014-05-21 08:04:59 -0400861 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
862 * rspiocb which got deferred
863 *
864 * @phba: pointer to lpfc HBA data structure.
865 *
866 * This routine will cleanup completed slow path events after HBA is reset
867 * when bringing down the SLI Layer.
868 *
869 *
870 * Return codes
871 * void.
872 **/
873static void
874lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
875{
876 struct lpfc_iocbq *rspiocbq;
877 struct hbq_dmabuf *dmabuf;
878 struct lpfc_cq_event *cq_event;
879
880 spin_lock_irq(&phba->hbalock);
881 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
882 spin_unlock_irq(&phba->hbalock);
883
884 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
885 /* Get the response iocb from the head of work queue */
886 spin_lock_irq(&phba->hbalock);
887 list_remove_head(&phba->sli4_hba.sp_queue_event,
888 cq_event, struct lpfc_cq_event, list);
889 spin_unlock_irq(&phba->hbalock);
890
891 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
892 case CQE_CODE_COMPL_WQE:
893 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
894 cq_event);
895 lpfc_sli_release_iocbq(phba, rspiocbq);
896 break;
897 case CQE_CODE_RECEIVE:
898 case CQE_CODE_RECEIVE_V1:
899 dmabuf = container_of(cq_event, struct hbq_dmabuf,
900 cq_event);
901 lpfc_in_buf_free(phba, &dmabuf->dbuf);
902 }
903 }
904}
905
906/**
James Smartbcece5f2014-04-04 13:51:34 -0400907 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
908 * @phba: pointer to lpfc HBA data structure.
909 *
910 * This routine will cleanup posted ELS buffers after the HBA is reset
911 * when bringing down the SLI Layer.
912 *
913 *
914 * Return codes
915 * void.
916 **/
917static void
918lpfc_hba_free_post_buf(struct lpfc_hba *phba)
919{
920 struct lpfc_sli *psli = &phba->sli;
921 struct lpfc_sli_ring *pring;
922 struct lpfc_dmabuf *mp, *next_mp;
James Smart07eab622014-04-04 13:51:44 -0400923 LIST_HEAD(buflist);
924 int count;
James Smartbcece5f2014-04-04 13:51:34 -0400925
926 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
927 lpfc_sli_hbqbuf_free_all(phba);
928 else {
929 /* Cleanup preposted buffers on the ELS ring */
James Smart895427b2017-02-12 13:52:30 -0800930 pring = &psli->sli3_ring[LPFC_ELS_RING];
James Smart07eab622014-04-04 13:51:44 -0400931 spin_lock_irq(&phba->hbalock);
932 list_splice_init(&pring->postbufq, &buflist);
933 spin_unlock_irq(&phba->hbalock);
934
935 count = 0;
936 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
James Smartbcece5f2014-04-04 13:51:34 -0400937 list_del(&mp->list);
James Smart07eab622014-04-04 13:51:44 -0400938 count++;
James Smartbcece5f2014-04-04 13:51:34 -0400939 lpfc_mbuf_free(phba, mp->virt, mp->phys);
940 kfree(mp);
941 }
James Smart07eab622014-04-04 13:51:44 -0400942
943 spin_lock_irq(&phba->hbalock);
944 pring->postbufq_cnt -= count;
James Smartbcece5f2014-04-04 13:51:34 -0400945 spin_unlock_irq(&phba->hbalock);
946 }
947}
948
949/**
950 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
951 * @phba: pointer to lpfc HBA data structure.
952 *
953 * This routine will cleanup the txcmplq after the HBA is reset when bringing
954 * down the SLI Layer.
955 *
956 * Return codes
957 * void
958 **/
959static void
960lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
961{
962 struct lpfc_sli *psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -0800963 struct lpfc_queue *qp = NULL;
James Smartbcece5f2014-04-04 13:51:34 -0400964 struct lpfc_sli_ring *pring;
965 LIST_HEAD(completions);
966 int i;
James Smartc1dd9112018-01-30 15:58:57 -0800967 struct lpfc_iocbq *piocb, *next_iocb;
James Smartbcece5f2014-04-04 13:51:34 -0400968
James Smart895427b2017-02-12 13:52:30 -0800969 if (phba->sli_rev != LPFC_SLI_REV4) {
970 for (i = 0; i < psli->num_rings; i++) {
971 pring = &psli->sli3_ring[i];
James Smartbcece5f2014-04-04 13:51:34 -0400972 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -0800973 /* At this point in time the HBA is either reset or DOA
974 * Nothing should be on txcmplq as it will
975 * NEVER complete.
976 */
977 list_splice_init(&pring->txcmplq, &completions);
978 pring->txcmplq_cnt = 0;
James Smartbcece5f2014-04-04 13:51:34 -0400979 spin_unlock_irq(&phba->hbalock);
980
James Smart895427b2017-02-12 13:52:30 -0800981 lpfc_sli_abort_iocb_ring(phba, pring);
982 }
James Smartbcece5f2014-04-04 13:51:34 -0400983 /* Cancel all the IOCBs from the completions list */
James Smart895427b2017-02-12 13:52:30 -0800984 lpfc_sli_cancel_iocbs(phba, &completions,
985 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
986 return;
987 }
988 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
989 pring = qp->pring;
990 if (!pring)
991 continue;
992 spin_lock_irq(&pring->ring_lock);
James Smartc1dd9112018-01-30 15:58:57 -0800993 list_for_each_entry_safe(piocb, next_iocb,
994 &pring->txcmplq, list)
995 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
James Smart895427b2017-02-12 13:52:30 -0800996 list_splice_init(&pring->txcmplq, &completions);
997 pring->txcmplq_cnt = 0;
998 spin_unlock_irq(&pring->ring_lock);
James Smartbcece5f2014-04-04 13:51:34 -0400999 lpfc_sli_abort_iocb_ring(phba, pring);
1000 }
James Smart895427b2017-02-12 13:52:30 -08001001 /* Cancel all the IOCBs from the completions list */
1002 lpfc_sli_cancel_iocbs(phba, &completions,
1003 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smartbcece5f2014-04-04 13:51:34 -04001004}
1005
1006/**
James Smart3772a992009-05-22 14:50:54 -04001007 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smartbcece5f2014-04-04 13:51:34 -04001008 int i;
James Smarte59058c2008-08-24 21:49:00 -04001009 * @phba: pointer to lpfc HBA data structure.
1010 *
1011 * This routine will do uninitialization after the HBA is reset when bring
1012 * down the SLI Layer.
1013 *
1014 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001015 * 0 - success.
James Smarte59058c2008-08-24 21:49:00 -04001016 * Any other value - error.
1017 **/
James Smart3772a992009-05-22 14:50:54 -04001018static int
1019lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001020{
James Smartbcece5f2014-04-04 13:51:34 -04001021 lpfc_hba_free_post_buf(phba);
1022 lpfc_hba_clean_txcmplq(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001023 return 0;
1024}
James Smart5af5eee2010-10-22 11:06:38 -04001025
James Smartda0436e2009-05-22 14:51:39 -04001026/**
1027 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
1028 * @phba: pointer to lpfc HBA data structure.
1029 *
1030 * This routine will do uninitialization after the HBA is reset when bring
1031 * down the SLI Layer.
1032 *
1033 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001034 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001035 * Any other value - error.
1036 **/
1037static int
1038lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1039{
1040 struct lpfc_scsi_buf *psb, *psb_next;
James Smart86c67372017-04-21 16:05:04 -07001041 struct lpfc_nvmet_rcv_ctx *ctxp, *ctxp_next;
James Smartda0436e2009-05-22 14:51:39 -04001042 LIST_HEAD(aborts);
James Smart895427b2017-02-12 13:52:30 -08001043 LIST_HEAD(nvme_aborts);
James Smart86c67372017-04-21 16:05:04 -07001044 LIST_HEAD(nvmet_aborts);
James Smartda0436e2009-05-22 14:51:39 -04001045 unsigned long iflag = 0;
James Smart0f65ff62010-02-26 14:14:23 -05001046 struct lpfc_sglq *sglq_entry = NULL;
James Smartcf1a1d32017-12-08 17:18:03 -08001047 int cnt;
James Smart0f65ff62010-02-26 14:14:23 -05001048
James Smart895427b2017-02-12 13:52:30 -08001049
1050 lpfc_sli_hbqbuf_free_all(phba);
James Smartbcece5f2014-04-04 13:51:34 -04001051 lpfc_hba_clean_txcmplq(phba);
1052
James Smartda0436e2009-05-22 14:51:39 -04001053 /* At this point in time the HBA is either reset or DOA. Either
1054 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
James Smart895427b2017-02-12 13:52:30 -08001055 * on the lpfc_els_sgl_list so that it can either be freed if the
James Smartda0436e2009-05-22 14:51:39 -04001056 * driver is unloading or reposted if the driver is restarting
1057 * the port.
1058 */
James Smart895427b2017-02-12 13:52:30 -08001059 spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */
James Smartda0436e2009-05-22 14:51:39 -04001060 /* scsl_buf_list */
James Smart895427b2017-02-12 13:52:30 -08001061 /* sgl_list_lock required because worker thread uses this
James Smartda0436e2009-05-22 14:51:39 -04001062 * list.
1063 */
James Smart895427b2017-02-12 13:52:30 -08001064 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05001065 list_for_each_entry(sglq_entry,
1066 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1067 sglq_entry->state = SGL_FREED;
1068
James Smartda0436e2009-05-22 14:51:39 -04001069 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
James Smart895427b2017-02-12 13:52:30 -08001070 &phba->sli4_hba.lpfc_els_sgl_list);
1071
James Smartf358dd02017-02-12 13:52:34 -08001072
James Smart895427b2017-02-12 13:52:30 -08001073 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04001074 /* abts_scsi_buf_list_lock required because worker thread uses this
1075 * list.
1076 */
James Smart895427b2017-02-12 13:52:30 -08001077 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
1078 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1079 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
1080 &aborts);
1081 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1082 }
1083
1084 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1085 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1086 list_splice_init(&phba->sli4_hba.lpfc_abts_nvme_buf_list,
1087 &nvme_aborts);
James Smart86c67372017-04-21 16:05:04 -07001088 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1089 &nvmet_aborts);
James Smart895427b2017-02-12 13:52:30 -08001090 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1091 }
1092
James Smartda0436e2009-05-22 14:51:39 -04001093 spin_unlock_irq(&phba->hbalock);
1094
1095 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1096 psb->pCmd = NULL;
1097 psb->status = IOSTAT_SUCCESS;
1098 }
James Smarta40fc5f2013-04-17 20:17:40 -04001099 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1100 list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
1101 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
James Smart68e814f2014-05-21 08:04:59 -04001102
James Smart86c67372017-04-21 16:05:04 -07001103 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smartcf1a1d32017-12-08 17:18:03 -08001104 cnt = 0;
James Smart86c67372017-04-21 16:05:04 -07001105 list_for_each_entry_safe(psb, psb_next, &nvme_aborts, list) {
1106 psb->pCmd = NULL;
1107 psb->status = IOSTAT_SUCCESS;
James Smartcf1a1d32017-12-08 17:18:03 -08001108 cnt++;
James Smart86c67372017-04-21 16:05:04 -07001109 }
1110 spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag);
James Smartcf1a1d32017-12-08 17:18:03 -08001111 phba->put_nvme_bufs += cnt;
James Smart86c67372017-04-21 16:05:04 -07001112 list_splice(&nvme_aborts, &phba->lpfc_nvme_buf_list_put);
1113 spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag);
1114
1115 list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) {
1116 ctxp->flag &= ~(LPFC_NVMET_XBUSY | LPFC_NVMET_ABORT_OP);
James Smart6c621a22017-05-15 15:20:45 -07001117 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
James Smart86c67372017-04-21 16:05:04 -07001118 }
James Smart895427b2017-02-12 13:52:30 -08001119 }
James Smart895427b2017-02-12 13:52:30 -08001120
James Smart68e814f2014-05-21 08:04:59 -04001121 lpfc_sli4_free_sp_events(phba);
James Smartda0436e2009-05-22 14:51:39 -04001122 return 0;
1123}
1124
1125/**
1126 * lpfc_hba_down_post - Wrapper func for hba down post routine
1127 * @phba: pointer to lpfc HBA data structure.
1128 *
1129 * This routine wraps the actual SLI3 or SLI4 routine for performing
1130 * uninitialization after the HBA is reset when bring down the SLI Layer.
1131 *
1132 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001133 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001134 * Any other value - error.
1135 **/
1136int
1137lpfc_hba_down_post(struct lpfc_hba *phba)
1138{
1139 return (*phba->lpfc_hba_down_post)(phba);
1140}
Jamie Wellnitz41415862006-02-28 19:25:27 -05001141
James Smarte59058c2008-08-24 21:49:00 -04001142/**
James Smart3621a712009-04-06 18:47:14 -04001143 * lpfc_hb_timeout - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001144 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1145 *
1146 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1147 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1148 * work-port-events bitmap and the worker thread is notified. This timeout
1149 * event will be used by the worker thread to invoke the actual timeout
1150 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1151 * be performed in the timeout handler and the HBA timeout event bit shall
1152 * be cleared by the worker thread after it has taken the event bitmap out.
1153 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001154static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07001155lpfc_hb_timeout(struct timer_list *t)
James Smart858c9f62007-06-17 19:56:39 -05001156{
1157 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001158 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -05001159 unsigned long iflag;
1160
Kees Cookf22eb4d2017-09-06 20:24:26 -07001161 phba = from_timer(phba, t, hb_tmofunc);
James Smart93996272008-08-24 21:50:30 -04001162
1163 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -05001164 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001165 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1166 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -05001167 phba->pport->work_port_events |= WORKER_HB_TMO;
1168 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1169
James Smart93996272008-08-24 21:50:30 -04001170 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -04001171 if (!tmo_posted)
1172 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -05001173 return;
1174}
1175
James Smarte59058c2008-08-24 21:49:00 -04001176/**
James Smart19ca7602010-11-20 23:11:55 -05001177 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1178 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1179 *
1180 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1181 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1182 * work-port-events bitmap and the worker thread is notified. This timeout
1183 * event will be used by the worker thread to invoke the actual timeout
1184 * handler routine, lpfc_rrq_handler. Any periodical operations will
1185 * be performed in the timeout handler and the RRQ timeout event bit shall
1186 * be cleared by the worker thread after it has taken the event bitmap out.
1187 **/
1188static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07001189lpfc_rrq_timeout(struct timer_list *t)
James Smart19ca7602010-11-20 23:11:55 -05001190{
1191 struct lpfc_hba *phba;
James Smart19ca7602010-11-20 23:11:55 -05001192 unsigned long iflag;
1193
Kees Cookf22eb4d2017-09-06 20:24:26 -07001194 phba = from_timer(phba, t, rrq_tmr);
James Smart19ca7602010-11-20 23:11:55 -05001195 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001196 if (!(phba->pport->load_flag & FC_UNLOADING))
1197 phba->hba_flag |= HBA_RRQ_ACTIVE;
1198 else
1199 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
James Smart19ca7602010-11-20 23:11:55 -05001200 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001201
1202 if (!(phba->pport->load_flag & FC_UNLOADING))
1203 lpfc_worker_wake_up(phba);
James Smart19ca7602010-11-20 23:11:55 -05001204}
1205
1206/**
James Smart3621a712009-04-06 18:47:14 -04001207 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -04001208 * @phba: pointer to lpfc hba data structure.
1209 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1210 *
1211 * This is the callback function to the lpfc heart-beat mailbox command.
1212 * If configured, the lpfc driver issues the heart-beat mailbox command to
1213 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1214 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1215 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1216 * heart-beat outstanding state. Once the mailbox command comes back and
1217 * no error conditions detected, the heart-beat mailbox command timer is
1218 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1219 * state is cleared for the next heart-beat. If the timer expired with the
1220 * heart-beat outstanding state set, the driver will put the HBA offline.
1221 **/
James Smart858c9f62007-06-17 19:56:39 -05001222static void
1223lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1224{
1225 unsigned long drvr_flag;
1226
1227 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1228 phba->hb_outstanding = 0;
1229 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1230
James Smart93996272008-08-24 21:50:30 -04001231 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -05001232 mempool_free(pmboxq, phba->mbox_mem_pool);
1233 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1234 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -04001235 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -05001236 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001237 jiffies +
1238 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001239 return;
1240}
1241
James Smarte59058c2008-08-24 21:49:00 -04001242/**
James Smart3621a712009-04-06 18:47:14 -04001243 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001244 * @phba: pointer to lpfc hba data structure.
1245 *
1246 * This is the actual HBA-timer timeout handler to be invoked by the worker
1247 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1248 * handler performs any periodic operations needed for the device. If such
1249 * periodic event has already been attended to either in the interrupt handler
1250 * or by processing slow-ring or fast-ring events within the HBA-timer
1251 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1252 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1253 * is configured and there is no heart-beat mailbox command outstanding, a
1254 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1255 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1256 * to offline.
1257 **/
James Smart858c9f62007-06-17 19:56:39 -05001258void
1259lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1260{
James Smart45ed1192009-10-02 15:17:02 -04001261 struct lpfc_vport **vports;
James Smart858c9f62007-06-17 19:56:39 -05001262 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -05001263 struct lpfc_dmabuf *buf_ptr;
James Smart45ed1192009-10-02 15:17:02 -04001264 int retval, i;
James Smart858c9f62007-06-17 19:56:39 -05001265 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -05001266 LIST_HEAD(completions);
James Smart0cf07f842017-06-01 21:07:10 -07001267 struct lpfc_queue *qp;
1268 unsigned long time_elapsed;
1269 uint32_t tick_cqe, max_cqe, val;
1270 uint64_t tot, data1, data2, data3;
Dick Kennedy66d7ce92017-08-23 16:55:42 -07001271 struct lpfc_nvmet_tgtport *tgtp;
James Smart0cf07f842017-06-01 21:07:10 -07001272 struct lpfc_register reg_data;
James Smart66a210f2018-04-09 14:24:23 -07001273 struct nvme_fc_local_port *localport;
1274 struct lpfc_nvme_lport *lport;
1275 struct lpfc_nvme_ctrl_stat *cstat;
James Smart0cf07f842017-06-01 21:07:10 -07001276 void __iomem *eqdreg = phba->sli4_hba.u.if_type2.EQDregaddr;
James Smart858c9f62007-06-17 19:56:39 -05001277
James Smart45ed1192009-10-02 15:17:02 -04001278 vports = lpfc_create_vport_work_array(phba);
1279 if (vports != NULL)
James Smart4258e982015-12-16 18:11:58 -05001280 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart45ed1192009-10-02 15:17:02 -04001281 lpfc_rcv_seq_check_edtov(vports[i]);
James Smart4258e982015-12-16 18:11:58 -05001282 lpfc_fdmi_num_disc_check(vports[i]);
1283 }
James Smart45ed1192009-10-02 15:17:02 -04001284 lpfc_destroy_vport_work_array(phba, vports);
1285
James Smart858c9f62007-06-17 19:56:39 -05001286 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -04001287 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -05001288 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1289 return;
1290
James Smart0cf07f842017-06-01 21:07:10 -07001291 if (phba->cfg_auto_imax) {
1292 if (!phba->last_eqdelay_time) {
1293 phba->last_eqdelay_time = jiffies;
1294 goto skip_eqdelay;
1295 }
1296 time_elapsed = jiffies - phba->last_eqdelay_time;
1297 phba->last_eqdelay_time = jiffies;
1298
1299 tot = 0xffff;
1300 /* Check outstanding IO count */
1301 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1302 if (phba->nvmet_support) {
Dick Kennedy66d7ce92017-08-23 16:55:42 -07001303 tgtp = phba->targetport->private;
1304 /* Calculate outstanding IOs */
1305 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
1306 tot += atomic_read(&tgtp->xmt_fcp_release);
1307 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
James Smart0cf07f842017-06-01 21:07:10 -07001308 } else {
James Smart66a210f2018-04-09 14:24:23 -07001309 localport = phba->pport->localport;
1310 if (!localport || !localport->private)
1311 goto skip_eqdelay;
1312 lport = (struct lpfc_nvme_lport *)
1313 localport->private;
1314 tot = 0;
1315 for (i = 0;
1316 i < phba->cfg_nvme_io_channel; i++) {
1317 cstat = &lport->cstat[i];
1318 data1 = atomic_read(
1319 &cstat->fc4NvmeInputRequests);
1320 data2 = atomic_read(
1321 &cstat->fc4NvmeOutputRequests);
1322 data3 = atomic_read(
1323 &cstat->fc4NvmeControlRequests);
1324 tot += (data1 + data2 + data3);
1325 tot -= atomic_read(
1326 &cstat->fc4NvmeIoCmpls);
1327 }
James Smart0cf07f842017-06-01 21:07:10 -07001328 }
1329 }
1330
1331 /* Interrupts per sec per EQ */
1332 val = phba->cfg_fcp_imax / phba->io_channel_irqs;
1333 tick_cqe = val / CONFIG_HZ; /* Per tick per EQ */
1334
1335 /* Assume 1 CQE/ISR, calc max CQEs allowed for time duration */
1336 max_cqe = time_elapsed * tick_cqe;
1337
1338 for (i = 0; i < phba->io_channel_irqs; i++) {
1339 /* Fast-path EQ */
1340 qp = phba->sli4_hba.hba_eq[i];
1341 if (!qp)
1342 continue;
1343
1344 /* Use no EQ delay if we don't have many outstanding
1345 * IOs, or if we are only processing 1 CQE/ISR or less.
1346 * Otherwise, assume we can process up to lpfc_fcp_imax
1347 * interrupts per HBA.
1348 */
1349 if (tot < LPFC_NODELAY_MAX_IO ||
1350 qp->EQ_cqe_cnt <= max_cqe)
1351 val = 0;
1352 else
1353 val = phba->cfg_fcp_imax;
1354
1355 if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) {
1356 /* Use EQ Delay Register method */
1357
1358 /* Convert for EQ Delay register */
1359 if (val) {
1360 /* First, interrupts per sec per EQ */
1361 val = phba->cfg_fcp_imax /
1362 phba->io_channel_irqs;
1363
1364 /* us delay between each interrupt */
1365 val = LPFC_SEC_TO_USEC / val;
1366 }
1367 if (val != qp->q_mode) {
1368 reg_data.word0 = 0;
1369 bf_set(lpfc_sliport_eqdelay_id,
1370 &reg_data, qp->queue_id);
1371 bf_set(lpfc_sliport_eqdelay_delay,
1372 &reg_data, val);
1373 writel(reg_data.word0, eqdreg);
1374 }
1375 } else {
1376 /* Use mbox command method */
1377 if (val != qp->q_mode)
1378 lpfc_modify_hba_eq_delay(phba, i,
1379 1, val);
1380 }
1381
1382 /*
1383 * val is cfg_fcp_imax or 0 for mbox delay or us delay
1384 * between interrupts for EQDR.
1385 */
1386 qp->q_mode = val;
1387 qp->EQ_cqe_cnt = 0;
1388 }
1389 }
1390
1391skip_eqdelay:
James Smart858c9f62007-06-17 19:56:39 -05001392 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -05001393
James Smart256ec0d2013-04-17 20:14:58 -04001394 if (time_after(phba->last_completion_time +
1395 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1396 jiffies)) {
James Smart858c9f62007-06-17 19:56:39 -05001397 spin_unlock_irq(&phba->pport->work_port_lock);
1398 if (!phba->hb_outstanding)
1399 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001400 jiffies +
1401 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001402 else
1403 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001404 jiffies +
1405 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001406 return;
1407 }
1408 spin_unlock_irq(&phba->pport->work_port_lock);
1409
James Smart0ff10d42008-01-11 01:52:36 -05001410 if (phba->elsbuf_cnt &&
1411 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1412 spin_lock_irq(&phba->hbalock);
1413 list_splice_init(&phba->elsbuf, &completions);
1414 phba->elsbuf_cnt = 0;
1415 phba->elsbuf_prev_cnt = 0;
1416 spin_unlock_irq(&phba->hbalock);
1417
1418 while (!list_empty(&completions)) {
1419 list_remove_head(&completions, buf_ptr,
1420 struct lpfc_dmabuf, list);
1421 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1422 kfree(buf_ptr);
1423 }
1424 }
1425 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1426
James Smart858c9f62007-06-17 19:56:39 -05001427 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -05001428 if (phba->cfg_enable_hba_heartbeat) {
1429 if (!phba->hb_outstanding) {
James Smartbc739052010-08-04 16:11:18 -04001430 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1431 (list_empty(&psli->mboxq))) {
1432 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1433 GFP_KERNEL);
1434 if (!pmboxq) {
1435 mod_timer(&phba->hb_tmofunc,
1436 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001437 msecs_to_jiffies(1000 *
1438 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001439 return;
1440 }
James Smart13815c82008-01-11 01:52:48 -05001441
James Smartbc739052010-08-04 16:11:18 -04001442 lpfc_heart_beat(phba, pmboxq);
1443 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1444 pmboxq->vport = phba->pport;
1445 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1446 MBX_NOWAIT);
James Smart13815c82008-01-11 01:52:48 -05001447
James Smartbc739052010-08-04 16:11:18 -04001448 if (retval != MBX_BUSY &&
1449 retval != MBX_SUCCESS) {
1450 mempool_free(pmboxq,
1451 phba->mbox_mem_pool);
1452 mod_timer(&phba->hb_tmofunc,
1453 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001454 msecs_to_jiffies(1000 *
1455 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001456 return;
1457 }
1458 phba->skipped_hb = 0;
1459 phba->hb_outstanding = 1;
1460 } else if (time_before_eq(phba->last_completion_time,
1461 phba->skipped_hb)) {
1462 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1463 "2857 Last completion time not "
1464 " updated in %d ms\n",
1465 jiffies_to_msecs(jiffies
1466 - phba->last_completion_time));
1467 } else
1468 phba->skipped_hb = jiffies;
1469
James Smart858c9f62007-06-17 19:56:39 -05001470 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001471 jiffies +
1472 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001473 return;
James Smart13815c82008-01-11 01:52:48 -05001474 } else {
1475 /*
1476 * If heart beat timeout called with hb_outstanding set
James Smartdcf2a4e2010-09-29 11:18:53 -04001477 * we need to give the hb mailbox cmd a chance to
1478 * complete or TMO.
James Smart13815c82008-01-11 01:52:48 -05001479 */
James Smartdcf2a4e2010-09-29 11:18:53 -04001480 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1481 "0459 Adapter heartbeat still out"
1482 "standing:last compl time was %d ms.\n",
1483 jiffies_to_msecs(jiffies
1484 - phba->last_completion_time));
1485 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001486 jiffies +
1487 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001488 }
James Smart4258e982015-12-16 18:11:58 -05001489 } else {
1490 mod_timer(&phba->hb_tmofunc,
1491 jiffies +
1492 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001493 }
1494}
1495
James Smarte59058c2008-08-24 21:49:00 -04001496/**
James Smart3621a712009-04-06 18:47:14 -04001497 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -04001498 * @phba: pointer to lpfc hba data structure.
1499 *
1500 * This routine is called to bring the HBA offline when HBA hardware error
1501 * other than Port Error 6 has been detected.
1502 **/
James Smart09372822008-01-11 01:52:54 -05001503static void
1504lpfc_offline_eratt(struct lpfc_hba *phba)
1505{
1506 struct lpfc_sli *psli = &phba->sli;
1507
1508 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001509 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -05001510 spin_unlock_irq(&phba->hbalock);
James Smart618a5232012-06-12 13:54:36 -04001511 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart09372822008-01-11 01:52:54 -05001512
1513 lpfc_offline(phba);
1514 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001515 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001516 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001517 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001518 lpfc_hba_down_post(phba);
1519 lpfc_sli_brdready(phba, HS_MBRDY);
1520 lpfc_unblock_mgmt_io(phba);
1521 phba->link_state = LPFC_HBA_ERROR;
1522 return;
1523}
1524
James Smarte59058c2008-08-24 21:49:00 -04001525/**
James Smartda0436e2009-05-22 14:51:39 -04001526 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1527 * @phba: pointer to lpfc hba data structure.
1528 *
1529 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1530 * other than Port Error 6 has been detected.
1531 **/
James Smarta88dbb62013-04-17 20:18:39 -04001532void
James Smartda0436e2009-05-22 14:51:39 -04001533lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1534{
James Smart946727d2015-04-07 15:07:09 -04001535 spin_lock_irq(&phba->hbalock);
1536 phba->link_state = LPFC_HBA_ERROR;
1537 spin_unlock_irq(&phba->hbalock);
1538
James Smart618a5232012-06-12 13:54:36 -04001539 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smartda0436e2009-05-22 14:51:39 -04001540 lpfc_offline(phba);
James Smartda0436e2009-05-22 14:51:39 -04001541 lpfc_hba_down_post(phba);
James Smartda0436e2009-05-22 14:51:39 -04001542 lpfc_unblock_mgmt_io(phba);
James Smartda0436e2009-05-22 14:51:39 -04001543}
1544
1545/**
James Smarta257bf92009-04-06 18:48:10 -04001546 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1547 * @phba: pointer to lpfc hba data structure.
1548 *
1549 * This routine is invoked to handle the deferred HBA hardware error
1550 * conditions. This type of error is indicated by HBA by setting ER1
1551 * and another ER bit in the host status register. The driver will
1552 * wait until the ER1 bit clears before handling the error condition.
1553 **/
1554static void
1555lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1556{
1557 uint32_t old_host_status = phba->work_hs;
James Smarta257bf92009-04-06 18:48:10 -04001558 struct lpfc_sli *psli = &phba->sli;
1559
James Smartf4b4c682009-05-22 14:53:12 -04001560 /* If the pci channel is offline, ignore possible errors,
1561 * since we cannot communicate with the pci card anyway.
1562 */
1563 if (pci_channel_offline(phba->pcidev)) {
1564 spin_lock_irq(&phba->hbalock);
1565 phba->hba_flag &= ~DEFER_ERATT;
1566 spin_unlock_irq(&phba->hbalock);
1567 return;
1568 }
1569
James Smarta257bf92009-04-06 18:48:10 -04001570 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1571 "0479 Deferred Adapter Hardware Error "
1572 "Data: x%x x%x x%x\n",
1573 phba->work_hs,
1574 phba->work_status[0], phba->work_status[1]);
1575
1576 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001577 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001578 spin_unlock_irq(&phba->hbalock);
1579
1580
1581 /*
1582 * Firmware stops when it triggred erratt. That could cause the I/Os
1583 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1584 * SCSI layer retry it after re-establishing link.
1585 */
James Smartdb55fba2014-04-04 13:52:02 -04001586 lpfc_sli_abort_fcp_rings(phba);
James Smarta257bf92009-04-06 18:48:10 -04001587
1588 /*
1589 * There was a firmware error. Take the hba offline and then
1590 * attempt to restart it.
1591 */
James Smart618a5232012-06-12 13:54:36 -04001592 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smarta257bf92009-04-06 18:48:10 -04001593 lpfc_offline(phba);
1594
1595 /* Wait for the ER1 bit to clear.*/
1596 while (phba->work_hs & HS_FFER1) {
1597 msleep(100);
James Smart9940b972011-03-11 16:06:12 -05001598 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1599 phba->work_hs = UNPLUG_ERR ;
1600 break;
1601 }
James Smarta257bf92009-04-06 18:48:10 -04001602 /* If driver is unloading let the worker thread continue */
1603 if (phba->pport->load_flag & FC_UNLOADING) {
1604 phba->work_hs = 0;
1605 break;
1606 }
1607 }
1608
1609 /*
1610 * This is to ptrotect against a race condition in which
1611 * first write to the host attention register clear the
1612 * host status register.
1613 */
1614 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1615 phba->work_hs = old_host_status & ~HS_FFER1;
1616
James Smart3772a992009-05-22 14:50:54 -04001617 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001618 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001619 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001620 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1621 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1622}
1623
James Smart3772a992009-05-22 14:50:54 -04001624static void
1625lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1626{
1627 struct lpfc_board_event_header board_event;
1628 struct Scsi_Host *shost;
1629
1630 board_event.event_type = FC_REG_BOARD_EVENT;
1631 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1632 shost = lpfc_shost_from_vport(phba->pport);
1633 fc_host_post_vendor_event(shost, fc_get_event_number(),
1634 sizeof(board_event),
1635 (char *) &board_event,
1636 LPFC_NL_VENDOR_ID);
1637}
1638
James Smarta257bf92009-04-06 18:48:10 -04001639/**
James Smart3772a992009-05-22 14:50:54 -04001640 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001641 * @phba: pointer to lpfc hba data structure.
1642 *
1643 * This routine is invoked to handle the following HBA hardware error
1644 * conditions:
1645 * 1 - HBA error attention interrupt
1646 * 2 - DMA ring index out of range
1647 * 3 - Mailbox command came back as unknown
1648 **/
James Smart3772a992009-05-22 14:50:54 -04001649static void
1650lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001651{
James Smart2e0fef82007-06-17 19:56:36 -05001652 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001653 struct lpfc_sli *psli = &phba->sli;
James Smartd2873e42006-08-18 17:46:43 -04001654 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001655 unsigned long temperature;
1656 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001657 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001658
Linas Vepstas8d63f372007-02-14 14:28:36 -06001659 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001660 * since we cannot communicate with the pci card anyway.
1661 */
1662 if (pci_channel_offline(phba->pcidev)) {
1663 spin_lock_irq(&phba->hbalock);
1664 phba->hba_flag &= ~DEFER_ERATT;
1665 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001666 return;
James Smart3772a992009-05-22 14:50:54 -04001667 }
1668
James Smart13815c82008-01-11 01:52:48 -05001669 /* If resets are disabled then leave the HBA alone and return */
1670 if (!phba->cfg_enable_hba_reset)
1671 return;
dea31012005-04-17 16:05:31 -05001672
James Smartea2151b2008-09-07 11:52:10 -04001673 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001674 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001675
James Smarta257bf92009-04-06 18:48:10 -04001676 if (phba->hba_flag & DEFER_ERATT)
1677 lpfc_handle_deferred_eratt(phba);
1678
James Smartdcf2a4e2010-09-29 11:18:53 -04001679 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1680 if (phba->work_hs & HS_FFER6)
1681 /* Re-establishing Link */
1682 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1683 "1301 Re-establishing Link "
1684 "Data: x%x x%x x%x\n",
1685 phba->work_hs, phba->work_status[0],
1686 phba->work_status[1]);
1687 if (phba->work_hs & HS_FFER8)
1688 /* Device Zeroization */
1689 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1690 "2861 Host Authentication device "
1691 "zeroization Data:x%x x%x x%x\n",
1692 phba->work_hs, phba->work_status[0],
1693 phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001694
James Smart92d7f7b2007-06-17 19:56:38 -05001695 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001696 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001697 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001698
1699 /*
1700 * Firmware stops when it triggled erratt with HS_FFER6.
1701 * That could cause the I/Os dropped by the firmware.
1702 * Error iocb (I/O) on txcmplq and let the SCSI layer
1703 * retry it after re-establishing link.
1704 */
James Smartdb55fba2014-04-04 13:52:02 -04001705 lpfc_sli_abort_fcp_rings(phba);
dea31012005-04-17 16:05:31 -05001706
dea31012005-04-17 16:05:31 -05001707 /*
1708 * There was a firmware error. Take the hba offline and then
1709 * attempt to restart it.
1710 */
James Smart618a5232012-06-12 13:54:36 -04001711 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
dea31012005-04-17 16:05:31 -05001712 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001713 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001714 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001715 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001716 return;
1717 }
James Smart46fa3112007-04-25 09:51:45 -04001718 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001719 } else if (phba->work_hs & HS_CRIT_TEMP) {
1720 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1721 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1722 temp_event_data.event_code = LPFC_CRIT_TEMP;
1723 temp_event_data.data = (uint32_t)temperature;
1724
1725 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001726 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001727 "(%ld), taking this port offline "
1728 "Data: x%x x%x x%x\n",
1729 temperature, phba->work_hs,
1730 phba->work_status[0], phba->work_status[1]);
1731
1732 shost = lpfc_shost_from_vport(phba->pport);
1733 fc_host_post_vendor_event(shost, fc_get_event_number(),
1734 sizeof(temp_event_data),
1735 (char *) &temp_event_data,
1736 SCSI_NL_VID_TYPE_PCI
1737 | PCI_VENDOR_ID_EMULEX);
1738
James Smart7af67052007-10-27 13:38:11 -04001739 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001740 phba->over_temp_state = HBA_OVER_TEMP;
1741 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001742 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001743
dea31012005-04-17 16:05:31 -05001744 } else {
1745 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001746 * failure is a value other than FFER6. Do not call the offline
1747 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001748 */
1749 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001750 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001751 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001752 phba->work_hs,
dea31012005-04-17 16:05:31 -05001753 phba->work_status[0], phba->work_status[1]);
1754
James Smartd2873e42006-08-18 17:46:43 -04001755 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001756 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001757 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001758 sizeof(event_data), (char *) &event_data,
1759 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1760
James Smart09372822008-01-11 01:52:54 -05001761 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001762 }
James Smart93996272008-08-24 21:50:30 -04001763 return;
dea31012005-04-17 16:05:31 -05001764}
1765
James Smarte59058c2008-08-24 21:49:00 -04001766/**
James Smart618a5232012-06-12 13:54:36 -04001767 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1768 * @phba: pointer to lpfc hba data structure.
1769 * @mbx_action: flag for mailbox shutdown action.
1770 *
1771 * This routine is invoked to perform an SLI4 port PCI function reset in
1772 * response to port status register polling attention. It waits for port
1773 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1774 * During this process, interrupt vectors are freed and later requested
1775 * for handling possible port resource change.
1776 **/
1777static int
James Smarte10b2022014-02-20 09:57:43 -05001778lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1779 bool en_rn_msg)
James Smart618a5232012-06-12 13:54:36 -04001780{
1781 int rc;
1782 uint32_t intr_mode;
1783
James Smart27d6ac02018-02-22 08:18:42 -08001784 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
James Smart65791f12016-07-06 12:35:56 -07001785 LPFC_SLI_INTF_IF_TYPE_2) {
1786 /*
1787 * On error status condition, driver need to wait for port
1788 * ready before performing reset.
1789 */
1790 rc = lpfc_sli4_pdev_status_reg_wait(phba);
James Smart0e916ee2016-07-06 12:36:06 -07001791 if (rc)
James Smart65791f12016-07-06 12:35:56 -07001792 return rc;
James Smart618a5232012-06-12 13:54:36 -04001793 }
James Smart0e916ee2016-07-06 12:36:06 -07001794
James Smart65791f12016-07-06 12:35:56 -07001795 /* need reset: attempt for port recovery */
1796 if (en_rn_msg)
1797 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1798 "2887 Reset Needed: Attempting Port "
1799 "Recovery...\n");
1800 lpfc_offline_prep(phba, mbx_action);
1801 lpfc_offline(phba);
1802 /* release interrupt for possible resource change */
1803 lpfc_sli4_disable_intr(phba);
James Smart5a9eeff2018-11-29 16:09:32 -08001804 rc = lpfc_sli_brdrestart(phba);
1805 if (rc) {
1806 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1807 "6309 Failed to restart board\n");
1808 return rc;
1809 }
James Smart65791f12016-07-06 12:35:56 -07001810 /* request and enable interrupt */
1811 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1812 if (intr_mode == LPFC_INTR_ERROR) {
1813 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1814 "3175 Failed to enable interrupt\n");
1815 return -EIO;
1816 }
1817 phba->intr_mode = intr_mode;
1818 rc = lpfc_online(phba);
1819 if (rc == 0)
1820 lpfc_unblock_mgmt_io(phba);
1821
James Smart618a5232012-06-12 13:54:36 -04001822 return rc;
1823}
1824
1825/**
James Smartda0436e2009-05-22 14:51:39 -04001826 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1827 * @phba: pointer to lpfc hba data structure.
1828 *
1829 * This routine is invoked to handle the SLI4 HBA hardware error attention
1830 * conditions.
1831 **/
1832static void
1833lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1834{
1835 struct lpfc_vport *vport = phba->pport;
1836 uint32_t event_data;
1837 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001838 uint32_t if_type;
James Smart2e90f4b2011-12-13 13:22:37 -05001839 struct lpfc_register portstat_reg = {0};
1840 uint32_t reg_err1, reg_err2;
1841 uint32_t uerrlo_reg, uemasklo_reg;
James Smart65791f12016-07-06 12:35:56 -07001842 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
James Smarte10b2022014-02-20 09:57:43 -05001843 bool en_rn_msg = true;
James Smart946727d2015-04-07 15:07:09 -04001844 struct temp_event temp_event_data;
James Smart65791f12016-07-06 12:35:56 -07001845 struct lpfc_register portsmphr_reg;
1846 int rc, i;
James Smartda0436e2009-05-22 14:51:39 -04001847
1848 /* If the pci channel is offline, ignore possible errors, since
1849 * we cannot communicate with the pci card anyway.
1850 */
1851 if (pci_channel_offline(phba->pcidev))
1852 return;
James Smartda0436e2009-05-22 14:51:39 -04001853
James Smart65791f12016-07-06 12:35:56 -07001854 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
James Smart2fcee4b2010-12-15 17:57:46 -05001855 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1856 switch (if_type) {
1857 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart2e90f4b2011-12-13 13:22:37 -05001858 pci_rd_rc1 = lpfc_readl(
1859 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1860 &uerrlo_reg);
1861 pci_rd_rc2 = lpfc_readl(
1862 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1863 &uemasklo_reg);
1864 /* consider PCI bus read error as pci_channel_offline */
1865 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1866 return;
James Smart65791f12016-07-06 12:35:56 -07001867 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
1868 lpfc_sli4_offline_eratt(phba);
1869 return;
1870 }
1871 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1872 "7623 Checking UE recoverable");
1873
1874 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
1875 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1876 &portsmphr_reg.word0))
1877 continue;
1878
1879 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
1880 &portsmphr_reg);
1881 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1882 LPFC_PORT_SEM_UE_RECOVERABLE)
1883 break;
1884 /*Sleep for 1Sec, before checking SEMAPHORE */
1885 msleep(1000);
1886 }
1887
1888 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1889 "4827 smphr_port_status x%x : Waited %dSec",
1890 smphr_port_status, i);
1891
1892 /* Recoverable UE, reset the HBA device */
1893 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1894 LPFC_PORT_SEM_UE_RECOVERABLE) {
1895 for (i = 0; i < 20; i++) {
1896 msleep(1000);
1897 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1898 &portsmphr_reg.word0) &&
1899 (LPFC_POST_STAGE_PORT_READY ==
1900 bf_get(lpfc_port_smphr_port_status,
1901 &portsmphr_reg))) {
1902 rc = lpfc_sli4_port_sta_fn_reset(phba,
1903 LPFC_MBX_NO_WAIT, en_rn_msg);
1904 if (rc == 0)
1905 return;
1906 lpfc_printf_log(phba,
1907 KERN_ERR, LOG_INIT,
1908 "4215 Failed to recover UE");
1909 break;
1910 }
1911 }
1912 }
1913 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1914 "7624 Firmware not ready: Failing UE recovery,"
1915 " waited %dSec", i);
James Smart2fcee4b2010-12-15 17:57:46 -05001916 lpfc_sli4_offline_eratt(phba);
1917 break;
James Smart946727d2015-04-07 15:07:09 -04001918
James Smart2fcee4b2010-12-15 17:57:46 -05001919 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08001920 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2e90f4b2011-12-13 13:22:37 -05001921 pci_rd_rc1 = lpfc_readl(
1922 phba->sli4_hba.u.if_type2.STATUSregaddr,
1923 &portstat_reg.word0);
1924 /* consider PCI bus read error as pci_channel_offline */
James Smart6b5151f2012-01-18 16:24:06 -05001925 if (pci_rd_rc1 == -EIO) {
1926 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1927 "3151 PCI bus read access failure: x%x\n",
1928 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
James Smart2e90f4b2011-12-13 13:22:37 -05001929 return;
James Smart6b5151f2012-01-18 16:24:06 -05001930 }
James Smart2e90f4b2011-12-13 13:22:37 -05001931 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1932 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
James Smart2fcee4b2010-12-15 17:57:46 -05001933 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
James Smart2fcee4b2010-12-15 17:57:46 -05001934 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1935 "2889 Port Overtemperature event, "
James Smart946727d2015-04-07 15:07:09 -04001936 "taking port offline Data: x%x x%x\n",
1937 reg_err1, reg_err2);
1938
James Smart310429e2016-07-06 12:35:54 -07001939 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04001940 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1941 temp_event_data.event_code = LPFC_CRIT_TEMP;
1942 temp_event_data.data = 0xFFFFFFFF;
1943
1944 shost = lpfc_shost_from_vport(phba->pport);
1945 fc_host_post_vendor_event(shost, fc_get_event_number(),
1946 sizeof(temp_event_data),
1947 (char *)&temp_event_data,
1948 SCSI_NL_VID_TYPE_PCI
1949 | PCI_VENDOR_ID_EMULEX);
1950
James Smart2fcee4b2010-12-15 17:57:46 -05001951 spin_lock_irq(&phba->hbalock);
1952 phba->over_temp_state = HBA_OVER_TEMP;
1953 spin_unlock_irq(&phba->hbalock);
1954 lpfc_sli4_offline_eratt(phba);
James Smart946727d2015-04-07 15:07:09 -04001955 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001956 }
James Smart2e90f4b2011-12-13 13:22:37 -05001957 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smarte10b2022014-02-20 09:57:43 -05001958 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
James Smart2e90f4b2011-12-13 13:22:37 -05001959 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte10b2022014-02-20 09:57:43 -05001960 "3143 Port Down: Firmware Update "
1961 "Detected\n");
1962 en_rn_msg = false;
1963 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smart2e90f4b2011-12-13 13:22:37 -05001964 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1965 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1966 "3144 Port Down: Debug Dump\n");
1967 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1968 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1969 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1970 "3145 Port Down: Provisioning\n");
James Smart618a5232012-06-12 13:54:36 -04001971
James Smart946727d2015-04-07 15:07:09 -04001972 /* If resets are disabled then leave the HBA alone and return */
1973 if (!phba->cfg_enable_hba_reset)
1974 return;
1975
James Smart618a5232012-06-12 13:54:36 -04001976 /* Check port status register for function reset */
James Smarte10b2022014-02-20 09:57:43 -05001977 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1978 en_rn_msg);
James Smart618a5232012-06-12 13:54:36 -04001979 if (rc == 0) {
1980 /* don't report event on forced debug dump */
1981 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1982 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1983 return;
1984 else
1985 break;
James Smart2fcee4b2010-12-15 17:57:46 -05001986 }
James Smart618a5232012-06-12 13:54:36 -04001987 /* fall through for not able to recover */
James Smart6b5151f2012-01-18 16:24:06 -05001988 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1989 "3152 Unrecoverable error, bring the port "
1990 "offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05001991 lpfc_sli4_offline_eratt(phba);
1992 break;
1993 case LPFC_SLI_INTF_IF_TYPE_1:
1994 default:
1995 break;
1996 }
James Smart2e90f4b2011-12-13 13:22:37 -05001997 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1998 "3123 Report dump event to upper layer\n");
1999 /* Send an internal error event to mgmt application */
2000 lpfc_board_errevt_to_mgmt(phba);
2001
2002 event_data = FC_REG_DUMP_EVENT;
2003 shost = lpfc_shost_from_vport(vport);
2004 fc_host_post_vendor_event(shost, fc_get_event_number(),
2005 sizeof(event_data), (char *) &event_data,
2006 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
James Smartda0436e2009-05-22 14:51:39 -04002007}
2008
2009/**
2010 * lpfc_handle_eratt - Wrapper func for handling hba error attention
2011 * @phba: pointer to lpfc HBA data structure.
2012 *
2013 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
2014 * routine from the API jump table function pointer from the lpfc_hba struct.
2015 *
2016 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02002017 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04002018 * Any other value - error.
2019 **/
2020void
2021lpfc_handle_eratt(struct lpfc_hba *phba)
2022{
2023 (*phba->lpfc_handle_eratt)(phba);
2024}
2025
2026/**
James Smart3621a712009-04-06 18:47:14 -04002027 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04002028 * @phba: pointer to lpfc hba data structure.
2029 *
2030 * This routine is invoked from the worker thread to handle a HBA host
James Smart895427b2017-02-12 13:52:30 -08002031 * attention link event. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002032 **/
dea31012005-04-17 16:05:31 -05002033void
James Smart2e0fef82007-06-17 19:56:36 -05002034lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002035{
James Smart2e0fef82007-06-17 19:56:36 -05002036 struct lpfc_vport *vport = phba->pport;
2037 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05002038 LPFC_MBOXQ_t *pmb;
2039 volatile uint32_t control;
2040 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05002041 int rc = 0;
dea31012005-04-17 16:05:31 -05002042
2043 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05002044 if (!pmb) {
2045 rc = 1;
dea31012005-04-17 16:05:31 -05002046 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05002047 }
dea31012005-04-17 16:05:31 -05002048
2049 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05002050 if (!mp) {
2051 rc = 2;
dea31012005-04-17 16:05:31 -05002052 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05002053 }
dea31012005-04-17 16:05:31 -05002054
2055 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05002056 if (!mp->virt) {
2057 rc = 3;
dea31012005-04-17 16:05:31 -05002058 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05002059 }
dea31012005-04-17 16:05:31 -05002060
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05002061 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04002062 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05002063
2064 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05002065 lpfc_read_topology(phba, pmb, mp);
2066 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05002067 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04002068 /* Block ELS IOCBs until we have processed this mbox command */
James Smart895427b2017-02-12 13:52:30 -08002069 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04002070 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05002071 if (rc == MBX_NOT_FINISHED) {
2072 rc = 4;
James Smart14691152006-12-02 13:34:28 -05002073 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05002074 }
dea31012005-04-17 16:05:31 -05002075
2076 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05002077 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002078 writel(HA_LATT, phba->HAregaddr);
2079 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05002080 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002081
2082 return;
2083
James Smart14691152006-12-02 13:34:28 -05002084lpfc_handle_latt_free_mbuf:
James Smart895427b2017-02-12 13:52:30 -08002085 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05002086 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05002087lpfc_handle_latt_free_mp:
2088 kfree(mp);
2089lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04002090 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002091lpfc_handle_latt_err_exit:
2092 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05002093 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002094 psli->sli_flag |= LPFC_PROCESS_LA;
2095 control = readl(phba->HCregaddr);
2096 control |= HC_LAINT_ENA;
2097 writel(control, phba->HCregaddr);
2098 readl(phba->HCregaddr); /* flush */
2099
2100 /* Clear Link Attention in HA REG */
2101 writel(HA_LATT, phba->HAregaddr);
2102 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05002103 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002104 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002105 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002106
James Smart09372822008-01-11 01:52:54 -05002107 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
2108 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05002109
2110 return;
2111}
2112
James Smarte59058c2008-08-24 21:49:00 -04002113/**
James Smart3621a712009-04-06 18:47:14 -04002114 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04002115 * @phba: pointer to lpfc hba data structure.
2116 * @vpd: pointer to the vital product data.
2117 * @len: length of the vital product data in bytes.
2118 *
2119 * This routine parses the Vital Product Data (VPD). The VPD is treated as
2120 * an array of characters. In this routine, the ModelName, ProgramType, and
2121 * ModelDesc, etc. fields of the phba data structure will be populated.
2122 *
2123 * Return codes
2124 * 0 - pointer to the VPD passed in is NULL
2125 * 1 - success
2126 **/
James Smart3772a992009-05-22 14:50:54 -04002127int
James Smart2e0fef82007-06-17 19:56:36 -05002128lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05002129{
2130 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05002131 int Length;
dea31012005-04-17 16:05:31 -05002132 int i, j;
2133 int finished = 0;
2134 int index = 0;
2135
2136 if (!vpd)
2137 return 0;
2138
2139 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05002140 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002141 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05002142 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
2143 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002144 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05002145 switch (vpd[index]) {
2146 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002147 case 0x91:
dea31012005-04-17 16:05:31 -05002148 index += 1;
2149 lenlo = vpd[index];
2150 index += 1;
2151 lenhi = vpd[index];
2152 index += 1;
2153 i = ((((unsigned short)lenhi) << 8) + lenlo);
2154 index += i;
2155 break;
2156 case 0x90:
2157 index += 1;
2158 lenlo = vpd[index];
2159 index += 1;
2160 lenhi = vpd[index];
2161 index += 1;
2162 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002163 if (Length > len - index)
2164 Length = len - index;
dea31012005-04-17 16:05:31 -05002165 while (Length > 0) {
2166 /* Look for Serial Number */
2167 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
2168 index += 2;
2169 i = vpd[index];
2170 index += 1;
2171 j = 0;
2172 Length -= (3+i);
2173 while(i--) {
2174 phba->SerialNumber[j++] = vpd[index++];
2175 if (j == 31)
2176 break;
2177 }
2178 phba->SerialNumber[j] = 0;
2179 continue;
2180 }
2181 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
2182 phba->vpd_flag |= VPD_MODEL_DESC;
2183 index += 2;
2184 i = vpd[index];
2185 index += 1;
2186 j = 0;
2187 Length -= (3+i);
2188 while(i--) {
2189 phba->ModelDesc[j++] = vpd[index++];
2190 if (j == 255)
2191 break;
2192 }
2193 phba->ModelDesc[j] = 0;
2194 continue;
2195 }
2196 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
2197 phba->vpd_flag |= VPD_MODEL_NAME;
2198 index += 2;
2199 i = vpd[index];
2200 index += 1;
2201 j = 0;
2202 Length -= (3+i);
2203 while(i--) {
2204 phba->ModelName[j++] = vpd[index++];
2205 if (j == 79)
2206 break;
2207 }
2208 phba->ModelName[j] = 0;
2209 continue;
2210 }
2211 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2212 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2213 index += 2;
2214 i = vpd[index];
2215 index += 1;
2216 j = 0;
2217 Length -= (3+i);
2218 while(i--) {
2219 phba->ProgramType[j++] = vpd[index++];
2220 if (j == 255)
2221 break;
2222 }
2223 phba->ProgramType[j] = 0;
2224 continue;
2225 }
2226 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2227 phba->vpd_flag |= VPD_PORT;
2228 index += 2;
2229 i = vpd[index];
2230 index += 1;
2231 j = 0;
2232 Length -= (3+i);
2233 while(i--) {
James Smartcd1c8302011-10-10 21:33:25 -04002234 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2235 (phba->sli4_hba.pport_name_sta ==
2236 LPFC_SLI4_PPNAME_GET)) {
2237 j++;
2238 index++;
2239 } else
2240 phba->Port[j++] = vpd[index++];
2241 if (j == 19)
2242 break;
dea31012005-04-17 16:05:31 -05002243 }
James Smartcd1c8302011-10-10 21:33:25 -04002244 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2245 (phba->sli4_hba.pport_name_sta ==
2246 LPFC_SLI4_PPNAME_NON))
2247 phba->Port[j] = 0;
dea31012005-04-17 16:05:31 -05002248 continue;
2249 }
2250 else {
2251 index += 2;
2252 i = vpd[index];
2253 index += 1;
2254 index += i;
2255 Length -= (3 + i);
2256 }
2257 }
2258 finished = 0;
2259 break;
2260 case 0x78:
2261 finished = 1;
2262 break;
2263 default:
2264 index ++;
2265 break;
2266 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002267 }
dea31012005-04-17 16:05:31 -05002268
2269 return(1);
2270}
2271
James Smarte59058c2008-08-24 21:49:00 -04002272/**
James Smart3621a712009-04-06 18:47:14 -04002273 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04002274 * @phba: pointer to lpfc hba data structure.
2275 * @mdp: pointer to the data structure to hold the derived model name.
2276 * @descp: pointer to the data structure to hold the derived description.
2277 *
2278 * This routine retrieves HBA's description based on its registered PCI device
2279 * ID. The @descp passed into this function points to an array of 256 chars. It
2280 * shall be returned with the model name, maximum speed, and the host bus type.
2281 * The @mdp passed into this function points to an array of 80 chars. When the
2282 * function returns, the @mdp will be filled with the model name.
2283 **/
dea31012005-04-17 16:05:31 -05002284static void
James Smart2e0fef82007-06-17 19:56:36 -05002285lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05002286{
2287 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05002288 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002289 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04002290 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04002291 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002292 struct {
James Smarta747c9c2009-11-18 15:41:10 -05002293 char *name;
2294 char *bus;
2295 char *function;
2296 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002297
2298 if (mdp && mdp[0] != '\0'
2299 && descp && descp[0] != '\0')
2300 return;
2301
James Smartfbd8a6b2018-02-22 08:18:45 -08002302 if (phba->lmt & LMT_64Gb)
2303 max_speed = 64;
2304 else if (phba->lmt & LMT_32Gb)
James Smartd38dd522015-08-31 16:48:17 -04002305 max_speed = 32;
2306 else if (phba->lmt & LMT_16Gb)
James Smartc0c11512011-05-24 11:41:34 -04002307 max_speed = 16;
2308 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002309 max_speed = 10;
2310 else if (phba->lmt & LMT_8Gb)
2311 max_speed = 8;
2312 else if (phba->lmt & LMT_4Gb)
2313 max_speed = 4;
2314 else if (phba->lmt & LMT_2Gb)
2315 max_speed = 2;
James Smart4169d862012-09-29 11:32:09 -04002316 else if (phba->lmt & LMT_1Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002317 max_speed = 1;
James Smart4169d862012-09-29 11:32:09 -04002318 else
2319 max_speed = 0;
dea31012005-04-17 16:05:31 -05002320
2321 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05002322
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002323 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002324 case PCI_DEVICE_ID_FIREFLY:
James Smart12222f42014-05-21 08:05:19 -04002325 m = (typeof(m)){"LP6000", "PCI",
2326 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002327 break;
dea31012005-04-17 16:05:31 -05002328 case PCI_DEVICE_ID_SUPERFLY:
2329 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart12222f42014-05-21 08:05:19 -04002330 m = (typeof(m)){"LP7000", "PCI", ""};
dea31012005-04-17 16:05:31 -05002331 else
James Smart12222f42014-05-21 08:05:19 -04002332 m = (typeof(m)){"LP7000E", "PCI", ""};
2333 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002334 break;
2335 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002336 m = (typeof(m)){"LP8000", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002337 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002338 break;
2339 case PCI_DEVICE_ID_CENTAUR:
2340 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart12222f42014-05-21 08:05:19 -04002341 m = (typeof(m)){"LP9002", "PCI", ""};
dea31012005-04-17 16:05:31 -05002342 else
James Smart12222f42014-05-21 08:05:19 -04002343 m = (typeof(m)){"LP9000", "PCI", ""};
2344 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002345 break;
2346 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002347 m = (typeof(m)){"LP952", "PCI",
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_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05002351 m = (typeof(m)){"LP9802", "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_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05002355 m = (typeof(m)){"LP10000", "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_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05002359 m = (typeof(m)){"LPX1000", "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_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002363 m = (typeof(m)){"LP982", "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_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002367 m = (typeof(m)){"LP1050", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002368 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002369 break;
2370 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05002371 m = (typeof(m)){"LP11000", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002372 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002373 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002374 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002375 m = (typeof(m)){"LP11000-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_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002379 m = (typeof(m)){"LP11002-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002380 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002381 break;
2382 case PCI_DEVICE_ID_NEPTUNE:
James Smart12222f42014-05-21 08:05:19 -04002383 m = (typeof(m)){"LPe1000", "PCIe",
2384 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002385 break;
2386 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart12222f42014-05-21 08:05:19 -04002387 m = (typeof(m)){"LPe1000-SP", "PCIe",
2388 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002389 break;
2390 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart12222f42014-05-21 08:05:19 -04002391 m = (typeof(m)){"LPe1002-SP", "PCIe",
2392 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002393 break;
dea31012005-04-17 16:05:31 -05002394 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05002395 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002396 break;
2397 case PCI_DEVICE_ID_BSMB:
James Smart12222f42014-05-21 08:05:19 -04002398 m = (typeof(m)){"LP111", "PCI-X2",
2399 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002400 break;
2401 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05002402 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002403 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002404 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002405 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002406 break;
2407 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002408 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04002409 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002410 break;
dea31012005-04-17 16:05:31 -05002411 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05002412 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002413 break;
2414 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05002415 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002416 break;
2417 case PCI_DEVICE_ID_LP101:
James Smart12222f42014-05-21 08:05:19 -04002418 m = (typeof(m)){"LP101", "PCI-X",
2419 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002420 break;
2421 case PCI_DEVICE_ID_LP10000S:
James Smart12222f42014-05-21 08:05:19 -04002422 m = (typeof(m)){"LP10000-S", "PCI",
2423 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002424 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002425 case PCI_DEVICE_ID_LP11000S:
James Smart12222f42014-05-21 08:05:19 -04002426 m = (typeof(m)){"LP11000-S", "PCI-X2",
2427 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05002428 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002429 case PCI_DEVICE_ID_LPE11000S:
James Smart12222f42014-05-21 08:05:19 -04002430 m = (typeof(m)){"LPe11000-S", "PCIe",
2431 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002432 break;
James Smartb87eab32007-04-25 09:53:28 -04002433 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05002434 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002435 break;
2436 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05002437 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002438 break;
2439 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05002440 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002441 break;
2442 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002443 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002444 break;
2445 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002446 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002447 break;
2448 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05002449 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002450 break;
James Smart84774a42008-08-24 21:50:06 -04002451 case PCI_DEVICE_ID_HORNET:
James Smart12222f42014-05-21 08:05:19 -04002452 m = (typeof(m)){"LP21000", "PCIe",
2453 "Obsolete, Unsupported FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002454 GE = 1;
2455 break;
2456 case PCI_DEVICE_ID_PROTEUS_VF:
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_PF:
James Smarta747c9c2009-11-18 15:41:10 -05002461 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002462 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002463 break;
2464 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05002465 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002466 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002467 break;
James Smartda0436e2009-05-22 14:51:39 -04002468 case PCI_DEVICE_ID_TIGERSHARK:
2469 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002470 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04002471 break;
James Smarta747c9c2009-11-18 15:41:10 -05002472 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04002473 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002474 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2475 break;
2476 case PCI_DEVICE_ID_FALCON:
2477 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2478 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04002479 break;
James Smart98fc5dd2010-06-07 15:24:29 -04002480 case PCI_DEVICE_ID_BALIUS:
2481 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
James Smart12222f42014-05-21 08:05:19 -04002482 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart98fc5dd2010-06-07 15:24:29 -04002483 break;
James Smart085c6472010-11-20 23:11:37 -05002484 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04002485 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05002486 break;
James Smart12222f42014-05-21 08:05:19 -04002487 case PCI_DEVICE_ID_LANCER_FC_VF:
2488 m = (typeof(m)){"LPe16000", "PCIe",
2489 "Obsolete, Unsupported Fibre Channel Adapter"};
2490 break;
James Smart085c6472010-11-20 23:11:37 -05002491 case PCI_DEVICE_ID_LANCER_FCOE:
2492 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04002493 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05002494 break;
James Smart12222f42014-05-21 08:05:19 -04002495 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2496 oneConnect = 1;
2497 m = (typeof(m)){"OCe15100", "PCIe",
2498 "Obsolete, Unsupported FCoE"};
2499 break;
James Smartd38dd522015-08-31 16:48:17 -04002500 case PCI_DEVICE_ID_LANCER_G6_FC:
2501 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2502 break;
James Smartc238b9b2018-02-22 08:18:44 -08002503 case PCI_DEVICE_ID_LANCER_G7_FC:
2504 m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"};
2505 break;
James Smartf8cafd32012-08-03 12:42:51 -04002506 case PCI_DEVICE_ID_SKYHAWK:
2507 case PCI_DEVICE_ID_SKYHAWK_VF:
2508 oneConnect = 1;
2509 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2510 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002511 default:
James Smarta747c9c2009-11-18 15:41:10 -05002512 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002513 break;
dea31012005-04-17 16:05:31 -05002514 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002515
2516 if (mdp && mdp[0] == '\0')
2517 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04002518 /*
2519 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04002520 * and we put the port number on the end
2521 */
2522 if (descp && descp[0] == '\0') {
2523 if (oneConnect)
2524 snprintf(descp, 255,
James Smart4169d862012-09-29 11:32:09 -04002525 "Emulex OneConnect %s, %s Initiator %s",
James Smarta747c9c2009-11-18 15:41:10 -05002526 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04002527 phba->Port);
James Smart4169d862012-09-29 11:32:09 -04002528 else if (max_speed == 0)
2529 snprintf(descp, 255,
Sebastian Herbszt290237d2015-08-31 16:48:08 -04002530 "Emulex %s %s %s",
James Smart4169d862012-09-29 11:32:09 -04002531 m.name, m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002532 else
2533 snprintf(descp, 255,
2534 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05002535 m.name, max_speed, (GE) ? "GE" : "Gb",
2536 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002537 }
dea31012005-04-17 16:05:31 -05002538}
2539
James Smarte59058c2008-08-24 21:49:00 -04002540/**
James Smart3621a712009-04-06 18:47:14 -04002541 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04002542 * @phba: pointer to lpfc hba data structure.
2543 * @pring: pointer to a IOCB ring.
2544 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2545 *
2546 * This routine posts a given number of IOCBs with the associated DMA buffer
2547 * descriptors specified by the cnt argument to the given IOCB ring.
2548 *
2549 * Return codes
2550 * The number of IOCBs NOT able to be posted to the IOCB ring.
2551 **/
dea31012005-04-17 16:05:31 -05002552int
James Smart495a7142008-06-14 22:52:59 -04002553lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002554{
2555 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002556 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002557 struct lpfc_dmabuf *mp1, *mp2;
2558
2559 cnt += pring->missbufcnt;
2560
2561 /* While there are buffers to post */
2562 while (cnt > 0) {
2563 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002564 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002565 if (iocb == NULL) {
2566 pring->missbufcnt = cnt;
2567 return cnt;
2568 }
dea31012005-04-17 16:05:31 -05002569 icmd = &iocb->iocb;
2570
2571 /* 2 buffers can be posted per command */
2572 /* Allocate buffer to post */
2573 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2574 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002575 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2576 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002577 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002578 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002579 pring->missbufcnt = cnt;
2580 return cnt;
2581 }
2582
2583 INIT_LIST_HEAD(&mp1->list);
2584 /* Allocate buffer to post */
2585 if (cnt > 1) {
2586 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2587 if (mp2)
2588 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2589 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002590 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002591 kfree(mp2);
dea31012005-04-17 16:05:31 -05002592 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2593 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002594 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002595 pring->missbufcnt = cnt;
2596 return cnt;
2597 }
2598
2599 INIT_LIST_HEAD(&mp2->list);
2600 } else {
2601 mp2 = NULL;
2602 }
2603
2604 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2605 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2606 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2607 icmd->ulpBdeCount = 1;
2608 cnt--;
2609 if (mp2) {
2610 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2611 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2612 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2613 cnt--;
2614 icmd->ulpBdeCount = 2;
2615 }
2616
2617 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2618 icmd->ulpLe = 1;
2619
James Smart3772a992009-05-22 14:50:54 -04002620 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2621 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002622 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2623 kfree(mp1);
2624 cnt++;
2625 if (mp2) {
2626 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2627 kfree(mp2);
2628 cnt++;
2629 }
James Bottomley604a3e32005-10-29 10:28:33 -05002630 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002631 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002632 return cnt;
2633 }
dea31012005-04-17 16:05:31 -05002634 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002635 if (mp2)
dea31012005-04-17 16:05:31 -05002636 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002637 }
2638 pring->missbufcnt = 0;
2639 return 0;
2640}
2641
James Smarte59058c2008-08-24 21:49:00 -04002642/**
James Smart3621a712009-04-06 18:47:14 -04002643 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002644 * @phba: pointer to lpfc hba data structure.
2645 *
2646 * This routine posts initial receive IOCB buffers to the ELS ring. The
2647 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
James Smart895427b2017-02-12 13:52:30 -08002648 * set to 64 IOCBs. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002649 *
2650 * Return codes
2651 * 0 - success (currently always success)
2652 **/
dea31012005-04-17 16:05:31 -05002653static int
James Smart2e0fef82007-06-17 19:56:36 -05002654lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002655{
2656 struct lpfc_sli *psli = &phba->sli;
2657
2658 /* Ring 0, ELS / CT buffers */
James Smart895427b2017-02-12 13:52:30 -08002659 lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002660 /* Ring 2 - FCP no buffers needed */
2661
2662 return 0;
2663}
2664
2665#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2666
James Smarte59058c2008-08-24 21:49:00 -04002667/**
James Smart3621a712009-04-06 18:47:14 -04002668 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002669 * @HashResultPointer: pointer to an array as hash table.
2670 *
2671 * This routine sets up the initial values to the array of hash table entries
2672 * for the LC HBAs.
2673 **/
dea31012005-04-17 16:05:31 -05002674static void
2675lpfc_sha_init(uint32_t * HashResultPointer)
2676{
2677 HashResultPointer[0] = 0x67452301;
2678 HashResultPointer[1] = 0xEFCDAB89;
2679 HashResultPointer[2] = 0x98BADCFE;
2680 HashResultPointer[3] = 0x10325476;
2681 HashResultPointer[4] = 0xC3D2E1F0;
2682}
2683
James Smarte59058c2008-08-24 21:49:00 -04002684/**
James Smart3621a712009-04-06 18:47:14 -04002685 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002686 * @HashResultPointer: pointer to an initial/result hash table.
2687 * @HashWorkingPointer: pointer to an working hash table.
2688 *
2689 * This routine iterates an initial hash table pointed by @HashResultPointer
2690 * with the values from the working hash table pointeed by @HashWorkingPointer.
2691 * The results are putting back to the initial hash table, returned through
2692 * the @HashResultPointer as the result hash table.
2693 **/
dea31012005-04-17 16:05:31 -05002694static void
2695lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2696{
2697 int t;
2698 uint32_t TEMP;
2699 uint32_t A, B, C, D, E;
2700 t = 16;
2701 do {
2702 HashWorkingPointer[t] =
2703 S(1,
2704 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2705 8] ^
2706 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2707 } while (++t <= 79);
2708 t = 0;
2709 A = HashResultPointer[0];
2710 B = HashResultPointer[1];
2711 C = HashResultPointer[2];
2712 D = HashResultPointer[3];
2713 E = HashResultPointer[4];
2714
2715 do {
2716 if (t < 20) {
2717 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2718 } else if (t < 40) {
2719 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2720 } else if (t < 60) {
2721 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2722 } else {
2723 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2724 }
2725 TEMP += S(5, A) + E + HashWorkingPointer[t];
2726 E = D;
2727 D = C;
2728 C = S(30, B);
2729 B = A;
2730 A = TEMP;
2731 } while (++t <= 79);
2732
2733 HashResultPointer[0] += A;
2734 HashResultPointer[1] += B;
2735 HashResultPointer[2] += C;
2736 HashResultPointer[3] += D;
2737 HashResultPointer[4] += E;
2738
2739}
2740
James Smarte59058c2008-08-24 21:49:00 -04002741/**
James Smart3621a712009-04-06 18:47:14 -04002742 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002743 * @RandomChallenge: pointer to the entry of host challenge random number array.
2744 * @HashWorking: pointer to the entry of the working hash array.
2745 *
2746 * This routine calculates the working hash array referred by @HashWorking
2747 * from the challenge random numbers associated with the host, referred by
2748 * @RandomChallenge. The result is put into the entry of the working hash
2749 * array and returned by reference through @HashWorking.
2750 **/
dea31012005-04-17 16:05:31 -05002751static void
2752lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2753{
2754 *HashWorking = (*RandomChallenge ^ *HashWorking);
2755}
2756
James Smarte59058c2008-08-24 21:49:00 -04002757/**
James Smart3621a712009-04-06 18:47:14 -04002758 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002759 * @phba: pointer to lpfc hba data structure.
2760 * @hbainit: pointer to an array of unsigned 32-bit integers.
2761 *
2762 * This routine performs the special handling for LC HBA initialization.
2763 **/
dea31012005-04-17 16:05:31 -05002764void
2765lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2766{
2767 int t;
2768 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002769 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002770
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002771 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002772 if (!HashWorking)
2773 return;
2774
dea31012005-04-17 16:05:31 -05002775 HashWorking[0] = HashWorking[78] = *pwwnn++;
2776 HashWorking[1] = HashWorking[79] = *pwwnn;
2777
2778 for (t = 0; t < 7; t++)
2779 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2780
2781 lpfc_sha_init(hbainit);
2782 lpfc_sha_iterate(hbainit, HashWorking);
2783 kfree(HashWorking);
2784}
2785
James Smarte59058c2008-08-24 21:49:00 -04002786/**
James Smart3621a712009-04-06 18:47:14 -04002787 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002788 * @vport: pointer to a virtual N_Port data structure.
2789 *
2790 * This routine performs the necessary cleanups before deleting the @vport.
2791 * It invokes the discovery state machine to perform necessary state
2792 * transitions and to release the ndlps associated with the @vport. Note,
2793 * the physical port is treated as @vport 0.
2794 **/
James Smart87af33f2007-10-27 13:37:43 -04002795void
James Smart2e0fef82007-06-17 19:56:36 -05002796lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002797{
James Smart87af33f2007-10-27 13:37:43 -04002798 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002799 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002800 int i = 0;
dea31012005-04-17 16:05:31 -05002801
James Smart87af33f2007-10-27 13:37:43 -04002802 if (phba->link_state > LPFC_LINK_DOWN)
2803 lpfc_port_link_failure(vport);
2804
2805 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002806 if (!NLP_CHK_NODE_ACT(ndlp)) {
2807 ndlp = lpfc_enable_node(vport, ndlp,
2808 NLP_STE_UNUSED_NODE);
2809 if (!ndlp)
2810 continue;
2811 spin_lock_irq(&phba->ndlp_lock);
2812 NLP_SET_FREE_REQ(ndlp);
2813 spin_unlock_irq(&phba->ndlp_lock);
2814 /* Trigger the release of the ndlp memory */
2815 lpfc_nlp_put(ndlp);
2816 continue;
2817 }
2818 spin_lock_irq(&phba->ndlp_lock);
2819 if (NLP_CHK_FREE_REQ(ndlp)) {
2820 /* The ndlp should not be in memory free mode already */
2821 spin_unlock_irq(&phba->ndlp_lock);
2822 continue;
2823 } else
2824 /* Indicate request for freeing ndlp memory */
2825 NLP_SET_FREE_REQ(ndlp);
2826 spin_unlock_irq(&phba->ndlp_lock);
2827
James Smart58da1ff2008-04-07 10:15:56 -04002828 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2829 ndlp->nlp_DID == Fabric_DID) {
2830 /* Just free up ndlp with Fabric_DID for vports */
2831 lpfc_nlp_put(ndlp);
2832 continue;
2833 }
2834
James Smarteff4a012012-01-18 16:25:25 -05002835 /* take care of nodes in unused state before the state
2836 * machine taking action.
2837 */
2838 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2839 lpfc_nlp_put(ndlp);
2840 continue;
2841 }
2842
James Smart87af33f2007-10-27 13:37:43 -04002843 if (ndlp->nlp_type & NLP_FABRIC)
2844 lpfc_disc_state_machine(vport, ndlp, NULL,
2845 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002846
James Smart87af33f2007-10-27 13:37:43 -04002847 lpfc_disc_state_machine(vport, ndlp, NULL,
2848 NLP_EVT_DEVICE_RM);
2849 }
2850
James Smarta8adb832007-10-27 13:37:53 -04002851 /* At this point, ALL ndlp's should be gone
2852 * because of the previous NLP_EVT_DEVICE_RM.
2853 * Lets wait for this to happen, if needed.
2854 */
James Smart87af33f2007-10-27 13:37:43 -04002855 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002856 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04002857 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04002858 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002859 list_for_each_entry_safe(ndlp, next_ndlp,
2860 &vport->fc_nodes, nlp_listp) {
2861 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2862 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04002863 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05002864 "usgmap:x%x refcnt:%d\n",
2865 ndlp->nlp_DID, (void *)ndlp,
2866 ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01002867 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05002868 }
James Smarta8adb832007-10-27 13:37:53 -04002869 break;
James Smart87af33f2007-10-27 13:37:43 -04002870 }
James Smarta8adb832007-10-27 13:37:53 -04002871
2872 /* Wait for any activity on ndlps to settle */
2873 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002874 }
James Smart1151e3e2011-02-16 12:39:35 -05002875 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002876}
2877
James Smarte59058c2008-08-24 21:49:00 -04002878/**
James Smart3621a712009-04-06 18:47:14 -04002879 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002880 * @vport: pointer to a virtual N_Port data structure.
2881 *
2882 * This routine stops all the timers associated with a @vport. This function
2883 * is invoked before disabling or deleting a @vport. Note that the physical
2884 * port is treated as @vport 0.
2885 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002886void
2887lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002888{
James Smart92d7f7b2007-06-17 19:56:38 -05002889 del_timer_sync(&vport->els_tmofunc);
James Smart92494142011-02-16 12:39:44 -05002890 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002891 lpfc_can_disctmo(vport);
2892 return;
dea31012005-04-17 16:05:31 -05002893}
2894
James Smarte59058c2008-08-24 21:49:00 -04002895/**
James Smartecfd03c2010-02-12 14:41:27 -05002896 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2897 * @phba: pointer to lpfc hba data structure.
2898 *
2899 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2900 * caller of this routine should already hold the host lock.
2901 **/
2902void
2903__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2904{
James Smart5ac6b302010-10-22 11:05:36 -04002905 /* Clear pending FCF rediscovery wait flag */
2906 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2907
James Smartecfd03c2010-02-12 14:41:27 -05002908 /* Now, try to stop the timer */
2909 del_timer(&phba->fcf.redisc_wait);
2910}
2911
2912/**
2913 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2914 * @phba: pointer to lpfc hba data structure.
2915 *
2916 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2917 * checks whether the FCF rediscovery wait timer is pending with the host
2918 * lock held before proceeding with disabling the timer and clearing the
2919 * wait timer pendig flag.
2920 **/
2921void
2922lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2923{
2924 spin_lock_irq(&phba->hbalock);
2925 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2926 /* FCF rediscovery timer already fired or stopped */
2927 spin_unlock_irq(&phba->hbalock);
2928 return;
2929 }
2930 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002931 /* Clear failover in progress flags */
2932 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002933 spin_unlock_irq(&phba->hbalock);
2934}
2935
2936/**
James Smart3772a992009-05-22 14:50:54 -04002937 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002938 * @phba: pointer to lpfc hba data structure.
2939 *
2940 * This routine stops all the timers associated with a HBA. This function is
2941 * invoked before either putting a HBA offline or unloading the driver.
2942 **/
James Smart3772a992009-05-22 14:50:54 -04002943void
2944lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002945{
James Smart51ef4c22007-08-02 11:10:31 -04002946 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05002947 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002948 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002949 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002950 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002951 if (phba->sli_rev == LPFC_SLI_REV4) {
2952 del_timer_sync(&phba->rrq_tmr);
2953 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2954 }
James Smart3772a992009-05-22 14:50:54 -04002955 phba->hb_outstanding = 0;
2956
2957 switch (phba->pci_dev_grp) {
2958 case LPFC_PCI_DEV_LP:
2959 /* Stop any LightPulse device specific driver timers */
2960 del_timer_sync(&phba->fcp_poll_timer);
2961 break;
2962 case LPFC_PCI_DEV_OC:
2963 /* Stop any OneConnect device sepcific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002964 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002965 break;
2966 default:
2967 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2968 "0297 Invalid device group (x%x)\n",
2969 phba->pci_dev_grp);
2970 break;
2971 }
James Smart2e0fef82007-06-17 19:56:36 -05002972 return;
dea31012005-04-17 16:05:31 -05002973}
2974
James Smarte59058c2008-08-24 21:49:00 -04002975/**
James Smart3621a712009-04-06 18:47:14 -04002976 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002977 * @phba: pointer to lpfc hba data structure.
2978 *
2979 * This routine marks a HBA's management interface as blocked. Once the HBA's
2980 * management interface is marked as blocked, all the user space access to
2981 * the HBA, whether they are from sysfs interface or libdfc interface will
2982 * all be blocked. The HBA is set to block the management interface when the
2983 * driver prepares the HBA interface for online or offline.
2984 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01002985static void
James Smart618a5232012-06-12 13:54:36 -04002986lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
Adrian Bunka6ababd2007-11-05 18:07:33 +01002987{
2988 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04002989 uint8_t actcmd = MBX_HEARTBEAT;
2990 unsigned long timeout;
2991
Adrian Bunka6ababd2007-11-05 18:07:33 +01002992 spin_lock_irqsave(&phba->hbalock, iflag);
2993 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart618a5232012-06-12 13:54:36 -04002994 spin_unlock_irqrestore(&phba->hbalock, iflag);
2995 if (mbx_action == LPFC_MBX_NO_WAIT)
2996 return;
2997 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2998 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002999 if (phba->sli.mbox_active) {
James Smart6e7288d2010-06-07 15:23:35 -04003000 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
James Smarta183a152011-10-10 21:32:43 -04003001 /* Determine how long we might wait for the active mailbox
3002 * command to be gracefully completed by firmware.
3003 */
3004 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
3005 phba->sli.mbox_active) * 1000) + jiffies;
3006 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01003007 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04003008
James Smart6e7288d2010-06-07 15:23:35 -04003009 /* Wait for the outstnading mailbox command to complete */
3010 while (phba->sli.mbox_active) {
3011 /* Check active mailbox complete status every 2ms */
3012 msleep(2);
3013 if (time_after(jiffies, timeout)) {
3014 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3015 "2813 Mgmt IO is Blocked %x "
3016 "- mbox cmd %x still active\n",
3017 phba->sli.sli_flag, actcmd);
3018 break;
3019 }
3020 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01003021}
3022
James Smarte59058c2008-08-24 21:49:00 -04003023/**
James Smart6b5151f2012-01-18 16:24:06 -05003024 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
3025 * @phba: pointer to lpfc hba data structure.
3026 *
3027 * Allocate RPIs for all active remote nodes. This is needed whenever
3028 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
3029 * is to fixup the temporary rpi assignments.
3030 **/
3031void
3032lpfc_sli4_node_prep(struct lpfc_hba *phba)
3033{
3034 struct lpfc_nodelist *ndlp, *next_ndlp;
3035 struct lpfc_vport **vports;
James Smart9d3d3402017-04-21 16:05:00 -07003036 int i, rpi;
3037 unsigned long flags;
James Smart6b5151f2012-01-18 16:24:06 -05003038
3039 if (phba->sli_rev != LPFC_SLI_REV4)
3040 return;
3041
3042 vports = lpfc_create_vport_work_array(phba);
James Smart9d3d3402017-04-21 16:05:00 -07003043 if (vports == NULL)
3044 return;
James Smart6b5151f2012-01-18 16:24:06 -05003045
James Smart9d3d3402017-04-21 16:05:00 -07003046 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3047 if (vports[i]->load_flag & FC_UNLOADING)
3048 continue;
3049
3050 list_for_each_entry_safe(ndlp, next_ndlp,
3051 &vports[i]->fc_nodes,
3052 nlp_listp) {
3053 if (!NLP_CHK_NODE_ACT(ndlp))
3054 continue;
3055 rpi = lpfc_sli4_alloc_rpi(phba);
3056 if (rpi == LPFC_RPI_ALLOC_ERROR) {
3057 spin_lock_irqsave(&phba->ndlp_lock, flags);
3058 NLP_CLR_NODE_ACT(ndlp);
3059 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3060 continue;
James Smart6b5151f2012-01-18 16:24:06 -05003061 }
James Smart9d3d3402017-04-21 16:05:00 -07003062 ndlp->nlp_rpi = rpi;
3063 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3064 "0009 rpi:%x DID:%x "
3065 "flg:%x map:%x %p\n", ndlp->nlp_rpi,
3066 ndlp->nlp_DID, ndlp->nlp_flag,
3067 ndlp->nlp_usg_map, ndlp);
James Smart6b5151f2012-01-18 16:24:06 -05003068 }
3069 }
3070 lpfc_destroy_vport_work_array(phba, vports);
3071}
3072
3073/**
James Smart3621a712009-04-06 18:47:14 -04003074 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04003075 * @phba: pointer to lpfc hba data structure.
3076 *
3077 * This routine initializes the HBA and brings a HBA online. During this
3078 * process, the management interface is blocked to prevent user space access
3079 * to the HBA interfering with the driver initialization.
3080 *
3081 * Return codes
3082 * 0 - successful
3083 * 1 - failed
3084 **/
dea31012005-04-17 16:05:31 -05003085int
James Smart2e0fef82007-06-17 19:56:36 -05003086lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003087{
Julia Lawall372bd282008-12-16 16:15:08 +01003088 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04003089 struct lpfc_vport **vports;
Dick Kennedya145fda2017-08-23 16:55:44 -07003090 int i, error = 0;
James Smart16a3a202013-04-17 20:14:38 -04003091 bool vpis_cleared = false;
James Smart2e0fef82007-06-17 19:56:36 -05003092
dea31012005-04-17 16:05:31 -05003093 if (!phba)
3094 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01003095 vport = phba->pport;
dea31012005-04-17 16:05:31 -05003096
James Smart2e0fef82007-06-17 19:56:36 -05003097 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05003098 return 0;
3099
James Smarted957682007-06-17 19:56:37 -05003100 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003101 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05003102
James Smart618a5232012-06-12 13:54:36 -04003103 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05003104
James Smartda0436e2009-05-22 14:51:39 -04003105 if (phba->sli_rev == LPFC_SLI_REV4) {
3106 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
3107 lpfc_unblock_mgmt_io(phba);
3108 return 1;
3109 }
James Smart16a3a202013-04-17 20:14:38 -04003110 spin_lock_irq(&phba->hbalock);
3111 if (!phba->sli4_hba.max_cfg_param.vpi_used)
3112 vpis_cleared = true;
3113 spin_unlock_irq(&phba->hbalock);
Dick Kennedya145fda2017-08-23 16:55:44 -07003114
3115 /* Reestablish the local initiator port.
3116 * The offline process destroyed the previous lport.
3117 */
3118 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
3119 !phba->nvmet_support) {
3120 error = lpfc_nvme_create_localport(phba->pport);
3121 if (error)
3122 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3123 "6132 NVME restore reg failed "
3124 "on nvmei error x%x\n", error);
3125 }
James Smartda0436e2009-05-22 14:51:39 -04003126 } else {
James Smart895427b2017-02-12 13:52:30 -08003127 lpfc_sli_queue_init(phba);
James Smartda0436e2009-05-22 14:51:39 -04003128 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
3129 lpfc_unblock_mgmt_io(phba);
3130 return 1;
3131 }
James Smart46fa3112007-04-25 09:51:45 -04003132 }
dea31012005-04-17 16:05:31 -05003133
James Smart549e55c2007-08-02 11:09:51 -04003134 vports = lpfc_create_vport_work_array(phba);
Arnd Bergmannaeb66412016-03-14 15:29:44 +01003135 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003136 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003137 struct Scsi_Host *shost;
3138 shost = lpfc_shost_from_vport(vports[i]);
3139 spin_lock_irq(shost->host_lock);
3140 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
3141 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
3142 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart16a3a202013-04-17 20:14:38 -04003143 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart1c6834a2009-07-19 10:01:26 -04003144 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart16a3a202013-04-17 20:14:38 -04003145 if ((vpis_cleared) &&
3146 (vports[i]->port_type !=
3147 LPFC_PHYSICAL_PORT))
3148 vports[i]->vpi = 0;
3149 }
James Smart549e55c2007-08-02 11:09:51 -04003150 spin_unlock_irq(shost->host_lock);
3151 }
Arnd Bergmannaeb66412016-03-14 15:29:44 +01003152 }
3153 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003154
James Smart46fa3112007-04-25 09:51:45 -04003155 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05003156 return 0;
3157}
3158
James Smarte59058c2008-08-24 21:49:00 -04003159/**
James Smart3621a712009-04-06 18:47:14 -04003160 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04003161 * @phba: pointer to lpfc hba data structure.
3162 *
3163 * This routine marks a HBA's management interface as not blocked. Once the
3164 * HBA's management interface is marked as not blocked, all the user space
3165 * access to the HBA, whether they are from sysfs interface or libdfc
3166 * interface will be allowed. The HBA is set to block the management interface
3167 * when the driver prepares the HBA interface for online or offline and then
3168 * set to unblock the management interface afterwards.
3169 **/
James Smart46fa3112007-04-25 09:51:45 -04003170void
James Smart46fa3112007-04-25 09:51:45 -04003171lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
3172{
3173 unsigned long iflag;
3174
James Smart2e0fef82007-06-17 19:56:36 -05003175 spin_lock_irqsave(&phba->hbalock, iflag);
3176 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3177 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04003178}
3179
James Smarte59058c2008-08-24 21:49:00 -04003180/**
James Smart3621a712009-04-06 18:47:14 -04003181 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04003182 * @phba: pointer to lpfc hba data structure.
3183 *
3184 * This routine is invoked to prepare a HBA to be brought offline. It performs
3185 * unregistration login to all the nodes on all vports and flushes the mailbox
3186 * queue to make it ready to be brought offline.
3187 **/
James Smart46fa3112007-04-25 09:51:45 -04003188void
James Smart618a5232012-06-12 13:54:36 -04003189lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04003190{
James Smart2e0fef82007-06-17 19:56:36 -05003191 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04003192 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04003193 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05003194 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04003195 int i;
dea31012005-04-17 16:05:31 -05003196
James Smart2e0fef82007-06-17 19:56:36 -05003197 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003198 return;
dea31012005-04-17 16:05:31 -05003199
James Smart618a5232012-06-12 13:54:36 -04003200 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05003201
3202 lpfc_linkdown(phba);
3203
James Smart87af33f2007-10-27 13:37:43 -04003204 /* Issue an unreg_login to all nodes on all vports */
3205 vports = lpfc_create_vport_work_array(phba);
3206 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003207 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04003208 if (vports[i]->load_flag & FC_UNLOADING)
3209 continue;
James Smart72100cc2010-02-12 14:43:01 -05003210 shost = lpfc_shost_from_vport(vports[i]);
3211 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003212 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003213 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3214 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05003215 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05003216
James Smart87af33f2007-10-27 13:37:43 -04003217 shost = lpfc_shost_from_vport(vports[i]);
3218 list_for_each_entry_safe(ndlp, next_ndlp,
3219 &vports[i]->fc_nodes,
3220 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003221 if (!NLP_CHK_NODE_ACT(ndlp))
3222 continue;
James Smart87af33f2007-10-27 13:37:43 -04003223 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3224 continue;
3225 if (ndlp->nlp_type & NLP_FABRIC) {
3226 lpfc_disc_state_machine(vports[i], ndlp,
3227 NULL, NLP_EVT_DEVICE_RECOVERY);
3228 lpfc_disc_state_machine(vports[i], ndlp,
3229 NULL, NLP_EVT_DEVICE_RM);
3230 }
3231 spin_lock_irq(shost->host_lock);
3232 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart401ee0c2012-03-01 22:35:34 -05003233 spin_unlock_irq(shost->host_lock);
James Smart6b5151f2012-01-18 16:24:06 -05003234 /*
3235 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05003236 * RPI. Get a new RPI when the adapter port
3237 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05003238 */
James Smartbe6bb942015-04-07 15:07:22 -04003239 if (phba->sli_rev == LPFC_SLI_REV4) {
3240 lpfc_printf_vlog(ndlp->vport,
3241 KERN_INFO, LOG_NODE,
3242 "0011 lpfc_offline: "
3243 "ndlp:x%p did %x "
3244 "usgmap:x%x rpi:%x\n",
3245 ndlp, ndlp->nlp_DID,
3246 ndlp->nlp_usg_map,
3247 ndlp->nlp_rpi);
3248
James Smart6b5151f2012-01-18 16:24:06 -05003249 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smartbe6bb942015-04-07 15:07:22 -04003250 }
James Smart87af33f2007-10-27 13:37:43 -04003251 lpfc_unreg_rpi(vports[i], ndlp);
3252 }
3253 }
3254 }
James Smart09372822008-01-11 01:52:54 -05003255 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003256
James Smart618a5232012-06-12 13:54:36 -04003257 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
Dick Kennedyf485c182017-09-29 17:34:34 -07003258
3259 if (phba->wq)
3260 flush_workqueue(phba->wq);
James Smart46fa3112007-04-25 09:51:45 -04003261}
3262
James Smarte59058c2008-08-24 21:49:00 -04003263/**
James Smart3621a712009-04-06 18:47:14 -04003264 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04003265 * @phba: pointer to lpfc hba data structure.
3266 *
3267 * This routine actually brings a HBA offline. It stops all the timers
3268 * associated with the HBA, brings down the SLI layer, and eventually
3269 * marks the HBA as in offline state for the upper layer protocol.
3270 **/
James Smart46fa3112007-04-25 09:51:45 -04003271void
James Smart2e0fef82007-06-17 19:56:36 -05003272lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04003273{
James Smart549e55c2007-08-02 11:09:51 -04003274 struct Scsi_Host *shost;
3275 struct lpfc_vport **vports;
3276 int i;
James Smart46fa3112007-04-25 09:51:45 -04003277
James Smart549e55c2007-08-02 11:09:51 -04003278 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003279 return;
James Smart688a8862006-07-06 15:49:56 -04003280
James Smartda0436e2009-05-22 14:51:39 -04003281 /* stop port and all timers associated with this hba */
3282 lpfc_stop_port(phba);
Dick Kennedy4b40d022017-08-23 16:55:38 -07003283
3284 /* Tear down the local and target port registrations. The
3285 * nvme transports need to cleanup.
3286 */
3287 lpfc_nvmet_destroy_targetport(phba);
3288 lpfc_nvme_destroy_localport(phba->pport);
3289
James Smart51ef4c22007-08-02 11:10:31 -04003290 vports = lpfc_create_vport_work_array(phba);
3291 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003292 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04003293 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05003294 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05003295 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003296 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05003297 /* Bring down the SLI Layer and cleanup. The HBA is offline
3298 now. */
3299 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003300 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04003301 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003302 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04003303 vports = lpfc_create_vport_work_array(phba);
3304 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003305 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003306 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04003307 spin_lock_irq(shost->host_lock);
3308 vports[i]->work_port_events = 0;
3309 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3310 spin_unlock_irq(shost->host_lock);
3311 }
James Smart09372822008-01-11 01:52:54 -05003312 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003313}
3314
James Smarte59058c2008-08-24 21:49:00 -04003315/**
James Smart3621a712009-04-06 18:47:14 -04003316 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04003317 * @phba: pointer to lpfc hba data structure.
3318 *
3319 * This routine is to free all the SCSI buffers and IOCBs from the driver
3320 * list back to kernel. It is called from lpfc_pci_remove_one to free
3321 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04003322 **/
James Smart8a9d2e82012-05-09 21:16:12 -04003323static void
James Smart2e0fef82007-06-17 19:56:36 -05003324lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003325{
3326 struct lpfc_scsi_buf *sb, *sb_next;
dea31012005-04-17 16:05:31 -05003327
James Smart895427b2017-02-12 13:52:30 -08003328 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3329 return;
3330
James Smart2e0fef82007-06-17 19:56:36 -05003331 spin_lock_irq(&phba->hbalock);
James Smarta40fc5f2013-04-17 20:17:40 -04003332
dea31012005-04-17 16:05:31 -05003333 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smarta40fc5f2013-04-17 20:17:40 -04003334
3335 spin_lock(&phba->scsi_buf_list_put_lock);
3336 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3337 list) {
dea31012005-04-17 16:05:31 -05003338 list_del(&sb->list);
Romain Perier771db5c2017-07-06 10:13:05 +02003339 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05003340 sb->dma_handle);
dea31012005-04-17 16:05:31 -05003341 kfree(sb);
3342 phba->total_scsi_bufs--;
3343 }
James Smarta40fc5f2013-04-17 20:17:40 -04003344 spin_unlock(&phba->scsi_buf_list_put_lock);
3345
3346 spin_lock(&phba->scsi_buf_list_get_lock);
3347 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3348 list) {
3349 list_del(&sb->list);
Romain Perier771db5c2017-07-06 10:13:05 +02003350 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smarta40fc5f2013-04-17 20:17:40 -04003351 sb->dma_handle);
3352 kfree(sb);
3353 phba->total_scsi_bufs--;
3354 }
3355 spin_unlock(&phba->scsi_buf_list_get_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003356 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003357}
James Smart8a9d2e82012-05-09 21:16:12 -04003358/**
James Smart895427b2017-02-12 13:52:30 -08003359 * lpfc_nvme_free - Free all the NVME buffers and IOCBs from driver lists
3360 * @phba: pointer to lpfc hba data structure.
3361 *
3362 * This routine is to free all the NVME buffers and IOCBs from the driver
3363 * list back to kernel. It is called from lpfc_pci_remove_one to free
3364 * the internal resources before the device is removed from the system.
3365 **/
3366static void
3367lpfc_nvme_free(struct lpfc_hba *phba)
3368{
3369 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
James Smart895427b2017-02-12 13:52:30 -08003370
3371 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3372 return;
3373
3374 spin_lock_irq(&phba->hbalock);
3375
3376 /* Release all the lpfc_nvme_bufs maintained by this host. */
3377 spin_lock(&phba->nvme_buf_list_put_lock);
3378 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3379 &phba->lpfc_nvme_buf_list_put, list) {
3380 list_del(&lpfc_ncmd->list);
James Smartcf1a1d32017-12-08 17:18:03 -08003381 phba->put_nvme_bufs--;
Romain Perier771db5c2017-07-06 10:13:05 +02003382 dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
James Smart895427b2017-02-12 13:52:30 -08003383 lpfc_ncmd->dma_handle);
3384 kfree(lpfc_ncmd);
3385 phba->total_nvme_bufs--;
3386 }
3387 spin_unlock(&phba->nvme_buf_list_put_lock);
3388
3389 spin_lock(&phba->nvme_buf_list_get_lock);
3390 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3391 &phba->lpfc_nvme_buf_list_get, list) {
3392 list_del(&lpfc_ncmd->list);
James Smartcf1a1d32017-12-08 17:18:03 -08003393 phba->get_nvme_bufs--;
Romain Perier771db5c2017-07-06 10:13:05 +02003394 dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
James Smart895427b2017-02-12 13:52:30 -08003395 lpfc_ncmd->dma_handle);
3396 kfree(lpfc_ncmd);
3397 phba->total_nvme_bufs--;
3398 }
3399 spin_unlock(&phba->nvme_buf_list_get_lock);
James Smart895427b2017-02-12 13:52:30 -08003400 spin_unlock_irq(&phba->hbalock);
3401}
3402/**
3403 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
James Smart8a9d2e82012-05-09 21:16:12 -04003404 * @phba: pointer to lpfc hba data structure.
3405 *
3406 * This routine first calculates the sizes of the current els and allocated
3407 * scsi sgl lists, and then goes through all sgls to updates the physical
3408 * XRIs assigned due to port function reset. During port initialization, the
3409 * current els and allocated scsi sgl lists are 0s.
3410 *
3411 * Return codes
3412 * 0 - successful (for now, it always returns 0)
3413 **/
3414int
James Smart895427b2017-02-12 13:52:30 -08003415lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
James Smart8a9d2e82012-05-09 21:16:12 -04003416{
3417 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
James Smart895427b2017-02-12 13:52:30 -08003418 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart8a9d2e82012-05-09 21:16:12 -04003419 LIST_HEAD(els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003420 int rc;
3421
3422 /*
3423 * update on pci function's els xri-sgl list
3424 */
3425 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart895427b2017-02-12 13:52:30 -08003426
James Smart8a9d2e82012-05-09 21:16:12 -04003427 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3428 /* els xri-sgl expanded */
3429 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3430 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3431 "3157 ELS xri-sgl count increased from "
3432 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3433 els_xri_cnt);
3434 /* allocate the additional els sgls */
3435 for (i = 0; i < xri_cnt; i++) {
3436 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3437 GFP_KERNEL);
3438 if (sglq_entry == NULL) {
3439 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3440 "2562 Failure to allocate an "
3441 "ELS sgl entry:%d\n", i);
3442 rc = -ENOMEM;
3443 goto out_free_mem;
3444 }
3445 sglq_entry->buff_type = GEN_BUFF_TYPE;
3446 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3447 &sglq_entry->phys);
3448 if (sglq_entry->virt == NULL) {
3449 kfree(sglq_entry);
3450 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3451 "2563 Failure to allocate an "
3452 "ELS mbuf:%d\n", i);
3453 rc = -ENOMEM;
3454 goto out_free_mem;
3455 }
3456 sglq_entry->sgl = sglq_entry->virt;
3457 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3458 sglq_entry->state = SGL_FREED;
3459 list_add_tail(&sglq_entry->list, &els_sgl_list);
3460 }
James Smart38c20672013-03-01 16:37:44 -05003461 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003462 spin_lock(&phba->sli4_hba.sgl_list_lock);
3463 list_splice_init(&els_sgl_list,
3464 &phba->sli4_hba.lpfc_els_sgl_list);
3465 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart38c20672013-03-01 16:37:44 -05003466 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003467 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3468 /* els xri-sgl shrinked */
3469 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3470 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3471 "3158 ELS xri-sgl count decreased from "
3472 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3473 els_xri_cnt);
3474 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003475 spin_lock(&phba->sli4_hba.sgl_list_lock);
3476 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
3477 &els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003478 /* release extra els sgls from list */
3479 for (i = 0; i < xri_cnt; i++) {
3480 list_remove_head(&els_sgl_list,
3481 sglq_entry, struct lpfc_sglq, list);
3482 if (sglq_entry) {
James Smart895427b2017-02-12 13:52:30 -08003483 __lpfc_mbuf_free(phba, sglq_entry->virt,
3484 sglq_entry->phys);
James Smart8a9d2e82012-05-09 21:16:12 -04003485 kfree(sglq_entry);
3486 }
3487 }
James Smart895427b2017-02-12 13:52:30 -08003488 list_splice_init(&els_sgl_list,
3489 &phba->sli4_hba.lpfc_els_sgl_list);
3490 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003491 spin_unlock_irq(&phba->hbalock);
3492 } else
3493 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3494 "3163 ELS xri-sgl count unchanged: %d\n",
3495 els_xri_cnt);
3496 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3497
3498 /* update xris to els sgls on the list */
3499 sglq_entry = NULL;
3500 sglq_entry_next = NULL;
3501 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
James Smart895427b2017-02-12 13:52:30 -08003502 &phba->sli4_hba.lpfc_els_sgl_list, list) {
James Smart8a9d2e82012-05-09 21:16:12 -04003503 lxri = lpfc_sli4_next_xritag(phba);
3504 if (lxri == NO_XRI) {
3505 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3506 "2400 Failed to allocate xri for "
3507 "ELS sgl\n");
3508 rc = -ENOMEM;
3509 goto out_free_mem;
3510 }
3511 sglq_entry->sli4_lxritag = lxri;
3512 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3513 }
James Smart895427b2017-02-12 13:52:30 -08003514 return 0;
3515
3516out_free_mem:
3517 lpfc_free_els_sgl_list(phba);
3518 return rc;
3519}
3520
3521/**
James Smartf358dd02017-02-12 13:52:34 -08003522 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
3523 * @phba: pointer to lpfc hba data structure.
3524 *
3525 * This routine first calculates the sizes of the current els and allocated
3526 * scsi sgl lists, and then goes through all sgls to updates the physical
3527 * XRIs assigned due to port function reset. During port initialization, the
3528 * current els and allocated scsi sgl lists are 0s.
3529 *
3530 * Return codes
3531 * 0 - successful (for now, it always returns 0)
3532 **/
3533int
3534lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
3535{
3536 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3537 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart6c621a22017-05-15 15:20:45 -07003538 uint16_t nvmet_xri_cnt;
James Smartf358dd02017-02-12 13:52:34 -08003539 LIST_HEAD(nvmet_sgl_list);
3540 int rc;
3541
3542 /*
3543 * update on pci function's nvmet xri-sgl list
3544 */
3545 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart61f3d4b2017-05-15 15:20:41 -07003546
James Smart6c621a22017-05-15 15:20:45 -07003547 /* For NVMET, ALL remaining XRIs are dedicated for IO processing */
3548 nvmet_xri_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
James Smartf358dd02017-02-12 13:52:34 -08003549 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
3550 /* els xri-sgl expanded */
3551 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
3552 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3553 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
3554 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
3555 /* allocate the additional nvmet sgls */
3556 for (i = 0; i < xri_cnt; i++) {
3557 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3558 GFP_KERNEL);
3559 if (sglq_entry == NULL) {
3560 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3561 "6303 Failure to allocate an "
3562 "NVMET sgl entry:%d\n", i);
3563 rc = -ENOMEM;
3564 goto out_free_mem;
3565 }
3566 sglq_entry->buff_type = NVMET_BUFF_TYPE;
3567 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
3568 &sglq_entry->phys);
3569 if (sglq_entry->virt == NULL) {
3570 kfree(sglq_entry);
3571 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3572 "6304 Failure to allocate an "
3573 "NVMET buf:%d\n", i);
3574 rc = -ENOMEM;
3575 goto out_free_mem;
3576 }
3577 sglq_entry->sgl = sglq_entry->virt;
3578 memset(sglq_entry->sgl, 0,
3579 phba->cfg_sg_dma_buf_size);
3580 sglq_entry->state = SGL_FREED;
3581 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
3582 }
3583 spin_lock_irq(&phba->hbalock);
3584 spin_lock(&phba->sli4_hba.sgl_list_lock);
3585 list_splice_init(&nvmet_sgl_list,
3586 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3587 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3588 spin_unlock_irq(&phba->hbalock);
3589 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
3590 /* nvmet xri-sgl shrunk */
3591 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
3592 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3593 "6305 NVMET xri-sgl count decreased from "
3594 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
3595 nvmet_xri_cnt);
3596 spin_lock_irq(&phba->hbalock);
3597 spin_lock(&phba->sli4_hba.sgl_list_lock);
3598 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
3599 &nvmet_sgl_list);
3600 /* release extra nvmet sgls from list */
3601 for (i = 0; i < xri_cnt; i++) {
3602 list_remove_head(&nvmet_sgl_list,
3603 sglq_entry, struct lpfc_sglq, list);
3604 if (sglq_entry) {
3605 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
3606 sglq_entry->phys);
3607 kfree(sglq_entry);
3608 }
3609 }
3610 list_splice_init(&nvmet_sgl_list,
3611 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3612 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3613 spin_unlock_irq(&phba->hbalock);
3614 } else
3615 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3616 "6306 NVMET xri-sgl count unchanged: %d\n",
3617 nvmet_xri_cnt);
3618 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
3619
3620 /* update xris to nvmet sgls on the list */
3621 sglq_entry = NULL;
3622 sglq_entry_next = NULL;
3623 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3624 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
3625 lxri = lpfc_sli4_next_xritag(phba);
3626 if (lxri == NO_XRI) {
3627 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3628 "6307 Failed to allocate xri for "
3629 "NVMET sgl\n");
3630 rc = -ENOMEM;
3631 goto out_free_mem;
3632 }
3633 sglq_entry->sli4_lxritag = lxri;
3634 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3635 }
3636 return 0;
3637
3638out_free_mem:
3639 lpfc_free_nvmet_sgl_list(phba);
3640 return rc;
3641}
3642
3643/**
James Smart895427b2017-02-12 13:52:30 -08003644 * lpfc_sli4_scsi_sgl_update - update xri-sgl sizing and mapping
3645 * @phba: pointer to lpfc hba data structure.
3646 *
3647 * This routine first calculates the sizes of the current els and allocated
3648 * scsi sgl lists, and then goes through all sgls to updates the physical
3649 * XRIs assigned due to port function reset. During port initialization, the
3650 * current els and allocated scsi sgl lists are 0s.
3651 *
3652 * Return codes
3653 * 0 - successful (for now, it always returns 0)
3654 **/
3655int
3656lpfc_sli4_scsi_sgl_update(struct lpfc_hba *phba)
3657{
3658 struct lpfc_scsi_buf *psb, *psb_next;
3659 uint16_t i, lxri, els_xri_cnt, scsi_xri_cnt;
3660 LIST_HEAD(scsi_sgl_list);
3661 int rc;
3662
3663 /*
3664 * update on pci function's els xri-sgl list
3665 */
3666 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3667 phba->total_scsi_bufs = 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003668
3669 /*
3670 * update on pci function's allocated scsi xri-sgl list
3671 */
James Smart8a9d2e82012-05-09 21:16:12 -04003672 /* maximum number of xris available for scsi buffers */
3673 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3674 els_xri_cnt;
3675
James Smart895427b2017-02-12 13:52:30 -08003676 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3677 return 0;
3678
3679 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3680 phba->sli4_hba.scsi_xri_max = /* Split them up */
3681 (phba->sli4_hba.scsi_xri_max *
3682 phba->cfg_xri_split) / 100;
James Smart8a9d2e82012-05-09 21:16:12 -04003683
James Smarta40fc5f2013-04-17 20:17:40 -04003684 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003685 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003686 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3687 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
James Smart164cecd2013-09-06 12:22:38 -04003688 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003689 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003690
James Smarte8c0a772017-04-21 16:04:49 -07003691 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3692 "6060 Current allocated SCSI xri-sgl count:%d, "
3693 "maximum SCSI xri count:%d (split:%d)\n",
3694 phba->sli4_hba.scsi_xri_cnt,
3695 phba->sli4_hba.scsi_xri_max, phba->cfg_xri_split);
3696
James Smart8a9d2e82012-05-09 21:16:12 -04003697 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3698 /* max scsi xri shrinked below the allocated scsi buffers */
3699 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3700 phba->sli4_hba.scsi_xri_max;
3701 /* release the extra allocated scsi buffers */
3702 for (i = 0; i < scsi_xri_cnt; i++) {
3703 list_remove_head(&scsi_sgl_list, psb,
3704 struct lpfc_scsi_buf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04003705 if (psb) {
Romain Perier771db5c2017-07-06 10:13:05 +02003706 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
James Smarta2fc4aef2014-09-03 12:57:55 -04003707 psb->data, psb->dma_handle);
3708 kfree(psb);
3709 }
James Smart8a9d2e82012-05-09 21:16:12 -04003710 }
James Smarta40fc5f2013-04-17 20:17:40 -04003711 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003712 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
James Smarta40fc5f2013-04-17 20:17:40 -04003713 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003714 }
3715
3716 /* update xris associated to remaining allocated scsi buffers */
3717 psb = NULL;
3718 psb_next = NULL;
3719 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3720 lxri = lpfc_sli4_next_xritag(phba);
3721 if (lxri == NO_XRI) {
3722 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3723 "2560 Failed to allocate xri for "
3724 "scsi buffer\n");
3725 rc = -ENOMEM;
3726 goto out_free_mem;
3727 }
3728 psb->cur_iocbq.sli4_lxritag = lxri;
3729 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3730 }
James Smarta40fc5f2013-04-17 20:17:40 -04003731 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003732 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003733 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3734 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
James Smart164cecd2013-09-06 12:22:38 -04003735 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003736 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
dea31012005-04-17 16:05:31 -05003737 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003738
3739out_free_mem:
James Smart8a9d2e82012-05-09 21:16:12 -04003740 lpfc_scsi_free(phba);
3741 return rc;
dea31012005-04-17 16:05:31 -05003742}
3743
James Smart96418b52017-03-04 09:30:31 -08003744static uint64_t
3745lpfc_get_wwpn(struct lpfc_hba *phba)
3746{
3747 uint64_t wwn;
3748 int rc;
3749 LPFC_MBOXQ_t *mboxq;
3750 MAILBOX_t *mb;
3751
James Smart96418b52017-03-04 09:30:31 -08003752 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
3753 GFP_KERNEL);
3754 if (!mboxq)
3755 return (uint64_t)-1;
3756
3757 /* First get WWN of HBA instance */
3758 lpfc_read_nv(phba, mboxq);
3759 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
3760 if (rc != MBX_SUCCESS) {
3761 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3762 "6019 Mailbox failed , mbxCmd x%x "
3763 "READ_NV, mbxStatus x%x\n",
3764 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
3765 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
3766 mempool_free(mboxq, phba->mbox_mem_pool);
3767 return (uint64_t) -1;
3768 }
3769 mb = &mboxq->u.mb;
3770 memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
3771 /* wwn is WWPN of HBA instance */
3772 mempool_free(mboxq, phba->mbox_mem_pool);
3773 if (phba->sli_rev == LPFC_SLI_REV4)
3774 return be64_to_cpu(wwn);
3775 else
Maurizio Lombardi286871a2017-08-23 16:55:48 -07003776 return rol64(wwn, 32);
James Smart96418b52017-03-04 09:30:31 -08003777}
3778
James Smarte59058c2008-08-24 21:49:00 -04003779/**
James Smart895427b2017-02-12 13:52:30 -08003780 * lpfc_sli4_nvme_sgl_update - update xri-sgl sizing and mapping
3781 * @phba: pointer to lpfc hba data structure.
3782 *
3783 * This routine first calculates the sizes of the current els and allocated
3784 * scsi sgl lists, and then goes through all sgls to updates the physical
3785 * XRIs assigned due to port function reset. During port initialization, the
3786 * current els and allocated scsi sgl lists are 0s.
3787 *
3788 * Return codes
3789 * 0 - successful (for now, it always returns 0)
3790 **/
3791int
3792lpfc_sli4_nvme_sgl_update(struct lpfc_hba *phba)
3793{
3794 struct lpfc_nvme_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
3795 uint16_t i, lxri, els_xri_cnt;
3796 uint16_t nvme_xri_cnt, nvme_xri_max;
3797 LIST_HEAD(nvme_sgl_list);
James Smartcf1a1d32017-12-08 17:18:03 -08003798 int rc, cnt;
James Smart895427b2017-02-12 13:52:30 -08003799
3800 phba->total_nvme_bufs = 0;
James Smartcf1a1d32017-12-08 17:18:03 -08003801 phba->get_nvme_bufs = 0;
3802 phba->put_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08003803
3804 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3805 return 0;
3806 /*
3807 * update on pci function's allocated nvme xri-sgl list
3808 */
3809
3810 /* maximum number of xris available for nvme buffers */
3811 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3812 nvme_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3813 phba->sli4_hba.nvme_xri_max = nvme_xri_max;
3814 phba->sli4_hba.nvme_xri_max -= phba->sli4_hba.scsi_xri_max;
3815
3816 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3817 "6074 Current allocated NVME xri-sgl count:%d, "
3818 "maximum NVME xri count:%d\n",
3819 phba->sli4_hba.nvme_xri_cnt,
3820 phba->sli4_hba.nvme_xri_max);
3821
3822 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3823 spin_lock(&phba->nvme_buf_list_put_lock);
3824 list_splice_init(&phba->lpfc_nvme_buf_list_get, &nvme_sgl_list);
3825 list_splice(&phba->lpfc_nvme_buf_list_put, &nvme_sgl_list);
James Smartcf1a1d32017-12-08 17:18:03 -08003826 cnt = phba->get_nvme_bufs + phba->put_nvme_bufs;
3827 phba->get_nvme_bufs = 0;
3828 phba->put_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08003829 spin_unlock(&phba->nvme_buf_list_put_lock);
3830 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3831
3832 if (phba->sli4_hba.nvme_xri_cnt > phba->sli4_hba.nvme_xri_max) {
3833 /* max nvme xri shrunk below the allocated nvme buffers */
3834 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3835 nvme_xri_cnt = phba->sli4_hba.nvme_xri_cnt -
3836 phba->sli4_hba.nvme_xri_max;
3837 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3838 /* release the extra allocated nvme buffers */
3839 for (i = 0; i < nvme_xri_cnt; i++) {
3840 list_remove_head(&nvme_sgl_list, lpfc_ncmd,
3841 struct lpfc_nvme_buf, list);
3842 if (lpfc_ncmd) {
Romain Perier771db5c2017-07-06 10:13:05 +02003843 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
James Smart895427b2017-02-12 13:52:30 -08003844 lpfc_ncmd->data,
3845 lpfc_ncmd->dma_handle);
3846 kfree(lpfc_ncmd);
3847 }
3848 }
3849 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3850 phba->sli4_hba.nvme_xri_cnt -= nvme_xri_cnt;
3851 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3852 }
3853
3854 /* update xris associated to remaining allocated nvme buffers */
3855 lpfc_ncmd = NULL;
3856 lpfc_ncmd_next = NULL;
3857 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3858 &nvme_sgl_list, list) {
3859 lxri = lpfc_sli4_next_xritag(phba);
3860 if (lxri == NO_XRI) {
3861 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3862 "6075 Failed to allocate xri for "
3863 "nvme buffer\n");
3864 rc = -ENOMEM;
3865 goto out_free_mem;
3866 }
3867 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
3868 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3869 }
3870 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3871 spin_lock(&phba->nvme_buf_list_put_lock);
3872 list_splice_init(&nvme_sgl_list, &phba->lpfc_nvme_buf_list_get);
James Smartcf1a1d32017-12-08 17:18:03 -08003873 phba->get_nvme_bufs = cnt;
James Smart895427b2017-02-12 13:52:30 -08003874 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
3875 spin_unlock(&phba->nvme_buf_list_put_lock);
3876 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3877 return 0;
3878
3879out_free_mem:
3880 lpfc_nvme_free(phba);
3881 return rc;
3882}
3883
3884/**
James Smart3621a712009-04-06 18:47:14 -04003885 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04003886 * @phba: pointer to lpfc hba data structure.
3887 * @instance: a unique integer ID to this FC port.
3888 * @dev: pointer to the device data structure.
3889 *
3890 * This routine creates a FC port for the upper layer protocol. The FC port
3891 * can be created on top of either a physical port or a virtual port provided
3892 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3893 * and associates the FC port created before adding the shost into the SCSI
3894 * layer.
3895 *
3896 * Return codes
3897 * @vport - pointer to the virtual N_Port data structure.
3898 * NULL - port create failed.
3899 **/
James Smart2e0fef82007-06-17 19:56:36 -05003900struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04003901lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04003902{
James Smart2e0fef82007-06-17 19:56:36 -05003903 struct lpfc_vport *vport;
James Smart895427b2017-02-12 13:52:30 -08003904 struct Scsi_Host *shost = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003905 int error = 0;
James Smart96418b52017-03-04 09:30:31 -08003906 int i;
3907 uint64_t wwn;
3908 bool use_no_reset_hba = false;
James Smart56bc8022017-06-15 22:56:43 -07003909 int rc;
James Smart96418b52017-03-04 09:30:31 -08003910
James Smart56bc8022017-06-15 22:56:43 -07003911 if (lpfc_no_hba_reset_cnt) {
3912 if (phba->sli_rev < LPFC_SLI_REV4 &&
3913 dev == &phba->pcidev->dev) {
3914 /* Reset the port first */
3915 lpfc_sli_brdrestart(phba);
3916 rc = lpfc_sli_chipset_init(phba);
3917 if (rc)
3918 return NULL;
3919 }
3920 wwn = lpfc_get_wwpn(phba);
3921 }
James Smart96418b52017-03-04 09:30:31 -08003922
3923 for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
3924 if (wwn == lpfc_no_hba_reset[i]) {
3925 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3926 "6020 Setting use_no_reset port=%llx\n",
3927 wwn);
3928 use_no_reset_hba = true;
3929 break;
3930 }
3931 }
James Smart47a86172007-04-25 09:53:22 -04003932
James Smart895427b2017-02-12 13:52:30 -08003933 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
3934 if (dev != &phba->pcidev->dev) {
3935 shost = scsi_host_alloc(&lpfc_vport_template,
3936 sizeof(struct lpfc_vport));
3937 } else {
James Smart96418b52017-03-04 09:30:31 -08003938 if (!use_no_reset_hba)
James Smart895427b2017-02-12 13:52:30 -08003939 shost = scsi_host_alloc(&lpfc_template,
3940 sizeof(struct lpfc_vport));
3941 else
James Smart96418b52017-03-04 09:30:31 -08003942 shost = scsi_host_alloc(&lpfc_template_no_hr,
James Smart895427b2017-02-12 13:52:30 -08003943 sizeof(struct lpfc_vport));
3944 }
3945 } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
3946 shost = scsi_host_alloc(&lpfc_template_nvme,
James Smartea4142f2015-04-07 15:07:13 -04003947 sizeof(struct lpfc_vport));
3948 }
James Smart2e0fef82007-06-17 19:56:36 -05003949 if (!shost)
3950 goto out;
James Smart47a86172007-04-25 09:53:22 -04003951
James Smart2e0fef82007-06-17 19:56:36 -05003952 vport = (struct lpfc_vport *) shost->hostdata;
3953 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05003954 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05003955 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05003956 vport->fc_rscn_flush = 0;
James Smart3de2a652007-08-02 11:09:59 -04003957 lpfc_get_vport_cfgparam(vport);
James Smart895427b2017-02-12 13:52:30 -08003958
James Smart2e0fef82007-06-17 19:56:36 -05003959 shost->unique_id = instance;
3960 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04003961 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05003962 shost->this_id = -1;
3963 shost->max_cmd_len = 16;
James Smart8b0dff12015-05-22 10:42:38 -04003964 shost->nr_hw_queues = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04003965 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05003966 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04003967 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smart5b9e70b2018-09-10 10:30:42 -07003968 shost->sg_tablesize = phba->cfg_scsi_seg_cnt;
James Smartda0436e2009-05-22 14:51:39 -04003969 }
James Smart81301a92008-12-04 22:39:46 -05003970
James Smart47a86172007-04-25 09:53:22 -04003971 /*
James Smart2e0fef82007-06-17 19:56:36 -05003972 * Set initial can_queue value since 0 is no longer supported and
3973 * scsi_add_host will fail. This will be adjusted later based on the
3974 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04003975 */
James Smart2e0fef82007-06-17 19:56:36 -05003976 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04003977 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05003978 shost->transportt = lpfc_vport_transport_template;
3979 vport->port_type = LPFC_NPIV_PORT;
3980 } else {
3981 shost->transportt = lpfc_transport_template;
3982 vport->port_type = LPFC_PHYSICAL_PORT;
3983 }
James Smart47a86172007-04-25 09:53:22 -04003984
James Smart2e0fef82007-06-17 19:56:36 -05003985 /* Initialize all internally managed lists. */
3986 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04003987 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05003988 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04003989
Kees Cookf22eb4d2017-09-06 20:24:26 -07003990 timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0);
James Smart47a86172007-04-25 09:53:22 -04003991
Kees Cookf22eb4d2017-09-06 20:24:26 -07003992 timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0);
James Smart92494142011-02-16 12:39:44 -05003993
Kees Cookf22eb4d2017-09-06 20:24:26 -07003994 timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0);
James Smart92494142011-02-16 12:39:44 -05003995
James Bottomleyd139b9b2009-11-05 13:33:12 -06003996 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05003997 if (error)
3998 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04003999
James Smart523128e2018-09-10 10:30:46 -07004000 spin_lock_irq(&phba->port_list_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004001 list_add_tail(&vport->listentry, &phba->port_list);
James Smart523128e2018-09-10 10:30:46 -07004002 spin_unlock_irq(&phba->port_list_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004003 return vport;
James Smart47a86172007-04-25 09:53:22 -04004004
James Smart2e0fef82007-06-17 19:56:36 -05004005out_put_shost:
4006 scsi_host_put(shost);
4007out:
4008 return NULL;
James Smart47a86172007-04-25 09:53:22 -04004009}
4010
James Smarte59058c2008-08-24 21:49:00 -04004011/**
James Smart3621a712009-04-06 18:47:14 -04004012 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04004013 * @vport: pointer to an lpfc virtual N_Port data structure.
4014 *
4015 * This routine destroys a FC port from the upper layer protocol. All the
4016 * resources associated with the port are released.
4017 **/
James Smart2e0fef82007-06-17 19:56:36 -05004018void
4019destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04004020{
James Smart92d7f7b2007-06-17 19:56:38 -05004021 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4022 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04004023
James Smart858c9f62007-06-17 19:56:39 -05004024 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05004025 fc_remove_host(shost);
4026 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04004027
James Smart523128e2018-09-10 10:30:46 -07004028 spin_lock_irq(&phba->port_list_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004029 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -07004030 spin_unlock_irq(&phba->port_list_lock);
James Smart47a86172007-04-25 09:53:22 -04004031
James Smart92d7f7b2007-06-17 19:56:38 -05004032 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04004033 return;
James Smart47a86172007-04-25 09:53:22 -04004034}
4035
James Smarte59058c2008-08-24 21:49:00 -04004036/**
James Smart3621a712009-04-06 18:47:14 -04004037 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04004038 *
4039 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
4040 * uses the kernel idr facility to perform the task.
4041 *
4042 * Return codes:
4043 * instance - a unique integer ID allocated as the new instance.
4044 * -1 - lpfc get instance failed.
4045 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004046int
4047lpfc_get_instance(void)
4048{
Tejun Heoab516032013-02-27 17:04:44 -08004049 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05004050
Tejun Heoab516032013-02-27 17:04:44 -08004051 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
4052 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05004053}
4054
James Smarte59058c2008-08-24 21:49:00 -04004055/**
James Smart3621a712009-04-06 18:47:14 -04004056 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04004057 * @shost: pointer to SCSI host data structure.
4058 * @time: elapsed time of the scan in jiffies.
4059 *
4060 * This routine is called by the SCSI layer with a SCSI host to determine
4061 * whether the scan host is finished.
4062 *
4063 * Note: there is no scan_start function as adapter initialization will have
4064 * asynchronously kicked off the link initialization.
4065 *
4066 * Return codes
4067 * 0 - SCSI host scan is not over yet.
4068 * 1 - SCSI host scan is over.
4069 **/
James Smart47a86172007-04-25 09:53:22 -04004070int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
4071{
James Smart2e0fef82007-06-17 19:56:36 -05004072 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4073 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05004074 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04004075
James Smart858c9f62007-06-17 19:56:39 -05004076 spin_lock_irq(shost->host_lock);
4077
James Smart51ef4c22007-08-02 11:10:31 -04004078 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05004079 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004080 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05004081 }
James Smart256ec0d2013-04-17 20:14:58 -04004082 if (time >= msecs_to_jiffies(30 * 1000)) {
James Smart2e0fef82007-06-17 19:56:36 -05004083 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004084 "0461 Scanning longer than 30 "
4085 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05004086 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004087 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004088 }
James Smart256ec0d2013-04-17 20:14:58 -04004089 if (time >= msecs_to_jiffies(15 * 1000) &&
4090 phba->link_state <= LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05004091 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004092 "0465 Link down longer than 15 "
4093 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05004094 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05004095 goto finished;
James Smart47a86172007-04-25 09:53:22 -04004096 }
4097
James Smart2e0fef82007-06-17 19:56:36 -05004098 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05004099 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004100 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05004101 goto finished;
James Smart256ec0d2013-04-17 20:14:58 -04004102 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
James Smart858c9f62007-06-17 19:56:39 -05004103 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004104 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05004105 goto finished;
4106
4107 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004108
4109finished:
James Smart858c9f62007-06-17 19:56:39 -05004110 spin_unlock_irq(shost->host_lock);
4111 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05004112}
4113
James Smartcd713482018-10-23 13:41:01 -07004114void lpfc_host_supported_speeds_set(struct Scsi_Host *shost)
4115{
4116 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4117 struct lpfc_hba *phba = vport->phba;
4118
4119 fc_host_supported_speeds(shost) = 0;
James Smart1dc5ec22018-10-23 13:41:11 -07004120 if (phba->lmt & LMT_128Gb)
4121 fc_host_supported_speeds(shost) |= FC_PORTSPEED_128GBIT;
James Smartcd713482018-10-23 13:41:01 -07004122 if (phba->lmt & LMT_64Gb)
4123 fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT;
4124 if (phba->lmt & LMT_32Gb)
4125 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
4126 if (phba->lmt & LMT_16Gb)
4127 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
4128 if (phba->lmt & LMT_10Gb)
4129 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
4130 if (phba->lmt & LMT_8Gb)
4131 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
4132 if (phba->lmt & LMT_4Gb)
4133 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
4134 if (phba->lmt & LMT_2Gb)
4135 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
4136 if (phba->lmt & LMT_1Gb)
4137 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
4138}
4139
James Smarte59058c2008-08-24 21:49:00 -04004140/**
James Smart3621a712009-04-06 18:47:14 -04004141 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04004142 * @shost: pointer to SCSI host data structure.
4143 *
4144 * This routine initializes a given SCSI host attributes on a FC port. The
4145 * SCSI host can be either on top of a physical port or a virtual port.
4146 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004147void lpfc_host_attrib_init(struct Scsi_Host *shost)
4148{
4149 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4150 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04004151 /*
James Smart2e0fef82007-06-17 19:56:36 -05004152 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04004153 */
4154
James Smart2e0fef82007-06-17 19:56:36 -05004155 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
4156 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04004157 fc_host_supported_classes(shost) = FC_COS_CLASS3;
4158
4159 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05004160 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04004161 fc_host_supported_fc4s(shost)[2] = 1;
4162 fc_host_supported_fc4s(shost)[7] = 1;
4163
James Smart92d7f7b2007-06-17 19:56:38 -05004164 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
4165 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04004166
James Smartcd713482018-10-23 13:41:01 -07004167 lpfc_host_supported_speeds_set(shost);
James Smart47a86172007-04-25 09:53:22 -04004168
4169 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05004170 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
4171 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04004172
Mike Christie0af5d702010-09-15 16:52:31 -05004173 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
4174
James Smart47a86172007-04-25 09:53:22 -04004175 /* This value is also unchanging */
4176 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05004177 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04004178 fc_host_active_fc4s(shost)[2] = 1;
4179 fc_host_active_fc4s(shost)[7] = 1;
4180
James Smart92d7f7b2007-06-17 19:56:38 -05004181 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04004182 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04004183 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04004184 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04004185}
dea31012005-04-17 16:05:31 -05004186
James Smarte59058c2008-08-24 21:49:00 -04004187/**
James Smartda0436e2009-05-22 14:51:39 -04004188 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04004189 * @phba: pointer to lpfc hba data structure.
4190 *
James Smartda0436e2009-05-22 14:51:39 -04004191 * This routine is invoked to stop an SLI3 device port, it stops the device
4192 * from generating interrupts and stops the device driver's timers for the
4193 * device.
James Smarte59058c2008-08-24 21:49:00 -04004194 **/
James Smartdb2378e2008-02-08 18:49:51 -05004195static void
James Smartda0436e2009-05-22 14:51:39 -04004196lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05004197{
James Smartda0436e2009-05-22 14:51:39 -04004198 /* Clear all interrupt enable conditions */
4199 writel(0, phba->HCregaddr);
4200 readl(phba->HCregaddr); /* flush */
4201 /* Clear all pending interrupts */
4202 writel(0xffffffff, phba->HAregaddr);
4203 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04004204
James Smartda0436e2009-05-22 14:51:39 -04004205 /* Reset some HBA SLI setup states */
4206 lpfc_stop_hba_timers(phba);
4207 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05004208}
4209
James Smarte59058c2008-08-24 21:49:00 -04004210/**
James Smartda0436e2009-05-22 14:51:39 -04004211 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05004212 * @phba: pointer to lpfc hba data structure.
4213 *
James Smartda0436e2009-05-22 14:51:39 -04004214 * This routine is invoked to stop an SLI4 device port, it stops the device
4215 * from generating interrupts and stops the device driver's timers for the
4216 * device.
4217 **/
4218static void
4219lpfc_stop_port_s4(struct lpfc_hba *phba)
4220{
4221 /* Reset some HBA SLI4 setup states */
4222 lpfc_stop_hba_timers(phba);
4223 phba->pport->work_port_events = 0;
4224 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04004225}
4226
4227/**
4228 * lpfc_stop_port - Wrapper function for stopping hba port
4229 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05004230 *
James Smartda0436e2009-05-22 14:51:39 -04004231 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
4232 * the API jump table function pointer from the lpfc_hba struct.
4233 **/
4234void
4235lpfc_stop_port(struct lpfc_hba *phba)
4236{
4237 phba->lpfc_stop_port(phba);
Dick Kennedyf485c182017-09-29 17:34:34 -07004238
4239 if (phba->wq)
4240 flush_workqueue(phba->wq);
James Smartda0436e2009-05-22 14:51:39 -04004241}
4242
4243/**
James Smartecfd03c2010-02-12 14:41:27 -05004244 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
4245 * @phba: Pointer to hba for which this call is being executed.
4246 *
4247 * This routine starts the timer waiting for the FCF rediscovery to complete.
4248 **/
4249void
4250lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
4251{
4252 unsigned long fcf_redisc_wait_tmo =
4253 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
4254 /* Start fcf rediscovery wait period timer */
4255 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
4256 spin_lock_irq(&phba->hbalock);
4257 /* Allow action to new fcf asynchronous event */
4258 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
4259 /* Mark the FCF rediscovery pending state */
4260 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
4261 spin_unlock_irq(&phba->hbalock);
4262}
4263
4264/**
4265 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
4266 * @ptr: Map to lpfc_hba data structure pointer.
4267 *
4268 * This routine is invoked when waiting for FCF table rediscover has been
4269 * timed out. If new FCF record(s) has (have) been discovered during the
4270 * wait period, a new FCF event shall be added to the FCOE async event
4271 * list, and then worker thread shall be waked up for processing from the
4272 * worker thread context.
4273 **/
Rashika Kheriae399b222014-09-03 12:55:28 -04004274static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07004275lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t)
James Smartecfd03c2010-02-12 14:41:27 -05004276{
Kees Cookf22eb4d2017-09-06 20:24:26 -07004277 struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait);
James Smartecfd03c2010-02-12 14:41:27 -05004278
4279 /* Don't send FCF rediscovery event if timer cancelled */
4280 spin_lock_irq(&phba->hbalock);
4281 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
4282 spin_unlock_irq(&phba->hbalock);
4283 return;
4284 }
4285 /* Clear FCF rediscovery timer pending flag */
4286 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
4287 /* FCF rediscovery event to worker thread */
4288 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
4289 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004290 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04004291 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05004292 /* wake up worker thread */
4293 lpfc_worker_wake_up(phba);
4294}
4295
4296/**
James Smartda0436e2009-05-22 14:51:39 -04004297 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
4298 * @phba: pointer to lpfc hba data structure.
4299 * @acqe_link: pointer to the async link completion queue entry.
4300 *
James Smart23288b72018-05-04 20:37:53 -07004301 * This routine is to parse the SLI4 link-attention link fault code.
James Smartda0436e2009-05-22 14:51:39 -04004302 **/
James Smart23288b72018-05-04 20:37:53 -07004303static void
James Smartda0436e2009-05-22 14:51:39 -04004304lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
4305 struct lpfc_acqe_link *acqe_link)
4306{
James Smartda0436e2009-05-22 14:51:39 -04004307 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
4308 case LPFC_ASYNC_LINK_FAULT_NONE:
4309 case LPFC_ASYNC_LINK_FAULT_LOCAL:
4310 case LPFC_ASYNC_LINK_FAULT_REMOTE:
James Smart23288b72018-05-04 20:37:53 -07004311 case LPFC_ASYNC_LINK_FAULT_LR_LRR:
James Smartda0436e2009-05-22 14:51:39 -04004312 break;
4313 default:
4314 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart23288b72018-05-04 20:37:53 -07004315 "0398 Unknown link fault code: x%x\n",
James Smartda0436e2009-05-22 14:51:39 -04004316 bf_get(lpfc_acqe_link_fault, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04004317 break;
4318 }
James Smartda0436e2009-05-22 14:51:39 -04004319}
4320
4321/**
4322 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
4323 * @phba: pointer to lpfc hba data structure.
4324 * @acqe_link: pointer to the async link completion queue entry.
4325 *
4326 * This routine is to parse the SLI4 link attention type and translate it
4327 * into the base driver's link attention type coding.
4328 *
4329 * Return: Link attention type in terms of base driver's coding.
4330 **/
4331static uint8_t
4332lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
4333 struct lpfc_acqe_link *acqe_link)
4334{
4335 uint8_t att_type;
4336
4337 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
4338 case LPFC_ASYNC_LINK_STATUS_DOWN:
4339 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05004340 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04004341 break;
4342 case LPFC_ASYNC_LINK_STATUS_UP:
4343 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05004344 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004345 break;
4346 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05004347 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04004348 break;
4349 default:
4350 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4351 "0399 Invalid link attention type: x%x\n",
4352 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05004353 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004354 break;
4355 }
4356 return att_type;
4357}
4358
4359/**
James Smart8b68cd52012-09-29 11:32:37 -04004360 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
4361 * @phba: pointer to lpfc hba data structure.
4362 *
4363 * This routine is to get an SLI3 FC port's link speed in Mbps.
4364 *
4365 * Return: link speed in terms of Mbps.
4366 **/
4367uint32_t
4368lpfc_sli_port_speed_get(struct lpfc_hba *phba)
4369{
4370 uint32_t link_speed;
4371
4372 if (!lpfc_is_link_up(phba))
4373 return 0;
4374
James Smarta085e872015-12-16 18:12:02 -05004375 if (phba->sli_rev <= LPFC_SLI_REV3) {
4376 switch (phba->fc_linkspeed) {
4377 case LPFC_LINK_SPEED_1GHZ:
4378 link_speed = 1000;
4379 break;
4380 case LPFC_LINK_SPEED_2GHZ:
4381 link_speed = 2000;
4382 break;
4383 case LPFC_LINK_SPEED_4GHZ:
4384 link_speed = 4000;
4385 break;
4386 case LPFC_LINK_SPEED_8GHZ:
4387 link_speed = 8000;
4388 break;
4389 case LPFC_LINK_SPEED_10GHZ:
4390 link_speed = 10000;
4391 break;
4392 case LPFC_LINK_SPEED_16GHZ:
4393 link_speed = 16000;
4394 break;
4395 default:
4396 link_speed = 0;
4397 }
4398 } else {
4399 if (phba->sli4_hba.link_state.logical_speed)
4400 link_speed =
4401 phba->sli4_hba.link_state.logical_speed;
4402 else
4403 link_speed = phba->sli4_hba.link_state.speed;
James Smart8b68cd52012-09-29 11:32:37 -04004404 }
4405 return link_speed;
4406}
4407
4408/**
4409 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
4410 * @phba: pointer to lpfc hba data structure.
4411 * @evt_code: asynchronous event code.
4412 * @speed_code: asynchronous event link speed code.
4413 *
4414 * This routine is to parse the giving SLI4 async event link speed code into
4415 * value of Mbps for the link speed.
4416 *
4417 * Return: link speed in terms of Mbps.
4418 **/
4419static uint32_t
4420lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
4421 uint8_t speed_code)
4422{
4423 uint32_t port_speed;
4424
4425 switch (evt_code) {
4426 case LPFC_TRAILER_CODE_LINK:
4427 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004428 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smart8b68cd52012-09-29 11:32:37 -04004429 port_speed = 0;
4430 break;
James Smart26d830e2015-04-07 15:07:17 -04004431 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004432 port_speed = 10;
4433 break;
James Smart26d830e2015-04-07 15:07:17 -04004434 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004435 port_speed = 100;
4436 break;
James Smart26d830e2015-04-07 15:07:17 -04004437 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004438 port_speed = 1000;
4439 break;
James Smart26d830e2015-04-07 15:07:17 -04004440 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004441 port_speed = 10000;
4442 break;
James Smart26d830e2015-04-07 15:07:17 -04004443 case LPFC_ASYNC_LINK_SPEED_20GBPS:
4444 port_speed = 20000;
4445 break;
4446 case LPFC_ASYNC_LINK_SPEED_25GBPS:
4447 port_speed = 25000;
4448 break;
4449 case LPFC_ASYNC_LINK_SPEED_40GBPS:
4450 port_speed = 40000;
4451 break;
James Smart8b68cd52012-09-29 11:32:37 -04004452 default:
4453 port_speed = 0;
4454 }
4455 break;
4456 case LPFC_TRAILER_CODE_FC:
4457 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004458 case LPFC_FC_LA_SPEED_UNKNOWN:
James Smart8b68cd52012-09-29 11:32:37 -04004459 port_speed = 0;
4460 break;
James Smart26d830e2015-04-07 15:07:17 -04004461 case LPFC_FC_LA_SPEED_1G:
James Smart8b68cd52012-09-29 11:32:37 -04004462 port_speed = 1000;
4463 break;
James Smart26d830e2015-04-07 15:07:17 -04004464 case LPFC_FC_LA_SPEED_2G:
James Smart8b68cd52012-09-29 11:32:37 -04004465 port_speed = 2000;
4466 break;
James Smart26d830e2015-04-07 15:07:17 -04004467 case LPFC_FC_LA_SPEED_4G:
James Smart8b68cd52012-09-29 11:32:37 -04004468 port_speed = 4000;
4469 break;
James Smart26d830e2015-04-07 15:07:17 -04004470 case LPFC_FC_LA_SPEED_8G:
James Smart8b68cd52012-09-29 11:32:37 -04004471 port_speed = 8000;
4472 break;
James Smart26d830e2015-04-07 15:07:17 -04004473 case LPFC_FC_LA_SPEED_10G:
James Smart8b68cd52012-09-29 11:32:37 -04004474 port_speed = 10000;
4475 break;
James Smart26d830e2015-04-07 15:07:17 -04004476 case LPFC_FC_LA_SPEED_16G:
James Smart8b68cd52012-09-29 11:32:37 -04004477 port_speed = 16000;
4478 break;
James Smartd38dd522015-08-31 16:48:17 -04004479 case LPFC_FC_LA_SPEED_32G:
4480 port_speed = 32000;
4481 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08004482 case LPFC_FC_LA_SPEED_64G:
4483 port_speed = 64000;
4484 break;
James Smart1dc5ec22018-10-23 13:41:11 -07004485 case LPFC_FC_LA_SPEED_128G:
4486 port_speed = 128000;
4487 break;
James Smart8b68cd52012-09-29 11:32:37 -04004488 default:
4489 port_speed = 0;
4490 }
4491 break;
4492 default:
4493 port_speed = 0;
4494 }
4495 return port_speed;
4496}
4497
4498/**
James Smart70f3c072010-12-15 17:57:33 -05004499 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04004500 * @phba: pointer to lpfc hba data structure.
4501 * @acqe_link: pointer to the async link completion queue entry.
4502 *
James Smart70f3c072010-12-15 17:57:33 -05004503 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04004504 **/
4505static void
4506lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
4507 struct lpfc_acqe_link *acqe_link)
4508{
4509 struct lpfc_dmabuf *mp;
4510 LPFC_MBOXQ_t *pmb;
4511 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05004512 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04004513 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05004514 int rc;
James Smartda0436e2009-05-22 14:51:39 -04004515
4516 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05004517 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04004518 return;
James Smart32b97932009-07-19 10:01:21 -04004519 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004520 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4521 if (!pmb) {
4522 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4523 "0395 The mboxq allocation failed\n");
4524 return;
4525 }
4526 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4527 if (!mp) {
4528 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4529 "0396 The lpfc_dmabuf allocation failed\n");
4530 goto out_free_pmb;
4531 }
4532 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4533 if (!mp->virt) {
4534 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4535 "0397 The mbuf allocation failed\n");
4536 goto out_free_dmabuf;
4537 }
4538
4539 /* Cleanup any outstanding ELS commands */
4540 lpfc_els_flush_all_cmd(phba);
4541
4542 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004543 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smartda0436e2009-05-22 14:51:39 -04004544
4545 /* Update link event statistics */
4546 phba->sli.slistat.link_event++;
4547
James Smart76a95d72010-11-20 23:11:48 -05004548 /* Create lpfc_handle_latt mailbox command from link ACQE */
4549 lpfc_read_topology(phba, pmb, mp);
4550 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04004551 pmb->vport = phba->pport;
4552
James Smartda0436e2009-05-22 14:51:39 -04004553 /* Keep the link status for extra SLI4 state machine reference */
4554 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004555 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
4556 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04004557 phba->sli4_hba.link_state.duplex =
4558 bf_get(lpfc_acqe_link_duplex, acqe_link);
4559 phba->sli4_hba.link_state.status =
4560 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05004561 phba->sli4_hba.link_state.type =
4562 bf_get(lpfc_acqe_link_type, acqe_link);
4563 phba->sli4_hba.link_state.number =
4564 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04004565 phba->sli4_hba.link_state.fault =
4566 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05004567 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004568 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
4569
James Smart70f3c072010-12-15 17:57:33 -05004570 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04004571 "2900 Async FC/FCoE Link event - Speed:%dGBit "
4572 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
4573 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05004574 phba->sli4_hba.link_state.speed,
4575 phba->sli4_hba.link_state.topology,
4576 phba->sli4_hba.link_state.status,
4577 phba->sli4_hba.link_state.type,
4578 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004579 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004580 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05004581 /*
4582 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
4583 * topology info. Note: Optional for non FC-AL ports.
4584 */
4585 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
4586 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4587 if (rc == MBX_NOT_FINISHED)
4588 goto out_free_dmabuf;
4589 return;
4590 }
4591 /*
4592 * For FCoE Mode: fill in all the topology information we need and call
4593 * the READ_TOPOLOGY completion routine to continue without actually
4594 * sending the READ_TOPOLOGY mailbox command to the port.
4595 */
James Smart23288b72018-05-04 20:37:53 -07004596 /* Initialize completion status */
James Smart76a95d72010-11-20 23:11:48 -05004597 mb = &pmb->u.mb;
James Smart23288b72018-05-04 20:37:53 -07004598 mb->mbxStatus = MBX_SUCCESS;
4599
4600 /* Parse port fault information field */
4601 lpfc_sli4_parse_latt_fault(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05004602
4603 /* Parse and translate link attention fields */
4604 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
4605 la->eventTag = acqe_link->event_tag;
4606 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
4607 bf_set(lpfc_mbx_read_top_link_spd, la,
James Smarta085e872015-12-16 18:12:02 -05004608 (bf_get(lpfc_acqe_link_speed, acqe_link)));
James Smart76a95d72010-11-20 23:11:48 -05004609
4610 /* Fake the the following irrelvant fields */
4611 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
4612 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
4613 bf_set(lpfc_mbx_read_top_il, la, 0);
4614 bf_set(lpfc_mbx_read_top_pb, la, 0);
4615 bf_set(lpfc_mbx_read_top_fa, la, 0);
4616 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04004617
4618 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05004619 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04004620
4621 return;
4622
4623out_free_dmabuf:
4624 kfree(mp);
4625out_free_pmb:
4626 mempool_free(pmb, phba->mbox_mem_pool);
4627}
4628
4629/**
James Smart1dc5ec22018-10-23 13:41:11 -07004630 * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read
4631 * topology.
4632 * @phba: pointer to lpfc hba data structure.
4633 * @evt_code: asynchronous event code.
4634 * @speed_code: asynchronous event link speed code.
4635 *
4636 * This routine is to parse the giving SLI4 async event link speed code into
4637 * value of Read topology link speed.
4638 *
4639 * Return: link speed in terms of Read topology.
4640 **/
4641static uint8_t
4642lpfc_async_link_speed_to_read_top(struct lpfc_hba *phba, uint8_t speed_code)
4643{
4644 uint8_t port_speed;
4645
4646 switch (speed_code) {
4647 case LPFC_FC_LA_SPEED_1G:
4648 port_speed = LPFC_LINK_SPEED_1GHZ;
4649 break;
4650 case LPFC_FC_LA_SPEED_2G:
4651 port_speed = LPFC_LINK_SPEED_2GHZ;
4652 break;
4653 case LPFC_FC_LA_SPEED_4G:
4654 port_speed = LPFC_LINK_SPEED_4GHZ;
4655 break;
4656 case LPFC_FC_LA_SPEED_8G:
4657 port_speed = LPFC_LINK_SPEED_8GHZ;
4658 break;
4659 case LPFC_FC_LA_SPEED_16G:
4660 port_speed = LPFC_LINK_SPEED_16GHZ;
4661 break;
4662 case LPFC_FC_LA_SPEED_32G:
4663 port_speed = LPFC_LINK_SPEED_32GHZ;
4664 break;
4665 case LPFC_FC_LA_SPEED_64G:
4666 port_speed = LPFC_LINK_SPEED_64GHZ;
4667 break;
4668 case LPFC_FC_LA_SPEED_128G:
4669 port_speed = LPFC_LINK_SPEED_128GHZ;
4670 break;
4671 case LPFC_FC_LA_SPEED_256G:
4672 port_speed = LPFC_LINK_SPEED_256GHZ;
4673 break;
4674 default:
4675 port_speed = 0;
4676 break;
4677 }
4678
4679 return port_speed;
4680}
4681
4682#define trunk_link_status(__idx)\
4683 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
4684 ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\
4685 "Link up" : "Link down") : "NA"
4686/* Did port __idx reported an error */
4687#define trunk_port_fault(__idx)\
4688 bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\
4689 (port_fault & (1 << __idx) ? "YES" : "NO") : "NA"
4690
4691static void
4692lpfc_update_trunk_link_status(struct lpfc_hba *phba,
4693 struct lpfc_acqe_fc_la *acqe_fc)
4694{
4695 uint8_t port_fault = bf_get(lpfc_acqe_fc_la_trunk_linkmask, acqe_fc);
4696 uint8_t err = bf_get(lpfc_acqe_fc_la_trunk_fault, acqe_fc);
4697
4698 phba->sli4_hba.link_state.speed =
4699 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
4700 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
4701
4702 phba->sli4_hba.link_state.logical_speed =
4703 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc);
4704 /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */
4705 phba->fc_linkspeed =
4706 lpfc_async_link_speed_to_read_top(
4707 phba,
4708 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
4709
4710 if (bf_get(lpfc_acqe_fc_la_trunk_config_port0, acqe_fc)) {
4711 phba->trunk_link.link0.state =
4712 bf_get(lpfc_acqe_fc_la_trunk_link_status_port0, acqe_fc)
4713 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
James Smart529b3dd2018-12-13 15:17:54 -08004714 phba->trunk_link.link0.fault = port_fault & 0x1 ? err : 0;
James Smart1dc5ec22018-10-23 13:41:11 -07004715 }
4716 if (bf_get(lpfc_acqe_fc_la_trunk_config_port1, acqe_fc)) {
4717 phba->trunk_link.link1.state =
4718 bf_get(lpfc_acqe_fc_la_trunk_link_status_port1, acqe_fc)
4719 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
James Smart529b3dd2018-12-13 15:17:54 -08004720 phba->trunk_link.link1.fault = port_fault & 0x2 ? err : 0;
James Smart1dc5ec22018-10-23 13:41:11 -07004721 }
4722 if (bf_get(lpfc_acqe_fc_la_trunk_config_port2, acqe_fc)) {
4723 phba->trunk_link.link2.state =
4724 bf_get(lpfc_acqe_fc_la_trunk_link_status_port2, acqe_fc)
4725 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
James Smart529b3dd2018-12-13 15:17:54 -08004726 phba->trunk_link.link2.fault = port_fault & 0x4 ? err : 0;
James Smart1dc5ec22018-10-23 13:41:11 -07004727 }
4728 if (bf_get(lpfc_acqe_fc_la_trunk_config_port3, acqe_fc)) {
4729 phba->trunk_link.link3.state =
4730 bf_get(lpfc_acqe_fc_la_trunk_link_status_port3, acqe_fc)
4731 ? LPFC_LINK_UP : LPFC_LINK_DOWN;
James Smart529b3dd2018-12-13 15:17:54 -08004732 phba->trunk_link.link3.fault = port_fault & 0x8 ? err : 0;
James Smart1dc5ec22018-10-23 13:41:11 -07004733 }
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;
Hannes Reinecke56de8352019-02-18 08:34:19 +01007364 int error;
James Smart3772a992009-05-22 14:50:54 -04007365
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02007366 if (!pdev)
Hannes Reinecke56de8352019-02-18 08:34:19 +01007367 return -ENODEV;
James Smart3772a992009-05-22 14:50:54 -04007368
7369 /* Set the device DMA mask size */
Hannes Reinecke56de8352019-02-18 08:34:19 +01007370 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
7371 if (error)
7372 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
7373 if (error)
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02007374 return error;
Hannes Reinecke56de8352019-02-18 08:34:19 +01007375 error = -ENODEV;
James Smart3772a992009-05-22 14:50:54 -04007376
7377 /* Get the bus address of Bar0 and Bar2 and the number of bytes
7378 * required by each mapping.
7379 */
7380 phba->pci_bar0_map = pci_resource_start(pdev, 0);
7381 bar0map_len = pci_resource_len(pdev, 0);
7382
7383 phba->pci_bar2_map = pci_resource_start(pdev, 2);
7384 bar2map_len = pci_resource_len(pdev, 2);
7385
7386 /* Map HBA SLIM to a kernel virtual address. */
7387 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
7388 if (!phba->slim_memmap_p) {
7389 dev_printk(KERN_ERR, &pdev->dev,
7390 "ioremap failed for SLIM memory.\n");
7391 goto out;
7392 }
7393
7394 /* Map HBA Control Registers to a kernel virtual address. */
7395 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
7396 if (!phba->ctrl_regs_memmap_p) {
7397 dev_printk(KERN_ERR, &pdev->dev,
7398 "ioremap failed for HBA control registers.\n");
7399 goto out_iounmap_slim;
7400 }
7401
7402 /* Allocate memory for SLI-2 structures */
Joe Perches1aee3832014-09-03 12:56:12 -04007403 phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7404 &phba->slim2p.phys, GFP_KERNEL);
James Smart3772a992009-05-22 14:50:54 -04007405 if (!phba->slim2p.virt)
7406 goto out_iounmap;
7407
James Smart3772a992009-05-22 14:50:54 -04007408 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04007409 phba->mbox_ext = (phba->slim2p.virt +
7410 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04007411 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
7412 phba->IOCBs = (phba->slim2p.virt +
7413 offsetof(struct lpfc_sli2_slim, IOCBs));
7414
7415 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
7416 lpfc_sli_hbq_size(),
7417 &phba->hbqslimp.phys,
7418 GFP_KERNEL);
7419 if (!phba->hbqslimp.virt)
7420 goto out_free_slim;
7421
7422 hbq_count = lpfc_sli_hbq_count();
7423 ptr = phba->hbqslimp.virt;
7424 for (i = 0; i < hbq_count; ++i) {
7425 phba->hbqs[i].hbq_virt = ptr;
7426 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
7427 ptr += (lpfc_hbq_defs[i]->entry_count *
7428 sizeof(struct lpfc_hbq_entry));
7429 }
7430 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
7431 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
7432
7433 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
7434
James Smart3772a992009-05-22 14:50:54 -04007435 phba->MBslimaddr = phba->slim_memmap_p;
7436 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
7437 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
7438 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
7439 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04007440
dea31012005-04-17 16:05:31 -05007441 return 0;
7442
dea31012005-04-17 16:05:31 -05007443out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04007444 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7445 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05007446out_iounmap:
7447 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05007448out_iounmap_slim:
dea31012005-04-17 16:05:31 -05007449 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05007450out:
7451 return error;
7452}
7453
James Smarte59058c2008-08-24 21:49:00 -04007454/**
James Smart3772a992009-05-22 14:50:54 -04007455 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
7456 * @phba: pointer to lpfc hba data structure.
7457 *
7458 * This routine is invoked to unset the PCI device memory space for device
7459 * with SLI-3 interface spec.
7460 **/
7461static void
7462lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
7463{
7464 struct pci_dev *pdev;
7465
7466 /* Obtain PCI device reference */
7467 if (!phba->pcidev)
7468 return;
7469 else
7470 pdev = phba->pcidev;
7471
7472 /* Free coherent DMA memory allocated */
7473 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
7474 phba->hbqslimp.virt, phba->hbqslimp.phys);
7475 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7476 phba->slim2p.virt, phba->slim2p.phys);
7477
7478 /* I/O memory unmap */
7479 iounmap(phba->ctrl_regs_memmap_p);
7480 iounmap(phba->slim_memmap_p);
7481
7482 return;
7483}
7484
7485/**
James Smartda0436e2009-05-22 14:51:39 -04007486 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
7487 * @phba: pointer to lpfc hba data structure.
7488 *
7489 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
7490 * done and check status.
7491 *
7492 * Return 0 if successful, otherwise -ENODEV.
7493 **/
7494int
7495lpfc_sli4_post_status_check(struct lpfc_hba *phba)
7496{
James Smart2fcee4b2010-12-15 17:57:46 -05007497 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
7498 struct lpfc_register reg_data;
7499 int i, port_error = 0;
7500 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04007501
James Smart9940b972011-03-11 16:06:12 -05007502 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
7503 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05007504 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04007505 return -ENODEV;
7506
James Smartda0436e2009-05-22 14:51:39 -04007507 /* Wait up to 30 seconds for the SLI Port POST done and ready */
7508 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05007509 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
7510 &portsmphr_reg.word0) ||
7511 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007512 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04007513 port_error = -ENODEV;
7514 break;
7515 }
James Smart2fcee4b2010-12-15 17:57:46 -05007516 if (LPFC_POST_STAGE_PORT_READY ==
7517 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04007518 break;
James Smartda0436e2009-05-22 14:51:39 -04007519 msleep(10);
7520 }
7521
James Smart2fcee4b2010-12-15 17:57:46 -05007522 /*
7523 * If there was a port error during POST, then don't proceed with
7524 * other register reads as the data may not be valid. Just exit.
7525 */
7526 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04007527 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05007528 "1408 Port Failed POST - portsmphr=0x%x, "
7529 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
7530 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
7531 portsmphr_reg.word0,
7532 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
7533 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
7534 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
7535 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
7536 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
7537 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
7538 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
7539 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
7540 } else {
James Smart28baac72010-02-12 14:42:03 -05007541 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05007542 "2534 Device Info: SLIFamily=0x%x, "
7543 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
7544 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05007545 bf_get(lpfc_sli_intf_sli_family,
7546 &phba->sli4_hba.sli_intf),
7547 bf_get(lpfc_sli_intf_slirev,
7548 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05007549 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05007550 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05007551 bf_get(lpfc_sli_intf_sli_hint1,
7552 &phba->sli4_hba.sli_intf),
7553 bf_get(lpfc_sli_intf_sli_hint2,
7554 &phba->sli4_hba.sli_intf),
7555 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05007556 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05007557 /*
7558 * Check for other Port errors during the initialization
7559 * process. Fail the load if the port did not come up
7560 * correctly.
7561 */
7562 if_type = bf_get(lpfc_sli_intf_if_type,
7563 &phba->sli4_hba.sli_intf);
7564 switch (if_type) {
7565 case LPFC_SLI_INTF_IF_TYPE_0:
7566 phba->sli4_hba.ue_mask_lo =
7567 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
7568 phba->sli4_hba.ue_mask_hi =
7569 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
7570 uerrlo_reg.word0 =
7571 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
7572 uerrhi_reg.word0 =
7573 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
7574 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
7575 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
7576 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7577 "1422 Unrecoverable Error "
7578 "Detected during POST "
7579 "uerr_lo_reg=0x%x, "
7580 "uerr_hi_reg=0x%x, "
7581 "ue_mask_lo_reg=0x%x, "
7582 "ue_mask_hi_reg=0x%x\n",
7583 uerrlo_reg.word0,
7584 uerrhi_reg.word0,
7585 phba->sli4_hba.ue_mask_lo,
7586 phba->sli4_hba.ue_mask_hi);
7587 port_error = -ENODEV;
7588 }
7589 break;
7590 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08007591 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2fcee4b2010-12-15 17:57:46 -05007592 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05007593 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
7594 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04007595 (bf_get(lpfc_sliport_status_err, &reg_data) &&
7596 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007597 phba->work_status[0] =
7598 readl(phba->sli4_hba.u.if_type2.
7599 ERR1regaddr);
7600 phba->work_status[1] =
7601 readl(phba->sli4_hba.u.if_type2.
7602 ERR2regaddr);
7603 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05007604 "2888 Unrecoverable port error "
7605 "following POST: port status reg "
7606 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05007607 "error 1=0x%x, error 2=0x%x\n",
7608 reg_data.word0,
7609 portsmphr_reg.word0,
7610 phba->work_status[0],
7611 phba->work_status[1]);
7612 port_error = -ENODEV;
7613 }
7614 break;
7615 case LPFC_SLI_INTF_IF_TYPE_1:
7616 default:
7617 break;
7618 }
James Smart28baac72010-02-12 14:42:03 -05007619 }
James Smartda0436e2009-05-22 14:51:39 -04007620 return port_error;
7621}
7622
7623/**
7624 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
7625 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05007626 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04007627 *
7628 * This routine is invoked to set up SLI4 BAR0 PCI config space register
7629 * memory map.
7630 **/
7631static void
James Smart2fcee4b2010-12-15 17:57:46 -05007632lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04007633{
James Smart2fcee4b2010-12-15 17:57:46 -05007634 switch (if_type) {
7635 case LPFC_SLI_INTF_IF_TYPE_0:
7636 phba->sli4_hba.u.if_type0.UERRLOregaddr =
7637 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
7638 phba->sli4_hba.u.if_type0.UERRHIregaddr =
7639 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
7640 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
7641 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
7642 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
7643 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
7644 phba->sli4_hba.SLIINTFregaddr =
7645 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7646 break;
7647 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart0cf07f842017-06-01 21:07:10 -07007648 phba->sli4_hba.u.if_type2.EQDregaddr =
7649 phba->sli4_hba.conf_regs_memmap_p +
7650 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007651 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007652 phba->sli4_hba.conf_regs_memmap_p +
7653 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007654 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007655 phba->sli4_hba.conf_regs_memmap_p +
7656 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007657 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007658 phba->sli4_hba.conf_regs_memmap_p +
7659 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007660 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007661 phba->sli4_hba.conf_regs_memmap_p +
7662 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007663 phba->sli4_hba.SLIINTFregaddr =
7664 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7665 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007666 phba->sli4_hba.conf_regs_memmap_p +
7667 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007668 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05007669 phba->sli4_hba.conf_regs_memmap_p +
7670 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05007671 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05007672 phba->sli4_hba.conf_regs_memmap_p +
7673 LPFC_ULP0_WQ_DOORBELL;
James Smart9dd35422018-02-22 08:18:41 -08007674 phba->sli4_hba.CQDBregaddr =
James Smart2fcee4b2010-12-15 17:57:46 -05007675 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
James Smart9dd35422018-02-22 08:18:41 -08007676 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
James Smart2fcee4b2010-12-15 17:57:46 -05007677 phba->sli4_hba.MQDBregaddr =
7678 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
7679 phba->sli4_hba.BMBXregaddr =
7680 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
7681 break;
James Smart27d6ac02018-02-22 08:18:42 -08007682 case LPFC_SLI_INTF_IF_TYPE_6:
7683 phba->sli4_hba.u.if_type2.EQDregaddr =
7684 phba->sli4_hba.conf_regs_memmap_p +
7685 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
7686 phba->sli4_hba.u.if_type2.ERR1regaddr =
7687 phba->sli4_hba.conf_regs_memmap_p +
7688 LPFC_CTL_PORT_ER1_OFFSET;
7689 phba->sli4_hba.u.if_type2.ERR2regaddr =
7690 phba->sli4_hba.conf_regs_memmap_p +
7691 LPFC_CTL_PORT_ER2_OFFSET;
7692 phba->sli4_hba.u.if_type2.CTRLregaddr =
7693 phba->sli4_hba.conf_regs_memmap_p +
7694 LPFC_CTL_PORT_CTL_OFFSET;
7695 phba->sli4_hba.u.if_type2.STATUSregaddr =
7696 phba->sli4_hba.conf_regs_memmap_p +
7697 LPFC_CTL_PORT_STA_OFFSET;
7698 phba->sli4_hba.PSMPHRregaddr =
7699 phba->sli4_hba.conf_regs_memmap_p +
7700 LPFC_CTL_PORT_SEM_OFFSET;
7701 phba->sli4_hba.BMBXregaddr =
7702 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
7703 break;
James Smart2fcee4b2010-12-15 17:57:46 -05007704 case LPFC_SLI_INTF_IF_TYPE_1:
7705 default:
7706 dev_printk(KERN_ERR, &phba->pcidev->dev,
7707 "FATAL - unsupported SLI4 interface type - %d\n",
7708 if_type);
7709 break;
7710 }
James Smartda0436e2009-05-22 14:51:39 -04007711}
7712
7713/**
7714 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
7715 * @phba: pointer to lpfc hba data structure.
7716 *
James Smart27d6ac02018-02-22 08:18:42 -08007717 * This routine is invoked to set up SLI4 BAR1 register memory map.
James Smartda0436e2009-05-22 14:51:39 -04007718 **/
7719static void
James Smart27d6ac02018-02-22 08:18:42 -08007720lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04007721{
James Smart27d6ac02018-02-22 08:18:42 -08007722 switch (if_type) {
7723 case LPFC_SLI_INTF_IF_TYPE_0:
7724 phba->sli4_hba.PSMPHRregaddr =
7725 phba->sli4_hba.ctrl_regs_memmap_p +
7726 LPFC_SLIPORT_IF0_SMPHR;
7727 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7728 LPFC_HST_ISR0;
7729 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7730 LPFC_HST_IMR0;
7731 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7732 LPFC_HST_ISCR0;
7733 break;
7734 case LPFC_SLI_INTF_IF_TYPE_6:
7735 phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7736 LPFC_IF6_RQ_DOORBELL;
7737 phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7738 LPFC_IF6_WQ_DOORBELL;
7739 phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7740 LPFC_IF6_CQ_DOORBELL;
7741 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7742 LPFC_IF6_EQ_DOORBELL;
7743 phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7744 LPFC_IF6_MQ_DOORBELL;
7745 break;
7746 case LPFC_SLI_INTF_IF_TYPE_2:
7747 case LPFC_SLI_INTF_IF_TYPE_1:
7748 default:
7749 dev_err(&phba->pcidev->dev,
7750 "FATAL - unsupported SLI4 interface type - %d\n",
7751 if_type);
7752 break;
7753 }
James Smartda0436e2009-05-22 14:51:39 -04007754}
7755
7756/**
7757 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
7758 * @phba: pointer to lpfc hba data structure.
7759 * @vf: virtual function number
7760 *
7761 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
7762 * based on the given viftual function number, @vf.
7763 *
7764 * Return 0 if successful, otherwise -ENODEV.
7765 **/
7766static int
7767lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
7768{
7769 if (vf > LPFC_VIR_FUNC_MAX)
7770 return -ENODEV;
7771
7772 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05007773 vf * LPFC_VFR_PAGE_SIZE +
7774 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04007775 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05007776 vf * LPFC_VFR_PAGE_SIZE +
7777 LPFC_ULP0_WQ_DOORBELL);
James Smart9dd35422018-02-22 08:18:41 -08007778 phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7779 vf * LPFC_VFR_PAGE_SIZE +
7780 LPFC_EQCQ_DOORBELL);
7781 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
James Smartda0436e2009-05-22 14:51:39 -04007782 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7783 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
7784 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7785 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
7786 return 0;
7787}
7788
7789/**
7790 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
7791 * @phba: pointer to lpfc hba data structure.
7792 *
7793 * This routine is invoked to create the bootstrap mailbox
7794 * region consistent with the SLI-4 interface spec. This
7795 * routine allocates all memory necessary to communicate
7796 * mailbox commands to the port and sets up all alignment
7797 * needs. No locks are expected to be held when calling
7798 * this routine.
7799 *
7800 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007801 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04007802 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04007803 **/
7804static int
7805lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
7806{
7807 uint32_t bmbx_size;
7808 struct lpfc_dmabuf *dmabuf;
7809 struct dma_address *dma_address;
7810 uint32_t pa_addr;
7811 uint64_t phys_addr;
7812
7813 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
7814 if (!dmabuf)
7815 return -ENOMEM;
7816
7817 /*
7818 * The bootstrap mailbox region is comprised of 2 parts
7819 * plus an alignment restriction of 16 bytes.
7820 */
7821 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
Joe Perches1aee3832014-09-03 12:56:12 -04007822 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
7823 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04007824 if (!dmabuf->virt) {
7825 kfree(dmabuf);
7826 return -ENOMEM;
7827 }
James Smartda0436e2009-05-22 14:51:39 -04007828
7829 /*
7830 * Initialize the bootstrap mailbox pointers now so that the register
7831 * operations are simple later. The mailbox dma address is required
7832 * to be 16-byte aligned. Also align the virtual memory as each
7833 * maibox is copied into the bmbx mailbox region before issuing the
7834 * command to the port.
7835 */
7836 phba->sli4_hba.bmbx.dmabuf = dmabuf;
7837 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
7838
7839 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
7840 LPFC_ALIGN_16_BYTE);
7841 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
7842 LPFC_ALIGN_16_BYTE);
7843
7844 /*
7845 * Set the high and low physical addresses now. The SLI4 alignment
7846 * requirement is 16 bytes and the mailbox is posted to the port
7847 * as two 30-bit addresses. The other data is a bit marking whether
7848 * the 30-bit address is the high or low address.
7849 * Upcast bmbx aphys to 64bits so shift instruction compiles
7850 * clean on 32 bit machines.
7851 */
7852 dma_address = &phba->sli4_hba.bmbx.dma_address;
7853 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
7854 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
7855 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
7856 LPFC_BMBX_BIT1_ADDR_HI);
7857
7858 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
7859 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
7860 LPFC_BMBX_BIT1_ADDR_LO);
7861 return 0;
7862}
7863
7864/**
7865 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
7866 * @phba: pointer to lpfc hba data structure.
7867 *
7868 * This routine is invoked to teardown the bootstrap mailbox
7869 * region and release all host resources. This routine requires
7870 * the caller to ensure all mailbox commands recovered, no
7871 * additional mailbox comands are sent, and interrupts are disabled
7872 * before calling this routine.
7873 *
7874 **/
7875static void
7876lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
7877{
7878 dma_free_coherent(&phba->pcidev->dev,
7879 phba->sli4_hba.bmbx.bmbx_size,
7880 phba->sli4_hba.bmbx.dmabuf->virt,
7881 phba->sli4_hba.bmbx.dmabuf->phys);
7882
7883 kfree(phba->sli4_hba.bmbx.dmabuf);
7884 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
7885}
7886
7887/**
7888 * lpfc_sli4_read_config - Get the config parameters.
7889 * @phba: pointer to lpfc hba data structure.
7890 *
7891 * This routine is invoked to read the configuration parameters from the HBA.
7892 * The configuration parameters are used to set the base and maximum values
7893 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
7894 * allocation for the port.
7895 *
7896 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007897 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007898 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007899 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007900 **/
James Smartff78d8f2011-12-13 13:21:35 -05007901int
James Smartda0436e2009-05-22 14:51:39 -04007902lpfc_sli4_read_config(struct lpfc_hba *phba)
7903{
7904 LPFC_MBOXQ_t *pmb;
7905 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04007906 union lpfc_sli4_cfg_shdr *shdr;
7907 uint32_t shdr_status, shdr_add_status;
7908 struct lpfc_mbx_get_func_cfg *get_func_cfg;
7909 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04007910 char *pdesc_0;
James Smartc6918162016-10-13 15:06:16 -07007911 uint16_t forced_link_speed;
7912 uint32_t if_type;
James Smart8aa134a2012-08-14 14:25:29 -04007913 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04007914
7915 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7916 if (!pmb) {
7917 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7918 "2011 Unable to allocate memory for issuing "
7919 "SLI_CONFIG_SPECIAL mailbox command\n");
7920 return -ENOMEM;
7921 }
7922
7923 lpfc_read_config(phba, pmb);
7924
7925 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
7926 if (rc != MBX_SUCCESS) {
7927 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7928 "2012 Mailbox failed , mbxCmd x%x "
7929 "READ_CONFIG, mbxStatus x%x\n",
7930 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7931 bf_get(lpfc_mqe_status, &pmb->u.mqe));
7932 rc = -EIO;
7933 } else {
7934 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05007935 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
7936 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
7937 phba->sli4_hba.lnk_info.lnk_tp =
7938 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
7939 phba->sli4_hba.lnk_info.lnk_no =
7940 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
7941 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7942 "3081 lnk_type:%d, lnk_numb:%d\n",
7943 phba->sli4_hba.lnk_info.lnk_tp,
7944 phba->sli4_hba.lnk_info.lnk_no);
7945 } else
7946 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
7947 "3082 Mailbox (x%x) returned ldv:x0\n",
7948 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart44fd7fe2017-08-23 16:55:47 -07007949 if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) {
7950 phba->bbcredit_support = 1;
7951 phba->sli4_hba.bbscn_params.word0 = rd_config->word8;
7952 }
7953
James Smart1dc5ec22018-10-23 13:41:11 -07007954 phba->sli4_hba.conf_trunk =
7955 bf_get(lpfc_mbx_rd_conf_trunk, rd_config);
James Smart6d368e52011-05-24 11:44:12 -04007956 phba->sli4_hba.extents_in_use =
7957 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04007958 phba->sli4_hba.max_cfg_param.max_xri =
7959 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
7960 phba->sli4_hba.max_cfg_param.xri_base =
7961 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
7962 phba->sli4_hba.max_cfg_param.max_vpi =
7963 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
James Smart8b47ae62018-11-29 16:09:33 -08007964 /* Limit the max we support */
7965 if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS)
7966 phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS;
James Smartda0436e2009-05-22 14:51:39 -04007967 phba->sli4_hba.max_cfg_param.vpi_base =
7968 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
7969 phba->sli4_hba.max_cfg_param.max_rpi =
7970 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
7971 phba->sli4_hba.max_cfg_param.rpi_base =
7972 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
7973 phba->sli4_hba.max_cfg_param.max_vfi =
7974 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
7975 phba->sli4_hba.max_cfg_param.vfi_base =
7976 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
7977 phba->sli4_hba.max_cfg_param.max_fcfi =
7978 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04007979 phba->sli4_hba.max_cfg_param.max_eq =
7980 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
7981 phba->sli4_hba.max_cfg_param.max_rq =
7982 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
7983 phba->sli4_hba.max_cfg_param.max_wq =
7984 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
7985 phba->sli4_hba.max_cfg_param.max_cq =
7986 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
7987 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
7988 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
7989 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
7990 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05007991 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
7992 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04007993 phba->max_vports = phba->max_vpi;
7994 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04007995 "2003 cfg params Extents? %d "
7996 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04007997 "VPI(B:%d M:%d) "
7998 "VFI(B:%d M:%d) "
7999 "RPI(B:%d M:%d) "
James Smart2ea259e2017-02-12 13:52:27 -08008000 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n",
James Smart6d368e52011-05-24 11:44:12 -04008001 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04008002 phba->sli4_hba.max_cfg_param.xri_base,
8003 phba->sli4_hba.max_cfg_param.max_xri,
8004 phba->sli4_hba.max_cfg_param.vpi_base,
8005 phba->sli4_hba.max_cfg_param.max_vpi,
8006 phba->sli4_hba.max_cfg_param.vfi_base,
8007 phba->sli4_hba.max_cfg_param.max_vfi,
8008 phba->sli4_hba.max_cfg_param.rpi_base,
8009 phba->sli4_hba.max_cfg_param.max_rpi,
James Smart2ea259e2017-02-12 13:52:27 -08008010 phba->sli4_hba.max_cfg_param.max_fcfi,
8011 phba->sli4_hba.max_cfg_param.max_eq,
8012 phba->sli4_hba.max_cfg_param.max_cq,
8013 phba->sli4_hba.max_cfg_param.max_wq,
8014 phba->sli4_hba.max_cfg_param.max_rq);
8015
James Smartd38f33b2018-05-04 20:37:54 -07008016 /*
8017 * Calculate NVME queue resources based on how
8018 * many WQ/CQs are available.
8019 */
8020 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8021 length = phba->sli4_hba.max_cfg_param.max_wq;
8022 if (phba->sli4_hba.max_cfg_param.max_cq <
8023 phba->sli4_hba.max_cfg_param.max_wq)
8024 length = phba->sli4_hba.max_cfg_param.max_cq;
8025
8026 /*
8027 * Whats left after this can go toward NVME.
8028 * The minus 6 accounts for ELS, NVME LS, MBOX
8029 * fof plus a couple extra. When configured for
8030 * NVMET, FCP io channel WQs are not created.
8031 */
8032 length -= 6;
8033 if (!phba->nvmet_support)
8034 length -= phba->cfg_fcp_io_channel;
8035
8036 if (phba->cfg_nvme_io_channel > length) {
8037 lpfc_printf_log(
8038 phba, KERN_ERR, LOG_SLI,
8039 "2005 Reducing NVME IO channel to %d: "
8040 "WQ %d CQ %d NVMEIO %d FCPIO %d\n",
8041 length,
8042 phba->sli4_hba.max_cfg_param.max_wq,
8043 phba->sli4_hba.max_cfg_param.max_cq,
8044 phba->cfg_nvme_io_channel,
8045 phba->cfg_fcp_io_channel);
8046
8047 phba->cfg_nvme_io_channel = length;
8048 }
8049 }
James Smartda0436e2009-05-22 14:51:39 -04008050 }
James Smart912e3ac2011-05-24 11:42:11 -04008051
8052 if (rc)
8053 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04008054
James Smartc6918162016-10-13 15:06:16 -07008055 /* Update link speed if forced link speed is supported */
8056 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smart27d6ac02018-02-22 08:18:42 -08008057 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
James Smartc6918162016-10-13 15:06:16 -07008058 forced_link_speed =
8059 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
8060 if (forced_link_speed) {
8061 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
8062
8063 switch (forced_link_speed) {
8064 case LINK_SPEED_1G:
8065 phba->cfg_link_speed =
8066 LPFC_USER_LINK_SPEED_1G;
8067 break;
8068 case LINK_SPEED_2G:
8069 phba->cfg_link_speed =
8070 LPFC_USER_LINK_SPEED_2G;
8071 break;
8072 case LINK_SPEED_4G:
8073 phba->cfg_link_speed =
8074 LPFC_USER_LINK_SPEED_4G;
8075 break;
8076 case LINK_SPEED_8G:
8077 phba->cfg_link_speed =
8078 LPFC_USER_LINK_SPEED_8G;
8079 break;
8080 case LINK_SPEED_10G:
8081 phba->cfg_link_speed =
8082 LPFC_USER_LINK_SPEED_10G;
8083 break;
8084 case LINK_SPEED_16G:
8085 phba->cfg_link_speed =
8086 LPFC_USER_LINK_SPEED_16G;
8087 break;
8088 case LINK_SPEED_32G:
8089 phba->cfg_link_speed =
8090 LPFC_USER_LINK_SPEED_32G;
8091 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08008092 case LINK_SPEED_64G:
8093 phba->cfg_link_speed =
8094 LPFC_USER_LINK_SPEED_64G;
8095 break;
James Smartc6918162016-10-13 15:06:16 -07008096 case 0xffff:
8097 phba->cfg_link_speed =
8098 LPFC_USER_LINK_SPEED_AUTO;
8099 break;
8100 default:
8101 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8102 "0047 Unrecognized link "
8103 "speed : %d\n",
8104 forced_link_speed);
8105 phba->cfg_link_speed =
8106 LPFC_USER_LINK_SPEED_AUTO;
8107 }
8108 }
8109 }
8110
James Smartda0436e2009-05-22 14:51:39 -04008111 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -04008112 length = phba->sli4_hba.max_cfg_param.max_xri -
8113 lpfc_sli4_get_els_iocb_cnt(phba);
8114 if (phba->cfg_hba_queue_depth > length) {
8115 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8116 "3361 HBA queue depth changed from %d to %d\n",
8117 phba->cfg_hba_queue_depth, length);
8118 phba->cfg_hba_queue_depth = length;
8119 }
James Smart912e3ac2011-05-24 11:42:11 -04008120
James Smart27d6ac02018-02-22 08:18:42 -08008121 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smart912e3ac2011-05-24 11:42:11 -04008122 LPFC_SLI_INTF_IF_TYPE_2)
8123 goto read_cfg_out;
8124
8125 /* get the pf# and vf# for SLI4 if_type 2 port */
8126 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
8127 sizeof(struct lpfc_sli4_cfg_mhdr));
8128 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
8129 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
8130 length, LPFC_SLI4_MBX_EMBED);
8131
James Smart8aa134a2012-08-14 14:25:29 -04008132 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04008133 shdr = (union lpfc_sli4_cfg_shdr *)
8134 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
8135 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8136 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04008137 if (rc2 || shdr_status || shdr_add_status) {
James Smart912e3ac2011-05-24 11:42:11 -04008138 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8139 "3026 Mailbox failed , mbxCmd x%x "
8140 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
8141 bf_get(lpfc_mqe_command, &pmb->u.mqe),
8142 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04008143 goto read_cfg_out;
8144 }
8145
8146 /* search for fc_fcoe resrouce descriptor */
8147 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
James Smart912e3ac2011-05-24 11:42:11 -04008148
James Smart8aa134a2012-08-14 14:25:29 -04008149 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
8150 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
8151 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
8152 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
8153 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
8154 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
8155 goto read_cfg_out;
8156
James Smart912e3ac2011-05-24 11:42:11 -04008157 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04008158 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04008159 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04008160 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04008161 phba->sli4_hba.iov.pf_number =
8162 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
8163 phba->sli4_hba.iov.vf_number =
8164 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
8165 break;
8166 }
8167 }
8168
8169 if (i < LPFC_RSRC_DESC_MAX_NUM)
8170 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8171 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
8172 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
8173 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04008174 else
James Smart912e3ac2011-05-24 11:42:11 -04008175 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8176 "3028 GET_FUNCTION_CONFIG: failed to find "
Colin Ian Kingc4dba182018-10-16 18:28:53 +01008177 "Resource Descriptor:x%x\n",
James Smart912e3ac2011-05-24 11:42:11 -04008178 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04008179
8180read_cfg_out:
8181 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04008182 return rc;
8183}
8184
8185/**
James Smart2fcee4b2010-12-15 17:57:46 -05008186 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04008187 * @phba: pointer to lpfc hba data structure.
8188 *
James Smart2fcee4b2010-12-15 17:57:46 -05008189 * This routine is invoked to setup the port-side endian order when
8190 * the port if_type is 0. This routine has no function for other
8191 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04008192 *
8193 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008194 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008195 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008196 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008197 **/
8198static int
8199lpfc_setup_endian_order(struct lpfc_hba *phba)
8200{
8201 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05008202 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04008203 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
8204 HOST_ENDIAN_HIGH_WORD1};
8205
James Smart2fcee4b2010-12-15 17:57:46 -05008206 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8207 switch (if_type) {
8208 case LPFC_SLI_INTF_IF_TYPE_0:
8209 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8210 GFP_KERNEL);
8211 if (!mboxq) {
8212 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8213 "0492 Unable to allocate memory for "
8214 "issuing SLI_CONFIG_SPECIAL mailbox "
8215 "command\n");
8216 return -ENOMEM;
8217 }
James Smartda0436e2009-05-22 14:51:39 -04008218
James Smart2fcee4b2010-12-15 17:57:46 -05008219 /*
8220 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
8221 * two words to contain special data values and no other data.
8222 */
8223 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
8224 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
8225 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8226 if (rc != MBX_SUCCESS) {
8227 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8228 "0493 SLI_CONFIG_SPECIAL mailbox "
8229 "failed with status x%x\n",
8230 rc);
8231 rc = -EIO;
8232 }
8233 mempool_free(mboxq, phba->mbox_mem_pool);
8234 break;
James Smart27d6ac02018-02-22 08:18:42 -08008235 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2fcee4b2010-12-15 17:57:46 -05008236 case LPFC_SLI_INTF_IF_TYPE_2:
8237 case LPFC_SLI_INTF_IF_TYPE_1:
8238 default:
8239 break;
James Smartda0436e2009-05-22 14:51:39 -04008240 }
James Smartda0436e2009-05-22 14:51:39 -04008241 return rc;
8242}
8243
8244/**
James Smart895427b2017-02-12 13:52:30 -08008245 * lpfc_sli4_queue_verify - Verify and update EQ counts
James Smartda0436e2009-05-22 14:51:39 -04008246 * @phba: pointer to lpfc hba data structure.
8247 *
James Smart895427b2017-02-12 13:52:30 -08008248 * This routine is invoked to check the user settable queue counts for EQs.
8249 * After this routine is called the counts will be set to valid values that
James Smart5350d872011-10-10 21:33:49 -04008250 * adhere to the constraints of the system's interrupt vectors and the port's
8251 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04008252 *
8253 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008254 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008255 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04008256 **/
8257static int
James Smart5350d872011-10-10 21:33:49 -04008258lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04008259{
James Smart895427b2017-02-12 13:52:30 -08008260 int io_channel;
James Smart1ba981f2014-02-20 09:56:45 -05008261 int fof_vectors = phba->cfg_fof ? 1 : 0;
James Smartda0436e2009-05-22 14:51:39 -04008262
8263 /*
James Smart67d12732012-08-03 12:36:13 -04008264 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04008265 * device parameters
8266 */
8267
James Smart67d12732012-08-03 12:36:13 -04008268 /* Sanity check on HBA EQ parameters */
James Smart895427b2017-02-12 13:52:30 -08008269 io_channel = phba->io_channel_irqs;
James Smartda0436e2009-05-22 14:51:39 -04008270
James Smart895427b2017-02-12 13:52:30 -08008271 if (phba->sli4_hba.num_online_cpu < io_channel) {
James Smart82c3e9b2012-09-29 11:29:50 -04008272 lpfc_printf_log(phba,
8273 KERN_ERR, LOG_INIT,
James Smart90695ee2012-08-14 14:25:36 -04008274 "3188 Reducing IO channels to match number of "
James Smart7bb03bb2013-04-17 20:19:16 -04008275 "online CPUs: from %d to %d\n",
James Smart895427b2017-02-12 13:52:30 -08008276 io_channel, phba->sli4_hba.num_online_cpu);
8277 io_channel = phba->sli4_hba.num_online_cpu;
James Smart90695ee2012-08-14 14:25:36 -04008278 }
8279
James Smart895427b2017-02-12 13:52:30 -08008280 if (io_channel + fof_vectors > phba->sli4_hba.max_cfg_param.max_eq) {
James Smart82c3e9b2012-09-29 11:29:50 -04008281 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8282 "2575 Reducing IO channels to match number of "
8283 "available EQs: from %d to %d\n",
James Smart895427b2017-02-12 13:52:30 -08008284 io_channel,
James Smart82c3e9b2012-09-29 11:29:50 -04008285 phba->sli4_hba.max_cfg_param.max_eq);
James Smart895427b2017-02-12 13:52:30 -08008286 io_channel = phba->sli4_hba.max_cfg_param.max_eq - fof_vectors;
James Smartda0436e2009-05-22 14:51:39 -04008287 }
James Smart67d12732012-08-03 12:36:13 -04008288
James Smart895427b2017-02-12 13:52:30 -08008289 /* The actual number of FCP / NVME event queues adopted */
8290 if (io_channel != phba->io_channel_irqs)
8291 phba->io_channel_irqs = io_channel;
8292 if (phba->cfg_fcp_io_channel > io_channel)
8293 phba->cfg_fcp_io_channel = io_channel;
8294 if (phba->cfg_nvme_io_channel > io_channel)
8295 phba->cfg_nvme_io_channel = io_channel;
James Smartbcb24f62017-11-20 16:00:36 -08008296 if (phba->nvmet_support) {
8297 if (phba->cfg_nvme_io_channel < phba->cfg_nvmet_mrq)
8298 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
8299 }
8300 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
8301 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
James Smart895427b2017-02-12 13:52:30 -08008302
8303 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2d7dbc42017-02-12 13:52:35 -08008304 "2574 IO channels: irqs %d fcp %d nvme %d MRQ: %d\n",
James Smart895427b2017-02-12 13:52:30 -08008305 phba->io_channel_irqs, phba->cfg_fcp_io_channel,
James Smart2d7dbc42017-02-12 13:52:35 -08008306 phba->cfg_nvme_io_channel, phba->cfg_nvmet_mrq);
James Smartda0436e2009-05-22 14:51:39 -04008307
James Smartda0436e2009-05-22 14:51:39 -04008308 /* Get EQ depth from module parameter, fake the default for now */
8309 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8310 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8311
James Smart5350d872011-10-10 21:33:49 -04008312 /* Get CQ depth from module parameter, fake the default for now */
8313 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8314 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart5350d872011-10-10 21:33:49 -04008315 return 0;
James Smart895427b2017-02-12 13:52:30 -08008316}
8317
8318static int
8319lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx)
8320{
8321 struct lpfc_queue *qdesc;
James Smart895427b2017-02-12 13:52:30 -08008322
James Smarta51e41b2017-12-08 17:18:06 -08008323 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
James Smart81b96ed2017-11-20 16:00:29 -08008324 phba->sli4_hba.cq_esize,
James Smarta51e41b2017-12-08 17:18:06 -08008325 LPFC_CQE_EXP_COUNT);
James Smart895427b2017-02-12 13:52:30 -08008326 if (!qdesc) {
8327 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8328 "0508 Failed allocate fast-path NVME CQ (%d)\n",
8329 wqidx);
8330 return 1;
8331 }
James Smart7365f6f2018-02-22 08:18:46 -08008332 qdesc->qe_valid = 1;
James Smart895427b2017-02-12 13:52:30 -08008333 phba->sli4_hba.nvme_cq[wqidx] = qdesc;
8334
James Smarta51e41b2017-12-08 17:18:06 -08008335 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8336 LPFC_WQE128_SIZE, LPFC_WQE_EXP_COUNT);
James Smart895427b2017-02-12 13:52:30 -08008337 if (!qdesc) {
8338 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8339 "0509 Failed allocate fast-path NVME WQ (%d)\n",
8340 wqidx);
8341 return 1;
8342 }
8343 phba->sli4_hba.nvme_wq[wqidx] = qdesc;
8344 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8345 return 0;
8346}
8347
8348static int
8349lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx)
8350{
8351 struct lpfc_queue *qdesc;
James Smartc176ffa2018-01-30 15:58:46 -08008352 uint32_t wqesize;
James Smart895427b2017-02-12 13:52:30 -08008353
8354 /* Create Fast Path FCP CQs */
James Smartc176ffa2018-01-30 15:58:46 -08008355 if (phba->enab_exp_wqcq_pages)
James Smarta51e41b2017-12-08 17:18:06 -08008356 /* Increase the CQ size when WQEs contain an embedded cdb */
8357 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8358 phba->sli4_hba.cq_esize,
8359 LPFC_CQE_EXP_COUNT);
8360
8361 else
8362 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8363 phba->sli4_hba.cq_esize,
8364 phba->sli4_hba.cq_ecount);
James Smart895427b2017-02-12 13:52:30 -08008365 if (!qdesc) {
8366 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8367 "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx);
8368 return 1;
8369 }
James Smart7365f6f2018-02-22 08:18:46 -08008370 qdesc->qe_valid = 1;
James Smart895427b2017-02-12 13:52:30 -08008371 phba->sli4_hba.fcp_cq[wqidx] = qdesc;
8372
8373 /* Create Fast Path FCP WQs */
James Smartc176ffa2018-01-30 15:58:46 -08008374 if (phba->enab_exp_wqcq_pages) {
James Smarta51e41b2017-12-08 17:18:06 -08008375 /* Increase the WQ size when WQEs contain an embedded cdb */
James Smartc176ffa2018-01-30 15:58:46 -08008376 wqesize = (phba->fcp_embed_io) ?
8377 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
James Smarta51e41b2017-12-08 17:18:06 -08008378 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
James Smartc176ffa2018-01-30 15:58:46 -08008379 wqesize,
James Smarta51e41b2017-12-08 17:18:06 -08008380 LPFC_WQE_EXP_COUNT);
James Smartc176ffa2018-01-30 15:58:46 -08008381 } else
James Smarta51e41b2017-12-08 17:18:06 -08008382 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8383 phba->sli4_hba.wq_esize,
8384 phba->sli4_hba.wq_ecount);
James Smartc176ffa2018-01-30 15:58:46 -08008385
James Smart895427b2017-02-12 13:52:30 -08008386 if (!qdesc) {
8387 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8388 "0503 Failed allocate fast-path FCP WQ (%d)\n",
8389 wqidx);
8390 return 1;
8391 }
8392 phba->sli4_hba.fcp_wq[wqidx] = qdesc;
8393 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8394 return 0;
James Smart5350d872011-10-10 21:33:49 -04008395}
8396
8397/**
8398 * lpfc_sli4_queue_create - Create all the SLI4 queues
8399 * @phba: pointer to lpfc hba data structure.
8400 *
8401 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
8402 * operation. For each SLI4 queue type, the parameters such as queue entry
8403 * count (queue depth) shall be taken from the module parameter. For now,
8404 * we just use some constant number as place holder.
8405 *
8406 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07008407 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04008408 * -ENOMEM - No availble memory
8409 * -EIO - The mailbox failed to complete successfully.
8410 **/
8411int
8412lpfc_sli4_queue_create(struct lpfc_hba *phba)
8413{
8414 struct lpfc_queue *qdesc;
James Smartd1f525a2017-04-21 16:04:55 -07008415 int idx, io_channel;
James Smart5350d872011-10-10 21:33:49 -04008416
8417 /*
James Smart67d12732012-08-03 12:36:13 -04008418 * Create HBA Record arrays.
James Smart895427b2017-02-12 13:52:30 -08008419 * Both NVME and FCP will share that same vectors / EQs
James Smart5350d872011-10-10 21:33:49 -04008420 */
James Smart895427b2017-02-12 13:52:30 -08008421 io_channel = phba->io_channel_irqs;
8422 if (!io_channel)
James Smart67d12732012-08-03 12:36:13 -04008423 return -ERANGE;
James Smart5350d872011-10-10 21:33:49 -04008424
James Smart67d12732012-08-03 12:36:13 -04008425 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
8426 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
8427 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
8428 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
8429 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
8430 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
James Smart895427b2017-02-12 13:52:30 -08008431 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8432 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8433 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8434 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart67d12732012-08-03 12:36:13 -04008435
James Smart895427b2017-02-12 13:52:30 -08008436 phba->sli4_hba.hba_eq = kcalloc(io_channel,
8437 sizeof(struct lpfc_queue *),
8438 GFP_KERNEL);
James Smart67d12732012-08-03 12:36:13 -04008439 if (!phba->sli4_hba.hba_eq) {
James Smartda0436e2009-05-22 14:51:39 -04008440 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04008441 "2576 Failed allocate memory for "
8442 "fast-path EQ record array\n");
James Smartda0436e2009-05-22 14:51:39 -04008443 goto out_error;
8444 }
James Smart67d12732012-08-03 12:36:13 -04008445
James Smart895427b2017-02-12 13:52:30 -08008446 if (phba->cfg_fcp_io_channel) {
8447 phba->sli4_hba.fcp_cq = kcalloc(phba->cfg_fcp_io_channel,
8448 sizeof(struct lpfc_queue *),
8449 GFP_KERNEL);
8450 if (!phba->sli4_hba.fcp_cq) {
8451 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8452 "2577 Failed allocate memory for "
8453 "fast-path CQ record array\n");
8454 goto out_error;
8455 }
8456 phba->sli4_hba.fcp_wq = kcalloc(phba->cfg_fcp_io_channel,
8457 sizeof(struct lpfc_queue *),
8458 GFP_KERNEL);
8459 if (!phba->sli4_hba.fcp_wq) {
8460 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8461 "2578 Failed allocate memory for "
8462 "fast-path FCP WQ record array\n");
8463 goto out_error;
8464 }
8465 /*
8466 * Since the first EQ can have multiple CQs associated with it,
8467 * this array is used to quickly see if we have a FCP fast-path
8468 * CQ match.
8469 */
8470 phba->sli4_hba.fcp_cq_map = kcalloc(phba->cfg_fcp_io_channel,
8471 sizeof(uint16_t),
8472 GFP_KERNEL);
8473 if (!phba->sli4_hba.fcp_cq_map) {
8474 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8475 "2545 Failed allocate memory for "
8476 "fast-path CQ map\n");
8477 goto out_error;
8478 }
James Smart67d12732012-08-03 12:36:13 -04008479 }
8480
James Smart895427b2017-02-12 13:52:30 -08008481 if (phba->cfg_nvme_io_channel) {
8482 phba->sli4_hba.nvme_cq = kcalloc(phba->cfg_nvme_io_channel,
8483 sizeof(struct lpfc_queue *),
8484 GFP_KERNEL);
8485 if (!phba->sli4_hba.nvme_cq) {
8486 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8487 "6077 Failed allocate memory for "
8488 "fast-path CQ record array\n");
8489 goto out_error;
8490 }
8491
James Smart895427b2017-02-12 13:52:30 -08008492 phba->sli4_hba.nvme_wq = kcalloc(phba->cfg_nvme_io_channel,
8493 sizeof(struct lpfc_queue *),
8494 GFP_KERNEL);
8495 if (!phba->sli4_hba.nvme_wq) {
8496 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8497 "2581 Failed allocate memory for "
8498 "fast-path NVME WQ record array\n");
8499 goto out_error;
8500 }
8501
8502 /*
8503 * Since the first EQ can have multiple CQs associated with it,
8504 * this array is used to quickly see if we have a NVME fast-path
8505 * CQ match.
8506 */
8507 phba->sli4_hba.nvme_cq_map = kcalloc(phba->cfg_nvme_io_channel,
8508 sizeof(uint16_t),
8509 GFP_KERNEL);
8510 if (!phba->sli4_hba.nvme_cq_map) {
8511 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8512 "6078 Failed allocate memory for "
8513 "fast-path CQ map\n");
8514 goto out_error;
8515 }
James Smart2d7dbc42017-02-12 13:52:35 -08008516
8517 if (phba->nvmet_support) {
8518 phba->sli4_hba.nvmet_cqset = kcalloc(
8519 phba->cfg_nvmet_mrq,
8520 sizeof(struct lpfc_queue *),
8521 GFP_KERNEL);
8522 if (!phba->sli4_hba.nvmet_cqset) {
8523 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8524 "3121 Fail allocate memory for "
8525 "fast-path CQ set array\n");
8526 goto out_error;
8527 }
8528 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
8529 phba->cfg_nvmet_mrq,
8530 sizeof(struct lpfc_queue *),
8531 GFP_KERNEL);
8532 if (!phba->sli4_hba.nvmet_mrq_hdr) {
8533 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8534 "3122 Fail allocate memory for "
8535 "fast-path RQ set hdr array\n");
8536 goto out_error;
8537 }
8538 phba->sli4_hba.nvmet_mrq_data = kcalloc(
8539 phba->cfg_nvmet_mrq,
8540 sizeof(struct lpfc_queue *),
8541 GFP_KERNEL);
8542 if (!phba->sli4_hba.nvmet_mrq_data) {
8543 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8544 "3124 Fail allocate memory for "
8545 "fast-path RQ set data array\n");
8546 goto out_error;
8547 }
8548 }
James Smart67d12732012-08-03 12:36:13 -04008549 }
James Smartda0436e2009-05-22 14:51:39 -04008550
James Smart895427b2017-02-12 13:52:30 -08008551 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
James Smart67d12732012-08-03 12:36:13 -04008552
James Smart895427b2017-02-12 13:52:30 -08008553 /* Create HBA Event Queues (EQs) */
8554 for (idx = 0; idx < io_channel; idx++) {
James Smart67d12732012-08-03 12:36:13 -04008555 /* Create EQs */
James Smart81b96ed2017-11-20 16:00:29 -08008556 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8557 phba->sli4_hba.eq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008558 phba->sli4_hba.eq_ecount);
8559 if (!qdesc) {
8560 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04008561 "0497 Failed allocate EQ (%d)\n", idx);
8562 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008563 }
James Smart7365f6f2018-02-22 08:18:46 -08008564 qdesc->qe_valid = 1;
James Smart67d12732012-08-03 12:36:13 -04008565 phba->sli4_hba.hba_eq[idx] = qdesc;
James Smartda0436e2009-05-22 14:51:39 -04008566 }
8567
James Smart895427b2017-02-12 13:52:30 -08008568 /* FCP and NVME io channels are not required to be balanced */
8569
8570 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
8571 if (lpfc_alloc_fcp_wq_cq(phba, idx))
8572 goto out_error;
8573
8574 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
8575 if (lpfc_alloc_nvme_wq_cq(phba, idx))
8576 goto out_error;
James Smart67d12732012-08-03 12:36:13 -04008577
James Smart2d7dbc42017-02-12 13:52:35 -08008578 if (phba->nvmet_support) {
8579 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8580 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08008581 LPFC_DEFAULT_PAGE_SIZE,
8582 phba->sli4_hba.cq_esize,
8583 phba->sli4_hba.cq_ecount);
James Smart2d7dbc42017-02-12 13:52:35 -08008584 if (!qdesc) {
8585 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8586 "3142 Failed allocate NVME "
8587 "CQ Set (%d)\n", idx);
8588 goto out_error;
8589 }
James Smart7365f6f2018-02-22 08:18:46 -08008590 qdesc->qe_valid = 1;
James Smart2d7dbc42017-02-12 13:52:35 -08008591 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
8592 }
8593 }
8594
James Smartda0436e2009-05-22 14:51:39 -04008595 /*
James Smart67d12732012-08-03 12:36:13 -04008596 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04008597 */
8598
James Smartda0436e2009-05-22 14:51:39 -04008599 /* Create slow-path Mailbox Command Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008600 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8601 phba->sli4_hba.cq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008602 phba->sli4_hba.cq_ecount);
8603 if (!qdesc) {
8604 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8605 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04008606 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008607 }
James Smart7365f6f2018-02-22 08:18:46 -08008608 qdesc->qe_valid = 1;
James Smartda0436e2009-05-22 14:51:39 -04008609 phba->sli4_hba.mbx_cq = qdesc;
8610
8611 /* Create slow-path ELS Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008612 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8613 phba->sli4_hba.cq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008614 phba->sli4_hba.cq_ecount);
8615 if (!qdesc) {
8616 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8617 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -04008618 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008619 }
James Smart7365f6f2018-02-22 08:18:46 -08008620 qdesc->qe_valid = 1;
James Smartda0436e2009-05-22 14:51:39 -04008621 phba->sli4_hba.els_cq = qdesc;
8622
James Smartda0436e2009-05-22 14:51:39 -04008623
James Smart5350d872011-10-10 21:33:49 -04008624 /*
James Smart67d12732012-08-03 12:36:13 -04008625 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04008626 */
James Smartda0436e2009-05-22 14:51:39 -04008627
8628 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04008629
James Smart81b96ed2017-11-20 16:00:29 -08008630 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8631 phba->sli4_hba.mq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008632 phba->sli4_hba.mq_ecount);
8633 if (!qdesc) {
8634 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8635 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04008636 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008637 }
8638 phba->sli4_hba.mbx_wq = qdesc;
8639
8640 /*
James Smart67d12732012-08-03 12:36:13 -04008641 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04008642 */
James Smartda0436e2009-05-22 14:51:39 -04008643
8644 /* Create slow-path ELS Work Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008645 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8646 phba->sli4_hba.wq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008647 phba->sli4_hba.wq_ecount);
8648 if (!qdesc) {
8649 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8650 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04008651 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008652 }
8653 phba->sli4_hba.els_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08008654 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8655
8656 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8657 /* Create NVME LS Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008658 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8659 phba->sli4_hba.cq_esize,
James Smart895427b2017-02-12 13:52:30 -08008660 phba->sli4_hba.cq_ecount);
8661 if (!qdesc) {
8662 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8663 "6079 Failed allocate NVME LS CQ\n");
8664 goto out_error;
8665 }
James Smart7365f6f2018-02-22 08:18:46 -08008666 qdesc->qe_valid = 1;
James Smart895427b2017-02-12 13:52:30 -08008667 phba->sli4_hba.nvmels_cq = qdesc;
8668
8669 /* Create NVME LS Work Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008670 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8671 phba->sli4_hba.wq_esize,
James Smart895427b2017-02-12 13:52:30 -08008672 phba->sli4_hba.wq_ecount);
8673 if (!qdesc) {
8674 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8675 "6080 Failed allocate NVME LS WQ\n");
8676 goto out_error;
8677 }
8678 phba->sli4_hba.nvmels_wq = qdesc;
8679 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8680 }
James Smartda0436e2009-05-22 14:51:39 -04008681
James Smartda0436e2009-05-22 14:51:39 -04008682 /*
8683 * Create Receive Queue (RQ)
8684 */
James Smartda0436e2009-05-22 14:51:39 -04008685
8686 /* Create Receive Queue for header */
James Smart81b96ed2017-11-20 16:00:29 -08008687 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8688 phba->sli4_hba.rq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008689 phba->sli4_hba.rq_ecount);
8690 if (!qdesc) {
8691 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8692 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04008693 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008694 }
8695 phba->sli4_hba.hdr_rq = qdesc;
8696
8697 /* Create Receive Queue for data */
James Smart81b96ed2017-11-20 16:00:29 -08008698 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8699 phba->sli4_hba.rq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008700 phba->sli4_hba.rq_ecount);
8701 if (!qdesc) {
8702 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8703 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04008704 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008705 }
8706 phba->sli4_hba.dat_rq = qdesc;
8707
James Smart2d7dbc42017-02-12 13:52:35 -08008708 if (phba->nvmet_support) {
8709 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8710 /* Create NVMET Receive Queue for header */
8711 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08008712 LPFC_DEFAULT_PAGE_SIZE,
James Smart2d7dbc42017-02-12 13:52:35 -08008713 phba->sli4_hba.rq_esize,
James Smart61f3d4b2017-05-15 15:20:41 -07008714 LPFC_NVMET_RQE_DEF_COUNT);
James Smart2d7dbc42017-02-12 13:52:35 -08008715 if (!qdesc) {
8716 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8717 "3146 Failed allocate "
8718 "receive HRQ\n");
8719 goto out_error;
8720 }
8721 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
8722
8723 /* Only needed for header of RQ pair */
8724 qdesc->rqbp = kzalloc(sizeof(struct lpfc_rqb),
8725 GFP_KERNEL);
8726 if (qdesc->rqbp == NULL) {
8727 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8728 "6131 Failed allocate "
8729 "Header RQBP\n");
8730 goto out_error;
8731 }
8732
Dick Kennedy4b40d022017-08-23 16:55:38 -07008733 /* Put list in known state in case driver load fails. */
8734 INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list);
8735
James Smart2d7dbc42017-02-12 13:52:35 -08008736 /* Create NVMET Receive Queue for data */
8737 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08008738 LPFC_DEFAULT_PAGE_SIZE,
James Smart2d7dbc42017-02-12 13:52:35 -08008739 phba->sli4_hba.rq_esize,
James Smart61f3d4b2017-05-15 15:20:41 -07008740 LPFC_NVMET_RQE_DEF_COUNT);
James Smart2d7dbc42017-02-12 13:52:35 -08008741 if (!qdesc) {
8742 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8743 "3156 Failed allocate "
8744 "receive DRQ\n");
8745 goto out_error;
8746 }
8747 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
8748 }
8749 }
8750
James Smart1ba981f2014-02-20 09:56:45 -05008751 /* Create the Queues needed for Flash Optimized Fabric operations */
8752 if (phba->cfg_fof)
8753 lpfc_fof_queue_create(phba);
James Smartda0436e2009-05-22 14:51:39 -04008754 return 0;
8755
James Smartda0436e2009-05-22 14:51:39 -04008756out_error:
James Smart67d12732012-08-03 12:36:13 -04008757 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04008758 return -ENOMEM;
8759}
8760
James Smart895427b2017-02-12 13:52:30 -08008761static inline void
8762__lpfc_sli4_release_queue(struct lpfc_queue **qp)
8763{
8764 if (*qp != NULL) {
8765 lpfc_sli4_queue_free(*qp);
8766 *qp = NULL;
8767 }
8768}
8769
8770static inline void
8771lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
8772{
8773 int idx;
8774
8775 if (*qs == NULL)
8776 return;
8777
8778 for (idx = 0; idx < max; idx++)
8779 __lpfc_sli4_release_queue(&(*qs)[idx]);
8780
8781 kfree(*qs);
8782 *qs = NULL;
8783}
8784
8785static inline void
8786lpfc_sli4_release_queue_map(uint16_t **qmap)
8787{
8788 if (*qmap != NULL) {
8789 kfree(*qmap);
8790 *qmap = NULL;
8791 }
8792}
8793
James Smartda0436e2009-05-22 14:51:39 -04008794/**
8795 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
8796 * @phba: pointer to lpfc hba data structure.
8797 *
8798 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
8799 * operation.
8800 *
8801 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008802 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008803 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008804 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008805 **/
James Smart5350d872011-10-10 21:33:49 -04008806void
James Smartda0436e2009-05-22 14:51:39 -04008807lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
8808{
James Smart1ba981f2014-02-20 09:56:45 -05008809 if (phba->cfg_fof)
8810 lpfc_fof_queue_destroy(phba);
8811
James Smart895427b2017-02-12 13:52:30 -08008812 /* Release HBA eqs */
8813 lpfc_sli4_release_queues(&phba->sli4_hba.hba_eq, phba->io_channel_irqs);
James Smart67d12732012-08-03 12:36:13 -04008814
James Smart895427b2017-02-12 13:52:30 -08008815 /* Release FCP cqs */
8816 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_cq,
James Smartd1f525a2017-04-21 16:04:55 -07008817 phba->cfg_fcp_io_channel);
James Smart67d12732012-08-03 12:36:13 -04008818
James Smart895427b2017-02-12 13:52:30 -08008819 /* Release FCP wqs */
8820 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_wq,
James Smartd1f525a2017-04-21 16:04:55 -07008821 phba->cfg_fcp_io_channel);
James Smart67d12732012-08-03 12:36:13 -04008822
8823 /* Release FCP CQ mapping array */
James Smart895427b2017-02-12 13:52:30 -08008824 lpfc_sli4_release_queue_map(&phba->sli4_hba.fcp_cq_map);
8825
8826 /* Release NVME cqs */
8827 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_cq,
8828 phba->cfg_nvme_io_channel);
8829
8830 /* Release NVME wqs */
8831 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_wq,
8832 phba->cfg_nvme_io_channel);
8833
8834 /* Release NVME CQ mapping array */
8835 lpfc_sli4_release_queue_map(&phba->sli4_hba.nvme_cq_map);
James Smartda0436e2009-05-22 14:51:39 -04008836
James Smartbcb24f62017-11-20 16:00:36 -08008837 if (phba->nvmet_support) {
8838 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
8839 phba->cfg_nvmet_mrq);
James Smart2d7dbc42017-02-12 13:52:35 -08008840
James Smartbcb24f62017-11-20 16:00:36 -08008841 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
8842 phba->cfg_nvmet_mrq);
8843 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
8844 phba->cfg_nvmet_mrq);
8845 }
James Smart2d7dbc42017-02-12 13:52:35 -08008846
James Smartda0436e2009-05-22 14:51:39 -04008847 /* Release mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08008848 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
James Smartda0436e2009-05-22 14:51:39 -04008849
8850 /* Release ELS work queue */
James Smart895427b2017-02-12 13:52:30 -08008851 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
8852
8853 /* Release ELS work queue */
8854 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
James Smartda0436e2009-05-22 14:51:39 -04008855
8856 /* Release unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08008857 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
8858 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
James Smartda0436e2009-05-22 14:51:39 -04008859
James Smartda0436e2009-05-22 14:51:39 -04008860 /* Release ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08008861 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
8862
8863 /* Release NVME LS complete queue */
8864 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
James Smartda0436e2009-05-22 14:51:39 -04008865
8866 /* Release mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08008867 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
8868
8869 /* Everything on this list has been freed */
8870 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
8871}
8872
8873int
James Smart895427b2017-02-12 13:52:30 -08008874lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
8875{
8876 struct lpfc_rqb *rqbp;
8877 struct lpfc_dmabuf *h_buf;
8878 struct rqb_dmabuf *rqb_buffer;
8879
8880 rqbp = rq->rqbp;
8881 while (!list_empty(&rqbp->rqb_buffer_list)) {
8882 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
8883 struct lpfc_dmabuf, list);
8884
8885 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
8886 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
8887 rqbp->buffer_count--;
8888 }
8889 return 1;
8890}
8891
8892static int
8893lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
8894 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
8895 int qidx, uint32_t qtype)
8896{
8897 struct lpfc_sli_ring *pring;
8898 int rc;
8899
8900 if (!eq || !cq || !wq) {
8901 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8902 "6085 Fast-path %s (%d) not allocated\n",
8903 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
8904 return -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04008905 }
James Smartda0436e2009-05-22 14:51:39 -04008906
James Smart895427b2017-02-12 13:52:30 -08008907 /* create the Cq first */
8908 rc = lpfc_cq_create(phba, cq, eq,
8909 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
8910 if (rc) {
8911 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8912 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
8913 qidx, (uint32_t)rc);
8914 return rc;
8915 }
James Smart81b96ed2017-11-20 16:00:29 -08008916 cq->chann = qidx;
James Smart895427b2017-02-12 13:52:30 -08008917
8918 if (qtype != LPFC_MBOX) {
8919 /* Setup nvme_cq_map for fast lookup */
8920 if (cq_map)
8921 *cq_map = cq->queue_id;
8922
8923 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8924 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
8925 qidx, cq->queue_id, qidx, eq->queue_id);
8926
8927 /* create the wq */
8928 rc = lpfc_wq_create(phba, wq, cq, qtype);
8929 if (rc) {
8930 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8931 "6123 Fail setup fastpath WQ (%d), rc = 0x%x\n",
8932 qidx, (uint32_t)rc);
8933 /* no need to tear down cq - caller will do so */
8934 return rc;
8935 }
James Smart81b96ed2017-11-20 16:00:29 -08008936 wq->chann = qidx;
James Smart895427b2017-02-12 13:52:30 -08008937
8938 /* Bind this CQ/WQ to the NVME ring */
8939 pring = wq->pring;
8940 pring->sli.sli4.wqp = (void *)wq;
8941 cq->pring = pring;
8942
8943 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8944 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
8945 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
8946 } else {
8947 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
8948 if (rc) {
8949 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8950 "0539 Failed setup of slow-path MQ: "
8951 "rc = 0x%x\n", rc);
8952 /* no need to tear down cq - caller will do so */
8953 return rc;
8954 }
8955
8956 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8957 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
8958 phba->sli4_hba.mbx_wq->queue_id,
8959 phba->sli4_hba.mbx_cq->queue_id);
8960 }
8961
8962 return 0;
James Smartda0436e2009-05-22 14:51:39 -04008963}
8964
8965/**
8966 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
8967 * @phba: pointer to lpfc hba data structure.
8968 *
8969 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
8970 * operation.
8971 *
8972 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008973 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008974 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008975 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008976 **/
8977int
8978lpfc_sli4_queue_setup(struct lpfc_hba *phba)
8979{
James Smart962bc512013-01-03 15:44:00 -05008980 uint32_t shdr_status, shdr_add_status;
8981 union lpfc_sli4_cfg_shdr *shdr;
8982 LPFC_MBOXQ_t *mboxq;
James Smart895427b2017-02-12 13:52:30 -08008983 int qidx;
8984 uint32_t length, io_channel;
8985 int rc = -ENOMEM;
James Smart962bc512013-01-03 15:44:00 -05008986
8987 /* Check for dual-ULP support */
8988 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8989 if (!mboxq) {
8990 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8991 "3249 Unable to allocate memory for "
8992 "QUERY_FW_CFG mailbox command\n");
8993 return -ENOMEM;
8994 }
8995 length = (sizeof(struct lpfc_mbx_query_fw_config) -
8996 sizeof(struct lpfc_sli4_cfg_mhdr));
8997 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8998 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
8999 length, LPFC_SLI4_MBX_EMBED);
9000
9001 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9002
9003 shdr = (union lpfc_sli4_cfg_shdr *)
9004 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
9005 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9006 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
9007 if (shdr_status || shdr_add_status || rc) {
9008 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9009 "3250 QUERY_FW_CFG mailbox failed with status "
9010 "x%x add_status x%x, mbx status x%x\n",
9011 shdr_status, shdr_add_status, rc);
9012 if (rc != MBX_TIMEOUT)
9013 mempool_free(mboxq, phba->mbox_mem_pool);
9014 rc = -ENXIO;
9015 goto out_error;
9016 }
9017
9018 phba->sli4_hba.fw_func_mode =
9019 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
9020 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
9021 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
James Smart8b017a32015-05-21 13:55:18 -04009022 phba->sli4_hba.physical_port =
9023 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
James Smart962bc512013-01-03 15:44:00 -05009024 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9025 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
9026 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
9027 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
9028
9029 if (rc != MBX_TIMEOUT)
9030 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04009031
9032 /*
James Smart67d12732012-08-03 12:36:13 -04009033 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04009034 */
James Smart895427b2017-02-12 13:52:30 -08009035 io_channel = phba->io_channel_irqs;
James Smartda0436e2009-05-22 14:51:39 -04009036
James Smart67d12732012-08-03 12:36:13 -04009037 /* Set up HBA event queue */
James Smart895427b2017-02-12 13:52:30 -08009038 if (io_channel && !phba->sli4_hba.hba_eq) {
James Smart2e90f4b2011-12-13 13:22:37 -05009039 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9040 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05009041 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04009042 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05009043 }
James Smart895427b2017-02-12 13:52:30 -08009044 for (qidx = 0; qidx < io_channel; qidx++) {
9045 if (!phba->sli4_hba.hba_eq[qidx]) {
James Smartda0436e2009-05-22 14:51:39 -04009046 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9047 "0522 Fast-path EQ (%d) not "
James Smart895427b2017-02-12 13:52:30 -08009048 "allocated\n", qidx);
James Smart1b511972011-12-13 13:23:09 -05009049 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009050 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009051 }
James Smart895427b2017-02-12 13:52:30 -08009052 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[qidx],
9053 phba->cfg_fcp_imax);
James Smartda0436e2009-05-22 14:51:39 -04009054 if (rc) {
9055 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9056 "0523 Failed setup of fast-path EQ "
James Smart895427b2017-02-12 13:52:30 -08009057 "(%d), rc = 0x%x\n", qidx,
James Smarta2fc4aef2014-09-03 12:57:55 -04009058 (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08009059 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009060 }
9061 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009062 "2584 HBA EQ setup: queue[%d]-id=%d\n",
9063 qidx, phba->sli4_hba.hba_eq[qidx]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04009064 }
9065
James Smart895427b2017-02-12 13:52:30 -08009066 if (phba->cfg_nvme_io_channel) {
9067 if (!phba->sli4_hba.nvme_cq || !phba->sli4_hba.nvme_wq) {
James Smart67d12732012-08-03 12:36:13 -04009068 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009069 "6084 Fast-path NVME %s array not allocated\n",
9070 (phba->sli4_hba.nvme_cq) ? "CQ" : "WQ");
James Smart67d12732012-08-03 12:36:13 -04009071 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009072 goto out_destroy;
James Smart67d12732012-08-03 12:36:13 -04009073 }
9074
James Smart895427b2017-02-12 13:52:30 -08009075 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
9076 rc = lpfc_create_wq_cq(phba,
9077 phba->sli4_hba.hba_eq[
9078 qidx % io_channel],
9079 phba->sli4_hba.nvme_cq[qidx],
9080 phba->sli4_hba.nvme_wq[qidx],
9081 &phba->sli4_hba.nvme_cq_map[qidx],
9082 qidx, LPFC_NVME);
9083 if (rc) {
9084 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9085 "6123 Failed to setup fastpath "
9086 "NVME WQ/CQ (%d), rc = 0x%x\n",
9087 qidx, (uint32_t)rc);
9088 goto out_destroy;
9089 }
9090 }
James Smart67d12732012-08-03 12:36:13 -04009091 }
9092
James Smart895427b2017-02-12 13:52:30 -08009093 if (phba->cfg_fcp_io_channel) {
9094 /* Set up fast-path FCP Response Complete Queue */
9095 if (!phba->sli4_hba.fcp_cq || !phba->sli4_hba.fcp_wq) {
James Smart67d12732012-08-03 12:36:13 -04009096 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009097 "3148 Fast-path FCP %s array not allocated\n",
9098 phba->sli4_hba.fcp_cq ? "WQ" : "CQ");
James Smart67d12732012-08-03 12:36:13 -04009099 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009100 goto out_destroy;
James Smart67d12732012-08-03 12:36:13 -04009101 }
9102
James Smart895427b2017-02-12 13:52:30 -08009103 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
9104 rc = lpfc_create_wq_cq(phba,
9105 phba->sli4_hba.hba_eq[
9106 qidx % io_channel],
9107 phba->sli4_hba.fcp_cq[qidx],
9108 phba->sli4_hba.fcp_wq[qidx],
9109 &phba->sli4_hba.fcp_cq_map[qidx],
9110 qidx, LPFC_FCP);
9111 if (rc) {
9112 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9113 "0535 Failed to setup fastpath "
9114 "FCP WQ/CQ (%d), rc = 0x%x\n",
9115 qidx, (uint32_t)rc);
9116 goto out_destroy;
9117 }
9118 }
James Smart67d12732012-08-03 12:36:13 -04009119 }
James Smartda0436e2009-05-22 14:51:39 -04009120
9121 /*
James Smart895427b2017-02-12 13:52:30 -08009122 * Set up Slow Path Complete Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04009123 */
9124
James Smart895427b2017-02-12 13:52:30 -08009125 /* Set up slow-path MBOX CQ/MQ */
9126
9127 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
James Smartda0436e2009-05-22 14:51:39 -04009128 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009129 "0528 %s not allocated\n",
9130 phba->sli4_hba.mbx_cq ?
James Smartd1f525a2017-04-21 16:04:55 -07009131 "Mailbox WQ" : "Mailbox CQ");
James Smart1b511972011-12-13 13:23:09 -05009132 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009133 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009134 }
James Smart895427b2017-02-12 13:52:30 -08009135
9136 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
James Smartd1f525a2017-04-21 16:04:55 -07009137 phba->sli4_hba.mbx_cq,
9138 phba->sli4_hba.mbx_wq,
9139 NULL, 0, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04009140 if (rc) {
9141 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009142 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
9143 (uint32_t)rc);
9144 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009145 }
James Smart2d7dbc42017-02-12 13:52:35 -08009146 if (phba->nvmet_support) {
9147 if (!phba->sli4_hba.nvmet_cqset) {
9148 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9149 "3165 Fast-path NVME CQ Set "
9150 "array not allocated\n");
9151 rc = -ENOMEM;
9152 goto out_destroy;
9153 }
9154 if (phba->cfg_nvmet_mrq > 1) {
9155 rc = lpfc_cq_create_set(phba,
9156 phba->sli4_hba.nvmet_cqset,
9157 phba->sli4_hba.hba_eq,
9158 LPFC_WCQ, LPFC_NVMET);
9159 if (rc) {
9160 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9161 "3164 Failed setup of NVME CQ "
9162 "Set, rc = 0x%x\n",
9163 (uint32_t)rc);
9164 goto out_destroy;
9165 }
9166 } else {
9167 /* Set up NVMET Receive Complete Queue */
9168 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
9169 phba->sli4_hba.hba_eq[0],
9170 LPFC_WCQ, LPFC_NVMET);
9171 if (rc) {
9172 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9173 "6089 Failed setup NVMET CQ: "
9174 "rc = 0x%x\n", (uint32_t)rc);
9175 goto out_destroy;
9176 }
James Smart81b96ed2017-11-20 16:00:29 -08009177 phba->sli4_hba.nvmet_cqset[0]->chann = 0;
9178
James Smart2d7dbc42017-02-12 13:52:35 -08009179 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9180 "6090 NVMET CQ setup: cq-id=%d, "
9181 "parent eq-id=%d\n",
9182 phba->sli4_hba.nvmet_cqset[0]->queue_id,
9183 phba->sli4_hba.hba_eq[0]->queue_id);
9184 }
9185 }
James Smartda0436e2009-05-22 14:51:39 -04009186
James Smart895427b2017-02-12 13:52:30 -08009187 /* Set up slow-path ELS WQ/CQ */
9188 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
James Smartda0436e2009-05-22 14:51:39 -04009189 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009190 "0530 ELS %s not allocated\n",
9191 phba->sli4_hba.els_cq ? "WQ" : "CQ");
James Smart1b511972011-12-13 13:23:09 -05009192 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009193 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009194 }
James Smart895427b2017-02-12 13:52:30 -08009195 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
9196 phba->sli4_hba.els_cq,
9197 phba->sli4_hba.els_wq,
9198 NULL, 0, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04009199 if (rc) {
9200 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08009201 "0529 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
9202 (uint32_t)rc);
9203 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009204 }
9205 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9206 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
9207 phba->sli4_hba.els_wq->queue_id,
9208 phba->sli4_hba.els_cq->queue_id);
9209
James Smart895427b2017-02-12 13:52:30 -08009210 if (phba->cfg_nvme_io_channel) {
9211 /* Set up NVME LS Complete Queue */
9212 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
9213 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9214 "6091 LS %s not allocated\n",
9215 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
9216 rc = -ENOMEM;
9217 goto out_destroy;
9218 }
9219 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
9220 phba->sli4_hba.nvmels_cq,
9221 phba->sli4_hba.nvmels_wq,
9222 NULL, 0, LPFC_NVME_LS);
9223 if (rc) {
9224 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9225 "0529 Failed setup of NVVME LS WQ/CQ: "
9226 "rc = 0x%x\n", (uint32_t)rc);
9227 goto out_destroy;
9228 }
9229
9230 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9231 "6096 ELS WQ setup: wq-id=%d, "
9232 "parent cq-id=%d\n",
9233 phba->sli4_hba.nvmels_wq->queue_id,
9234 phba->sli4_hba.nvmels_cq->queue_id);
9235 }
9236
James Smart2d7dbc42017-02-12 13:52:35 -08009237 /*
9238 * Create NVMET Receive Queue (RQ)
9239 */
9240 if (phba->nvmet_support) {
9241 if ((!phba->sli4_hba.nvmet_cqset) ||
9242 (!phba->sli4_hba.nvmet_mrq_hdr) ||
9243 (!phba->sli4_hba.nvmet_mrq_data)) {
9244 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9245 "6130 MRQ CQ Queues not "
9246 "allocated\n");
9247 rc = -ENOMEM;
9248 goto out_destroy;
9249 }
9250 if (phba->cfg_nvmet_mrq > 1) {
9251 rc = lpfc_mrq_create(phba,
9252 phba->sli4_hba.nvmet_mrq_hdr,
9253 phba->sli4_hba.nvmet_mrq_data,
9254 phba->sli4_hba.nvmet_cqset,
9255 LPFC_NVMET);
9256 if (rc) {
9257 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9258 "6098 Failed setup of NVMET "
9259 "MRQ: rc = 0x%x\n",
9260 (uint32_t)rc);
9261 goto out_destroy;
9262 }
9263
9264 } else {
9265 rc = lpfc_rq_create(phba,
9266 phba->sli4_hba.nvmet_mrq_hdr[0],
9267 phba->sli4_hba.nvmet_mrq_data[0],
9268 phba->sli4_hba.nvmet_cqset[0],
9269 LPFC_NVMET);
9270 if (rc) {
9271 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9272 "6057 Failed setup of NVMET "
9273 "Receive Queue: rc = 0x%x\n",
9274 (uint32_t)rc);
9275 goto out_destroy;
9276 }
9277
9278 lpfc_printf_log(
9279 phba, KERN_INFO, LOG_INIT,
9280 "6099 NVMET RQ setup: hdr-rq-id=%d, "
9281 "dat-rq-id=%d parent cq-id=%d\n",
9282 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
9283 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
9284 phba->sli4_hba.nvmet_cqset[0]->queue_id);
9285
9286 }
9287 }
9288
James Smartda0436e2009-05-22 14:51:39 -04009289 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
9290 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9291 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05009292 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009293 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009294 }
James Smart73d91e52011-10-10 21:32:10 -04009295
James Smartda0436e2009-05-22 14:51:39 -04009296 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04009297 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04009298 if (rc) {
9299 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9300 "0541 Failed setup of Receive Queue: "
James Smarta2fc4aef2014-09-03 12:57:55 -04009301 "rc = 0x%x\n", (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08009302 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009303 }
James Smart73d91e52011-10-10 21:32:10 -04009304
James Smartda0436e2009-05-22 14:51:39 -04009305 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9306 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
9307 "parent cq-id=%d\n",
9308 phba->sli4_hba.hdr_rq->queue_id,
9309 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04009310 phba->sli4_hba.els_cq->queue_id);
James Smart1ba981f2014-02-20 09:56:45 -05009311
9312 if (phba->cfg_fof) {
9313 rc = lpfc_fof_queue_setup(phba);
9314 if (rc) {
9315 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9316 "0549 Failed setup of FOF Queues: "
9317 "rc = 0x%x\n", rc);
James Smart895427b2017-02-12 13:52:30 -08009318 goto out_destroy;
James Smart1ba981f2014-02-20 09:56:45 -05009319 }
9320 }
James Smart2c9c5a02015-04-07 15:07:15 -04009321
James Smart43140ca2017-03-04 09:30:34 -08009322 for (qidx = 0; qidx < io_channel; qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
James Smart0cf07f842017-06-01 21:07:10 -07009323 lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT,
9324 phba->cfg_fcp_imax);
James Smart43140ca2017-03-04 09:30:34 -08009325
James Smartda0436e2009-05-22 14:51:39 -04009326 return 0;
9327
James Smart895427b2017-02-12 13:52:30 -08009328out_destroy:
9329 lpfc_sli4_queue_unset(phba);
James Smartda0436e2009-05-22 14:51:39 -04009330out_error:
9331 return rc;
9332}
9333
9334/**
9335 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
9336 * @phba: pointer to lpfc hba data structure.
9337 *
9338 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
9339 * operation.
9340 *
9341 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009342 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009343 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009344 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009345 **/
9346void
9347lpfc_sli4_queue_unset(struct lpfc_hba *phba)
9348{
James Smart895427b2017-02-12 13:52:30 -08009349 int qidx;
James Smartda0436e2009-05-22 14:51:39 -04009350
James Smart1ba981f2014-02-20 09:56:45 -05009351 /* Unset the queues created for Flash Optimized Fabric operations */
9352 if (phba->cfg_fof)
9353 lpfc_fof_queue_destroy(phba);
James Smart895427b2017-02-12 13:52:30 -08009354
James Smartda0436e2009-05-22 14:51:39 -04009355 /* Unset mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08009356 if (phba->sli4_hba.mbx_wq)
9357 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
9358
9359 /* Unset NVME LS work queue */
9360 if (phba->sli4_hba.nvmels_wq)
9361 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
9362
James Smartda0436e2009-05-22 14:51:39 -04009363 /* Unset ELS work queue */
Colin Ian King019c0d62017-05-06 23:13:55 +01009364 if (phba->sli4_hba.els_wq)
James Smart895427b2017-02-12 13:52:30 -08009365 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
9366
James Smartda0436e2009-05-22 14:51:39 -04009367 /* Unset unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08009368 if (phba->sli4_hba.hdr_rq)
9369 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
9370 phba->sli4_hba.dat_rq);
9371
James Smartda0436e2009-05-22 14:51:39 -04009372 /* Unset FCP work queue */
James Smart895427b2017-02-12 13:52:30 -08009373 if (phba->sli4_hba.fcp_wq)
9374 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
9375 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[qidx]);
9376
9377 /* Unset NVME work queue */
9378 if (phba->sli4_hba.nvme_wq) {
9379 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
9380 lpfc_wq_destroy(phba, phba->sli4_hba.nvme_wq[qidx]);
James Smart67d12732012-08-03 12:36:13 -04009381 }
James Smart895427b2017-02-12 13:52:30 -08009382
James Smartda0436e2009-05-22 14:51:39 -04009383 /* Unset mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08009384 if (phba->sli4_hba.mbx_cq)
9385 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
9386
James Smartda0436e2009-05-22 14:51:39 -04009387 /* Unset ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08009388 if (phba->sli4_hba.els_cq)
9389 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
9390
9391 /* Unset NVME LS complete queue */
9392 if (phba->sli4_hba.nvmels_cq)
9393 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
9394
9395 /* Unset NVME response complete queue */
9396 if (phba->sli4_hba.nvme_cq)
9397 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
9398 lpfc_cq_destroy(phba, phba->sli4_hba.nvme_cq[qidx]);
9399
James Smartbcb24f62017-11-20 16:00:36 -08009400 if (phba->nvmet_support) {
9401 /* Unset NVMET MRQ queue */
9402 if (phba->sli4_hba.nvmet_mrq_hdr) {
9403 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9404 lpfc_rq_destroy(
9405 phba,
James Smart2d7dbc42017-02-12 13:52:35 -08009406 phba->sli4_hba.nvmet_mrq_hdr[qidx],
9407 phba->sli4_hba.nvmet_mrq_data[qidx]);
James Smartbcb24f62017-11-20 16:00:36 -08009408 }
James Smart2d7dbc42017-02-12 13:52:35 -08009409
James Smartbcb24f62017-11-20 16:00:36 -08009410 /* Unset NVMET CQ Set complete queue */
9411 if (phba->sli4_hba.nvmet_cqset) {
9412 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9413 lpfc_cq_destroy(
9414 phba, phba->sli4_hba.nvmet_cqset[qidx]);
9415 }
James Smart2d7dbc42017-02-12 13:52:35 -08009416 }
9417
James Smartda0436e2009-05-22 14:51:39 -04009418 /* Unset FCP response complete queue */
James Smart895427b2017-02-12 13:52:30 -08009419 if (phba->sli4_hba.fcp_cq)
9420 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
9421 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[qidx]);
9422
James Smartda0436e2009-05-22 14:51:39 -04009423 /* Unset fast-path event queue */
James Smart895427b2017-02-12 13:52:30 -08009424 if (phba->sli4_hba.hba_eq)
9425 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++)
9426 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[qidx]);
James Smartda0436e2009-05-22 14:51:39 -04009427}
9428
9429/**
9430 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
9431 * @phba: pointer to lpfc hba data structure.
9432 *
9433 * This routine is invoked to allocate and set up a pool of completion queue
9434 * events. The body of the completion queue event is a completion queue entry
9435 * CQE. For now, this pool is used for the interrupt service routine to queue
9436 * the following HBA completion queue events for the worker thread to process:
9437 * - Mailbox asynchronous events
9438 * - Receive queue completion unsolicited events
9439 * Later, this can be used for all the slow-path events.
9440 *
9441 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009442 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009443 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04009444 **/
9445static int
9446lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
9447{
9448 struct lpfc_cq_event *cq_event;
9449 int i;
9450
9451 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
9452 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
9453 if (!cq_event)
9454 goto out_pool_create_fail;
9455 list_add_tail(&cq_event->list,
9456 &phba->sli4_hba.sp_cqe_event_pool);
9457 }
9458 return 0;
9459
9460out_pool_create_fail:
9461 lpfc_sli4_cq_event_pool_destroy(phba);
9462 return -ENOMEM;
9463}
9464
9465/**
9466 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
9467 * @phba: pointer to lpfc hba data structure.
9468 *
9469 * This routine is invoked to free the pool of completion queue events at
9470 * driver unload time. Note that, it is the responsibility of the driver
9471 * cleanup routine to free all the outstanding completion-queue events
9472 * allocated from this pool back into the pool before invoking this routine
9473 * to destroy the pool.
9474 **/
9475static void
9476lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
9477{
9478 struct lpfc_cq_event *cq_event, *next_cq_event;
9479
9480 list_for_each_entry_safe(cq_event, next_cq_event,
9481 &phba->sli4_hba.sp_cqe_event_pool, list) {
9482 list_del(&cq_event->list);
9483 kfree(cq_event);
9484 }
9485}
9486
9487/**
9488 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9489 * @phba: pointer to lpfc hba data structure.
9490 *
9491 * This routine is the lock free version of the API invoked to allocate a
9492 * completion-queue event from the free pool.
9493 *
9494 * Return: Pointer to the newly allocated completion-queue event if successful
9495 * NULL otherwise.
9496 **/
9497struct lpfc_cq_event *
9498__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9499{
9500 struct lpfc_cq_event *cq_event = NULL;
9501
9502 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
9503 struct lpfc_cq_event, list);
9504 return cq_event;
9505}
9506
9507/**
9508 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9509 * @phba: pointer to lpfc hba data structure.
9510 *
9511 * This routine is the lock version of the API invoked to allocate a
9512 * completion-queue event from the free pool.
9513 *
9514 * Return: Pointer to the newly allocated completion-queue event if successful
9515 * NULL otherwise.
9516 **/
9517struct lpfc_cq_event *
9518lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9519{
9520 struct lpfc_cq_event *cq_event;
9521 unsigned long iflags;
9522
9523 spin_lock_irqsave(&phba->hbalock, iflags);
9524 cq_event = __lpfc_sli4_cq_event_alloc(phba);
9525 spin_unlock_irqrestore(&phba->hbalock, iflags);
9526 return cq_event;
9527}
9528
9529/**
9530 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9531 * @phba: pointer to lpfc hba data structure.
9532 * @cq_event: pointer to the completion queue event to be freed.
9533 *
9534 * This routine is the lock free version of the API invoked to release a
9535 * completion-queue event back into the free pool.
9536 **/
9537void
9538__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9539 struct lpfc_cq_event *cq_event)
9540{
9541 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
9542}
9543
9544/**
9545 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9546 * @phba: pointer to lpfc hba data structure.
9547 * @cq_event: pointer to the completion queue event to be freed.
9548 *
9549 * This routine is the lock version of the API invoked to release a
9550 * completion-queue event back into the free pool.
9551 **/
9552void
9553lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9554 struct lpfc_cq_event *cq_event)
9555{
9556 unsigned long iflags;
9557 spin_lock_irqsave(&phba->hbalock, iflags);
9558 __lpfc_sli4_cq_event_release(phba, cq_event);
9559 spin_unlock_irqrestore(&phba->hbalock, iflags);
9560}
9561
9562/**
9563 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
9564 * @phba: pointer to lpfc hba data structure.
9565 *
9566 * This routine is to free all the pending completion-queue events to the
9567 * back into the free pool for device reset.
9568 **/
9569static void
9570lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
9571{
9572 LIST_HEAD(cqelist);
9573 struct lpfc_cq_event *cqe;
9574 unsigned long iflags;
9575
9576 /* Retrieve all the pending WCQEs from pending WCQE lists */
9577 spin_lock_irqsave(&phba->hbalock, iflags);
9578 /* Pending FCP XRI abort events */
9579 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
9580 &cqelist);
9581 /* Pending ELS XRI abort events */
9582 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
9583 &cqelist);
9584 /* Pending asynnc events */
9585 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
9586 &cqelist);
9587 spin_unlock_irqrestore(&phba->hbalock, iflags);
9588
9589 while (!list_empty(&cqelist)) {
9590 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
9591 lpfc_sli4_cq_event_release(phba, cqe);
9592 }
9593}
9594
9595/**
9596 * lpfc_pci_function_reset - Reset pci function.
9597 * @phba: pointer to lpfc hba data structure.
9598 *
9599 * This routine is invoked to request a PCI function reset. It will destroys
9600 * all resources assigned to the PCI function which originates this request.
9601 *
9602 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009603 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009604 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009605 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009606 **/
9607int
9608lpfc_pci_function_reset(struct lpfc_hba *phba)
9609{
9610 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05009611 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04009612 uint32_t shdr_status, shdr_add_status;
James Smart2f6fa2c2014-09-03 12:57:08 -04009613 uint32_t rdy_chk;
9614 uint32_t port_reset = 0;
James Smartda0436e2009-05-22 14:51:39 -04009615 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05009616 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -05009617 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -04009618
James Smart2fcee4b2010-12-15 17:57:46 -05009619 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9620 switch (if_type) {
9621 case LPFC_SLI_INTF_IF_TYPE_0:
9622 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
9623 GFP_KERNEL);
9624 if (!mboxq) {
9625 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9626 "0494 Unable to allocate memory for "
9627 "issuing SLI_FUNCTION_RESET mailbox "
9628 "command\n");
9629 return -ENOMEM;
9630 }
9631
9632 /* Setup PCI function reset mailbox-ioctl command */
9633 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9634 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
9635 LPFC_SLI4_MBX_EMBED);
9636 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9637 shdr = (union lpfc_sli4_cfg_shdr *)
9638 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
9639 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9640 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
9641 &shdr->response);
9642 if (rc != MBX_TIMEOUT)
9643 mempool_free(mboxq, phba->mbox_mem_pool);
9644 if (shdr_status || shdr_add_status || rc) {
9645 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9646 "0495 SLI_FUNCTION_RESET mailbox "
9647 "failed with status x%x add_status x%x,"
9648 " mbx status x%x\n",
9649 shdr_status, shdr_add_status, rc);
9650 rc = -ENXIO;
9651 }
9652 break;
9653 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08009654 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2f6fa2c2014-09-03 12:57:08 -04009655wait:
9656 /*
9657 * Poll the Port Status Register and wait for RDY for
9658 * up to 30 seconds. If the port doesn't respond, treat
9659 * it as an error.
9660 */
James Smart77d093f2015-04-07 15:07:08 -04009661 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
James Smart2f6fa2c2014-09-03 12:57:08 -04009662 if (lpfc_readl(phba->sli4_hba.u.if_type2.
9663 STATUSregaddr, &reg_data.word0)) {
9664 rc = -ENODEV;
9665 goto out;
9666 }
9667 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
9668 break;
9669 msleep(20);
9670 }
9671
9672 if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
9673 phba->work_status[0] = readl(
9674 phba->sli4_hba.u.if_type2.ERR1regaddr);
9675 phba->work_status[1] = readl(
9676 phba->sli4_hba.u.if_type2.ERR2regaddr);
9677 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9678 "2890 Port not ready, port status reg "
9679 "0x%x error 1=0x%x, error 2=0x%x\n",
9680 reg_data.word0,
9681 phba->work_status[0],
9682 phba->work_status[1]);
9683 rc = -ENODEV;
9684 goto out;
9685 }
9686
9687 if (!port_reset) {
9688 /*
9689 * Reset the port now
9690 */
James Smart2fcee4b2010-12-15 17:57:46 -05009691 reg_data.word0 = 0;
9692 bf_set(lpfc_sliport_ctrl_end, &reg_data,
9693 LPFC_SLIPORT_LITTLE_ENDIAN);
9694 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
9695 LPFC_SLIPORT_INIT_PORT);
9696 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
9697 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -05009698 /* flush */
James Smart2b81f942012-03-01 22:37:18 -05009699 pci_read_config_word(phba->pcidev,
9700 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -05009701
James Smart2f6fa2c2014-09-03 12:57:08 -04009702 port_reset = 1;
9703 msleep(20);
9704 goto wait;
9705 } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
9706 rc = -ENODEV;
9707 goto out;
James Smart2fcee4b2010-12-15 17:57:46 -05009708 }
9709 break;
James Smart2f6fa2c2014-09-03 12:57:08 -04009710
James Smart2fcee4b2010-12-15 17:57:46 -05009711 case LPFC_SLI_INTF_IF_TYPE_1:
9712 default:
9713 break;
James Smartda0436e2009-05-22 14:51:39 -04009714 }
9715
James Smart73d91e52011-10-10 21:32:10 -04009716out:
James Smart2fcee4b2010-12-15 17:57:46 -05009717 /* Catch the not-ready port failure after a port reset. */
James Smart2f6fa2c2014-09-03 12:57:08 -04009718 if (rc) {
James Smart229adb02013-04-17 20:16:51 -04009719 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9720 "3317 HBA not functional: IP Reset Failed "
James Smart2f6fa2c2014-09-03 12:57:08 -04009721 "try: echo fw_reset > board_mode\n");
James Smart2fcee4b2010-12-15 17:57:46 -05009722 rc = -ENODEV;
James Smart229adb02013-04-17 20:16:51 -04009723 }
James Smart2fcee4b2010-12-15 17:57:46 -05009724
James Smartda0436e2009-05-22 14:51:39 -04009725 return rc;
9726}
9727
9728/**
James Smartda0436e2009-05-22 14:51:39 -04009729 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
9730 * @phba: pointer to lpfc hba data structure.
9731 *
9732 * This routine is invoked to set up the PCI device memory space for device
9733 * with SLI-4 interface spec.
9734 *
9735 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009736 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009737 * other values - error
9738 **/
9739static int
9740lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
9741{
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02009742 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -04009743 unsigned long bar0map_len, bar1map_len, bar2map_len;
9744 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05009745 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04009746
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02009747 if (!pdev)
Hannes Reinecke56de8352019-02-18 08:34:19 +01009748 return -ENODEV;
James Smartda0436e2009-05-22 14:51:39 -04009749
9750 /* Set the device DMA mask size */
Hannes Reinecke56de8352019-02-18 08:34:19 +01009751 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
9752 if (error)
9753 error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
9754 if (error)
Christoph Hellwigf30e1bf2018-10-18 15:10:21 +02009755 return error;
James Smartda0436e2009-05-22 14:51:39 -04009756
James Smart2fcee4b2010-12-15 17:57:46 -05009757 /*
9758 * The BARs and register set definitions and offset locations are
9759 * dependent on the if_type.
9760 */
9761 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
9762 &phba->sli4_hba.sli_intf.word0)) {
9763 return error;
9764 }
9765
9766 /* There is no SLI3 failback for SLI4 devices. */
9767 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
9768 LPFC_SLI_INTF_VALID) {
9769 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9770 "2894 SLI_INTF reg contents invalid "
9771 "sli_intf reg 0x%x\n",
9772 phba->sli4_hba.sli_intf.word0);
9773 return error;
9774 }
9775
9776 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9777 /*
9778 * Get the bus address of SLI4 device Bar regions and the
9779 * number of bytes required by each mapping. The mapping of the
9780 * particular PCI BARs regions is dependent on the type of
9781 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04009782 */
James Smartf5ca6f22013-09-06 12:21:09 -04009783 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
9784 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
9785 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
James Smart2fcee4b2010-12-15 17:57:46 -05009786
9787 /*
9788 * Map SLI4 PCI Config Space Register base to a kernel virtual
9789 * addr
9790 */
9791 phba->sli4_hba.conf_regs_memmap_p =
9792 ioremap(phba->pci_bar0_map, bar0map_len);
9793 if (!phba->sli4_hba.conf_regs_memmap_p) {
9794 dev_printk(KERN_ERR, &pdev->dev,
9795 "ioremap failed for SLI4 PCI config "
9796 "registers.\n");
9797 goto out;
9798 }
James Smartf5ca6f22013-09-06 12:21:09 -04009799 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05009800 /* Set up BAR0 PCI config space register memory map */
9801 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05009802 } else {
9803 phba->pci_bar0_map = pci_resource_start(pdev, 1);
9804 bar0map_len = pci_resource_len(pdev, 1);
James Smart27d6ac02018-02-22 08:18:42 -08009805 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
James Smart2fcee4b2010-12-15 17:57:46 -05009806 dev_printk(KERN_ERR, &pdev->dev,
9807 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
9808 goto out;
9809 }
9810 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04009811 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05009812 if (!phba->sli4_hba.conf_regs_memmap_p) {
9813 dev_printk(KERN_ERR, &pdev->dev,
9814 "ioremap failed for SLI4 PCI config "
9815 "registers.\n");
9816 goto out;
9817 }
9818 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04009819 }
9820
James Smarte4b97942017-11-20 16:00:31 -08009821 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
9822 if (pci_resource_start(pdev, PCI_64BIT_BAR2)) {
9823 /*
9824 * Map SLI4 if type 0 HBA Control Register base to a
9825 * kernel virtual address and setup the registers.
9826 */
9827 phba->pci_bar1_map = pci_resource_start(pdev,
9828 PCI_64BIT_BAR2);
9829 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
9830 phba->sli4_hba.ctrl_regs_memmap_p =
9831 ioremap(phba->pci_bar1_map,
9832 bar1map_len);
9833 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
9834 dev_err(&pdev->dev,
9835 "ioremap failed for SLI4 HBA "
9836 "control registers.\n");
9837 error = -ENOMEM;
9838 goto out_iounmap_conf;
9839 }
9840 phba->pci_bar2_memmap_p =
9841 phba->sli4_hba.ctrl_regs_memmap_p;
James Smart27d6ac02018-02-22 08:18:42 -08009842 lpfc_sli4_bar1_register_memmap(phba, if_type);
James Smarte4b97942017-11-20 16:00:31 -08009843 } else {
9844 error = -ENOMEM;
James Smart2fcee4b2010-12-15 17:57:46 -05009845 goto out_iounmap_conf;
9846 }
James Smartda0436e2009-05-22 14:51:39 -04009847 }
9848
James Smart27d6ac02018-02-22 08:18:42 -08009849 if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) &&
9850 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
9851 /*
9852 * Map SLI4 if type 6 HBA Doorbell Register base to a kernel
9853 * virtual address and setup the registers.
9854 */
9855 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
9856 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
9857 phba->sli4_hba.drbl_regs_memmap_p =
9858 ioremap(phba->pci_bar1_map, bar1map_len);
9859 if (!phba->sli4_hba.drbl_regs_memmap_p) {
9860 dev_err(&pdev->dev,
9861 "ioremap failed for SLI4 HBA doorbell registers.\n");
9862 goto out_iounmap_conf;
9863 }
9864 phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
9865 lpfc_sli4_bar1_register_memmap(phba, if_type);
9866 }
9867
James Smarte4b97942017-11-20 16:00:31 -08009868 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
9869 if (pci_resource_start(pdev, PCI_64BIT_BAR4)) {
9870 /*
9871 * Map SLI4 if type 0 HBA Doorbell Register base to
9872 * a kernel virtual address and setup the registers.
9873 */
9874 phba->pci_bar2_map = pci_resource_start(pdev,
9875 PCI_64BIT_BAR4);
9876 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
9877 phba->sli4_hba.drbl_regs_memmap_p =
9878 ioremap(phba->pci_bar2_map,
9879 bar2map_len);
9880 if (!phba->sli4_hba.drbl_regs_memmap_p) {
9881 dev_err(&pdev->dev,
9882 "ioremap failed for SLI4 HBA"
9883 " doorbell registers.\n");
9884 error = -ENOMEM;
9885 goto out_iounmap_ctrl;
9886 }
9887 phba->pci_bar4_memmap_p =
9888 phba->sli4_hba.drbl_regs_memmap_p;
9889 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
9890 if (error)
9891 goto out_iounmap_all;
9892 } else {
9893 error = -ENOMEM;
James Smart2fcee4b2010-12-15 17:57:46 -05009894 goto out_iounmap_all;
James Smarte4b97942017-11-20 16:00:31 -08009895 }
James Smartda0436e2009-05-22 14:51:39 -04009896 }
9897
James Smart1351e692018-02-22 08:18:43 -08009898 if (if_type == LPFC_SLI_INTF_IF_TYPE_6 &&
9899 pci_resource_start(pdev, PCI_64BIT_BAR4)) {
9900 /*
9901 * Map SLI4 if type 6 HBA DPP Register base to a kernel
9902 * virtual address and setup the registers.
9903 */
9904 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
9905 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
9906 phba->sli4_hba.dpp_regs_memmap_p =
9907 ioremap(phba->pci_bar2_map, bar2map_len);
9908 if (!phba->sli4_hba.dpp_regs_memmap_p) {
9909 dev_err(&pdev->dev,
9910 "ioremap failed for SLI4 HBA dpp registers.\n");
9911 goto out_iounmap_ctrl;
9912 }
9913 phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
9914 }
9915
James Smartb71413d2018-02-22 08:18:40 -08009916 /* Set up the EQ/CQ register handeling functions now */
James Smart27d6ac02018-02-22 08:18:42 -08009917 switch (if_type) {
9918 case LPFC_SLI_INTF_IF_TYPE_0:
9919 case LPFC_SLI_INTF_IF_TYPE_2:
James Smartb71413d2018-02-22 08:18:40 -08009920 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr;
9921 phba->sli4_hba.sli4_eq_release = lpfc_sli4_eq_release;
9922 phba->sli4_hba.sli4_cq_release = lpfc_sli4_cq_release;
James Smart27d6ac02018-02-22 08:18:42 -08009923 break;
9924 case LPFC_SLI_INTF_IF_TYPE_6:
9925 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_if6_eq_clr_intr;
9926 phba->sli4_hba.sli4_eq_release = lpfc_sli4_if6_eq_release;
9927 phba->sli4_hba.sli4_cq_release = lpfc_sli4_if6_cq_release;
9928 break;
9929 default:
9930 break;
James Smartb71413d2018-02-22 08:18:40 -08009931 }
9932
James Smartda0436e2009-05-22 14:51:39 -04009933 return 0;
9934
9935out_iounmap_all:
9936 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9937out_iounmap_ctrl:
9938 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9939out_iounmap_conf:
9940 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9941out:
9942 return error;
9943}
9944
9945/**
9946 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
9947 * @phba: pointer to lpfc hba data structure.
9948 *
9949 * This routine is invoked to unset the PCI device memory space for device
9950 * with SLI-4 interface spec.
9951 **/
9952static void
9953lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
9954{
James Smart2e90f4b2011-12-13 13:22:37 -05009955 uint32_t if_type;
9956 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -04009957
James Smart2e90f4b2011-12-13 13:22:37 -05009958 switch (if_type) {
9959 case LPFC_SLI_INTF_IF_TYPE_0:
9960 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9961 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9962 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9963 break;
9964 case LPFC_SLI_INTF_IF_TYPE_2:
9965 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9966 break;
James Smart27d6ac02018-02-22 08:18:42 -08009967 case LPFC_SLI_INTF_IF_TYPE_6:
9968 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9969 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9970 break;
James Smart2e90f4b2011-12-13 13:22:37 -05009971 case LPFC_SLI_INTF_IF_TYPE_1:
9972 default:
9973 dev_printk(KERN_ERR, &phba->pcidev->dev,
9974 "FATAL - unsupported SLI4 interface type - %d\n",
9975 if_type);
9976 break;
9977 }
James Smartda0436e2009-05-22 14:51:39 -04009978}
9979
9980/**
James Smart3772a992009-05-22 14:50:54 -04009981 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
9982 * @phba: pointer to lpfc hba data structure.
9983 *
9984 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009985 * with SLI-3 interface specs.
James Smart3772a992009-05-22 14:50:54 -04009986 *
9987 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009988 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009989 * other values - error
9990 **/
9991static int
9992lpfc_sli_enable_msix(struct lpfc_hba *phba)
9993{
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009994 int rc;
James Smart3772a992009-05-22 14:50:54 -04009995 LPFC_MBOXQ_t *pmb;
9996
9997 /* Set up MSI-X multi-message vectors */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009998 rc = pci_alloc_irq_vectors(phba->pcidev,
9999 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
10000 if (rc < 0) {
James Smart3772a992009-05-22 14:50:54 -040010001 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10002 "0420 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +020010003 goto vec_fail_out;
James Smart3772a992009-05-22 14:50:54 -040010004 }
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010005
James Smart3772a992009-05-22 14:50:54 -040010006 /*
10007 * Assign MSI-X vectors to interrupt handlers
10008 */
10009
10010 /* vector-0 is associated to slow-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010011 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
James Smarted243d32015-05-21 13:55:25 -040010012 &lpfc_sli_sp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -040010013 LPFC_SP_DRIVER_HANDLER_NAME, phba);
10014 if (rc) {
10015 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10016 "0421 MSI-X slow-path request_irq failed "
10017 "(%d)\n", rc);
10018 goto msi_fail_out;
10019 }
10020
10021 /* vector-1 is associated to fast-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010022 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
James Smarted243d32015-05-21 13:55:25 -040010023 &lpfc_sli_fp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -040010024 LPFC_FP_DRIVER_HANDLER_NAME, phba);
10025
10026 if (rc) {
10027 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10028 "0429 MSI-X fast-path request_irq failed "
10029 "(%d)\n", rc);
10030 goto irq_fail_out;
10031 }
10032
10033 /*
10034 * Configure HBA MSI-X attention conditions to messages
10035 */
10036 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
10037
10038 if (!pmb) {
10039 rc = -ENOMEM;
10040 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10041 "0474 Unable to allocate memory for issuing "
10042 "MBOX_CONFIG_MSI command\n");
10043 goto mem_fail_out;
10044 }
10045 rc = lpfc_config_msi(phba, pmb);
10046 if (rc)
10047 goto mbx_fail_out;
10048 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
10049 if (rc != MBX_SUCCESS) {
10050 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
10051 "0351 Config MSI mailbox command failed, "
10052 "mbxCmd x%x, mbxStatus x%x\n",
10053 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
10054 goto mbx_fail_out;
10055 }
10056
10057 /* Free memory allocated for mailbox command */
10058 mempool_free(pmb, phba->mbox_mem_pool);
10059 return rc;
10060
10061mbx_fail_out:
10062 /* Free memory allocated for mailbox command */
10063 mempool_free(pmb, phba->mbox_mem_pool);
10064
10065mem_fail_out:
10066 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010067 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
James Smart3772a992009-05-22 14:50:54 -040010068
10069irq_fail_out:
10070 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010071 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
James Smart3772a992009-05-22 14:50:54 -040010072
10073msi_fail_out:
10074 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010075 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +020010076
10077vec_fail_out:
James Smart3772a992009-05-22 14:50:54 -040010078 return rc;
10079}
10080
10081/**
James Smart3772a992009-05-22 14:50:54 -040010082 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
10083 * @phba: pointer to lpfc hba data structure.
10084 *
10085 * This routine is invoked to enable the MSI interrupt mode to device with
10086 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
10087 * enable the MSI vector. The device driver is responsible for calling the
10088 * request_irq() to register MSI vector with a interrupt the handler, which
10089 * is done in this function.
10090 *
10091 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010092 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -040010093 * other values - error
10094 */
10095static int
10096lpfc_sli_enable_msi(struct lpfc_hba *phba)
10097{
10098 int rc;
10099
10100 rc = pci_enable_msi(phba->pcidev);
10101 if (!rc)
10102 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10103 "0462 PCI enable MSI mode success.\n");
10104 else {
10105 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10106 "0471 PCI enable MSI mode failed (%d)\n", rc);
10107 return rc;
10108 }
10109
10110 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
James Smarted243d32015-05-21 13:55:25 -040010111 0, LPFC_DRIVER_NAME, phba);
James Smart3772a992009-05-22 14:50:54 -040010112 if (rc) {
10113 pci_disable_msi(phba->pcidev);
10114 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10115 "0478 MSI request_irq failed (%d)\n", rc);
10116 }
10117 return rc;
10118}
10119
10120/**
James Smart3772a992009-05-22 14:50:54 -040010121 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
10122 * @phba: pointer to lpfc hba data structure.
10123 *
10124 * This routine is invoked to enable device interrupt and associate driver's
10125 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
10126 * spec. Depends on the interrupt mode configured to the driver, the driver
10127 * will try to fallback from the configured interrupt mode to an interrupt
10128 * mode which is supported by the platform, kernel, and device in the order
10129 * of:
10130 * MSI-X -> MSI -> IRQ.
10131 *
10132 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010133 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -040010134 * other values - error
10135 **/
10136static uint32_t
10137lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
10138{
10139 uint32_t intr_mode = LPFC_INTR_ERROR;
10140 int retval;
10141
10142 if (cfg_mode == 2) {
10143 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
10144 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
10145 if (!retval) {
10146 /* Now, try to enable MSI-X interrupt mode */
10147 retval = lpfc_sli_enable_msix(phba);
10148 if (!retval) {
10149 /* Indicate initialization to MSI-X mode */
10150 phba->intr_type = MSIX;
10151 intr_mode = 2;
10152 }
10153 }
10154 }
10155
10156 /* Fallback to MSI if MSI-X initialization failed */
10157 if (cfg_mode >= 1 && phba->intr_type == NONE) {
10158 retval = lpfc_sli_enable_msi(phba);
10159 if (!retval) {
10160 /* Indicate initialization to MSI mode */
10161 phba->intr_type = MSI;
10162 intr_mode = 1;
10163 }
10164 }
10165
10166 /* Fallback to INTx if both MSI-X/MSI initalization failed */
10167 if (phba->intr_type == NONE) {
10168 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
10169 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
10170 if (!retval) {
10171 /* Indicate initialization to INTx mode */
10172 phba->intr_type = INTx;
10173 intr_mode = 0;
10174 }
10175 }
10176 return intr_mode;
10177}
10178
10179/**
10180 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
10181 * @phba: pointer to lpfc hba data structure.
10182 *
10183 * This routine is invoked to disable device interrupt and disassociate the
10184 * driver's interrupt handler(s) from interrupt vector(s) to device with
10185 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
10186 * release the interrupt vector(s) for the message signaled interrupt.
10187 **/
10188static void
10189lpfc_sli_disable_intr(struct lpfc_hba *phba)
10190{
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010191 int nr_irqs, i;
10192
James Smart3772a992009-05-22 14:50:54 -040010193 if (phba->intr_type == MSIX)
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010194 nr_irqs = LPFC_MSIX_VECTORS;
10195 else
10196 nr_irqs = 1;
10197
10198 for (i = 0; i < nr_irqs; i++)
10199 free_irq(pci_irq_vector(phba->pcidev, i), phba);
10200 pci_free_irq_vectors(phba->pcidev);
James Smart3772a992009-05-22 14:50:54 -040010201
10202 /* Reset interrupt management states */
10203 phba->intr_type = NONE;
10204 phba->sli.slistat.sli_intr = 0;
James Smart3772a992009-05-22 14:50:54 -040010205}
10206
10207/**
James Smart895427b2017-02-12 13:52:30 -080010208 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
James Smart7bb03bb2013-04-17 20:19:16 -040010209 * @phba: pointer to lpfc hba data structure.
James Smart895427b2017-02-12 13:52:30 -080010210 * @vectors: number of msix vectors allocated.
James Smart7bb03bb2013-04-17 20:19:16 -040010211 *
James Smart895427b2017-02-12 13:52:30 -080010212 * The routine will figure out the CPU affinity assignment for every
10213 * MSI-X vector allocated for the HBA. The hba_eq_hdl will be updated
10214 * with a pointer to the CPU mask that defines ALL the CPUs this vector
10215 * can be associated with. If the vector can be unquely associated with
10216 * a single CPU, that CPU will be recorded in hba_eq_hdl[index].cpu.
10217 * In addition, the CPU to IO channel mapping will be calculated
10218 * and the phba->sli4_hba.cpu_map array will reflect this.
James Smart7bb03bb2013-04-17 20:19:16 -040010219 */
James Smart895427b2017-02-12 13:52:30 -080010220static void
10221lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
James Smart7bb03bb2013-04-17 20:19:16 -040010222{
10223 struct lpfc_vector_map_info *cpup;
James Smart895427b2017-02-12 13:52:30 -080010224 int index = 0;
10225 int vec = 0;
James Smart7bb03bb2013-04-17 20:19:16 -040010226 int cpu;
James Smart7bb03bb2013-04-17 20:19:16 -040010227#ifdef CONFIG_X86
10228 struct cpuinfo_x86 *cpuinfo;
10229#endif
James Smart7bb03bb2013-04-17 20:19:16 -040010230
10231 /* Init cpu_map array */
10232 memset(phba->sli4_hba.cpu_map, 0xff,
10233 (sizeof(struct lpfc_vector_map_info) *
James Smart895427b2017-02-12 13:52:30 -080010234 phba->sli4_hba.num_present_cpu));
James Smart7bb03bb2013-04-17 20:19:16 -040010235
10236 /* Update CPU map with physical id and core id of each CPU */
10237 cpup = phba->sli4_hba.cpu_map;
10238 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
10239#ifdef CONFIG_X86
10240 cpuinfo = &cpu_data(cpu);
10241 cpup->phys_id = cpuinfo->phys_proc_id;
10242 cpup->core_id = cpuinfo->cpu_core_id;
10243#else
10244 /* No distinction between CPUs for other platforms */
10245 cpup->phys_id = 0;
10246 cpup->core_id = 0;
10247#endif
James Smart895427b2017-02-12 13:52:30 -080010248 cpup->channel_id = index; /* For now round robin */
10249 cpup->irq = pci_irq_vector(phba->pcidev, vec);
10250 vec++;
10251 if (vec >= vectors)
10252 vec = 0;
10253 index++;
10254 if (index >= phba->cfg_fcp_io_channel)
10255 index = 0;
James Smart7bb03bb2013-04-17 20:19:16 -040010256 cpup++;
10257 }
James Smart7bb03bb2013-04-17 20:19:16 -040010258}
10259
10260
10261/**
James Smartda0436e2009-05-22 14:51:39 -040010262 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
10263 * @phba: pointer to lpfc hba data structure.
10264 *
10265 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010266 * with SLI-4 interface spec.
James Smartda0436e2009-05-22 14:51:39 -040010267 *
10268 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010269 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040010270 * other values - error
10271 **/
10272static int
10273lpfc_sli4_enable_msix(struct lpfc_hba *phba)
10274{
James Smart75baf692010-06-08 18:31:21 -040010275 int vectors, rc, index;
James Smartb83d0052017-06-01 21:07:05 -070010276 char *name;
James Smartda0436e2009-05-22 14:51:39 -040010277
10278 /* Set up MSI-X multi-message vectors */
James Smart895427b2017-02-12 13:52:30 -080010279 vectors = phba->io_channel_irqs;
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010280 if (phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -050010281 vectors++;
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010282
James Smartf358dd02017-02-12 13:52:34 -080010283 rc = pci_alloc_irq_vectors(phba->pcidev,
10284 (phba->nvmet_support) ? 1 : 2,
10285 vectors, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY);
Alexander Gordeev4f871e12014-09-03 12:56:29 -040010286 if (rc < 0) {
James Smartda0436e2009-05-22 14:51:39 -040010287 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10288 "0484 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +020010289 goto vec_fail_out;
James Smartda0436e2009-05-22 14:51:39 -040010290 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -040010291 vectors = rc;
James Smart75baf692010-06-08 18:31:21 -040010292
James Smart7bb03bb2013-04-17 20:19:16 -040010293 /* Assign MSI-X vectors to interrupt handlers */
James Smart67d12732012-08-03 12:36:13 -040010294 for (index = 0; index < vectors; index++) {
James Smartb83d0052017-06-01 21:07:05 -070010295 name = phba->sli4_hba.hba_eq_hdl[index].handler_name;
10296 memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ);
10297 snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ,
James Smart4305f182012-08-03 12:36:33 -040010298 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -040010299
James Smart895427b2017-02-12 13:52:30 -080010300 phba->sli4_hba.hba_eq_hdl[index].idx = index;
10301 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
10302 atomic_set(&phba->sli4_hba.hba_eq_hdl[index].hba_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -050010303 if (phba->cfg_fof && (index == (vectors - 1)))
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_fof_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 Smart1ba981f2014-02-20 09:56:45 -050010308 else
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010309 rc = request_irq(pci_irq_vector(phba->pcidev, index),
James Smarted243d32015-05-21 13:55:25 -040010310 &lpfc_sli4_hba_intr_handler, 0,
James Smartb83d0052017-06-01 21:07:05 -070010311 name,
James Smart895427b2017-02-12 13:52:30 -080010312 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -040010313 if (rc) {
10314 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10315 "0486 MSI-X fast-path (%d) "
10316 "request_irq failed (%d)\n", index, rc);
10317 goto cfg_fail_out;
10318 }
10319 }
10320
James Smart1ba981f2014-02-20 09:56:45 -050010321 if (phba->cfg_fof)
10322 vectors--;
10323
James Smart895427b2017-02-12 13:52:30 -080010324 if (vectors != phba->io_channel_irqs) {
James Smart82c3e9b2012-09-29 11:29:50 -040010325 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10326 "3238 Reducing IO channels to match number of "
10327 "MSI-X vectors, requested %d got %d\n",
James Smart895427b2017-02-12 13:52:30 -080010328 phba->io_channel_irqs, vectors);
10329 if (phba->cfg_fcp_io_channel > vectors)
10330 phba->cfg_fcp_io_channel = vectors;
10331 if (phba->cfg_nvme_io_channel > vectors)
10332 phba->cfg_nvme_io_channel = vectors;
10333 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
10334 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
10335 else
10336 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
James Smart82c3e9b2012-09-29 11:29:50 -040010337 }
James Smart895427b2017-02-12 13:52:30 -080010338 lpfc_cpu_affinity_check(phba, vectors);
James Smart7bb03bb2013-04-17 20:19:16 -040010339
James Smartda0436e2009-05-22 14:51:39 -040010340 return rc;
10341
10342cfg_fail_out:
10343 /* free the irq already requested */
James Smart895427b2017-02-12 13:52:30 -080010344 for (--index; index >= 0; index--)
10345 free_irq(pci_irq_vector(phba->pcidev, index),
10346 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -040010347
James Smartda0436e2009-05-22 14:51:39 -040010348 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010349 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +020010350
10351vec_fail_out:
James Smartda0436e2009-05-22 14:51:39 -040010352 return rc;
10353}
10354
10355/**
James Smartda0436e2009-05-22 14:51:39 -040010356 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
10357 * @phba: pointer to lpfc hba data structure.
10358 *
10359 * This routine is invoked to enable the MSI interrupt mode to device with
10360 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
10361 * to enable the MSI vector. The device driver is responsible for calling
10362 * the request_irq() to register MSI vector with a interrupt the handler,
10363 * which is done in this function.
10364 *
10365 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010366 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040010367 * other values - error
10368 **/
10369static int
10370lpfc_sli4_enable_msi(struct lpfc_hba *phba)
10371{
10372 int rc, index;
10373
10374 rc = pci_enable_msi(phba->pcidev);
10375 if (!rc)
10376 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10377 "0487 PCI enable MSI mode success.\n");
10378 else {
10379 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10380 "0488 PCI enable MSI mode failed (%d)\n", rc);
10381 return rc;
10382 }
10383
10384 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
James Smarted243d32015-05-21 13:55:25 -040010385 0, LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -040010386 if (rc) {
10387 pci_disable_msi(phba->pcidev);
10388 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10389 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -040010390 return rc;
James Smartda0436e2009-05-22 14:51:39 -040010391 }
10392
James Smart895427b2017-02-12 13:52:30 -080010393 for (index = 0; index < phba->io_channel_irqs; index++) {
10394 phba->sli4_hba.hba_eq_hdl[index].idx = index;
10395 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smartda0436e2009-05-22 14:51:39 -040010396 }
10397
James Smart1ba981f2014-02-20 09:56:45 -050010398 if (phba->cfg_fof) {
James Smart895427b2017-02-12 13:52:30 -080010399 phba->sli4_hba.hba_eq_hdl[index].idx = index;
10400 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smart1ba981f2014-02-20 09:56:45 -050010401 }
James Smart75baf692010-06-08 18:31:21 -040010402 return 0;
James Smartda0436e2009-05-22 14:51:39 -040010403}
10404
10405/**
James Smartda0436e2009-05-22 14:51:39 -040010406 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
10407 * @phba: pointer to lpfc hba data structure.
10408 *
10409 * This routine is invoked to enable device interrupt and associate driver's
10410 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
10411 * interface spec. Depends on the interrupt mode configured to the driver,
10412 * the driver will try to fallback from the configured interrupt mode to an
10413 * interrupt mode which is supported by the platform, kernel, and device in
10414 * the order of:
10415 * MSI-X -> MSI -> IRQ.
10416 *
10417 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010418 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040010419 * other values - error
10420 **/
10421static uint32_t
10422lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
10423{
10424 uint32_t intr_mode = LPFC_INTR_ERROR;
James Smart895427b2017-02-12 13:52:30 -080010425 int retval, idx;
James Smartda0436e2009-05-22 14:51:39 -040010426
10427 if (cfg_mode == 2) {
10428 /* Preparation before conf_msi mbox cmd */
10429 retval = 0;
10430 if (!retval) {
10431 /* Now, try to enable MSI-X interrupt mode */
10432 retval = lpfc_sli4_enable_msix(phba);
10433 if (!retval) {
10434 /* Indicate initialization to MSI-X mode */
10435 phba->intr_type = MSIX;
10436 intr_mode = 2;
10437 }
10438 }
10439 }
10440
10441 /* Fallback to MSI if MSI-X initialization failed */
10442 if (cfg_mode >= 1 && phba->intr_type == NONE) {
10443 retval = lpfc_sli4_enable_msi(phba);
10444 if (!retval) {
10445 /* Indicate initialization to MSI mode */
10446 phba->intr_type = MSI;
10447 intr_mode = 1;
10448 }
10449 }
10450
10451 /* Fallback to INTx if both MSI-X/MSI initalization failed */
10452 if (phba->intr_type == NONE) {
10453 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
10454 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
10455 if (!retval) {
James Smart895427b2017-02-12 13:52:30 -080010456 struct lpfc_hba_eq_hdl *eqhdl;
10457
James Smartda0436e2009-05-22 14:51:39 -040010458 /* Indicate initialization to INTx mode */
10459 phba->intr_type = INTx;
10460 intr_mode = 0;
James Smart895427b2017-02-12 13:52:30 -080010461
10462 for (idx = 0; idx < phba->io_channel_irqs; idx++) {
10463 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
10464 eqhdl->idx = idx;
10465 eqhdl->phba = phba;
10466 atomic_set(&eqhdl->hba_eq_in_use, 1);
James Smartda0436e2009-05-22 14:51:39 -040010467 }
James Smart1ba981f2014-02-20 09:56:45 -050010468 if (phba->cfg_fof) {
James Smart895427b2017-02-12 13:52:30 -080010469 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
10470 eqhdl->idx = idx;
10471 eqhdl->phba = phba;
10472 atomic_set(&eqhdl->hba_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -050010473 }
James Smartda0436e2009-05-22 14:51:39 -040010474 }
10475 }
10476 return intr_mode;
10477}
10478
10479/**
10480 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
10481 * @phba: pointer to lpfc hba data structure.
10482 *
10483 * This routine is invoked to disable device interrupt and disassociate
10484 * the driver's interrupt handler(s) from interrupt vector(s) to device
10485 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
10486 * will release the interrupt vector(s) for the message signaled interrupt.
10487 **/
10488static void
10489lpfc_sli4_disable_intr(struct lpfc_hba *phba)
10490{
10491 /* Disable the currently initialized interrupt mode */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010492 if (phba->intr_type == MSIX) {
10493 int index;
10494
10495 /* Free up MSI-X multi-message vectors */
James Smart895427b2017-02-12 13:52:30 -080010496 for (index = 0; index < phba->io_channel_irqs; index++)
10497 free_irq(pci_irq_vector(phba->pcidev, index),
10498 &phba->sli4_hba.hba_eq_hdl[index]);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010499
10500 if (phba->cfg_fof)
James Smart895427b2017-02-12 13:52:30 -080010501 free_irq(pci_irq_vector(phba->pcidev, index),
10502 &phba->sli4_hba.hba_eq_hdl[index]);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010503 } else {
James Smartda0436e2009-05-22 14:51:39 -040010504 free_irq(phba->pcidev->irq, phba);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010505 }
10506
10507 pci_free_irq_vectors(phba->pcidev);
James Smartda0436e2009-05-22 14:51:39 -040010508
10509 /* Reset interrupt management states */
10510 phba->intr_type = NONE;
10511 phba->sli.slistat.sli_intr = 0;
James Smartda0436e2009-05-22 14:51:39 -040010512}
10513
10514/**
James Smart3772a992009-05-22 14:50:54 -040010515 * lpfc_unset_hba - Unset SLI3 hba device initialization
10516 * @phba: pointer to lpfc hba data structure.
10517 *
10518 * This routine is invoked to unset the HBA device initialization steps to
10519 * a device with SLI-3 interface spec.
10520 **/
10521static void
10522lpfc_unset_hba(struct lpfc_hba *phba)
10523{
10524 struct lpfc_vport *vport = phba->pport;
10525 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
10526
10527 spin_lock_irq(shost->host_lock);
10528 vport->load_flag |= FC_UNLOADING;
10529 spin_unlock_irq(shost->host_lock);
10530
James Smart72859902012-01-18 16:25:38 -050010531 kfree(phba->vpi_bmask);
10532 kfree(phba->vpi_ids);
10533
James Smart3772a992009-05-22 14:50:54 -040010534 lpfc_stop_hba_timers(phba);
10535
10536 phba->pport->work_port_events = 0;
10537
10538 lpfc_sli_hba_down(phba);
10539
10540 lpfc_sli_brdrestart(phba);
10541
10542 lpfc_sli_disable_intr(phba);
10543
10544 return;
10545}
10546
10547/**
James Smart5af5eee2010-10-22 11:06:38 -040010548 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
10549 * @phba: Pointer to HBA context object.
10550 *
10551 * This function is called in the SLI4 code path to wait for completion
10552 * of device's XRIs exchange busy. It will check the XRI exchange busy
10553 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
10554 * that, it will check the XRI exchange busy on outstanding FCP and ELS
10555 * I/Os every 30 seconds, log error message, and wait forever. Only when
10556 * all XRI exchange busy complete, the driver unload shall proceed with
10557 * invoking the function reset ioctl mailbox command to the CNA and the
10558 * the rest of the driver unload resource release.
10559 **/
10560static void
10561lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
10562{
10563 int wait_time = 0;
James Smart895427b2017-02-12 13:52:30 -080010564 int nvme_xri_cmpl = 1;
James Smart86c67372017-04-21 16:05:04 -070010565 int nvmet_xri_cmpl = 1;
James Smart895427b2017-02-12 13:52:30 -080010566 int fcp_xri_cmpl = 1;
James Smart5af5eee2010-10-22 11:06:38 -040010567 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
10568
James Smartc3725bd2017-11-20 16:00:42 -080010569 /* Driver just aborted IOs during the hba_unset process. Pause
10570 * here to give the HBA time to complete the IO and get entries
10571 * into the abts lists.
10572 */
10573 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5);
10574
10575 /* Wait for NVME pending IO to flush back to transport. */
10576 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
10577 lpfc_nvme_wait_for_io_drain(phba);
10578
James Smart895427b2017-02-12 13:52:30 -080010579 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
10580 fcp_xri_cmpl =
10581 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
James Smart86c67372017-04-21 16:05:04 -070010582 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -080010583 nvme_xri_cmpl =
10584 list_empty(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
James Smart86c67372017-04-21 16:05:04 -070010585 nvmet_xri_cmpl =
10586 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
10587 }
James Smart895427b2017-02-12 13:52:30 -080010588
James Smartf358dd02017-02-12 13:52:34 -080010589 while (!fcp_xri_cmpl || !els_xri_cmpl || !nvme_xri_cmpl ||
10590 !nvmet_xri_cmpl) {
James Smart5af5eee2010-10-22 11:06:38 -040010591 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
James Smart68c9b552018-06-26 08:24:25 -070010592 if (!nvmet_xri_cmpl)
10593 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10594 "6424 NVMET XRI exchange busy "
10595 "wait time: %d seconds.\n",
10596 wait_time/1000);
James Smart895427b2017-02-12 13:52:30 -080010597 if (!nvme_xri_cmpl)
10598 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10599 "6100 NVME XRI exchange busy "
10600 "wait time: %d seconds.\n",
10601 wait_time/1000);
James Smart5af5eee2010-10-22 11:06:38 -040010602 if (!fcp_xri_cmpl)
10603 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10604 "2877 FCP XRI exchange busy "
10605 "wait time: %d seconds.\n",
10606 wait_time/1000);
10607 if (!els_xri_cmpl)
10608 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10609 "2878 ELS XRI exchange busy "
10610 "wait time: %d seconds.\n",
10611 wait_time/1000);
10612 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
10613 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
10614 } else {
10615 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
10616 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
10617 }
James Smart86c67372017-04-21 16:05:04 -070010618 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -080010619 nvme_xri_cmpl = list_empty(
10620 &phba->sli4_hba.lpfc_abts_nvme_buf_list);
James Smart86c67372017-04-21 16:05:04 -070010621 nvmet_xri_cmpl = list_empty(
10622 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
10623 }
James Smart895427b2017-02-12 13:52:30 -080010624
10625 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
10626 fcp_xri_cmpl = list_empty(
10627 &phba->sli4_hba.lpfc_abts_scsi_buf_list);
10628
James Smart5af5eee2010-10-22 11:06:38 -040010629 els_xri_cmpl =
10630 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -080010631
James Smart5af5eee2010-10-22 11:06:38 -040010632 }
10633}
10634
10635/**
James Smartda0436e2009-05-22 14:51:39 -040010636 * lpfc_sli4_hba_unset - Unset the fcoe hba
10637 * @phba: Pointer to HBA context object.
10638 *
10639 * This function is called in the SLI4 code path to reset the HBA's FCoE
10640 * function. The caller is not required to hold any lock. This routine
10641 * issues PCI function reset mailbox command to reset the FCoE function.
10642 * At the end of the function, it calls lpfc_hba_down_post function to
10643 * free any pending commands.
10644 **/
10645static void
10646lpfc_sli4_hba_unset(struct lpfc_hba *phba)
10647{
10648 int wait_cnt = 0;
10649 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -040010650 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -040010651
10652 lpfc_stop_hba_timers(phba);
10653 phba->sli4_hba.intr_enable = 0;
10654
10655 /*
10656 * Gracefully wait out the potential current outstanding asynchronous
10657 * mailbox command.
10658 */
10659
10660 /* First, block any pending async mailbox command from posted */
10661 spin_lock_irq(&phba->hbalock);
10662 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
10663 spin_unlock_irq(&phba->hbalock);
10664 /* Now, trying to wait it out if we can */
10665 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
10666 msleep(10);
10667 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
10668 break;
10669 }
10670 /* Forcefully release the outstanding mailbox command if timed out */
10671 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
10672 spin_lock_irq(&phba->hbalock);
10673 mboxq = phba->sli.mbox_active;
10674 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
10675 __lpfc_mbox_cmpl_put(phba, mboxq);
10676 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
10677 phba->sli.mbox_active = NULL;
10678 spin_unlock_irq(&phba->hbalock);
10679 }
10680
James Smart5af5eee2010-10-22 11:06:38 -040010681 /* Abort all iocbs associated with the hba */
10682 lpfc_sli_hba_iocb_abort(phba);
10683
10684 /* Wait for completion of device XRI exchange busy */
10685 lpfc_sli4_xri_exchange_busy_wait(phba);
10686
James Smartda0436e2009-05-22 14:51:39 -040010687 /* Disable PCI subsystem interrupt */
10688 lpfc_sli4_disable_intr(phba);
10689
James Smart912e3ac2011-05-24 11:42:11 -040010690 /* Disable SR-IOV if enabled */
10691 if (phba->cfg_sriov_nr_virtfn)
10692 pci_disable_sriov(pdev);
10693
James Smartda0436e2009-05-22 14:51:39 -040010694 /* Stop kthread signal shall trigger work_done one more time */
10695 kthread_stop(phba->worker_thread);
10696
James Smartd2cc9bc2018-09-10 10:30:50 -070010697 /* Disable FW logging to host memory */
James Smart1165a5c2018-11-29 16:09:39 -080010698 lpfc_ras_stop_fwlog(phba);
James Smartd2cc9bc2018-09-10 10:30:50 -070010699
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 Smart1165a5c2018-11-29 16:09:39 -080010709 /* Free RAS DMA memory */
10710 if (phba->ras_fwlog.ras_enabled)
10711 lpfc_sli4_ras_dma_free(phba);
10712
James Smartda0436e2009-05-22 14:51:39 -040010713 /* Stop the SLI4 device port */
10714 phba->pport->work_port_events = 0;
10715}
10716
James Smart28baac72010-02-12 14:42:03 -050010717 /**
10718 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
10719 * @phba: Pointer to HBA context object.
10720 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10721 *
10722 * This function is called in the SLI4 code path to read the port's
10723 * sli4 capabilities.
10724 *
10725 * This function may be be called from any context that can block-wait
10726 * for the completion. The expectation is that this routine is called
10727 * typically from probe_one or from the online routine.
10728 **/
10729int
10730lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10731{
10732 int rc;
10733 struct lpfc_mqe *mqe;
10734 struct lpfc_pc_sli4_params *sli4_params;
10735 uint32_t mbox_tmo;
10736
10737 rc = 0;
10738 mqe = &mboxq->u.mqe;
10739
10740 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -050010741 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -050010742 if (!phba->sli4_hba.intr_enable)
10743 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10744 else {
James Smarta183a152011-10-10 21:32:43 -040010745 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -050010746 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10747 }
10748
10749 if (unlikely(rc))
10750 return 1;
10751
10752 sli4_params = &phba->sli4_hba.pc_sli4_params;
10753 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
10754 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
10755 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
10756 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
10757 &mqe->un.sli4_params);
10758 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
10759 &mqe->un.sli4_params);
10760 sli4_params->proto_types = mqe->un.sli4_params.word3;
10761 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
10762 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
10763 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
10764 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
10765 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
10766 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
10767 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
10768 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
10769 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
10770 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
10771 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
10772 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
10773 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
10774 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
10775 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
10776 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
10777 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
10778 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
10779 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
10780 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -040010781
10782 /* Make sure that sge_supp_len can be handled by the driver */
10783 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10784 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10785
James Smart28baac72010-02-12 14:42:03 -050010786 return rc;
10787}
10788
James Smartda0436e2009-05-22 14:51:39 -040010789/**
James Smartfedd3b72011-02-16 12:39:24 -050010790 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
10791 * @phba: Pointer to HBA context object.
10792 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10793 *
10794 * This function is called in the SLI4 code path to read the port's
10795 * sli4 capabilities.
10796 *
10797 * This function may be be called from any context that can block-wait
10798 * for the completion. The expectation is that this routine is called
10799 * typically from probe_one or from the online routine.
10800 **/
10801int
10802lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10803{
10804 int rc;
10805 struct lpfc_mqe *mqe = &mboxq->u.mqe;
10806 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -040010807 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -050010808 int length;
James Smartbf316c72018-04-09 14:24:28 -070010809 bool exp_wqcq_pages = true;
James Smartfedd3b72011-02-16 12:39:24 -050010810 struct lpfc_sli4_parameters *mbx_sli4_parameters;
10811
James Smart6d368e52011-05-24 11:44:12 -040010812 /*
10813 * By default, the driver assumes the SLI4 port requires RPI
10814 * header postings. The SLI4_PARAM response will correct this
10815 * assumption.
10816 */
10817 phba->sli4_hba.rpi_hdrs_in_use = 1;
10818
James Smartfedd3b72011-02-16 12:39:24 -050010819 /* Read the port's SLI4 Config Parameters */
10820 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
10821 sizeof(struct lpfc_sli4_cfg_mhdr));
10822 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
10823 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
10824 length, LPFC_SLI4_MBX_EMBED);
10825 if (!phba->sli4_hba.intr_enable)
10826 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -040010827 else {
10828 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
10829 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10830 }
James Smartfedd3b72011-02-16 12:39:24 -050010831 if (unlikely(rc))
10832 return rc;
10833 sli4_params = &phba->sli4_hba.pc_sli4_params;
10834 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
10835 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
10836 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
10837 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
10838 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
10839 mbx_sli4_parameters);
10840 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
10841 mbx_sli4_parameters);
10842 if (bf_get(cfg_phwq, mbx_sli4_parameters))
10843 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
10844 else
10845 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
10846 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
10847 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
James Smart1ba981f2014-02-20 09:56:45 -050010848 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010849 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
10850 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
10851 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
10852 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
James Smart7365f6f2018-02-22 08:18:46 -080010853 sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters);
10854 sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters);
James Smart0c651872013-07-15 18:33:23 -040010855 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
James Smart66e9e6b2018-06-26 08:24:27 -070010856 sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010857 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
10858 mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080010859 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010860 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
10861 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -040010862 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
10863 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080010864 phba->nvme_support = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
10865 bf_get(cfg_xib, mbx_sli4_parameters));
10866
10867 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) ||
10868 !phba->nvme_support) {
10869 phba->nvme_support = 0;
10870 phba->nvmet_support = 0;
James Smartbcb24f62017-11-20 16:00:36 -080010871 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_OFF;
James Smart895427b2017-02-12 13:52:30 -080010872 phba->cfg_nvme_io_channel = 0;
10873 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
10874 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
10875 "6101 Disabling NVME support: "
10876 "Not supported by firmware: %d %d\n",
10877 bf_get(cfg_nvme, mbx_sli4_parameters),
10878 bf_get(cfg_xib, mbx_sli4_parameters));
10879
10880 /* If firmware doesn't support NVME, just use SCSI support */
10881 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
10882 return -ENODEV;
10883 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
10884 }
James Smart05580562011-05-24 11:40:48 -040010885
James Smart414abe02018-06-26 08:24:26 -070010886 /* Only embed PBDE for if_type 6, PBDE support requires xib be set */
10887 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
10888 LPFC_SLI_INTF_IF_TYPE_6) || (!bf_get(cfg_xib, mbx_sli4_parameters)))
10889 phba->cfg_enable_pbde = 0;
James Smart0bc2b7c2018-02-22 08:18:48 -080010890
James Smart20aefac2018-01-30 15:58:58 -080010891 /*
10892 * To support Suppress Response feature we must satisfy 3 conditions.
10893 * lpfc_suppress_rsp module parameter must be set (default).
10894 * In SLI4-Parameters Descriptor:
10895 * Extended Inline Buffers (XIB) must be supported.
10896 * Suppress Response IU Not Supported (SRIUNS) must NOT be supported
10897 * (double negative).
10898 */
10899 if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) &&
10900 !(bf_get(cfg_nosr, mbx_sli4_parameters)))
James Smartf358dd02017-02-12 13:52:34 -080010901 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
James Smart20aefac2018-01-30 15:58:58 -080010902 else
10903 phba->cfg_suppress_rsp = 0;
James Smartf358dd02017-02-12 13:52:34 -080010904
James Smart0cf07f842017-06-01 21:07:10 -070010905 if (bf_get(cfg_eqdr, mbx_sli4_parameters))
10906 phba->sli.sli_flag |= LPFC_SLI_USE_EQDR;
10907
James Smart05580562011-05-24 11:40:48 -040010908 /* Make sure that sge_supp_len can be handled by the driver */
10909 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10910 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10911
James Smartb5c53952016-03-31 14:12:30 -070010912 /*
James Smartc176ffa2018-01-30 15:58:46 -080010913 * Check whether the adapter supports an embedded copy of the
10914 * FCP CMD IU within the WQE for FCP_Ixxx commands. In order
10915 * to use this option, 128-byte WQEs must be used.
James Smartb5c53952016-03-31 14:12:30 -070010916 */
10917 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
10918 phba->fcp_embed_io = 1;
10919 else
10920 phba->fcp_embed_io = 0;
James Smart7bdedb32016-07-06 12:36:00 -070010921
James Smart0bc2b7c2018-02-22 08:18:48 -080010922 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME,
James Smart414abe02018-06-26 08:24:26 -070010923 "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n",
James Smart0bc2b7c2018-02-22 08:18:48 -080010924 bf_get(cfg_xib, mbx_sli4_parameters),
James Smart414abe02018-06-26 08:24:26 -070010925 phba->cfg_enable_pbde,
10926 phba->fcp_embed_io, phba->nvme_support,
James Smart4e565cf2018-02-22 08:18:50 -080010927 phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp);
James Smart0bc2b7c2018-02-22 08:18:48 -080010928
James Smartbf316c72018-04-09 14:24:28 -070010929 if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
10930 LPFC_SLI_INTF_IF_TYPE_2) &&
10931 (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) ==
James Smartc2217682018-05-24 21:09:00 -070010932 LPFC_SLI_INTF_FAMILY_LNCR_A0))
James Smartbf316c72018-04-09 14:24:28 -070010933 exp_wqcq_pages = false;
10934
James Smartc176ffa2018-01-30 15:58:46 -080010935 if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) &&
10936 (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) &&
James Smartbf316c72018-04-09 14:24:28 -070010937 exp_wqcq_pages &&
James Smartc176ffa2018-01-30 15:58:46 -080010938 (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT))
10939 phba->enab_exp_wqcq_pages = 1;
10940 else
10941 phba->enab_exp_wqcq_pages = 0;
James Smart7bdedb32016-07-06 12:36:00 -070010942 /*
10943 * Check if the SLI port supports MDS Diagnostics
10944 */
10945 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
10946 phba->mds_diags_support = 1;
10947 else
10948 phba->mds_diags_support = 0;
James Smartd2cc9bc2018-09-10 10:30:50 -070010949
James Smartfedd3b72011-02-16 12:39:24 -050010950 return 0;
10951}
10952
10953/**
James Smart3772a992009-05-22 14:50:54 -040010954 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
10955 * @pdev: pointer to PCI device
10956 * @pid: pointer to PCI device identifier
10957 *
10958 * This routine is to be called to attach a device with SLI-3 interface spec
10959 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10960 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10961 * information of the device and driver to see if the driver state that it can
10962 * support this kind of device. If the match is successful, the driver core
10963 * invokes this routine. If this routine determines it can claim the HBA, it
10964 * does all the initialization that it needs to do to handle the HBA properly.
10965 *
10966 * Return code
10967 * 0 - driver can claim the device
10968 * negative value - driver can not claim the device
10969 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010970static int
James Smart3772a992009-05-22 14:50:54 -040010971lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
10972{
10973 struct lpfc_hba *phba;
10974 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040010975 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -040010976 int error;
10977 uint32_t cfg_mode, intr_mode;
10978
10979 /* Allocate memory for HBA structure */
10980 phba = lpfc_hba_alloc(pdev);
10981 if (!phba)
10982 return -ENOMEM;
10983
10984 /* Perform generic PCI device enabling operation */
10985 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040010986 if (error)
James Smart3772a992009-05-22 14:50:54 -040010987 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -040010988
10989 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
10990 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
10991 if (error)
10992 goto out_disable_pci_dev;
10993
10994 /* Set up SLI-3 specific device PCI memory space */
10995 error = lpfc_sli_pci_mem_setup(phba);
10996 if (error) {
10997 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10998 "1402 Failed to set up pci memory space.\n");
10999 goto out_disable_pci_dev;
11000 }
11001
James Smart3772a992009-05-22 14:50:54 -040011002 /* Set up SLI-3 specific device driver resources */
11003 error = lpfc_sli_driver_resource_setup(phba);
11004 if (error) {
11005 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11006 "1404 Failed to set up driver resource.\n");
11007 goto out_unset_pci_mem_s3;
11008 }
11009
11010 /* Initialize and populate the iocb list per host */
James Smartd1f525a2017-04-21 16:04:55 -070011011
James Smart3772a992009-05-22 14:50:54 -040011012 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
11013 if (error) {
11014 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11015 "1405 Failed to initialize iocb list.\n");
11016 goto out_unset_driver_resource_s3;
11017 }
11018
11019 /* Set up common device driver resources */
11020 error = lpfc_setup_driver_resource_phase2(phba);
11021 if (error) {
11022 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11023 "1406 Failed to set up driver resource.\n");
11024 goto out_free_iocb_list;
11025 }
11026
James Smart079b5c92011-08-21 21:48:49 -040011027 /* Get the default values for Model Name and Description */
11028 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
11029
James Smart3772a992009-05-22 14:50:54 -040011030 /* Create SCSI host to the physical port */
11031 error = lpfc_create_shost(phba);
11032 if (error) {
11033 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11034 "1407 Failed to create scsi host.\n");
11035 goto out_unset_driver_resource;
11036 }
11037
11038 /* Configure sysfs attributes */
11039 vport = phba->pport;
11040 error = lpfc_alloc_sysfs_attr(vport);
11041 if (error) {
11042 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11043 "1476 Failed to allocate sysfs attr\n");
11044 goto out_destroy_shost;
11045 }
11046
James Smart6669f9b2009-10-02 15:16:45 -040011047 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -040011048 /* Now, trying to enable interrupt and bring up the device */
11049 cfg_mode = phba->cfg_use_msi;
11050 while (true) {
11051 /* Put device to a known state before enabling interrupt */
11052 lpfc_stop_port(phba);
11053 /* Configure and enable interrupt */
11054 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
11055 if (intr_mode == LPFC_INTR_ERROR) {
11056 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11057 "0431 Failed to enable interrupt.\n");
11058 error = -ENODEV;
11059 goto out_free_sysfs_attr;
11060 }
11061 /* SLI-3 HBA setup */
11062 if (lpfc_sli_hba_setup(phba)) {
11063 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11064 "1477 Failed to set up hba\n");
11065 error = -ENODEV;
11066 goto out_remove_device;
11067 }
11068
11069 /* Wait 50ms for the interrupts of previous mailbox commands */
11070 msleep(50);
11071 /* Check active interrupts on message signaled interrupts */
11072 if (intr_mode == 0 ||
11073 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
11074 /* Log the current active interrupt mode */
11075 phba->intr_mode = intr_mode;
11076 lpfc_log_intr_mode(phba, intr_mode);
11077 break;
11078 } else {
11079 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11080 "0447 Configure interrupt mode (%d) "
11081 "failed active interrupt test.\n",
11082 intr_mode);
11083 /* Disable the current interrupt mode */
11084 lpfc_sli_disable_intr(phba);
11085 /* Try next level of interrupt mode */
11086 cfg_mode = --intr_mode;
11087 }
11088 }
11089
11090 /* Perform post initialization setup */
11091 lpfc_post_init_setup(phba);
11092
11093 /* Check if there are static vports to be created. */
11094 lpfc_create_static_vport(phba);
11095
11096 return 0;
11097
11098out_remove_device:
11099 lpfc_unset_hba(phba);
11100out_free_sysfs_attr:
11101 lpfc_free_sysfs_attr(vport);
11102out_destroy_shost:
11103 lpfc_destroy_shost(phba);
11104out_unset_driver_resource:
11105 lpfc_unset_driver_resource_phase2(phba);
11106out_free_iocb_list:
11107 lpfc_free_iocb_list(phba);
11108out_unset_driver_resource_s3:
11109 lpfc_sli_driver_resource_unset(phba);
11110out_unset_pci_mem_s3:
11111 lpfc_sli_pci_mem_unset(phba);
11112out_disable_pci_dev:
11113 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040011114 if (shost)
11115 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -040011116out_free_phba:
11117 lpfc_hba_free(phba);
11118 return error;
11119}
11120
11121/**
11122 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -040011123 * @pdev: pointer to PCI device
11124 *
James Smart3772a992009-05-22 14:50:54 -040011125 * This routine is to be called to disattach a device with SLI-3 interface
11126 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
11127 * removed from PCI bus, it performs all the necessary cleanup for the HBA
11128 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -040011129 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011130static void
James Smart3772a992009-05-22 14:50:54 -040011131lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -050011132{
James Smart2e0fef82007-06-17 19:56:36 -050011133 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11134 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -050011135 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -050011136 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -050011137 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -050011138
James Smart549e55c2007-08-02 11:09:51 -040011139 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -040011140 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -040011141 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -050011142
James Smart858c9f62007-06-17 19:56:39 -050011143 lpfc_free_sysfs_attr(vport);
11144
James Smarteada2722008-12-04 22:39:13 -050011145 /* Release all the vports against this physical port */
11146 vports = lpfc_create_vport_work_array(phba);
11147 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040011148 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
11149 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
11150 continue;
James Smarteada2722008-12-04 22:39:13 -050011151 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040011152 }
James Smarteada2722008-12-04 22:39:13 -050011153 lpfc_destroy_vport_work_array(phba, vports);
11154
11155 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -050011156 fc_remove_host(shost);
11157 scsi_remove_host(shost);
James Smartd613b6a2017-02-12 13:52:37 -080011158
James Smart87af33f2007-10-27 13:37:43 -040011159 lpfc_cleanup(vport);
11160
James Smart2e0fef82007-06-17 19:56:36 -050011161 /*
11162 * Bring down the SLI Layer. This step disable all interrupts,
11163 * clears the rings, discards all mailbox commands, and resets
11164 * the HBA.
11165 */
James Smarta257bf92009-04-06 18:48:10 -040011166
Justin P. Mattock48e34d02010-12-30 15:07:58 -080011167 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -050011168 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -040011169 /* Stop kthread signal shall trigger work_done one more time */
11170 kthread_stop(phba->worker_thread);
11171 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -050011172 lpfc_sli_brdrestart(phba);
11173
James Smart72859902012-01-18 16:25:38 -050011174 kfree(phba->vpi_bmask);
11175 kfree(phba->vpi_ids);
11176
James Smart3772a992009-05-22 14:50:54 -040011177 lpfc_stop_hba_timers(phba);
James Smart523128e2018-09-10 10:30:46 -070011178 spin_lock_irq(&phba->port_list_lock);
James Smart858c9f62007-06-17 19:56:39 -050011179 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -070011180 spin_unlock_irq(&phba->port_list_lock);
James Smart858c9f62007-06-17 19:56:39 -050011181
James Smart858c9f62007-06-17 19:56:39 -050011182 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -050011183
James Smart912e3ac2011-05-24 11:42:11 -040011184 /* Disable SR-IOV if enabled */
11185 if (phba->cfg_sriov_nr_virtfn)
11186 pci_disable_sriov(pdev);
11187
James Smart5b75da22008-12-04 22:39:35 -050011188 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -040011189 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -050011190
James Smart858c9f62007-06-17 19:56:39 -050011191 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -050011192
11193 /*
11194 * Call scsi_free before mem_free since scsi bufs are released to their
11195 * corresponding pools here.
11196 */
11197 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -040011198 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -050011199
James Smart34b02dc2008-08-24 21:49:55 -040011200 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
11201 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -050011202
James Smart2e0fef82007-06-17 19:56:36 -050011203 /* Free resources associated with SLI2 interface */
11204 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -040011205 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -050011206
11207 /* unmap adapter SLIM and Control Registers */
11208 iounmap(phba->ctrl_regs_memmap_p);
11209 iounmap(phba->slim_memmap_p);
11210
James Smart3772a992009-05-22 14:50:54 -040011211 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -050011212
Johannes Thumshirne0c04832016-06-07 09:44:03 +020011213 pci_release_mem_regions(pdev);
James Smart2e0fef82007-06-17 19:56:36 -050011214 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -050011215}
11216
Linas Vepstas8d63f372007-02-14 14:28:36 -060011217/**
James Smart3772a992009-05-22 14:50:54 -040011218 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050011219 * @pdev: pointer to PCI device
11220 * @msg: power management message
11221 *
James Smart3772a992009-05-22 14:50:54 -040011222 * This routine is to be called from the kernel's PCI subsystem to support
11223 * system Power Management (PM) to device with SLI-3 interface spec. When
11224 * PM invokes this method, it quiesces the device by stopping the driver's
11225 * worker thread for the device, turning off device's interrupt and DMA,
11226 * and bring the device offline. Note that as the driver implements the
11227 * minimum PM requirements to a power-aware driver's PM support for the
11228 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
11229 * to the suspend() method call will be treated as SUSPEND and the driver will
11230 * fully reinitialize its device during resume() method call, the driver will
11231 * set device to PCI_D3hot state in PCI config space instead of setting it
11232 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -050011233 *
11234 * Return code
James Smart3772a992009-05-22 14:50:54 -040011235 * 0 - driver suspended the device
11236 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050011237 **/
11238static int
James Smart3772a992009-05-22 14:50:54 -040011239lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -050011240{
11241 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11242 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11243
11244 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11245 "0473 PCI device Power Management suspend.\n");
11246
11247 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040011248 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -050011249 lpfc_offline(phba);
11250 kthread_stop(phba->worker_thread);
11251
11252 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -040011253 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -050011254
11255 /* Save device state to PCI config space */
11256 pci_save_state(pdev);
11257 pci_set_power_state(pdev, PCI_D3hot);
11258
11259 return 0;
11260}
11261
11262/**
James Smart3772a992009-05-22 14:50:54 -040011263 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050011264 * @pdev: pointer to PCI device
11265 *
James Smart3772a992009-05-22 14:50:54 -040011266 * This routine is to be called from the kernel's PCI subsystem to support
11267 * system Power Management (PM) to device with SLI-3 interface spec. When PM
11268 * invokes this method, it restores the device's PCI config space state and
11269 * fully reinitializes the device and brings it online. Note that as the
11270 * driver implements the minimum PM requirements to a power-aware driver's
11271 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
11272 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
11273 * driver will fully reinitialize its device during resume() method call,
11274 * the device will be set to PCI_D0 directly in PCI config space before
11275 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -050011276 *
11277 * Return code
James Smart3772a992009-05-22 14:50:54 -040011278 * 0 - driver suspended the device
11279 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050011280 **/
11281static int
James Smart3772a992009-05-22 14:50:54 -040011282lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -050011283{
11284 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11285 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -050011286 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050011287 int error;
11288
11289 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11290 "0452 PCI device Power Management resume.\n");
11291
11292 /* Restore device state from PCI config space */
11293 pci_set_power_state(pdev, PCI_D0);
11294 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -040011295
James Smart1dfb5a42010-02-12 14:40:50 -050011296 /*
11297 * As the new kernel behavior of pci_restore_state() API call clears
11298 * device saved_state flag, need to save the restored state again.
11299 */
11300 pci_save_state(pdev);
11301
James Smart3a55b532008-12-04 22:38:54 -050011302 if (pdev->is_busmaster)
11303 pci_set_master(pdev);
11304
11305 /* Startup the kernel thread for this host adapter. */
11306 phba->worker_thread = kthread_run(lpfc_do_work, phba,
11307 "lpfc_worker_%d", phba->brd_no);
11308 if (IS_ERR(phba->worker_thread)) {
11309 error = PTR_ERR(phba->worker_thread);
11310 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11311 "0434 PM resume failed to start worker "
11312 "thread: error=x%x.\n", error);
11313 return error;
11314 }
11315
James Smart5b75da22008-12-04 22:39:35 -050011316 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040011317 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050011318 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -050011319 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -050011320 "0430 PM resume Failed to enable interrupt\n");
11321 return -EIO;
11322 } else
11323 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050011324
11325 /* Restart HBA and bring it online */
11326 lpfc_sli_brdrestart(phba);
11327 lpfc_online(phba);
11328
James Smart5b75da22008-12-04 22:39:35 -050011329 /* Log the current active interrupt mode */
11330 lpfc_log_intr_mode(phba, phba->intr_mode);
11331
James Smart3a55b532008-12-04 22:38:54 -050011332 return 0;
11333}
11334
11335/**
James Smart891478a2009-11-18 15:40:23 -050011336 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
11337 * @phba: pointer to lpfc hba data structure.
11338 *
11339 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -040011340 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -050011341 **/
11342static void
11343lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
11344{
11345 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11346 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -040011347
11348 /*
11349 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
11350 * and let the SCSI mid-layer to retry them to recover.
11351 */
James Smartdb55fba2014-04-04 13:52:02 -040011352 lpfc_sli_abort_fcp_rings(phba);
James Smart891478a2009-11-18 15:40:23 -050011353}
11354
11355/**
James Smart0d878412009-10-02 15:16:56 -040011356 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
11357 * @phba: pointer to lpfc hba data structure.
11358 *
11359 * This routine is called to prepare the SLI3 device for PCI slot reset. It
11360 * disables the device interrupt and pci device, and aborts the internal FCP
11361 * pending I/Os.
11362 **/
11363static void
11364lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
11365{
James Smart0d878412009-10-02 15:16:56 -040011366 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050011367 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -040011368
James Smart75baf692010-06-08 18:31:21 -040011369 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040011370 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040011371
James Smarte2af0d22010-03-15 11:25:32 -040011372 /* Block all SCSI devices' I/Os on the host */
11373 lpfc_scsi_dev_block(phba);
11374
James Smartea714f32013-04-17 20:18:47 -040011375 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
11376 lpfc_sli_flush_fcp_rings(phba);
11377
James Smarte2af0d22010-03-15 11:25:32 -040011378 /* stop all timers */
11379 lpfc_stop_hba_timers(phba);
11380
James Smart0d878412009-10-02 15:16:56 -040011381 /* Disable interrupt and pci device */
11382 lpfc_sli_disable_intr(phba);
11383 pci_disable_device(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -040011384}
11385
11386/**
11387 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
11388 * @phba: pointer to lpfc hba data structure.
11389 *
11390 * This routine is called to prepare the SLI3 device for PCI slot permanently
11391 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
11392 * pending I/Os.
11393 **/
11394static void
James Smart75baf692010-06-08 18:31:21 -040011395lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -040011396{
11397 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050011398 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -040011399 /* Block all SCSI devices' I/Os on the host */
11400 lpfc_scsi_dev_block(phba);
11401
11402 /* stop all timers */
11403 lpfc_stop_hba_timers(phba);
11404
James Smart0d878412009-10-02 15:16:56 -040011405 /* Clean up all driver's outstanding SCSI I/Os */
11406 lpfc_sli_flush_fcp_rings(phba);
11407}
11408
11409/**
James Smart3772a992009-05-22 14:50:54 -040011410 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -040011411 * @pdev: pointer to PCI device.
11412 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -060011413 *
James Smart3772a992009-05-22 14:50:54 -040011414 * This routine is called from the PCI subsystem for I/O error handling to
11415 * device with SLI-3 interface spec. This function is called by the PCI
11416 * subsystem after a PCI bus error affecting this device has been detected.
11417 * When this function is invoked, it will need to stop all the I/Os and
11418 * interrupt(s) to the device. Once that is done, it will return
11419 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
11420 * as desired.
James Smarte59058c2008-08-24 21:49:00 -040011421 *
11422 * Return codes
James Smart0d878412009-10-02 15:16:56 -040011423 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -040011424 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11425 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -040011426 **/
James Smart3772a992009-05-22 14:50:54 -040011427static pci_ers_result_t
11428lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -060011429{
James Smart51ef4c22007-08-02 11:10:31 -040011430 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11431 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011432
James Smart0d878412009-10-02 15:16:56 -040011433 switch (state) {
11434 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -050011435 /* Non-fatal error, prepare for recovery */
11436 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -040011437 return PCI_ERS_RESULT_CAN_RECOVER;
11438 case pci_channel_io_frozen:
11439 /* Fatal error, prepare for slot reset */
11440 lpfc_sli_prep_dev_for_reset(phba);
11441 return PCI_ERS_RESULT_NEED_RESET;
11442 case pci_channel_io_perm_failure:
11443 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -040011444 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011445 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -040011446 default:
11447 /* Unknown state, prepare and request slot reset */
11448 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11449 "0472 Unknown PCI error state: x%x\n", state);
11450 lpfc_sli_prep_dev_for_reset(phba);
11451 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -040011452 }
Linas Vepstas8d63f372007-02-14 14:28:36 -060011453}
11454
11455/**
James Smart3772a992009-05-22 14:50:54 -040011456 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -040011457 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -060011458 *
James Smart3772a992009-05-22 14:50:54 -040011459 * This routine is called from the PCI subsystem for error handling to
11460 * device with SLI-3 interface spec. This is called after PCI bus has been
11461 * reset to restart the PCI card from scratch, as if from a cold-boot.
11462 * During the PCI subsystem error recovery, after driver returns
11463 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
11464 * recovery and then call this routine before calling the .resume method
11465 * to recover the device. This function will initialize the HBA device,
11466 * enable the interrupt, but it will just put the HBA to offline state
11467 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -040011468 *
11469 * Return codes
James Smart3772a992009-05-22 14:50:54 -040011470 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11471 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -060011472 */
James Smart3772a992009-05-22 14:50:54 -040011473static pci_ers_result_t
11474lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060011475{
James Smart51ef4c22007-08-02 11:10:31 -040011476 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11477 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011478 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -050011479 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011480
11481 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +110011482 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -060011483 printk(KERN_ERR "lpfc: Cannot re-enable "
11484 "PCI device after reset.\n");
11485 return PCI_ERS_RESULT_DISCONNECT;
11486 }
11487
James Smart97207482008-12-04 22:39:19 -050011488 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050011489
11490 /*
11491 * As the new kernel behavior of pci_restore_state() API call clears
11492 * device saved_state flag, need to save the restored state again.
11493 */
11494 pci_save_state(pdev);
11495
James Smart97207482008-12-04 22:39:19 -050011496 if (pdev->is_busmaster)
11497 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011498
James Smart92d7f7b2007-06-17 19:56:38 -050011499 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040011500 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -050011501 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011502
James Smart5b75da22008-12-04 22:39:35 -050011503 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040011504 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050011505 if (intr_mode == LPFC_INTR_ERROR) {
11506 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11507 "0427 Cannot re-enable interrupt after "
11508 "slot reset.\n");
11509 return PCI_ERS_RESULT_DISCONNECT;
11510 } else
11511 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011512
James Smart75baf692010-06-08 18:31:21 -040011513 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -040011514 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011515 lpfc_offline(phba);
11516 lpfc_sli_brdrestart(phba);
11517
James Smart5b75da22008-12-04 22:39:35 -050011518 /* Log the current active interrupt mode */
11519 lpfc_log_intr_mode(phba, phba->intr_mode);
11520
Linas Vepstas8d63f372007-02-14 14:28:36 -060011521 return PCI_ERS_RESULT_RECOVERED;
11522}
11523
11524/**
James Smart3772a992009-05-22 14:50:54 -040011525 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -040011526 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -060011527 *
James Smart3772a992009-05-22 14:50:54 -040011528 * This routine is called from the PCI subsystem for error handling to device
11529 * with SLI-3 interface spec. It is called when kernel error recovery tells
11530 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
11531 * error recovery. After this call, traffic can start to flow from this device
11532 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -060011533 */
James Smart3772a992009-05-22 14:50:54 -040011534static void
11535lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060011536{
James Smart51ef4c22007-08-02 11:10:31 -040011537 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11538 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011539
James Smarte2af0d22010-03-15 11:25:32 -040011540 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -040011541 lpfc_online(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011542}
11543
James Smart3772a992009-05-22 14:50:54 -040011544/**
James Smartda0436e2009-05-22 14:51:39 -040011545 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
11546 * @phba: pointer to lpfc hba data structure.
11547 *
11548 * returns the number of ELS/CT IOCBs to reserve
11549 **/
11550int
11551lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
11552{
11553 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
11554
James Smartf1126682009-06-10 17:22:44 -040011555 if (phba->sli_rev == LPFC_SLI_REV4) {
11556 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -040011557 return 10;
James Smartf1126682009-06-10 17:22:44 -040011558 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -040011559 return 25;
James Smartf1126682009-06-10 17:22:44 -040011560 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -040011561 return 50;
James Smartf1126682009-06-10 17:22:44 -040011562 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -040011563 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -040011564 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -040011565 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -040011566 else if (max_xri <= 2048)
11567 return 200;
11568 else
11569 return 250;
James Smartf1126682009-06-10 17:22:44 -040011570 } else
11571 return 0;
James Smartda0436e2009-05-22 14:51:39 -040011572}
11573
11574/**
James Smart895427b2017-02-12 13:52:30 -080011575 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
11576 * @phba: pointer to lpfc hba data structure.
11577 *
James Smartf358dd02017-02-12 13:52:34 -080011578 * returns the number of ELS/CT + NVMET IOCBs to reserve
James Smart895427b2017-02-12 13:52:30 -080011579 **/
11580int
11581lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
11582{
11583 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
11584
James Smartf358dd02017-02-12 13:52:34 -080011585 if (phba->nvmet_support)
11586 max_xri += LPFC_NVMET_BUF_POST;
James Smart895427b2017-02-12 13:52:30 -080011587 return max_xri;
11588}
11589
11590
James Smart1feb8202018-02-22 08:18:47 -080011591static void
11592lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset,
11593 uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize,
11594 const struct firmware *fw)
11595{
James Smarta72d56b2018-05-04 20:37:52 -070011596 if ((offset == ADD_STATUS_FW_NOT_SUPPORTED) ||
11597 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
11598 magic_number != MAGIC_NUMER_G6) ||
11599 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC &&
11600 magic_number != MAGIC_NUMER_G7))
James Smart1feb8202018-02-22 08:18:47 -080011601 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11602 "3030 This firmware version is not supported on "
11603 "this HBA model. Device:%x Magic:%x Type:%x "
11604 "ID:%x Size %d %zd\n",
11605 phba->pcidev->device, magic_number, ftype, fid,
11606 fsize, fw->size);
11607 else
11608 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11609 "3022 FW Download failed. Device:%x Magic:%x Type:%x "
11610 "ID:%x Size %d %zd\n",
11611 phba->pcidev->device, magic_number, ftype, fid,
11612 fsize, fw->size);
11613}
11614
11615
James Smart895427b2017-02-12 13:52:30 -080011616/**
James Smart52d52442011-05-24 11:42:45 -040011617 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -040011618 * @fw: pointer to firmware image returned from request_firmware.
James Smartce396282012-09-29 11:30:56 -040011619 * @phba: pointer to lpfc hba data structure.
James Smart52d52442011-05-24 11:42:45 -040011620 *
James Smart52d52442011-05-24 11:42:45 -040011621 **/
James Smartce396282012-09-29 11:30:56 -040011622static void
11623lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -040011624{
James Smartce396282012-09-29 11:30:56 -040011625 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -050011626 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -040011627 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -040011628 struct list_head dma_buffer_list;
11629 int i, rc = 0;
11630 struct lpfc_dmabuf *dmabuf, *next;
11631 uint32_t offset = 0, temp_offset = 0;
James Smart6b6ef5d2016-10-13 15:06:17 -070011632 uint32_t magic_number, ftype, fid, fsize;
James Smart52d52442011-05-24 11:42:45 -040011633
James Smartc71ab862012-10-31 14:44:33 -040011634 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -040011635 if (!fw) {
11636 rc = -ENXIO;
11637 goto out;
11638 }
11639 image = (struct lpfc_grp_hdr *)fw->data;
11640
James Smart6b6ef5d2016-10-13 15:06:17 -070011641 magic_number = be32_to_cpu(image->magic_number);
11642 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
James Smart1feb8202018-02-22 08:18:47 -080011643 fid = bf_get_be32(lpfc_grp_hdr_id, image);
James Smart6b6ef5d2016-10-13 15:06:17 -070011644 fsize = be32_to_cpu(image->size);
11645
James Smart52d52442011-05-24 11:42:45 -040011646 INIT_LIST_HEAD(&dma_buffer_list);
James Smart52d52442011-05-24 11:42:45 -040011647 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -040011648 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -040011649 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartce396282012-09-29 11:30:56 -040011650 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -040011651 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -040011652 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -040011653 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
11654 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
11655 GFP_KERNEL);
11656 if (!dmabuf) {
11657 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040011658 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040011659 }
11660 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
11661 SLI4_PAGE_SIZE,
11662 &dmabuf->phys,
11663 GFP_KERNEL);
11664 if (!dmabuf->virt) {
11665 kfree(dmabuf);
11666 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040011667 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040011668 }
11669 list_add_tail(&dmabuf->list, &dma_buffer_list);
11670 }
11671 while (offset < fw->size) {
11672 temp_offset = offset;
11673 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -040011674 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -040011675 memcpy(dmabuf->virt,
11676 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -040011677 fw->size - temp_offset);
11678 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -040011679 break;
11680 }
James Smart52d52442011-05-24 11:42:45 -040011681 memcpy(dmabuf->virt, fw->data + temp_offset,
11682 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -040011683 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -040011684 }
11685 rc = lpfc_wr_object(phba, &dma_buffer_list,
11686 (fw->size - offset), &offset);
James Smart1feb8202018-02-22 08:18:47 -080011687 if (rc) {
11688 lpfc_log_write_firmware_error(phba, offset,
11689 magic_number, ftype, fid, fsize, fw);
James Smartce396282012-09-29 11:30:56 -040011690 goto release_out;
James Smart1feb8202018-02-22 08:18:47 -080011691 }
James Smart52d52442011-05-24 11:42:45 -040011692 }
11693 rc = offset;
James Smart1feb8202018-02-22 08:18:47 -080011694 } else
11695 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11696 "3029 Skipped Firmware update, Current "
11697 "Version:%s New Version:%s\n",
11698 fwrev, image->revision);
James Smartce396282012-09-29 11:30:56 -040011699
11700release_out:
James Smart52d52442011-05-24 11:42:45 -040011701 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
11702 list_del(&dmabuf->list);
11703 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
11704 dmabuf->virt, dmabuf->phys);
11705 kfree(dmabuf);
11706 }
James Smartce396282012-09-29 11:30:56 -040011707 release_firmware(fw);
11708out:
11709 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc71ab862012-10-31 14:44:33 -040011710 "3024 Firmware update done: %d.\n", rc);
James Smartce396282012-09-29 11:30:56 -040011711 return;
James Smart52d52442011-05-24 11:42:45 -040011712}
11713
11714/**
James Smartc71ab862012-10-31 14:44:33 -040011715 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
11716 * @phba: pointer to lpfc hba data structure.
11717 *
11718 * This routine is called to perform Linux generic firmware upgrade on device
11719 * that supports such feature.
11720 **/
11721int
11722lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
11723{
11724 uint8_t file_name[ELX_MODEL_NAME_SIZE];
11725 int ret;
11726 const struct firmware *fw;
11727
11728 /* Only supported on SLI4 interface type 2 for now */
James Smart27d6ac02018-02-22 08:18:42 -080011729 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smartc71ab862012-10-31 14:44:33 -040011730 LPFC_SLI_INTF_IF_TYPE_2)
11731 return -EPERM;
11732
11733 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
11734
11735 if (fw_upgrade == INT_FW_UPGRADE) {
11736 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
11737 file_name, &phba->pcidev->dev,
11738 GFP_KERNEL, (void *)phba,
11739 lpfc_write_firmware);
11740 } else if (fw_upgrade == RUN_FW_UPGRADE) {
11741 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
11742 if (!ret)
11743 lpfc_write_firmware(fw, (void *)phba);
11744 } else {
11745 ret = -EINVAL;
11746 }
11747
11748 return ret;
11749}
11750
11751/**
James Smartda0436e2009-05-22 14:51:39 -040011752 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
11753 * @pdev: pointer to PCI device
11754 * @pid: pointer to PCI device identifier
11755 *
11756 * This routine is called from the kernel's PCI subsystem to device with
11757 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11758 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
11759 * information of the device and driver to see if the driver state that it
11760 * can support this kind of device. If the match is successful, the driver
11761 * core invokes this routine. If this routine determines it can claim the HBA,
11762 * it does all the initialization that it needs to do to handle the HBA
11763 * properly.
11764 *
11765 * Return code
11766 * 0 - driver can claim the device
11767 * negative value - driver can not claim the device
11768 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011769static int
James Smartda0436e2009-05-22 14:51:39 -040011770lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
11771{
11772 struct lpfc_hba *phba;
11773 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040011774 struct Scsi_Host *shost = NULL;
James Smart6c621a22017-05-15 15:20:45 -070011775 int error;
James Smartda0436e2009-05-22 14:51:39 -040011776 uint32_t cfg_mode, intr_mode;
James Smartda0436e2009-05-22 14:51:39 -040011777
11778 /* Allocate memory for HBA structure */
11779 phba = lpfc_hba_alloc(pdev);
11780 if (!phba)
11781 return -ENOMEM;
11782
11783 /* Perform generic PCI device enabling operation */
11784 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040011785 if (error)
James Smartda0436e2009-05-22 14:51:39 -040011786 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -040011787
11788 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
11789 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
11790 if (error)
11791 goto out_disable_pci_dev;
11792
11793 /* Set up SLI-4 specific device PCI memory space */
11794 error = lpfc_sli4_pci_mem_setup(phba);
11795 if (error) {
11796 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11797 "1410 Failed to set up pci memory space.\n");
11798 goto out_disable_pci_dev;
11799 }
11800
James Smartda0436e2009-05-22 14:51:39 -040011801 /* Set up SLI-4 Specific device driver resources */
11802 error = lpfc_sli4_driver_resource_setup(phba);
11803 if (error) {
11804 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11805 "1412 Failed to set up driver resource.\n");
11806 goto out_unset_pci_mem_s4;
11807 }
11808
James Smart19ca7602010-11-20 23:11:55 -050011809 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -040011810 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -050011811
James Smartda0436e2009-05-22 14:51:39 -040011812 /* Set up common device driver resources */
11813 error = lpfc_setup_driver_resource_phase2(phba);
11814 if (error) {
11815 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11816 "1414 Failed to set up driver resource.\n");
James Smart6c621a22017-05-15 15:20:45 -070011817 goto out_unset_driver_resource_s4;
James Smartda0436e2009-05-22 14:51:39 -040011818 }
11819
James Smart079b5c92011-08-21 21:48:49 -040011820 /* Get the default values for Model Name and Description */
11821 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
11822
James Smartda0436e2009-05-22 14:51:39 -040011823 /* Create SCSI host to the physical port */
11824 error = lpfc_create_shost(phba);
11825 if (error) {
11826 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11827 "1415 Failed to create scsi host.\n");
11828 goto out_unset_driver_resource;
11829 }
11830
11831 /* Configure sysfs attributes */
11832 vport = phba->pport;
11833 error = lpfc_alloc_sysfs_attr(vport);
11834 if (error) {
11835 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11836 "1416 Failed to allocate sysfs attr\n");
11837 goto out_destroy_shost;
11838 }
11839
James Smart6669f9b2009-10-02 15:16:45 -040011840 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -040011841 /* Now, trying to enable interrupt and bring up the device */
11842 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -040011843
James Smart7b15db32013-01-03 15:43:29 -050011844 /* Put device to a known state before enabling interrupt */
11845 lpfc_stop_port(phba);
James Smart895427b2017-02-12 13:52:30 -080011846
James Smart7b15db32013-01-03 15:43:29 -050011847 /* Configure and enable interrupt */
11848 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
11849 if (intr_mode == LPFC_INTR_ERROR) {
11850 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11851 "0426 Failed to enable interrupt.\n");
11852 error = -ENODEV;
11853 goto out_free_sysfs_attr;
James Smartda0436e2009-05-22 14:51:39 -040011854 }
James Smart7b15db32013-01-03 15:43:29 -050011855 /* Default to single EQ for non-MSI-X */
James Smart895427b2017-02-12 13:52:30 -080011856 if (phba->intr_type != MSIX) {
11857 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
11858 phba->cfg_fcp_io_channel = 1;
James Smart2d7dbc42017-02-12 13:52:35 -080011859 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -080011860 phba->cfg_nvme_io_channel = 1;
James Smart2d7dbc42017-02-12 13:52:35 -080011861 if (phba->nvmet_support)
11862 phba->cfg_nvmet_mrq = 1;
11863 }
James Smart895427b2017-02-12 13:52:30 -080011864 phba->io_channel_irqs = 1;
11865 }
11866
James Smart7b15db32013-01-03 15:43:29 -050011867 /* Set up SLI-4 HBA */
11868 if (lpfc_sli4_hba_setup(phba)) {
11869 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11870 "1421 Failed to set up hba\n");
11871 error = -ENODEV;
11872 goto out_disable_intr;
11873 }
11874
11875 /* Log the current active interrupt mode */
11876 phba->intr_mode = intr_mode;
11877 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -040011878
11879 /* Perform post initialization setup */
11880 lpfc_post_init_setup(phba);
11881
James Smart01649562017-02-12 13:52:32 -080011882 /* NVME support in FW earlier in the driver load corrects the
11883 * FC4 type making a check for nvme_support unnecessary.
11884 */
11885 if ((phba->nvmet_support == 0) &&
11886 (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
11887 /* Create NVME binding with nvme_fc_transport. This
James Smartd1f525a2017-04-21 16:04:55 -070011888 * ensures the vport is initialized. If the localport
11889 * create fails, it should not unload the driver to
11890 * support field issues.
James Smart01649562017-02-12 13:52:32 -080011891 */
11892 error = lpfc_nvme_create_localport(vport);
11893 if (error) {
11894 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11895 "6004 NVME registration failed, "
11896 "error x%x\n",
11897 error);
James Smart01649562017-02-12 13:52:32 -080011898 }
11899 }
James Smart895427b2017-02-12 13:52:30 -080011900
James Smartc71ab862012-10-31 14:44:33 -040011901 /* check for firmware upgrade or downgrade */
11902 if (phba->cfg_request_firmware_upgrade)
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040011903 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -040011904
James Smart1c6834a2009-07-19 10:01:26 -040011905 /* Check if there are static vports to be created. */
11906 lpfc_create_static_vport(phba);
James Smartd2cc9bc2018-09-10 10:30:50 -070011907
11908 /* Enable RAS FW log support */
11909 lpfc_sli4_ras_setup(phba);
11910
James Smartda0436e2009-05-22 14:51:39 -040011911 return 0;
11912
11913out_disable_intr:
11914 lpfc_sli4_disable_intr(phba);
11915out_free_sysfs_attr:
11916 lpfc_free_sysfs_attr(vport);
11917out_destroy_shost:
11918 lpfc_destroy_shost(phba);
11919out_unset_driver_resource:
11920 lpfc_unset_driver_resource_phase2(phba);
James Smartda0436e2009-05-22 14:51:39 -040011921out_unset_driver_resource_s4:
11922 lpfc_sli4_driver_resource_unset(phba);
11923out_unset_pci_mem_s4:
11924 lpfc_sli4_pci_mem_unset(phba);
11925out_disable_pci_dev:
11926 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040011927 if (shost)
11928 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -040011929out_free_phba:
11930 lpfc_hba_free(phba);
11931 return error;
11932}
11933
11934/**
11935 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
11936 * @pdev: pointer to PCI device
11937 *
11938 * This routine is called from the kernel's PCI subsystem to device with
11939 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11940 * removed from PCI bus, it performs all the necessary cleanup for the HBA
11941 * device to be removed from the PCI subsystem properly.
11942 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011943static void
James Smartda0436e2009-05-22 14:51:39 -040011944lpfc_pci_remove_one_s4(struct pci_dev *pdev)
11945{
11946 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11947 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
11948 struct lpfc_vport **vports;
11949 struct lpfc_hba *phba = vport->phba;
11950 int i;
11951
11952 /* Mark the device unloading flag */
11953 spin_lock_irq(&phba->hbalock);
11954 vport->load_flag |= FC_UNLOADING;
11955 spin_unlock_irq(&phba->hbalock);
11956
11957 /* Free the HBA sysfs attributes */
11958 lpfc_free_sysfs_attr(vport);
11959
11960 /* Release all the vports against this physical port */
11961 vports = lpfc_create_vport_work_array(phba);
11962 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040011963 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
11964 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
11965 continue;
James Smartda0436e2009-05-22 14:51:39 -040011966 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040011967 }
James Smartda0436e2009-05-22 14:51:39 -040011968 lpfc_destroy_vport_work_array(phba, vports);
11969
11970 /* Remove FC host and then SCSI host with the physical port */
11971 fc_remove_host(shost);
11972 scsi_remove_host(shost);
James Smartda0436e2009-05-22 14:51:39 -040011973
James Smartda0436e2009-05-22 14:51:39 -040011974 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
11975 * localports are destroyed after to cleanup all transport memory.
11976 */
11977 lpfc_cleanup(vport);
11978 lpfc_nvmet_destroy_targetport(phba);
11979 lpfc_nvme_destroy_localport(vport);
11980
James Smart281d6192018-01-30 15:58:47 -080011981 /*
11982 * Bring down the SLI Layer. This step disables all interrupts,
11983 * clears the rings, discards all mailbox commands, and resets
11984 * the HBA FCoE function.
11985 */
11986 lpfc_debugfs_terminate(vport);
11987 lpfc_sli4_hba_unset(phba);
James Smartda0436e2009-05-22 14:51:39 -040011988
Dick Kennedy19017622017-09-29 17:34:27 -070011989 lpfc_stop_hba_timers(phba);
James Smart523128e2018-09-10 10:30:46 -070011990 spin_lock_irq(&phba->port_list_lock);
James Smartda0436e2009-05-22 14:51:39 -040011991 list_del_init(&vport->listentry);
James Smart523128e2018-09-10 10:30:46 -070011992 spin_unlock_irq(&phba->port_list_lock);
James Smartda0436e2009-05-22 14:51:39 -040011993
James Smart3677a3a2010-09-29 11:19:14 -040011994 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -040011995 * buffers are released to their corresponding pools here.
11996 */
11997 lpfc_scsi_free(phba);
James Smart895427b2017-02-12 13:52:30 -080011998 lpfc_nvme_free(phba);
James Smart01649562017-02-12 13:52:32 -080011999 lpfc_free_iocb_list(phba);
James Smart67d12732012-08-03 12:36:13 -040012000
James Smart0cdb84e2018-04-09 14:24:26 -070012001 lpfc_unset_driver_resource_phase2(phba);
James Smartda0436e2009-05-22 14:51:39 -040012002 lpfc_sli4_driver_resource_unset(phba);
12003
12004 /* Unmap adapter Control and Doorbell registers */
12005 lpfc_sli4_pci_mem_unset(phba);
12006
12007 /* Release PCI resources and disable device's PCI function */
12008 scsi_host_put(shost);
12009 lpfc_disable_pci_dev(phba);
12010
12011 /* Finally, free the driver's device data structure */
12012 lpfc_hba_free(phba);
12013
12014 return;
12015}
12016
12017/**
12018 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
12019 * @pdev: pointer to PCI device
12020 * @msg: power management message
12021 *
12022 * This routine is called from the kernel's PCI subsystem to support system
12023 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
12024 * this method, it quiesces the device by stopping the driver's worker
12025 * thread for the device, turning off device's interrupt and DMA, and bring
12026 * the device offline. Note that as the driver implements the minimum PM
12027 * requirements to a power-aware driver's PM support for suspend/resume -- all
12028 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
12029 * method call will be treated as SUSPEND and the driver will fully
12030 * reinitialize its device during resume() method call, the driver will set
12031 * device to PCI_D3hot state in PCI config space instead of setting it
12032 * according to the @msg provided by the PM.
12033 *
12034 * Return code
12035 * 0 - driver suspended the device
12036 * Error otherwise
12037 **/
12038static int
12039lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
12040{
12041 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12042 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12043
12044 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -040012045 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -040012046
12047 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040012048 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -040012049 lpfc_offline(phba);
12050 kthread_stop(phba->worker_thread);
12051
12052 /* Disable interrupt from device */
12053 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040012054 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040012055
12056 /* Save device state to PCI config space */
12057 pci_save_state(pdev);
12058 pci_set_power_state(pdev, PCI_D3hot);
12059
12060 return 0;
12061}
12062
12063/**
12064 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
12065 * @pdev: pointer to PCI device
12066 *
12067 * This routine is called from the kernel's PCI subsystem to support system
12068 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
12069 * this method, it restores the device's PCI config space state and fully
12070 * reinitializes the device and brings it online. Note that as the driver
12071 * implements the minimum PM requirements to a power-aware driver's PM for
12072 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
12073 * to the suspend() method call will be treated as SUSPEND and the driver
12074 * will fully reinitialize its device during resume() method call, the device
12075 * will be set to PCI_D0 directly in PCI config space before restoring the
12076 * state.
12077 *
12078 * Return code
12079 * 0 - driver suspended the device
12080 * Error otherwise
12081 **/
12082static int
12083lpfc_pci_resume_one_s4(struct pci_dev *pdev)
12084{
12085 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12086 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12087 uint32_t intr_mode;
12088 int error;
12089
12090 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
12091 "0292 PCI device Power Management resume.\n");
12092
12093 /* Restore device state from PCI config space */
12094 pci_set_power_state(pdev, PCI_D0);
12095 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050012096
12097 /*
12098 * As the new kernel behavior of pci_restore_state() API call clears
12099 * device saved_state flag, need to save the restored state again.
12100 */
12101 pci_save_state(pdev);
12102
James Smartda0436e2009-05-22 14:51:39 -040012103 if (pdev->is_busmaster)
12104 pci_set_master(pdev);
12105
12106 /* Startup the kernel thread for this host adapter. */
12107 phba->worker_thread = kthread_run(lpfc_do_work, phba,
12108 "lpfc_worker_%d", phba->brd_no);
12109 if (IS_ERR(phba->worker_thread)) {
12110 error = PTR_ERR(phba->worker_thread);
12111 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12112 "0293 PM resume failed to start worker "
12113 "thread: error=x%x.\n", error);
12114 return error;
12115 }
12116
12117 /* Configure and enable interrupt */
12118 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
12119 if (intr_mode == LPFC_INTR_ERROR) {
12120 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12121 "0294 PM resume Failed to enable interrupt\n");
12122 return -EIO;
12123 } else
12124 phba->intr_mode = intr_mode;
12125
12126 /* Restart HBA and bring it online */
12127 lpfc_sli_brdrestart(phba);
12128 lpfc_online(phba);
12129
12130 /* Log the current active interrupt mode */
12131 lpfc_log_intr_mode(phba, phba->intr_mode);
12132
12133 return 0;
12134}
12135
12136/**
James Smart75baf692010-06-08 18:31:21 -040012137 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
12138 * @phba: pointer to lpfc hba data structure.
12139 *
12140 * This routine is called to prepare the SLI4 device for PCI slot recover. It
12141 * aborts all the outstanding SCSI I/Os to the pci device.
12142 **/
12143static void
12144lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
12145{
James Smart75baf692010-06-08 18:31:21 -040012146 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12147 "2828 PCI channel I/O abort preparing for recovery\n");
12148 /*
12149 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
12150 * and let the SCSI mid-layer to retry them to recover.
12151 */
James Smartdb55fba2014-04-04 13:52:02 -040012152 lpfc_sli_abort_fcp_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040012153}
12154
12155/**
12156 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
12157 * @phba: pointer to lpfc hba data structure.
12158 *
12159 * This routine is called to prepare the SLI4 device for PCI slot reset. It
12160 * disables the device interrupt and pci device, and aborts the internal FCP
12161 * pending I/Os.
12162 **/
12163static void
12164lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
12165{
12166 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12167 "2826 PCI channel disable preparing for reset\n");
12168
12169 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040012170 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -040012171
12172 /* Block all SCSI devices' I/Os on the host */
12173 lpfc_scsi_dev_block(phba);
12174
James Smartea714f32013-04-17 20:18:47 -040012175 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
12176 lpfc_sli_flush_fcp_rings(phba);
12177
James Smartc3725bd2017-11-20 16:00:42 -080012178 /* Flush the outstanding NVME IOs if fc4 type enabled. */
12179 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
12180 lpfc_sli_flush_nvme_rings(phba);
12181
James Smart75baf692010-06-08 18:31:21 -040012182 /* stop all timers */
12183 lpfc_stop_hba_timers(phba);
12184
12185 /* Disable interrupt and pci device */
12186 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040012187 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -040012188 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -040012189}
12190
12191/**
12192 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
12193 * @phba: pointer to lpfc hba data structure.
12194 *
12195 * This routine is called to prepare the SLI4 device for PCI slot permanently
12196 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
12197 * pending I/Os.
12198 **/
12199static void
12200lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
12201{
12202 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12203 "2827 PCI channel permanent disable for failure\n");
12204
12205 /* Block all SCSI devices' I/Os on the host */
12206 lpfc_scsi_dev_block(phba);
12207
12208 /* stop all timers */
12209 lpfc_stop_hba_timers(phba);
12210
12211 /* Clean up all driver's outstanding SCSI I/Os */
12212 lpfc_sli_flush_fcp_rings(phba);
James Smartc3725bd2017-11-20 16:00:42 -080012213
12214 /* Flush the outstanding NVME IOs if fc4 type enabled. */
12215 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
12216 lpfc_sli_flush_nvme_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040012217}
12218
12219/**
James Smartda0436e2009-05-22 14:51:39 -040012220 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
12221 * @pdev: pointer to PCI device.
12222 * @state: the current PCI connection state.
12223 *
12224 * This routine is called from the PCI subsystem for error handling to device
12225 * with SLI-4 interface spec. This function is called by the PCI subsystem
12226 * after a PCI bus error affecting this device has been detected. When this
12227 * function is invoked, it will need to stop all the I/Os and interrupt(s)
12228 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
12229 * for the PCI subsystem to perform proper recovery as desired.
12230 *
12231 * Return codes
12232 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
12233 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12234 **/
12235static pci_ers_result_t
12236lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
12237{
James Smart75baf692010-06-08 18:31:21 -040012238 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12239 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12240
12241 switch (state) {
12242 case pci_channel_io_normal:
12243 /* Non-fatal error, prepare for recovery */
12244 lpfc_sli4_prep_dev_for_recover(phba);
12245 return PCI_ERS_RESULT_CAN_RECOVER;
12246 case pci_channel_io_frozen:
12247 /* Fatal error, prepare for slot reset */
12248 lpfc_sli4_prep_dev_for_reset(phba);
12249 return PCI_ERS_RESULT_NEED_RESET;
12250 case pci_channel_io_perm_failure:
12251 /* Permanent failure, prepare for device down */
12252 lpfc_sli4_prep_dev_for_perm_failure(phba);
12253 return PCI_ERS_RESULT_DISCONNECT;
12254 default:
12255 /* Unknown state, prepare and request slot reset */
12256 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12257 "2825 Unknown PCI error state: x%x\n", state);
12258 lpfc_sli4_prep_dev_for_reset(phba);
12259 return PCI_ERS_RESULT_NEED_RESET;
12260 }
James Smartda0436e2009-05-22 14:51:39 -040012261}
12262
12263/**
12264 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
12265 * @pdev: pointer to PCI device.
12266 *
12267 * This routine is called from the PCI subsystem for error handling to device
12268 * with SLI-4 interface spec. It is called after PCI bus has been reset to
12269 * restart the PCI card from scratch, as if from a cold-boot. During the
12270 * PCI subsystem error recovery, after the driver returns
12271 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
12272 * recovery and then call this routine before calling the .resume method to
12273 * recover the device. This function will initialize the HBA device, enable
12274 * the interrupt, but it will just put the HBA to offline state without
12275 * passing any I/O traffic.
12276 *
12277 * Return codes
12278 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
12279 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12280 */
12281static pci_ers_result_t
12282lpfc_io_slot_reset_s4(struct pci_dev *pdev)
12283{
James Smart75baf692010-06-08 18:31:21 -040012284 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12285 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12286 struct lpfc_sli *psli = &phba->sli;
12287 uint32_t intr_mode;
12288
12289 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
12290 if (pci_enable_device_mem(pdev)) {
12291 printk(KERN_ERR "lpfc: Cannot re-enable "
12292 "PCI device after reset.\n");
12293 return PCI_ERS_RESULT_DISCONNECT;
12294 }
12295
12296 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040012297
12298 /*
12299 * As the new kernel behavior of pci_restore_state() API call clears
12300 * device saved_state flag, need to save the restored state again.
12301 */
12302 pci_save_state(pdev);
12303
James Smart75baf692010-06-08 18:31:21 -040012304 if (pdev->is_busmaster)
12305 pci_set_master(pdev);
12306
12307 spin_lock_irq(&phba->hbalock);
12308 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
12309 spin_unlock_irq(&phba->hbalock);
12310
12311 /* Configure and enable interrupt */
12312 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
12313 if (intr_mode == LPFC_INTR_ERROR) {
12314 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12315 "2824 Cannot re-enable interrupt after "
12316 "slot reset.\n");
12317 return PCI_ERS_RESULT_DISCONNECT;
12318 } else
12319 phba->intr_mode = intr_mode;
12320
12321 /* Log the current active interrupt mode */
12322 lpfc_log_intr_mode(phba, phba->intr_mode);
12323
James Smartda0436e2009-05-22 14:51:39 -040012324 return PCI_ERS_RESULT_RECOVERED;
12325}
12326
12327/**
12328 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
12329 * @pdev: pointer to PCI device
12330 *
12331 * This routine is called from the PCI subsystem for error handling to device
12332 * with SLI-4 interface spec. It is called when kernel error recovery tells
12333 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
12334 * error recovery. After this call, traffic can start to flow from this device
12335 * again.
12336 **/
12337static void
12338lpfc_io_resume_s4(struct pci_dev *pdev)
12339{
James Smart75baf692010-06-08 18:31:21 -040012340 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12341 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12342
12343 /*
12344 * In case of slot reset, as function reset is performed through
12345 * mailbox command which needs DMA to be enabled, this operation
12346 * has to be moved to the io resume phase. Taking device offline
12347 * will perform the necessary cleanup.
12348 */
12349 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
12350 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040012351 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040012352 lpfc_offline(phba);
12353 lpfc_sli_brdrestart(phba);
12354 /* Bring the device back online */
12355 lpfc_online(phba);
12356 }
James Smartda0436e2009-05-22 14:51:39 -040012357}
12358
12359/**
James Smart3772a992009-05-22 14:50:54 -040012360 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
12361 * @pdev: pointer to PCI device
12362 * @pid: pointer to PCI device identifier
12363 *
12364 * This routine is to be registered to the kernel's PCI subsystem. When an
12365 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
12366 * at PCI device-specific information of the device and driver to see if the
12367 * driver state that it can support this kind of device. If the match is
12368 * successful, the driver core invokes this routine. This routine dispatches
12369 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
12370 * do all the initialization that it needs to do to handle the HBA device
12371 * properly.
12372 *
12373 * Return code
12374 * 0 - driver can claim the device
12375 * negative value - driver can not claim the device
12376 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012377static int
James Smart3772a992009-05-22 14:50:54 -040012378lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
12379{
12380 int rc;
James Smart8fa38512009-07-19 10:01:03 -040012381 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040012382
James Smart28baac72010-02-12 14:42:03 -050012383 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040012384 return -ENODEV;
12385
James Smart8fa38512009-07-19 10:01:03 -040012386 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050012387 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040012388 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040012389 else
James Smart3772a992009-05-22 14:50:54 -040012390 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040012391
James Smart3772a992009-05-22 14:50:54 -040012392 return rc;
12393}
12394
12395/**
12396 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
12397 * @pdev: pointer to PCI device
12398 *
12399 * This routine is to be registered to the kernel's PCI subsystem. When an
12400 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
12401 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
12402 * remove routine, which will perform all the necessary cleanup for the
12403 * device to be removed from the PCI subsystem properly.
12404 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012405static void
James Smart3772a992009-05-22 14:50:54 -040012406lpfc_pci_remove_one(struct pci_dev *pdev)
12407{
12408 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12409 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12410
12411 switch (phba->pci_dev_grp) {
12412 case LPFC_PCI_DEV_LP:
12413 lpfc_pci_remove_one_s3(pdev);
12414 break;
James Smartda0436e2009-05-22 14:51:39 -040012415 case LPFC_PCI_DEV_OC:
12416 lpfc_pci_remove_one_s4(pdev);
12417 break;
James Smart3772a992009-05-22 14:50:54 -040012418 default:
12419 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12420 "1424 Invalid PCI device group: 0x%x\n",
12421 phba->pci_dev_grp);
12422 break;
12423 }
12424 return;
12425}
12426
12427/**
12428 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
12429 * @pdev: pointer to PCI device
12430 * @msg: power management message
12431 *
12432 * This routine is to be registered to the kernel's PCI subsystem to support
12433 * system Power Management (PM). When PM invokes this method, it dispatches
12434 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
12435 * suspend the device.
12436 *
12437 * Return code
12438 * 0 - driver suspended the device
12439 * Error otherwise
12440 **/
12441static int
12442lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
12443{
12444 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12445 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12446 int rc = -ENODEV;
12447
12448 switch (phba->pci_dev_grp) {
12449 case LPFC_PCI_DEV_LP:
12450 rc = lpfc_pci_suspend_one_s3(pdev, msg);
12451 break;
James Smartda0436e2009-05-22 14:51:39 -040012452 case LPFC_PCI_DEV_OC:
12453 rc = lpfc_pci_suspend_one_s4(pdev, msg);
12454 break;
James Smart3772a992009-05-22 14:50:54 -040012455 default:
12456 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12457 "1425 Invalid PCI device group: 0x%x\n",
12458 phba->pci_dev_grp);
12459 break;
12460 }
12461 return rc;
12462}
12463
12464/**
12465 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
12466 * @pdev: pointer to PCI device
12467 *
12468 * This routine is to be registered to the kernel's PCI subsystem to support
12469 * system Power Management (PM). When PM invokes this method, it dispatches
12470 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
12471 * resume the device.
12472 *
12473 * Return code
12474 * 0 - driver suspended the device
12475 * Error otherwise
12476 **/
12477static int
12478lpfc_pci_resume_one(struct pci_dev *pdev)
12479{
12480 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12481 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12482 int rc = -ENODEV;
12483
12484 switch (phba->pci_dev_grp) {
12485 case LPFC_PCI_DEV_LP:
12486 rc = lpfc_pci_resume_one_s3(pdev);
12487 break;
James Smartda0436e2009-05-22 14:51:39 -040012488 case LPFC_PCI_DEV_OC:
12489 rc = lpfc_pci_resume_one_s4(pdev);
12490 break;
James Smart3772a992009-05-22 14:50:54 -040012491 default:
12492 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12493 "1426 Invalid PCI device group: 0x%x\n",
12494 phba->pci_dev_grp);
12495 break;
12496 }
12497 return rc;
12498}
12499
12500/**
12501 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
12502 * @pdev: pointer to PCI device.
12503 * @state: the current PCI connection state.
12504 *
12505 * This routine is registered to the PCI subsystem for error handling. This
12506 * function is called by the PCI subsystem after a PCI bus error affecting
12507 * this device has been detected. When this routine is invoked, it dispatches
12508 * the action to the proper SLI-3 or SLI-4 device error detected handling
12509 * routine, which will perform the proper error detected operation.
12510 *
12511 * Return codes
12512 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
12513 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12514 **/
12515static pci_ers_result_t
12516lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
12517{
12518 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12519 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12520 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
12521
12522 switch (phba->pci_dev_grp) {
12523 case LPFC_PCI_DEV_LP:
12524 rc = lpfc_io_error_detected_s3(pdev, state);
12525 break;
James Smartda0436e2009-05-22 14:51:39 -040012526 case LPFC_PCI_DEV_OC:
12527 rc = lpfc_io_error_detected_s4(pdev, state);
12528 break;
James Smart3772a992009-05-22 14:50:54 -040012529 default:
12530 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12531 "1427 Invalid PCI device group: 0x%x\n",
12532 phba->pci_dev_grp);
12533 break;
12534 }
12535 return rc;
12536}
12537
12538/**
12539 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
12540 * @pdev: pointer to PCI device.
12541 *
12542 * This routine is registered to the PCI subsystem for error handling. This
12543 * function is called after PCI bus has been reset to restart the PCI card
12544 * from scratch, as if from a cold-boot. When this routine is invoked, it
12545 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
12546 * routine, which will perform the proper device reset.
12547 *
12548 * Return codes
12549 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
12550 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12551 **/
12552static pci_ers_result_t
12553lpfc_io_slot_reset(struct pci_dev *pdev)
12554{
12555 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12556 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12557 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
12558
12559 switch (phba->pci_dev_grp) {
12560 case LPFC_PCI_DEV_LP:
12561 rc = lpfc_io_slot_reset_s3(pdev);
12562 break;
James Smartda0436e2009-05-22 14:51:39 -040012563 case LPFC_PCI_DEV_OC:
12564 rc = lpfc_io_slot_reset_s4(pdev);
12565 break;
James Smart3772a992009-05-22 14:50:54 -040012566 default:
12567 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12568 "1428 Invalid PCI device group: 0x%x\n",
12569 phba->pci_dev_grp);
12570 break;
12571 }
12572 return rc;
12573}
12574
12575/**
12576 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
12577 * @pdev: pointer to PCI device
12578 *
12579 * This routine is registered to the PCI subsystem for error handling. It
12580 * is called when kernel error recovery tells the lpfc driver that it is
12581 * OK to resume normal PCI operation after PCI bus error recovery. When
12582 * this routine is invoked, it dispatches the action to the proper SLI-3
12583 * or SLI-4 device io_resume routine, which will resume the device operation.
12584 **/
12585static void
12586lpfc_io_resume(struct pci_dev *pdev)
12587{
12588 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12589 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12590
12591 switch (phba->pci_dev_grp) {
12592 case LPFC_PCI_DEV_LP:
12593 lpfc_io_resume_s3(pdev);
12594 break;
James Smartda0436e2009-05-22 14:51:39 -040012595 case LPFC_PCI_DEV_OC:
12596 lpfc_io_resume_s4(pdev);
12597 break;
James Smart3772a992009-05-22 14:50:54 -040012598 default:
12599 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12600 "1429 Invalid PCI device group: 0x%x\n",
12601 phba->pci_dev_grp);
12602 break;
12603 }
12604 return;
12605}
12606
James Smart1ba981f2014-02-20 09:56:45 -050012607/**
12608 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
12609 * @phba: pointer to lpfc hba data structure.
12610 *
12611 * This routine checks to see if OAS is supported for this adapter. If
12612 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
12613 * the enable oas flag is cleared and the pool created for OAS device data
12614 * is destroyed.
12615 *
12616 **/
12617void
12618lpfc_sli4_oas_verify(struct lpfc_hba *phba)
12619{
12620
12621 if (!phba->cfg_EnableXLane)
12622 return;
12623
12624 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
12625 phba->cfg_fof = 1;
12626 } else {
James Smartf38fa0b2014-04-04 13:52:21 -040012627 phba->cfg_fof = 0;
James Smart1ba981f2014-02-20 09:56:45 -050012628 if (phba->device_data_mem_pool)
12629 mempool_destroy(phba->device_data_mem_pool);
12630 phba->device_data_mem_pool = NULL;
12631 }
12632
12633 return;
12634}
12635
12636/**
James Smartd2cc9bc2018-09-10 10:30:50 -070012637 * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter
12638 * @phba: pointer to lpfc hba data structure.
12639 *
12640 * This routine checks to see if RAS is supported by the adapter. Check the
12641 * function through which RAS support enablement is to be done.
12642 **/
12643void
12644lpfc_sli4_ras_init(struct lpfc_hba *phba)
12645{
12646 switch (phba->pcidev->device) {
12647 case PCI_DEVICE_ID_LANCER_G6_FC:
12648 case PCI_DEVICE_ID_LANCER_G7_FC:
12649 phba->ras_fwlog.ras_hwsupport = true;
James Smartcb349902018-11-29 16:09:27 -080012650 if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn) &&
12651 phba->cfg_ras_fwlog_buffsize)
James Smartd2cc9bc2018-09-10 10:30:50 -070012652 phba->ras_fwlog.ras_enabled = true;
12653 else
12654 phba->ras_fwlog.ras_enabled = false;
12655 break;
12656 default:
12657 phba->ras_fwlog.ras_hwsupport = false;
12658 }
12659}
12660
12661/**
James Smart1ba981f2014-02-20 09:56:45 -050012662 * lpfc_fof_queue_setup - Set up all the fof queues
12663 * @phba: pointer to lpfc hba data structure.
12664 *
12665 * This routine is invoked to set up all the fof queues for the FC HBA
12666 * operation.
12667 *
12668 * Return codes
12669 * 0 - successful
12670 * -ENOMEM - No available memory
12671 **/
12672int
12673lpfc_fof_queue_setup(struct lpfc_hba *phba)
12674{
James Smart895427b2017-02-12 13:52:30 -080012675 struct lpfc_sli_ring *pring;
James Smart1ba981f2014-02-20 09:56:45 -050012676 int rc;
12677
12678 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
12679 if (rc)
12680 return -ENOMEM;
12681
James Smartf38fa0b2014-04-04 13:52:21 -040012682 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050012683
12684 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
12685 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
12686 if (rc)
12687 goto out_oas_cq;
12688
12689 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
12690 phba->sli4_hba.oas_cq, LPFC_FCP);
12691 if (rc)
12692 goto out_oas_wq;
12693
James Smart895427b2017-02-12 13:52:30 -080012694 /* Bind this CQ/WQ to the NVME ring */
12695 pring = phba->sli4_hba.oas_wq->pring;
12696 pring->sli.sli4.wqp =
12697 (void *)phba->sli4_hba.oas_wq;
12698 phba->sli4_hba.oas_cq->pring = pring;
James Smart1ba981f2014-02-20 09:56:45 -050012699 }
12700
12701 return 0;
12702
12703out_oas_wq:
James Smartf38fa0b2014-04-04 13:52:21 -040012704 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
James Smart1ba981f2014-02-20 09:56:45 -050012705out_oas_cq:
12706 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
12707 return rc;
12708
12709}
12710
12711/**
12712 * lpfc_fof_queue_create - Create all the fof queues
12713 * @phba: pointer to lpfc hba data structure.
12714 *
12715 * This routine is invoked to allocate all the fof queues for the FC HBA
12716 * operation. For each SLI4 queue type, the parameters such as queue entry
12717 * count (queue depth) shall be taken from the module parameter. For now,
12718 * we just use some constant number as place holder.
12719 *
12720 * Return codes
12721 * 0 - successful
12722 * -ENOMEM - No availble memory
12723 * -EIO - The mailbox failed to complete successfully.
12724 **/
12725int
12726lpfc_fof_queue_create(struct lpfc_hba *phba)
12727{
12728 struct lpfc_queue *qdesc;
James Smartc176ffa2018-01-30 15:58:46 -080012729 uint32_t wqesize;
James Smart1ba981f2014-02-20 09:56:45 -050012730
12731 /* Create FOF EQ */
James Smart81b96ed2017-11-20 16:00:29 -080012732 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
12733 phba->sli4_hba.eq_esize,
James Smart1ba981f2014-02-20 09:56:45 -050012734 phba->sli4_hba.eq_ecount);
12735 if (!qdesc)
12736 goto out_error;
12737
James Smart7365f6f2018-02-22 08:18:46 -080012738 qdesc->qe_valid = 1;
James Smart1ba981f2014-02-20 09:56:45 -050012739 phba->sli4_hba.fof_eq = qdesc;
12740
James Smartf38fa0b2014-04-04 13:52:21 -040012741 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050012742
12743 /* Create OAS CQ */
James Smartc176ffa2018-01-30 15:58:46 -080012744 if (phba->enab_exp_wqcq_pages)
James Smarta51e41b2017-12-08 17:18:06 -080012745 qdesc = lpfc_sli4_queue_alloc(phba,
12746 LPFC_EXPANDED_PAGE_SIZE,
12747 phba->sli4_hba.cq_esize,
12748 LPFC_CQE_EXP_COUNT);
12749 else
12750 qdesc = lpfc_sli4_queue_alloc(phba,
12751 LPFC_DEFAULT_PAGE_SIZE,
12752 phba->sli4_hba.cq_esize,
12753 phba->sli4_hba.cq_ecount);
James Smart1ba981f2014-02-20 09:56:45 -050012754 if (!qdesc)
12755 goto out_error;
12756
James Smart7365f6f2018-02-22 08:18:46 -080012757 qdesc->qe_valid = 1;
James Smart1ba981f2014-02-20 09:56:45 -050012758 phba->sli4_hba.oas_cq = qdesc;
12759
12760 /* Create OAS WQ */
James Smartc176ffa2018-01-30 15:58:46 -080012761 if (phba->enab_exp_wqcq_pages) {
12762 wqesize = (phba->fcp_embed_io) ?
12763 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
James Smarta51e41b2017-12-08 17:18:06 -080012764 qdesc = lpfc_sli4_queue_alloc(phba,
12765 LPFC_EXPANDED_PAGE_SIZE,
James Smartc176ffa2018-01-30 15:58:46 -080012766 wqesize,
James Smarta51e41b2017-12-08 17:18:06 -080012767 LPFC_WQE_EXP_COUNT);
James Smartc176ffa2018-01-30 15:58:46 -080012768 } else
James Smarta51e41b2017-12-08 17:18:06 -080012769 qdesc = lpfc_sli4_queue_alloc(phba,
12770 LPFC_DEFAULT_PAGE_SIZE,
12771 phba->sli4_hba.wq_esize,
12772 phba->sli4_hba.wq_ecount);
James Smartc176ffa2018-01-30 15:58:46 -080012773
James Smart1ba981f2014-02-20 09:56:45 -050012774 if (!qdesc)
12775 goto out_error;
12776
12777 phba->sli4_hba.oas_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -080012778 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
James Smart1ba981f2014-02-20 09:56:45 -050012779
12780 }
12781 return 0;
12782
12783out_error:
12784 lpfc_fof_queue_destroy(phba);
12785 return -ENOMEM;
12786}
12787
12788/**
12789 * lpfc_fof_queue_destroy - Destroy all the fof queues
12790 * @phba: pointer to lpfc hba data structure.
12791 *
12792 * This routine is invoked to release all the SLI4 queues with the FC HBA
12793 * operation.
12794 *
12795 * Return codes
12796 * 0 - successful
12797 **/
12798int
12799lpfc_fof_queue_destroy(struct lpfc_hba *phba)
12800{
12801 /* Release FOF Event queue */
12802 if (phba->sli4_hba.fof_eq != NULL) {
12803 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
12804 phba->sli4_hba.fof_eq = NULL;
12805 }
12806
12807 /* Release OAS Completion queue */
12808 if (phba->sli4_hba.oas_cq != NULL) {
12809 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
12810 phba->sli4_hba.oas_cq = NULL;
12811 }
12812
12813 /* Release OAS Work queue */
12814 if (phba->sli4_hba.oas_wq != NULL) {
12815 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
12816 phba->sli4_hba.oas_wq = NULL;
12817 }
12818 return 0;
12819}
12820
dea31012005-04-17 16:05:31 -050012821MODULE_DEVICE_TABLE(pci, lpfc_id_table);
12822
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070012823static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060012824 .error_detected = lpfc_io_error_detected,
12825 .slot_reset = lpfc_io_slot_reset,
12826 .resume = lpfc_io_resume,
12827};
12828
dea31012005-04-17 16:05:31 -050012829static struct pci_driver lpfc_driver = {
12830 .name = LPFC_DRIVER_NAME,
12831 .id_table = lpfc_id_table,
12832 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012833 .remove = lpfc_pci_remove_one,
Anton Blanchard85e8a232017-02-13 08:49:20 +110012834 .shutdown = lpfc_pci_remove_one,
James Smart3a55b532008-12-04 22:38:54 -050012835 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040012836 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050012837 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050012838};
12839
James Smart3ef6d242012-01-18 16:23:48 -050012840static const struct file_operations lpfc_mgmt_fop = {
Al Viro858feac2013-04-14 22:39:37 -040012841 .owner = THIS_MODULE,
James Smart3ef6d242012-01-18 16:23:48 -050012842};
12843
12844static struct miscdevice lpfc_mgmt_dev = {
12845 .minor = MISC_DYNAMIC_MINOR,
12846 .name = "lpfcmgmt",
12847 .fops = &lpfc_mgmt_fop,
12848};
12849
James Smarte59058c2008-08-24 21:49:00 -040012850/**
James Smart3621a712009-04-06 18:47:14 -040012851 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040012852 *
12853 * This routine is to be invoked when the lpfc module is loaded into the
12854 * kernel. The special kernel macro module_init() is used to indicate the
12855 * role of this routine to the kernel as lpfc module entry point.
12856 *
12857 * Return codes
12858 * 0 - successful
12859 * -ENOMEM - FC attach transport failed
12860 * all others - failed
12861 */
dea31012005-04-17 16:05:31 -050012862static int __init
12863lpfc_init(void)
12864{
12865 int error = 0;
12866
12867 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012868 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050012869
James Smart3ef6d242012-01-18 16:23:48 -050012870 error = misc_register(&lpfc_mgmt_dev);
12871 if (error)
12872 printk(KERN_ERR "Could not register lpfcmgmt device, "
12873 "misc_register returned with status %d", error);
12874
James Smart458c0832016-07-06 12:36:07 -070012875 lpfc_transport_functions.vport_create = lpfc_vport_create;
12876 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
dea31012005-04-17 16:05:31 -050012877 lpfc_transport_template =
12878 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040012879 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050012880 return -ENOMEM;
James Smart458c0832016-07-06 12:36:07 -070012881 lpfc_vport_transport_template =
12882 fc_attach_transport(&lpfc_vport_transport_functions);
12883 if (lpfc_vport_transport_template == NULL) {
12884 fc_release_transport(lpfc_transport_template);
12885 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040012886 }
James Smart5fd11082018-03-05 12:04:04 -080012887 lpfc_nvme_cmd_template();
James Smartbd3061b2018-03-05 12:04:05 -080012888 lpfc_nvmet_cmd_template();
James Smart7bb03bb2013-04-17 20:19:16 -040012889
12890 /* Initialize in case vector mapping is needed */
James Smartb246de12013-05-31 17:03:07 -040012891 lpfc_used_cpu = NULL;
James Smart2ea259e2017-02-12 13:52:27 -080012892 lpfc_present_cpu = num_present_cpus();
James Smart7bb03bb2013-04-17 20:19:16 -040012893
dea31012005-04-17 16:05:31 -050012894 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050012895 if (error) {
dea31012005-04-17 16:05:31 -050012896 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070012897 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050012898 }
dea31012005-04-17 16:05:31 -050012899
12900 return error;
12901}
12902
James Smarte59058c2008-08-24 21:49:00 -040012903/**
James Smart3621a712009-04-06 18:47:14 -040012904 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040012905 *
12906 * This routine is invoked when the lpfc module is removed from the kernel.
12907 * The special kernel macro module_exit() is used to indicate the role of
12908 * this routine to the kernel as lpfc module exit point.
12909 */
dea31012005-04-17 16:05:31 -050012910static void __exit
12911lpfc_exit(void)
12912{
James Smart3ef6d242012-01-18 16:23:48 -050012913 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050012914 pci_unregister_driver(&lpfc_driver);
12915 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070012916 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050012917 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040012918 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
12919 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050012920 (1L << _dump_buf_data_order), _dump_buf_data);
12921 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
12922 }
12923
12924 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040012925 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
12926 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050012927 (1L << _dump_buf_dif_order), _dump_buf_dif);
12928 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
12929 }
James Smartb246de12013-05-31 17:03:07 -040012930 kfree(lpfc_used_cpu);
Johannes Thumshirn79739672015-08-31 16:48:11 -040012931 idr_destroy(&lpfc_hba_index);
dea31012005-04-17 16:05:31 -050012932}
12933
12934module_init(lpfc_init);
12935module_exit(lpfc_exit);
12936MODULE_LICENSE("GPL");
12937MODULE_DESCRIPTION(LPFC_MODULE_DESC);
James Smartd080abe2017-02-12 13:52:39 -080012938MODULE_AUTHOR("Broadcom");
dea31012005-04-17 16:05:31 -050012939MODULE_VERSION("0:" LPFC_DRIVER_VERSION);