blob: 576ab7ec7e9d7bcddc58a8e3953a158f40db9e11 [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 Smartd080abe2017-02-12 13:52:39 -08005 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
James Smart50611572016-03-31 14:12:34 -07006 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * EMULEX and SLI are trademarks of Emulex. *
James Smartd080abe2017-02-12 13:52:39 -08008 * www.broadcom.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04009 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -050010 * *
11 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
dea31012005-04-17 16:05:31 -050022 *******************************************************************/
23
dea31012005-04-17 16:05:31 -050024#include <linux/blkdev.h>
25#include <linux/delay.h>
26#include <linux/dma-mapping.h>
27#include <linux/idr.h>
28#include <linux/interrupt.h>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040029#include <linux/module.h>
dea31012005-04-17 16:05:31 -050030#include <linux/kthread.h>
31#include <linux/pci.h>
32#include <linux/spinlock.h>
James Smart92d7f7b2007-06-17 19:56:38 -050033#include <linux/ctype.h>
James Smart0d878412009-10-02 15:16:56 -040034#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
James Smart52d52442011-05-24 11:42:45 -040036#include <linux/firmware.h>
James Smart3ef6d242012-01-18 16:23:48 -050037#include <linux/miscdevice.h>
James Smart7bb03bb2013-04-17 20:19:16 -040038#include <linux/percpu.h>
James Smart895427b2017-02-12 13:52:30 -080039#include <linux/msi.h>
Maurizio Lombardi286871a2017-08-23 16:55:48 -070040#include <linux/bitops.h>
dea31012005-04-17 16:05:31 -050041
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040042#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050043#include <scsi/scsi_device.h>
44#include <scsi/scsi_host.h>
45#include <scsi/scsi_transport_fc.h>
James Smart86c67372017-04-21 16:05:04 -070046#include <scsi/scsi_tcq.h>
47#include <scsi/fc/fc_fs.h>
48
49#include <linux/nvme-fc-driver.h>
dea31012005-04-17 16:05:31 -050050
James Smartda0436e2009-05-22 14:51:39 -040051#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050052#include "lpfc_hw.h"
53#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040054#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040055#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050056#include "lpfc_disc.h"
dea31012005-04-17 16:05:31 -050057#include "lpfc.h"
James Smart895427b2017-02-12 13:52:30 -080058#include "lpfc_scsi.h"
59#include "lpfc_nvme.h"
James Smart86c67372017-04-21 16:05:04 -070060#include "lpfc_nvmet.h"
dea31012005-04-17 16:05:31 -050061#include "lpfc_logmsg.h"
62#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050063#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050064#include "lpfc_version.h"
James Smart12f44452016-07-06 12:36:03 -070065#include "lpfc_ids.h"
dea31012005-04-17 16:05:31 -050066
James Smart81301a92008-12-04 22:39:46 -050067char *_dump_buf_data;
68unsigned long _dump_buf_data_order;
69char *_dump_buf_dif;
70unsigned long _dump_buf_dif_order;
71spinlock_t _dump_buf_lock;
72
James Smart7bb03bb2013-04-17 20:19:16 -040073/* Used when mapping IRQ vectors in a driver centric manner */
James Smartb246de12013-05-31 17:03:07 -040074uint16_t *lpfc_used_cpu;
75uint32_t lpfc_present_cpu;
James Smart7bb03bb2013-04-17 20:19:16 -040076
dea31012005-04-17 16:05:31 -050077static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
78static int lpfc_post_rcv_buf(struct lpfc_hba *);
James Smart5350d872011-10-10 21:33:49 -040079static int lpfc_sli4_queue_verify(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040080static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
81static int lpfc_setup_endian_order(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040082static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040083static void lpfc_free_els_sgl_list(struct lpfc_hba *);
James Smartf358dd02017-02-12 13:52:34 -080084static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040085static void lpfc_init_sgl_list(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040086static int lpfc_init_active_sgl_array(struct lpfc_hba *);
87static void lpfc_free_active_sgl(struct lpfc_hba *);
88static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
89static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
90static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
91static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
92static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
James Smart618a5232012-06-12 13:54:36 -040093static void lpfc_sli4_disable_intr(struct lpfc_hba *);
94static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
James Smart1ba981f2014-02-20 09:56:45 -050095static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
dea31012005-04-17 16:05:31 -050096
97static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050098static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -050099static DEFINE_IDR(lpfc_hba_index);
James Smartf358dd02017-02-12 13:52:34 -0800100#define LPFC_NVMET_BUF_POST 254
dea31012005-04-17 16:05:31 -0500101
James Smarte59058c2008-08-24 21:49:00 -0400102/**
James Smart3621a712009-04-06 18:47:14 -0400103 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
James Smarte59058c2008-08-24 21:49:00 -0400104 * @phba: pointer to lpfc hba data structure.
105 *
106 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
107 * mailbox command. It retrieves the revision information from the HBA and
108 * collects the Vital Product Data (VPD) about the HBA for preparing the
109 * configuration of the HBA.
110 *
111 * Return codes:
112 * 0 - success.
113 * -ERESTART - requests the SLI layer to reset the HBA and try again.
114 * Any other value - indicates an error.
115 **/
dea31012005-04-17 16:05:31 -0500116int
James Smart2e0fef82007-06-17 19:56:36 -0500117lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500118{
119 lpfc_vpd_t *vp = &phba->vpd;
120 int i = 0, rc;
121 LPFC_MBOXQ_t *pmb;
122 MAILBOX_t *mb;
123 char *lpfc_vpd_data = NULL;
124 uint16_t offset = 0;
125 static char licensed[56] =
126 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -0400127 static int init_key = 1;
dea31012005-04-17 16:05:31 -0500128
129 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
130 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500131 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500132 return -ENOMEM;
133 }
134
James Smart04c68492009-05-22 14:52:52 -0400135 mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -0500136 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -0500137
138 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -0400139 if (init_key) {
140 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -0500141
James Smart65a29c12006-07-06 15:50:50 -0400142 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
143 *ptext = cpu_to_be32(*ptext);
144 init_key = 0;
145 }
dea31012005-04-17 16:05:31 -0500146
147 lpfc_read_nv(phba, pmb);
148 memset((char*)mb->un.varRDnvp.rsvd3, 0,
149 sizeof (mb->un.varRDnvp.rsvd3));
150 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
151 sizeof (licensed));
152
153 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
154
155 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500156 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400157 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500158 "error, mbxCmd x%x READ_NVPARM, "
159 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500160 mb->mbxCommand, mb->mbxStatus);
161 mempool_free(pmb, phba->mbox_mem_pool);
162 return -ERESTART;
163 }
164 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500165 sizeof(phba->wwnn));
166 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
167 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500168 }
169
James Smart92d7f7b2007-06-17 19:56:38 -0500170 phba->sli3_options = 0x0;
171
dea31012005-04-17 16:05:31 -0500172 /* Setup and issue mailbox READ REV command */
173 lpfc_read_rev(phba, pmb);
174 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
175 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500176 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400177 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500178 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500179 mb->mbxCommand, mb->mbxStatus);
180 mempool_free( pmb, phba->mbox_mem_pool);
181 return -ERESTART;
182 }
183
James Smart92d7f7b2007-06-17 19:56:38 -0500184
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500185 /*
186 * The value of rr must be 1 since the driver set the cv field to 1.
187 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500188 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500189 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500190 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500191 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400192 "0440 Adapter failed to init, READ_REV has "
193 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500194 mempool_free(pmb, phba->mbox_mem_pool);
195 return -ERESTART;
dea31012005-04-17 16:05:31 -0500196 }
197
James Smart495a7142008-06-14 22:52:59 -0400198 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
199 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500200 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400201 }
James Smarted957682007-06-17 19:56:37 -0500202
dea31012005-04-17 16:05:31 -0500203 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500204 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500205 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500206 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
207 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
208 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
209 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500210 vp->rev.biuRev = mb->un.varRdRev.biuRev;
211 vp->rev.smRev = mb->un.varRdRev.smRev;
212 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
213 vp->rev.endecRev = mb->un.varRdRev.endecRev;
214 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
215 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
216 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
217 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
218 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
219 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
220
James Smart92d7f7b2007-06-17 19:56:38 -0500221 /* If the sli feature level is less then 9, we must
222 * tear down all RPIs and VPIs on link down if NPIV
223 * is enabled.
224 */
225 if (vp->rev.feaLevelHigh < 9)
226 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
227
dea31012005-04-17 16:05:31 -0500228 if (lpfc_is_LC_HBA(phba->pcidev->device))
229 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
230 sizeof (phba->RandomData));
231
dea31012005-04-17 16:05:31 -0500232 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500233 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
234 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400235 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500236 do {
James Smarta0c87cb2009-07-19 10:01:10 -0400237 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
dea31012005-04-17 16:05:31 -0500238 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
239
240 if (rc != MBX_SUCCESS) {
241 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400242 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500243 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500244 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500245 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500246 }
James Smart04c68492009-05-22 14:52:52 -0400247 /* dump mem may return a zero when finished or we got a
248 * mailbox error, either way we are done.
249 */
250 if (mb->un.varDmp.word_cnt == 0)
251 break;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500252 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
253 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400254 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
255 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500256 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500257 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500258 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
259 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500260
261 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500262out_free_mbox:
263 mempool_free(pmb, phba->mbox_mem_pool);
264 return 0;
265}
266
James Smarte59058c2008-08-24 21:49:00 -0400267/**
James Smart3621a712009-04-06 18:47:14 -0400268 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
James Smarte59058c2008-08-24 21:49:00 -0400269 * @phba: pointer to lpfc hba data structure.
270 * @pmboxq: pointer to the driver internal queue element for mailbox command.
271 *
272 * This is the completion handler for driver's configuring asynchronous event
273 * mailbox command to the device. If the mailbox command returns successfully,
274 * it will set internal async event support flag to 1; otherwise, it will
275 * set internal async event support flag to 0.
276 **/
James Smart57127f12007-10-27 13:37:05 -0400277static void
278lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
279{
James Smart04c68492009-05-22 14:52:52 -0400280 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
James Smart57127f12007-10-27 13:37:05 -0400281 phba->temp_sensor_support = 1;
282 else
283 phba->temp_sensor_support = 0;
284 mempool_free(pmboxq, phba->mbox_mem_pool);
285 return;
286}
287
James Smarte59058c2008-08-24 21:49:00 -0400288/**
James Smart3621a712009-04-06 18:47:14 -0400289 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
James Smart97207482008-12-04 22:39:19 -0500290 * @phba: pointer to lpfc hba data structure.
291 * @pmboxq: pointer to the driver internal queue element for mailbox command.
292 *
293 * This is the completion handler for dump mailbox command for getting
294 * wake up parameters. When this command complete, the response contain
295 * Option rom version of the HBA. This function translate the version number
296 * into a human readable string and store it in OptionROMVersion.
297 **/
298static void
299lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
300{
301 struct prog_id *prg;
302 uint32_t prog_id_word;
303 char dist = ' ';
304 /* character array used for decoding dist type. */
305 char dist_char[] = "nabx";
306
James Smart04c68492009-05-22 14:52:52 -0400307 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
James Smart9f1e1b52008-12-04 22:39:40 -0500308 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500309 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500310 }
James Smart97207482008-12-04 22:39:19 -0500311
312 prg = (struct prog_id *) &prog_id_word;
313
314 /* word 7 contain option rom version */
James Smart04c68492009-05-22 14:52:52 -0400315 prog_id_word = pmboxq->u.mb.un.varWords[7];
James Smart97207482008-12-04 22:39:19 -0500316
317 /* Decode the Option rom version word to a readable string */
318 if (prg->dist < 4)
319 dist = dist_char[prg->dist];
320
321 if ((prg->dist == 3) && (prg->num == 0))
James Smarta2fc4aef2014-09-03 12:57:55 -0400322 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
James Smart97207482008-12-04 22:39:19 -0500323 prg->ver, prg->rev, prg->lev);
324 else
James Smarta2fc4aef2014-09-03 12:57:55 -0400325 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
James Smart97207482008-12-04 22:39:19 -0500326 prg->ver, prg->rev, prg->lev,
327 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500328 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500329 return;
330}
331
332/**
James Smart05580562011-05-24 11:40:48 -0400333 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
334 * cfg_soft_wwnn, cfg_soft_wwpn
335 * @vport: pointer to lpfc vport data structure.
336 *
337 *
338 * Return codes
339 * None.
340 **/
341void
342lpfc_update_vport_wwn(struct lpfc_vport *vport)
343{
James Smartaeb3c812017-04-21 16:05:02 -0700344 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
345 u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0];
346
James Smart05580562011-05-24 11:40:48 -0400347 /* If the soft name exists then update it using the service params */
348 if (vport->phba->cfg_soft_wwnn)
349 u64_to_wwn(vport->phba->cfg_soft_wwnn,
350 vport->fc_sparam.nodeName.u.wwn);
351 if (vport->phba->cfg_soft_wwpn)
352 u64_to_wwn(vport->phba->cfg_soft_wwpn,
353 vport->fc_sparam.portName.u.wwn);
354
355 /*
356 * If the name is empty or there exists a soft name
357 * then copy the service params name, otherwise use the fc name
358 */
359 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
360 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
361 sizeof(struct lpfc_name));
362 else
363 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
364 sizeof(struct lpfc_name));
365
James Smartaeb3c812017-04-21 16:05:02 -0700366 /*
367 * If the port name has changed, then set the Param changes flag
368 * to unreg the login
369 */
370 if (vport->fc_portname.u.wwn[0] != 0 &&
371 memcmp(&vport->fc_portname, &vport->fc_sparam.portName,
372 sizeof(struct lpfc_name)))
373 vport->vport_flag |= FAWWPN_PARAM_CHG;
374
375 if (vport->fc_portname.u.wwn[0] == 0 ||
376 vport->phba->cfg_soft_wwpn ||
377 (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) ||
378 vport->vport_flag & FAWWPN_SET) {
James Smart05580562011-05-24 11:40:48 -0400379 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
380 sizeof(struct lpfc_name));
James Smartaeb3c812017-04-21 16:05:02 -0700381 vport->vport_flag &= ~FAWWPN_SET;
382 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR)
383 vport->vport_flag |= FAWWPN_SET;
384 }
James Smart05580562011-05-24 11:40:48 -0400385 else
386 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
387 sizeof(struct lpfc_name));
388}
389
390/**
James Smart3621a712009-04-06 18:47:14 -0400391 * lpfc_config_port_post - Perform lpfc initialization after config port
James Smarte59058c2008-08-24 21:49:00 -0400392 * @phba: pointer to lpfc hba data structure.
393 *
394 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
395 * command call. It performs all internal resource and state setups on the
396 * port: post IOCB buffers, enable appropriate host interrupt attentions,
397 * ELS ring timers, etc.
398 *
399 * Return codes
400 * 0 - success.
401 * Any other value - error.
402 **/
dea31012005-04-17 16:05:31 -0500403int
James Smart2e0fef82007-06-17 19:56:36 -0500404lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500405{
James Smart2e0fef82007-06-17 19:56:36 -0500406 struct lpfc_vport *vport = phba->pport;
James Smarta257bf92009-04-06 18:48:10 -0400407 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500408 LPFC_MBOXQ_t *pmb;
409 MAILBOX_t *mb;
410 struct lpfc_dmabuf *mp;
411 struct lpfc_sli *psli = &phba->sli;
412 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500413 int i, j;
414 int rc;
dea31012005-04-17 16:05:31 -0500415
James Smart7af67052007-10-27 13:38:11 -0400416 spin_lock_irq(&phba->hbalock);
417 /*
418 * If the Config port completed correctly the HBA is not
419 * over heated any more.
420 */
421 if (phba->over_temp_state == HBA_OVER_TEMP)
422 phba->over_temp_state = HBA_NORMAL_TEMP;
423 spin_unlock_irq(&phba->hbalock);
424
dea31012005-04-17 16:05:31 -0500425 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
426 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500427 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500428 return -ENOMEM;
429 }
James Smart04c68492009-05-22 14:52:52 -0400430 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500431
dea31012005-04-17 16:05:31 -0500432 /* Get login parameters for NID. */
James Smart9f1177a2010-02-26 14:12:57 -0500433 rc = lpfc_read_sparam(phba, pmb, 0);
434 if (rc) {
435 mempool_free(pmb, phba->mbox_mem_pool);
436 return -ENOMEM;
437 }
438
James Smarted957682007-06-17 19:56:37 -0500439 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500440 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500441 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400442 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500443 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500444 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500445 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500446 mp = (struct lpfc_dmabuf *) pmb->context1;
James Smart9f1177a2010-02-26 14:12:57 -0500447 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500448 lpfc_mbuf_free(phba, mp->virt, mp->phys);
449 kfree(mp);
450 return -EIO;
451 }
452
453 mp = (struct lpfc_dmabuf *) pmb->context1;
454
James Smart2e0fef82007-06-17 19:56:36 -0500455 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500456 lpfc_mbuf_free(phba, mp->virt, mp->phys);
457 kfree(mp);
458 pmb->context1 = NULL;
James Smart05580562011-05-24 11:40:48 -0400459 lpfc_update_vport_wwn(vport);
James Smarta257bf92009-04-06 18:48:10 -0400460
461 /* Update the fc_host data structures with new wwn. */
462 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
463 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart21e9a0a2009-05-22 14:53:21 -0400464 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smarta257bf92009-04-06 18:48:10 -0400465
dea31012005-04-17 16:05:31 -0500466 /* If no serial number in VPD data, use low 6 bytes of WWNN */
467 /* This should be consolidated into parse_vpd ? - mr */
468 if (phba->SerialNumber[0] == 0) {
469 uint8_t *outptr;
470
James Smart2e0fef82007-06-17 19:56:36 -0500471 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500472 for (i = 0; i < 12; i++) {
473 status = *outptr++;
474 j = ((status & 0xf0) >> 4);
475 if (j <= 9)
476 phba->SerialNumber[i] =
477 (char)((uint8_t) 0x30 + (uint8_t) j);
478 else
479 phba->SerialNumber[i] =
480 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
481 i++;
482 j = (status & 0xf);
483 if (j <= 9)
484 phba->SerialNumber[i] =
485 (char)((uint8_t) 0x30 + (uint8_t) j);
486 else
487 phba->SerialNumber[i] =
488 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
489 }
490 }
491
dea31012005-04-17 16:05:31 -0500492 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500493 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500494 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500495 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400496 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500497 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500498 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500499 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500500 mempool_free( pmb, phba->mbox_mem_pool);
501 return -EIO;
502 }
503
James Smarta0c87cb2009-07-19 10:01:10 -0400504 /* Check if the port is disabled */
505 lpfc_sli_read_link_ste(phba);
506
dea31012005-04-17 16:05:31 -0500507 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -0400508 i = (mb->un.varRdConfig.max_xri + 1);
509 if (phba->cfg_hba_queue_depth > i) {
510 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
511 "3359 HBA queue depth changed from %d to %d\n",
512 phba->cfg_hba_queue_depth, i);
513 phba->cfg_hba_queue_depth = i;
514 }
515
516 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
517 i = (mb->un.varRdConfig.max_xri >> 3);
518 if (phba->pport->cfg_lun_queue_depth > i) {
519 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
520 "3360 LUN queue depth changed from %d to %d\n",
521 phba->pport->cfg_lun_queue_depth, i);
522 phba->pport->cfg_lun_queue_depth = i;
523 }
dea31012005-04-17 16:05:31 -0500524
525 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500526
527 /* Get the default values for Model Name and Description */
528 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
529
James Smart2e0fef82007-06-17 19:56:36 -0500530 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500531
James Smart0b727fe2007-10-27 13:37:25 -0400532 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smart895427b2017-02-12 13:52:30 -0800533 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
534 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
535 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
536 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500537
538 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500539 if (phba->sli_rev != 3)
540 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500541
James Smart93996272008-08-24 21:50:30 -0400542 /*
543 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
544 */
545 if (phba->intr_type == MSIX) {
546 rc = lpfc_config_msi(phba, pmb);
547 if (rc) {
548 mempool_free(pmb, phba->mbox_mem_pool);
549 return -EIO;
550 }
551 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
552 if (rc != MBX_SUCCESS) {
553 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
554 "0352 Config MSI mailbox command "
555 "failed, mbxCmd x%x, mbxStatus x%x\n",
James Smart04c68492009-05-22 14:52:52 -0400556 pmb->u.mb.mbxCommand,
557 pmb->u.mb.mbxStatus);
James Smart93996272008-08-24 21:50:30 -0400558 mempool_free(pmb, phba->mbox_mem_pool);
559 return -EIO;
560 }
561 }
562
James Smart04c68492009-05-22 14:52:52 -0400563 spin_lock_irq(&phba->hbalock);
James Smart93996272008-08-24 21:50:30 -0400564 /* Initialize ERATT handling flag */
565 phba->hba_flag &= ~HBA_ERATT_HANDLED;
566
dea31012005-04-17 16:05:31 -0500567 /* Enable appropriate host interrupts */
James Smart9940b972011-03-11 16:06:12 -0500568 if (lpfc_readl(phba->HCregaddr, &status)) {
569 spin_unlock_irq(&phba->hbalock);
570 return -EIO;
571 }
dea31012005-04-17 16:05:31 -0500572 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
573 if (psli->num_rings > 0)
574 status |= HC_R0INT_ENA;
575 if (psli->num_rings > 1)
576 status |= HC_R1INT_ENA;
577 if (psli->num_rings > 2)
578 status |= HC_R2INT_ENA;
579 if (psli->num_rings > 3)
580 status |= HC_R3INT_ENA;
581
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500582 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
583 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400584 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500585
dea31012005-04-17 16:05:31 -0500586 writel(status, phba->HCregaddr);
587 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500588 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500589
James Smart93996272008-08-24 21:50:30 -0400590 /* Set up ring-0 (ELS) timer */
591 timeout = phba->fc_ratov * 2;
James Smart256ec0d2013-04-17 20:14:58 -0400592 mod_timer(&vport->els_tmofunc,
593 jiffies + msecs_to_jiffies(1000 * timeout));
James Smart93996272008-08-24 21:50:30 -0400594 /* Set up heart beat (HB) timer */
James Smart256ec0d2013-04-17 20:14:58 -0400595 mod_timer(&phba->hb_tmofunc,
596 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -0500597 phba->hb_outstanding = 0;
598 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400599 /* Set up error attention (ERATT) polling timer */
James Smart256ec0d2013-04-17 20:14:58 -0400600 mod_timer(&phba->eratt_poll,
James Smart65791f12016-07-06 12:35:56 -0700601 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
dea31012005-04-17 16:05:31 -0500602
James Smarta0c87cb2009-07-19 10:01:10 -0400603 if (phba->hba_flag & LINK_DISABLED) {
604 lpfc_printf_log(phba,
605 KERN_ERR, LOG_INIT,
606 "2598 Adapter Link is disabled.\n");
607 lpfc_down_link(phba, pmb);
608 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
609 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
610 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
611 lpfc_printf_log(phba,
612 KERN_ERR, LOG_INIT,
613 "2599 Adapter failed to issue DOWN_LINK"
614 " mbox command rc 0x%x\n", rc);
615
616 mempool_free(pmb, phba->mbox_mem_pool);
617 return -EIO;
618 }
James Smarte40a02c2010-02-26 14:13:54 -0500619 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
James Smart026abb82011-12-13 13:20:45 -0500620 mempool_free(pmb, phba->mbox_mem_pool);
621 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
622 if (rc)
623 return rc;
dea31012005-04-17 16:05:31 -0500624 }
625 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400626 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500627 if (!pmb) {
628 phba->link_state = LPFC_HBA_ERROR;
629 return -ENOMEM;
630 }
631
James Smart57127f12007-10-27 13:37:05 -0400632 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
633 pmb->mbox_cmpl = lpfc_config_async_cmpl;
634 pmb->vport = phba->pport;
635 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500636
James Smart57127f12007-10-27 13:37:05 -0400637 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
638 lpfc_printf_log(phba,
639 KERN_ERR,
640 LOG_INIT,
641 "0456 Adapter failed to issue "
James Smarte4e74272009-07-19 10:01:38 -0400642 "ASYNCEVT_ENABLE mbox status x%x\n",
James Smart57127f12007-10-27 13:37:05 -0400643 rc);
644 mempool_free(pmb, phba->mbox_mem_pool);
645 }
James Smart97207482008-12-04 22:39:19 -0500646
647 /* Get Option rom version */
648 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500649 if (!pmb) {
650 phba->link_state = LPFC_HBA_ERROR;
651 return -ENOMEM;
652 }
653
James Smart97207482008-12-04 22:39:19 -0500654 lpfc_dump_wakeup_param(phba, pmb);
655 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
656 pmb->vport = phba->pport;
657 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
658
659 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
660 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
James Smarte4e74272009-07-19 10:01:38 -0400661 "to get Option ROM version status x%x\n", rc);
James Smart97207482008-12-04 22:39:19 -0500662 mempool_free(pmb, phba->mbox_mem_pool);
663 }
664
James Smartd7c255b2008-08-24 21:50:00 -0400665 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400666}
667
James Smarte59058c2008-08-24 21:49:00 -0400668/**
James Smart84d1b002010-02-12 14:42:33 -0500669 * lpfc_hba_init_link - Initialize the FC link
670 * @phba: pointer to lpfc hba data structure.
James Smart6e7288d2010-06-07 15:23:35 -0400671 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500672 *
673 * This routine will issue the INIT_LINK mailbox command call.
674 * It is available to other drivers through the lpfc_hba data
675 * structure for use as a delayed link up mechanism with the
676 * module parameter lpfc_suppress_link_up.
677 *
678 * Return code
679 * 0 - success
680 * Any other value - error
681 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400682static int
James Smart6e7288d2010-06-07 15:23:35 -0400683lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500684{
James Smart1b511972011-12-13 13:23:09 -0500685 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
686}
687
688/**
689 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
690 * @phba: pointer to lpfc hba data structure.
691 * @fc_topology: desired fc topology.
692 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
693 *
694 * This routine will issue the INIT_LINK mailbox command call.
695 * It is available to other drivers through the lpfc_hba data
696 * structure for use as a delayed link up mechanism with the
697 * module parameter lpfc_suppress_link_up.
698 *
699 * Return code
700 * 0 - success
701 * Any other value - error
702 **/
703int
704lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
705 uint32_t flag)
706{
James Smart84d1b002010-02-12 14:42:33 -0500707 struct lpfc_vport *vport = phba->pport;
708 LPFC_MBOXQ_t *pmb;
709 MAILBOX_t *mb;
710 int rc;
711
712 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
713 if (!pmb) {
714 phba->link_state = LPFC_HBA_ERROR;
715 return -ENOMEM;
716 }
717 mb = &pmb->u.mb;
718 pmb->vport = vport;
719
James Smart026abb82011-12-13 13:20:45 -0500720 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
721 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
722 !(phba->lmt & LMT_1Gb)) ||
723 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
724 !(phba->lmt & LMT_2Gb)) ||
725 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
726 !(phba->lmt & LMT_4Gb)) ||
727 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
728 !(phba->lmt & LMT_8Gb)) ||
729 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
730 !(phba->lmt & LMT_10Gb)) ||
731 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
James Smartd38dd522015-08-31 16:48:17 -0400732 !(phba->lmt & LMT_16Gb)) ||
733 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
James Smartfbd8a6b2018-02-22 08:18:45 -0800734 !(phba->lmt & LMT_32Gb)) ||
735 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) &&
736 !(phba->lmt & LMT_64Gb))) {
James Smart026abb82011-12-13 13:20:45 -0500737 /* Reset link speed to auto */
738 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
739 "1302 Invalid speed for this board:%d "
740 "Reset link speed to auto.\n",
741 phba->cfg_link_speed);
742 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
743 }
James Smart1b511972011-12-13 13:23:09 -0500744 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
James Smart84d1b002010-02-12 14:42:33 -0500745 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart1b511972011-12-13 13:23:09 -0500746 if (phba->sli_rev < LPFC_SLI_REV4)
747 lpfc_set_loopback_flag(phba);
James Smart6e7288d2010-06-07 15:23:35 -0400748 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart76a95d72010-11-20 23:11:48 -0500749 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
James Smart84d1b002010-02-12 14:42:33 -0500750 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
751 "0498 Adapter failed to init, mbxCmd x%x "
752 "INIT_LINK, mbxStatus x%x\n",
753 mb->mbxCommand, mb->mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -0500754 if (phba->sli_rev <= LPFC_SLI_REV3) {
755 /* Clear all interrupt enable conditions */
756 writel(0, phba->HCregaddr);
757 readl(phba->HCregaddr); /* flush */
758 /* Clear all pending interrupts */
759 writel(0xffffffff, phba->HAregaddr);
760 readl(phba->HAregaddr); /* flush */
761 }
James Smart84d1b002010-02-12 14:42:33 -0500762 phba->link_state = LPFC_HBA_ERROR;
James Smart6e7288d2010-06-07 15:23:35 -0400763 if (rc != MBX_BUSY || flag == MBX_POLL)
James Smart84d1b002010-02-12 14:42:33 -0500764 mempool_free(pmb, phba->mbox_mem_pool);
765 return -EIO;
766 }
James Smarte40a02c2010-02-26 14:13:54 -0500767 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
James Smart6e7288d2010-06-07 15:23:35 -0400768 if (flag == MBX_POLL)
769 mempool_free(pmb, phba->mbox_mem_pool);
James Smart84d1b002010-02-12 14:42:33 -0500770
771 return 0;
772}
773
774/**
775 * lpfc_hba_down_link - this routine downs the FC link
James Smart6e7288d2010-06-07 15:23:35 -0400776 * @phba: pointer to lpfc hba data structure.
777 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500778 *
779 * This routine will issue the DOWN_LINK mailbox command call.
780 * It is available to other drivers through the lpfc_hba data
781 * structure for use to stop the link.
782 *
783 * Return code
784 * 0 - success
785 * Any other value - error
786 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400787static int
James Smart6e7288d2010-06-07 15:23:35 -0400788lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500789{
790 LPFC_MBOXQ_t *pmb;
791 int rc;
792
793 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
794 if (!pmb) {
795 phba->link_state = LPFC_HBA_ERROR;
796 return -ENOMEM;
797 }
798
799 lpfc_printf_log(phba,
800 KERN_ERR, LOG_INIT,
801 "0491 Adapter Link is disabled.\n");
802 lpfc_down_link(phba, pmb);
803 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart6e7288d2010-06-07 15:23:35 -0400804 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart84d1b002010-02-12 14:42:33 -0500805 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
806 lpfc_printf_log(phba,
807 KERN_ERR, LOG_INIT,
808 "2522 Adapter failed to issue DOWN_LINK"
809 " mbox command rc 0x%x\n", rc);
810
811 mempool_free(pmb, phba->mbox_mem_pool);
812 return -EIO;
813 }
James Smart6e7288d2010-06-07 15:23:35 -0400814 if (flag == MBX_POLL)
815 mempool_free(pmb, phba->mbox_mem_pool);
816
James Smart84d1b002010-02-12 14:42:33 -0500817 return 0;
818}
819
820/**
James Smart3621a712009-04-06 18:47:14 -0400821 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400822 * @phba: pointer to lpfc HBA data structure.
823 *
824 * This routine will do LPFC uninitialization before the HBA is reset when
825 * bringing down the SLI Layer.
826 *
827 * Return codes
828 * 0 - success.
829 * Any other value - error.
830 **/
dea31012005-04-17 16:05:31 -0500831int
James Smart2e0fef82007-06-17 19:56:36 -0500832lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500833{
James Smart1b32f6a2008-02-08 18:49:39 -0500834 struct lpfc_vport **vports;
835 int i;
James Smart3772a992009-05-22 14:50:54 -0400836
837 if (phba->sli_rev <= LPFC_SLI_REV3) {
838 /* Disable interrupts */
839 writel(0, phba->HCregaddr);
840 readl(phba->HCregaddr); /* flush */
841 }
dea31012005-04-17 16:05:31 -0500842
James Smart1b32f6a2008-02-08 18:49:39 -0500843 if (phba->pport->load_flag & FC_UNLOADING)
844 lpfc_cleanup_discovery_resources(phba->pport);
845 else {
846 vports = lpfc_create_vport_work_array(phba);
847 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -0400848 for (i = 0; i <= phba->max_vports &&
849 vports[i] != NULL; i++)
James Smart1b32f6a2008-02-08 18:49:39 -0500850 lpfc_cleanup_discovery_resources(vports[i]);
851 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500852 }
853 return 0;
dea31012005-04-17 16:05:31 -0500854}
855
James Smarte59058c2008-08-24 21:49:00 -0400856/**
James Smart68e814f2014-05-21 08:04:59 -0400857 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
858 * rspiocb which got deferred
859 *
860 * @phba: pointer to lpfc HBA data structure.
861 *
862 * This routine will cleanup completed slow path events after HBA is reset
863 * when bringing down the SLI Layer.
864 *
865 *
866 * Return codes
867 * void.
868 **/
869static void
870lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
871{
872 struct lpfc_iocbq *rspiocbq;
873 struct hbq_dmabuf *dmabuf;
874 struct lpfc_cq_event *cq_event;
875
876 spin_lock_irq(&phba->hbalock);
877 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
878 spin_unlock_irq(&phba->hbalock);
879
880 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
881 /* Get the response iocb from the head of work queue */
882 spin_lock_irq(&phba->hbalock);
883 list_remove_head(&phba->sli4_hba.sp_queue_event,
884 cq_event, struct lpfc_cq_event, list);
885 spin_unlock_irq(&phba->hbalock);
886
887 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
888 case CQE_CODE_COMPL_WQE:
889 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
890 cq_event);
891 lpfc_sli_release_iocbq(phba, rspiocbq);
892 break;
893 case CQE_CODE_RECEIVE:
894 case CQE_CODE_RECEIVE_V1:
895 dmabuf = container_of(cq_event, struct hbq_dmabuf,
896 cq_event);
897 lpfc_in_buf_free(phba, &dmabuf->dbuf);
898 }
899 }
900}
901
902/**
James Smartbcece5f2014-04-04 13:51:34 -0400903 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
904 * @phba: pointer to lpfc HBA data structure.
905 *
906 * This routine will cleanup posted ELS buffers after the HBA is reset
907 * when bringing down the SLI Layer.
908 *
909 *
910 * Return codes
911 * void.
912 **/
913static void
914lpfc_hba_free_post_buf(struct lpfc_hba *phba)
915{
916 struct lpfc_sli *psli = &phba->sli;
917 struct lpfc_sli_ring *pring;
918 struct lpfc_dmabuf *mp, *next_mp;
James Smart07eab622014-04-04 13:51:44 -0400919 LIST_HEAD(buflist);
920 int count;
James Smartbcece5f2014-04-04 13:51:34 -0400921
922 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
923 lpfc_sli_hbqbuf_free_all(phba);
924 else {
925 /* Cleanup preposted buffers on the ELS ring */
James Smart895427b2017-02-12 13:52:30 -0800926 pring = &psli->sli3_ring[LPFC_ELS_RING];
James Smart07eab622014-04-04 13:51:44 -0400927 spin_lock_irq(&phba->hbalock);
928 list_splice_init(&pring->postbufq, &buflist);
929 spin_unlock_irq(&phba->hbalock);
930
931 count = 0;
932 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
James Smartbcece5f2014-04-04 13:51:34 -0400933 list_del(&mp->list);
James Smart07eab622014-04-04 13:51:44 -0400934 count++;
James Smartbcece5f2014-04-04 13:51:34 -0400935 lpfc_mbuf_free(phba, mp->virt, mp->phys);
936 kfree(mp);
937 }
James Smart07eab622014-04-04 13:51:44 -0400938
939 spin_lock_irq(&phba->hbalock);
940 pring->postbufq_cnt -= count;
James Smartbcece5f2014-04-04 13:51:34 -0400941 spin_unlock_irq(&phba->hbalock);
942 }
943}
944
945/**
946 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
947 * @phba: pointer to lpfc HBA data structure.
948 *
949 * This routine will cleanup the txcmplq after the HBA is reset when bringing
950 * down the SLI Layer.
951 *
952 * Return codes
953 * void
954 **/
955static void
956lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
957{
958 struct lpfc_sli *psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -0800959 struct lpfc_queue *qp = NULL;
James Smartbcece5f2014-04-04 13:51:34 -0400960 struct lpfc_sli_ring *pring;
961 LIST_HEAD(completions);
962 int i;
James Smartc1dd9112018-01-30 15:58:57 -0800963 struct lpfc_iocbq *piocb, *next_iocb;
James Smartbcece5f2014-04-04 13:51:34 -0400964
James Smart895427b2017-02-12 13:52:30 -0800965 if (phba->sli_rev != LPFC_SLI_REV4) {
966 for (i = 0; i < psli->num_rings; i++) {
967 pring = &psli->sli3_ring[i];
James Smartbcece5f2014-04-04 13:51:34 -0400968 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -0800969 /* At this point in time the HBA is either reset or DOA
970 * Nothing should be on txcmplq as it will
971 * NEVER complete.
972 */
973 list_splice_init(&pring->txcmplq, &completions);
974 pring->txcmplq_cnt = 0;
James Smartbcece5f2014-04-04 13:51:34 -0400975 spin_unlock_irq(&phba->hbalock);
976
James Smart895427b2017-02-12 13:52:30 -0800977 lpfc_sli_abort_iocb_ring(phba, pring);
978 }
James Smartbcece5f2014-04-04 13:51:34 -0400979 /* Cancel all the IOCBs from the completions list */
James Smart895427b2017-02-12 13:52:30 -0800980 lpfc_sli_cancel_iocbs(phba, &completions,
981 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
982 return;
983 }
984 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
985 pring = qp->pring;
986 if (!pring)
987 continue;
988 spin_lock_irq(&pring->ring_lock);
James Smartc1dd9112018-01-30 15:58:57 -0800989 list_for_each_entry_safe(piocb, next_iocb,
990 &pring->txcmplq, list)
991 piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ;
James Smart895427b2017-02-12 13:52:30 -0800992 list_splice_init(&pring->txcmplq, &completions);
993 pring->txcmplq_cnt = 0;
994 spin_unlock_irq(&pring->ring_lock);
James Smartbcece5f2014-04-04 13:51:34 -0400995 lpfc_sli_abort_iocb_ring(phba, pring);
996 }
James Smart895427b2017-02-12 13:52:30 -0800997 /* Cancel all the IOCBs from the completions list */
998 lpfc_sli_cancel_iocbs(phba, &completions,
999 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smartbcece5f2014-04-04 13:51:34 -04001000}
1001
1002/**
James Smart3772a992009-05-22 14:50:54 -04001003 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smartbcece5f2014-04-04 13:51:34 -04001004 int i;
James Smarte59058c2008-08-24 21:49:00 -04001005 * @phba: pointer to lpfc HBA data structure.
1006 *
1007 * This routine will do uninitialization after the HBA is reset when bring
1008 * down the SLI Layer.
1009 *
1010 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001011 * 0 - success.
James Smarte59058c2008-08-24 21:49:00 -04001012 * Any other value - error.
1013 **/
James Smart3772a992009-05-22 14:50:54 -04001014static int
1015lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001016{
James Smartbcece5f2014-04-04 13:51:34 -04001017 lpfc_hba_free_post_buf(phba);
1018 lpfc_hba_clean_txcmplq(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001019 return 0;
1020}
James Smart5af5eee2010-10-22 11:06:38 -04001021
James Smartda0436e2009-05-22 14:51:39 -04001022/**
1023 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
1024 * @phba: pointer to lpfc HBA data structure.
1025 *
1026 * This routine will do uninitialization after the HBA is reset when bring
1027 * down the SLI Layer.
1028 *
1029 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001030 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001031 * Any other value - error.
1032 **/
1033static int
1034lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1035{
1036 struct lpfc_scsi_buf *psb, *psb_next;
James Smart86c67372017-04-21 16:05:04 -07001037 struct lpfc_nvmet_rcv_ctx *ctxp, *ctxp_next;
James Smartda0436e2009-05-22 14:51:39 -04001038 LIST_HEAD(aborts);
James Smart895427b2017-02-12 13:52:30 -08001039 LIST_HEAD(nvme_aborts);
James Smart86c67372017-04-21 16:05:04 -07001040 LIST_HEAD(nvmet_aborts);
James Smartda0436e2009-05-22 14:51:39 -04001041 unsigned long iflag = 0;
James Smart0f65ff62010-02-26 14:14:23 -05001042 struct lpfc_sglq *sglq_entry = NULL;
James Smartcf1a1d32017-12-08 17:18:03 -08001043 int cnt;
James Smart0f65ff62010-02-26 14:14:23 -05001044
James Smart895427b2017-02-12 13:52:30 -08001045
1046 lpfc_sli_hbqbuf_free_all(phba);
James Smartbcece5f2014-04-04 13:51:34 -04001047 lpfc_hba_clean_txcmplq(phba);
1048
James Smartda0436e2009-05-22 14:51:39 -04001049 /* At this point in time the HBA is either reset or DOA. Either
1050 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
James Smart895427b2017-02-12 13:52:30 -08001051 * on the lpfc_els_sgl_list so that it can either be freed if the
James Smartda0436e2009-05-22 14:51:39 -04001052 * driver is unloading or reposted if the driver is restarting
1053 * the port.
1054 */
James Smart895427b2017-02-12 13:52:30 -08001055 spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */
James Smartda0436e2009-05-22 14:51:39 -04001056 /* scsl_buf_list */
James Smart895427b2017-02-12 13:52:30 -08001057 /* sgl_list_lock required because worker thread uses this
James Smartda0436e2009-05-22 14:51:39 -04001058 * list.
1059 */
James Smart895427b2017-02-12 13:52:30 -08001060 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05001061 list_for_each_entry(sglq_entry,
1062 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1063 sglq_entry->state = SGL_FREED;
1064
James Smartda0436e2009-05-22 14:51:39 -04001065 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
James Smart895427b2017-02-12 13:52:30 -08001066 &phba->sli4_hba.lpfc_els_sgl_list);
1067
James Smartf358dd02017-02-12 13:52:34 -08001068
James Smart895427b2017-02-12 13:52:30 -08001069 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04001070 /* abts_scsi_buf_list_lock required because worker thread uses this
1071 * list.
1072 */
James Smart895427b2017-02-12 13:52:30 -08001073 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
1074 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1075 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
1076 &aborts);
1077 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1078 }
1079
1080 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1081 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1082 list_splice_init(&phba->sli4_hba.lpfc_abts_nvme_buf_list,
1083 &nvme_aborts);
James Smart86c67372017-04-21 16:05:04 -07001084 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list,
1085 &nvmet_aborts);
James Smart895427b2017-02-12 13:52:30 -08001086 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1087 }
1088
James Smartda0436e2009-05-22 14:51:39 -04001089 spin_unlock_irq(&phba->hbalock);
1090
1091 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1092 psb->pCmd = NULL;
1093 psb->status = IOSTAT_SUCCESS;
1094 }
James Smarta40fc5f2013-04-17 20:17:40 -04001095 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1096 list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
1097 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
James Smart68e814f2014-05-21 08:04:59 -04001098
James Smart86c67372017-04-21 16:05:04 -07001099 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smartcf1a1d32017-12-08 17:18:03 -08001100 cnt = 0;
James Smart86c67372017-04-21 16:05:04 -07001101 list_for_each_entry_safe(psb, psb_next, &nvme_aborts, list) {
1102 psb->pCmd = NULL;
1103 psb->status = IOSTAT_SUCCESS;
James Smartcf1a1d32017-12-08 17:18:03 -08001104 cnt++;
James Smart86c67372017-04-21 16:05:04 -07001105 }
1106 spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag);
James Smartcf1a1d32017-12-08 17:18:03 -08001107 phba->put_nvme_bufs += cnt;
James Smart86c67372017-04-21 16:05:04 -07001108 list_splice(&nvme_aborts, &phba->lpfc_nvme_buf_list_put);
1109 spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag);
1110
1111 list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) {
1112 ctxp->flag &= ~(LPFC_NVMET_XBUSY | LPFC_NVMET_ABORT_OP);
James Smart6c621a22017-05-15 15:20:45 -07001113 lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf);
James Smart86c67372017-04-21 16:05:04 -07001114 }
James Smart895427b2017-02-12 13:52:30 -08001115 }
James Smart895427b2017-02-12 13:52:30 -08001116
James Smart68e814f2014-05-21 08:04:59 -04001117 lpfc_sli4_free_sp_events(phba);
James Smartda0436e2009-05-22 14:51:39 -04001118 return 0;
1119}
1120
1121/**
1122 * lpfc_hba_down_post - Wrapper func for hba down post routine
1123 * @phba: pointer to lpfc HBA data structure.
1124 *
1125 * This routine wraps the actual SLI3 or SLI4 routine for performing
1126 * uninitialization after the HBA is reset when bring down the SLI Layer.
1127 *
1128 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001129 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001130 * Any other value - error.
1131 **/
1132int
1133lpfc_hba_down_post(struct lpfc_hba *phba)
1134{
1135 return (*phba->lpfc_hba_down_post)(phba);
1136}
Jamie Wellnitz41415862006-02-28 19:25:27 -05001137
James Smarte59058c2008-08-24 21:49:00 -04001138/**
James Smart3621a712009-04-06 18:47:14 -04001139 * lpfc_hb_timeout - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001140 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1141 *
1142 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1143 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1144 * work-port-events bitmap and the worker thread is notified. This timeout
1145 * event will be used by the worker thread to invoke the actual timeout
1146 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1147 * be performed in the timeout handler and the HBA timeout event bit shall
1148 * be cleared by the worker thread after it has taken the event bitmap out.
1149 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001150static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07001151lpfc_hb_timeout(struct timer_list *t)
James Smart858c9f62007-06-17 19:56:39 -05001152{
1153 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001154 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -05001155 unsigned long iflag;
1156
Kees Cookf22eb4d2017-09-06 20:24:26 -07001157 phba = from_timer(phba, t, hb_tmofunc);
James Smart93996272008-08-24 21:50:30 -04001158
1159 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -05001160 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001161 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1162 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -05001163 phba->pport->work_port_events |= WORKER_HB_TMO;
1164 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1165
James Smart93996272008-08-24 21:50:30 -04001166 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -04001167 if (!tmo_posted)
1168 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -05001169 return;
1170}
1171
James Smarte59058c2008-08-24 21:49:00 -04001172/**
James Smart19ca7602010-11-20 23:11:55 -05001173 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1174 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1175 *
1176 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1177 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1178 * work-port-events bitmap and the worker thread is notified. This timeout
1179 * event will be used by the worker thread to invoke the actual timeout
1180 * handler routine, lpfc_rrq_handler. Any periodical operations will
1181 * be performed in the timeout handler and the RRQ timeout event bit shall
1182 * be cleared by the worker thread after it has taken the event bitmap out.
1183 **/
1184static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07001185lpfc_rrq_timeout(struct timer_list *t)
James Smart19ca7602010-11-20 23:11:55 -05001186{
1187 struct lpfc_hba *phba;
James Smart19ca7602010-11-20 23:11:55 -05001188 unsigned long iflag;
1189
Kees Cookf22eb4d2017-09-06 20:24:26 -07001190 phba = from_timer(phba, t, rrq_tmr);
James Smart19ca7602010-11-20 23:11:55 -05001191 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001192 if (!(phba->pport->load_flag & FC_UNLOADING))
1193 phba->hba_flag |= HBA_RRQ_ACTIVE;
1194 else
1195 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
James Smart19ca7602010-11-20 23:11:55 -05001196 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001197
1198 if (!(phba->pport->load_flag & FC_UNLOADING))
1199 lpfc_worker_wake_up(phba);
James Smart19ca7602010-11-20 23:11:55 -05001200}
1201
1202/**
James Smart3621a712009-04-06 18:47:14 -04001203 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -04001204 * @phba: pointer to lpfc hba data structure.
1205 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1206 *
1207 * This is the callback function to the lpfc heart-beat mailbox command.
1208 * If configured, the lpfc driver issues the heart-beat mailbox command to
1209 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1210 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1211 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1212 * heart-beat outstanding state. Once the mailbox command comes back and
1213 * no error conditions detected, the heart-beat mailbox command timer is
1214 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1215 * state is cleared for the next heart-beat. If the timer expired with the
1216 * heart-beat outstanding state set, the driver will put the HBA offline.
1217 **/
James Smart858c9f62007-06-17 19:56:39 -05001218static void
1219lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1220{
1221 unsigned long drvr_flag;
1222
1223 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1224 phba->hb_outstanding = 0;
1225 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1226
James Smart93996272008-08-24 21:50:30 -04001227 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -05001228 mempool_free(pmboxq, phba->mbox_mem_pool);
1229 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1230 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -04001231 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -05001232 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001233 jiffies +
1234 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001235 return;
1236}
1237
James Smarte59058c2008-08-24 21:49:00 -04001238/**
James Smart3621a712009-04-06 18:47:14 -04001239 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001240 * @phba: pointer to lpfc hba data structure.
1241 *
1242 * This is the actual HBA-timer timeout handler to be invoked by the worker
1243 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1244 * handler performs any periodic operations needed for the device. If such
1245 * periodic event has already been attended to either in the interrupt handler
1246 * or by processing slow-ring or fast-ring events within the HBA-timer
1247 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1248 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1249 * is configured and there is no heart-beat mailbox command outstanding, a
1250 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1251 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1252 * to offline.
1253 **/
James Smart858c9f62007-06-17 19:56:39 -05001254void
1255lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1256{
James Smart45ed1192009-10-02 15:17:02 -04001257 struct lpfc_vport **vports;
James Smart858c9f62007-06-17 19:56:39 -05001258 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -05001259 struct lpfc_dmabuf *buf_ptr;
James Smart45ed1192009-10-02 15:17:02 -04001260 int retval, i;
James Smart858c9f62007-06-17 19:56:39 -05001261 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -05001262 LIST_HEAD(completions);
James Smart0cf07f842017-06-01 21:07:10 -07001263 struct lpfc_queue *qp;
1264 unsigned long time_elapsed;
1265 uint32_t tick_cqe, max_cqe, val;
1266 uint64_t tot, data1, data2, data3;
Dick Kennedy66d7ce92017-08-23 16:55:42 -07001267 struct lpfc_nvmet_tgtport *tgtp;
James Smart0cf07f842017-06-01 21:07:10 -07001268 struct lpfc_register reg_data;
1269 void __iomem *eqdreg = phba->sli4_hba.u.if_type2.EQDregaddr;
James Smart858c9f62007-06-17 19:56:39 -05001270
James Smart45ed1192009-10-02 15:17:02 -04001271 vports = lpfc_create_vport_work_array(phba);
1272 if (vports != NULL)
James Smart4258e982015-12-16 18:11:58 -05001273 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart45ed1192009-10-02 15:17:02 -04001274 lpfc_rcv_seq_check_edtov(vports[i]);
James Smart4258e982015-12-16 18:11:58 -05001275 lpfc_fdmi_num_disc_check(vports[i]);
1276 }
James Smart45ed1192009-10-02 15:17:02 -04001277 lpfc_destroy_vport_work_array(phba, vports);
1278
James Smart858c9f62007-06-17 19:56:39 -05001279 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -04001280 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -05001281 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1282 return;
1283
James Smart0cf07f842017-06-01 21:07:10 -07001284 if (phba->cfg_auto_imax) {
1285 if (!phba->last_eqdelay_time) {
1286 phba->last_eqdelay_time = jiffies;
1287 goto skip_eqdelay;
1288 }
1289 time_elapsed = jiffies - phba->last_eqdelay_time;
1290 phba->last_eqdelay_time = jiffies;
1291
1292 tot = 0xffff;
1293 /* Check outstanding IO count */
1294 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1295 if (phba->nvmet_support) {
Dick Kennedy66d7ce92017-08-23 16:55:42 -07001296 tgtp = phba->targetport->private;
1297 /* Calculate outstanding IOs */
1298 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
1299 tot += atomic_read(&tgtp->xmt_fcp_release);
1300 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
James Smart0cf07f842017-06-01 21:07:10 -07001301 } else {
1302 tot = atomic_read(&phba->fc4NvmeIoCmpls);
1303 data1 = atomic_read(
1304 &phba->fc4NvmeInputRequests);
1305 data2 = atomic_read(
1306 &phba->fc4NvmeOutputRequests);
1307 data3 = atomic_read(
1308 &phba->fc4NvmeControlRequests);
1309 tot = (data1 + data2 + data3) - tot;
1310 }
1311 }
1312
1313 /* Interrupts per sec per EQ */
1314 val = phba->cfg_fcp_imax / phba->io_channel_irqs;
1315 tick_cqe = val / CONFIG_HZ; /* Per tick per EQ */
1316
1317 /* Assume 1 CQE/ISR, calc max CQEs allowed for time duration */
1318 max_cqe = time_elapsed * tick_cqe;
1319
1320 for (i = 0; i < phba->io_channel_irqs; i++) {
1321 /* Fast-path EQ */
1322 qp = phba->sli4_hba.hba_eq[i];
1323 if (!qp)
1324 continue;
1325
1326 /* Use no EQ delay if we don't have many outstanding
1327 * IOs, or if we are only processing 1 CQE/ISR or less.
1328 * Otherwise, assume we can process up to lpfc_fcp_imax
1329 * interrupts per HBA.
1330 */
1331 if (tot < LPFC_NODELAY_MAX_IO ||
1332 qp->EQ_cqe_cnt <= max_cqe)
1333 val = 0;
1334 else
1335 val = phba->cfg_fcp_imax;
1336
1337 if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) {
1338 /* Use EQ Delay Register method */
1339
1340 /* Convert for EQ Delay register */
1341 if (val) {
1342 /* First, interrupts per sec per EQ */
1343 val = phba->cfg_fcp_imax /
1344 phba->io_channel_irqs;
1345
1346 /* us delay between each interrupt */
1347 val = LPFC_SEC_TO_USEC / val;
1348 }
1349 if (val != qp->q_mode) {
1350 reg_data.word0 = 0;
1351 bf_set(lpfc_sliport_eqdelay_id,
1352 &reg_data, qp->queue_id);
1353 bf_set(lpfc_sliport_eqdelay_delay,
1354 &reg_data, val);
1355 writel(reg_data.word0, eqdreg);
1356 }
1357 } else {
1358 /* Use mbox command method */
1359 if (val != qp->q_mode)
1360 lpfc_modify_hba_eq_delay(phba, i,
1361 1, val);
1362 }
1363
1364 /*
1365 * val is cfg_fcp_imax or 0 for mbox delay or us delay
1366 * between interrupts for EQDR.
1367 */
1368 qp->q_mode = val;
1369 qp->EQ_cqe_cnt = 0;
1370 }
1371 }
1372
1373skip_eqdelay:
James Smart858c9f62007-06-17 19:56:39 -05001374 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -05001375
James Smart256ec0d2013-04-17 20:14:58 -04001376 if (time_after(phba->last_completion_time +
1377 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1378 jiffies)) {
James Smart858c9f62007-06-17 19:56:39 -05001379 spin_unlock_irq(&phba->pport->work_port_lock);
1380 if (!phba->hb_outstanding)
1381 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001382 jiffies +
1383 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001384 else
1385 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001386 jiffies +
1387 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001388 return;
1389 }
1390 spin_unlock_irq(&phba->pport->work_port_lock);
1391
James Smart0ff10d42008-01-11 01:52:36 -05001392 if (phba->elsbuf_cnt &&
1393 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1394 spin_lock_irq(&phba->hbalock);
1395 list_splice_init(&phba->elsbuf, &completions);
1396 phba->elsbuf_cnt = 0;
1397 phba->elsbuf_prev_cnt = 0;
1398 spin_unlock_irq(&phba->hbalock);
1399
1400 while (!list_empty(&completions)) {
1401 list_remove_head(&completions, buf_ptr,
1402 struct lpfc_dmabuf, list);
1403 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1404 kfree(buf_ptr);
1405 }
1406 }
1407 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1408
James Smart858c9f62007-06-17 19:56:39 -05001409 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -05001410 if (phba->cfg_enable_hba_heartbeat) {
1411 if (!phba->hb_outstanding) {
James Smartbc739052010-08-04 16:11:18 -04001412 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1413 (list_empty(&psli->mboxq))) {
1414 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1415 GFP_KERNEL);
1416 if (!pmboxq) {
1417 mod_timer(&phba->hb_tmofunc,
1418 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001419 msecs_to_jiffies(1000 *
1420 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001421 return;
1422 }
James Smart13815c82008-01-11 01:52:48 -05001423
James Smartbc739052010-08-04 16:11:18 -04001424 lpfc_heart_beat(phba, pmboxq);
1425 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1426 pmboxq->vport = phba->pport;
1427 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1428 MBX_NOWAIT);
James Smart13815c82008-01-11 01:52:48 -05001429
James Smartbc739052010-08-04 16:11:18 -04001430 if (retval != MBX_BUSY &&
1431 retval != MBX_SUCCESS) {
1432 mempool_free(pmboxq,
1433 phba->mbox_mem_pool);
1434 mod_timer(&phba->hb_tmofunc,
1435 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001436 msecs_to_jiffies(1000 *
1437 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001438 return;
1439 }
1440 phba->skipped_hb = 0;
1441 phba->hb_outstanding = 1;
1442 } else if (time_before_eq(phba->last_completion_time,
1443 phba->skipped_hb)) {
1444 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1445 "2857 Last completion time not "
1446 " updated in %d ms\n",
1447 jiffies_to_msecs(jiffies
1448 - phba->last_completion_time));
1449 } else
1450 phba->skipped_hb = jiffies;
1451
James Smart858c9f62007-06-17 19:56:39 -05001452 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001453 jiffies +
1454 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001455 return;
James Smart13815c82008-01-11 01:52:48 -05001456 } else {
1457 /*
1458 * If heart beat timeout called with hb_outstanding set
James Smartdcf2a4e2010-09-29 11:18:53 -04001459 * we need to give the hb mailbox cmd a chance to
1460 * complete or TMO.
James Smart13815c82008-01-11 01:52:48 -05001461 */
James Smartdcf2a4e2010-09-29 11:18:53 -04001462 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1463 "0459 Adapter heartbeat still out"
1464 "standing:last compl time was %d ms.\n",
1465 jiffies_to_msecs(jiffies
1466 - phba->last_completion_time));
1467 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001468 jiffies +
1469 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001470 }
James Smart4258e982015-12-16 18:11:58 -05001471 } else {
1472 mod_timer(&phba->hb_tmofunc,
1473 jiffies +
1474 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001475 }
1476}
1477
James Smarte59058c2008-08-24 21:49:00 -04001478/**
James Smart3621a712009-04-06 18:47:14 -04001479 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -04001480 * @phba: pointer to lpfc hba data structure.
1481 *
1482 * This routine is called to bring the HBA offline when HBA hardware error
1483 * other than Port Error 6 has been detected.
1484 **/
James Smart09372822008-01-11 01:52:54 -05001485static void
1486lpfc_offline_eratt(struct lpfc_hba *phba)
1487{
1488 struct lpfc_sli *psli = &phba->sli;
1489
1490 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001491 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -05001492 spin_unlock_irq(&phba->hbalock);
James Smart618a5232012-06-12 13:54:36 -04001493 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart09372822008-01-11 01:52:54 -05001494
1495 lpfc_offline(phba);
1496 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001497 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001498 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001499 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001500 lpfc_hba_down_post(phba);
1501 lpfc_sli_brdready(phba, HS_MBRDY);
1502 lpfc_unblock_mgmt_io(phba);
1503 phba->link_state = LPFC_HBA_ERROR;
1504 return;
1505}
1506
James Smarte59058c2008-08-24 21:49:00 -04001507/**
James Smartda0436e2009-05-22 14:51:39 -04001508 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1509 * @phba: pointer to lpfc hba data structure.
1510 *
1511 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1512 * other than Port Error 6 has been detected.
1513 **/
James Smarta88dbb62013-04-17 20:18:39 -04001514void
James Smartda0436e2009-05-22 14:51:39 -04001515lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1516{
James Smart946727d2015-04-07 15:07:09 -04001517 spin_lock_irq(&phba->hbalock);
1518 phba->link_state = LPFC_HBA_ERROR;
1519 spin_unlock_irq(&phba->hbalock);
1520
James Smart618a5232012-06-12 13:54:36 -04001521 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smartda0436e2009-05-22 14:51:39 -04001522 lpfc_offline(phba);
James Smartda0436e2009-05-22 14:51:39 -04001523 lpfc_hba_down_post(phba);
James Smartda0436e2009-05-22 14:51:39 -04001524 lpfc_unblock_mgmt_io(phba);
James Smartda0436e2009-05-22 14:51:39 -04001525}
1526
1527/**
James Smarta257bf92009-04-06 18:48:10 -04001528 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1529 * @phba: pointer to lpfc hba data structure.
1530 *
1531 * This routine is invoked to handle the deferred HBA hardware error
1532 * conditions. This type of error is indicated by HBA by setting ER1
1533 * and another ER bit in the host status register. The driver will
1534 * wait until the ER1 bit clears before handling the error condition.
1535 **/
1536static void
1537lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1538{
1539 uint32_t old_host_status = phba->work_hs;
James Smarta257bf92009-04-06 18:48:10 -04001540 struct lpfc_sli *psli = &phba->sli;
1541
James Smartf4b4c682009-05-22 14:53:12 -04001542 /* If the pci channel is offline, ignore possible errors,
1543 * since we cannot communicate with the pci card anyway.
1544 */
1545 if (pci_channel_offline(phba->pcidev)) {
1546 spin_lock_irq(&phba->hbalock);
1547 phba->hba_flag &= ~DEFER_ERATT;
1548 spin_unlock_irq(&phba->hbalock);
1549 return;
1550 }
1551
James Smarta257bf92009-04-06 18:48:10 -04001552 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1553 "0479 Deferred Adapter Hardware Error "
1554 "Data: x%x x%x x%x\n",
1555 phba->work_hs,
1556 phba->work_status[0], phba->work_status[1]);
1557
1558 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001559 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001560 spin_unlock_irq(&phba->hbalock);
1561
1562
1563 /*
1564 * Firmware stops when it triggred erratt. That could cause the I/Os
1565 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1566 * SCSI layer retry it after re-establishing link.
1567 */
James Smartdb55fba2014-04-04 13:52:02 -04001568 lpfc_sli_abort_fcp_rings(phba);
James Smarta257bf92009-04-06 18:48:10 -04001569
1570 /*
1571 * There was a firmware error. Take the hba offline and then
1572 * attempt to restart it.
1573 */
James Smart618a5232012-06-12 13:54:36 -04001574 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smarta257bf92009-04-06 18:48:10 -04001575 lpfc_offline(phba);
1576
1577 /* Wait for the ER1 bit to clear.*/
1578 while (phba->work_hs & HS_FFER1) {
1579 msleep(100);
James Smart9940b972011-03-11 16:06:12 -05001580 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1581 phba->work_hs = UNPLUG_ERR ;
1582 break;
1583 }
James Smarta257bf92009-04-06 18:48:10 -04001584 /* If driver is unloading let the worker thread continue */
1585 if (phba->pport->load_flag & FC_UNLOADING) {
1586 phba->work_hs = 0;
1587 break;
1588 }
1589 }
1590
1591 /*
1592 * This is to ptrotect against a race condition in which
1593 * first write to the host attention register clear the
1594 * host status register.
1595 */
1596 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1597 phba->work_hs = old_host_status & ~HS_FFER1;
1598
James Smart3772a992009-05-22 14:50:54 -04001599 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001600 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001601 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001602 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1603 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1604}
1605
James Smart3772a992009-05-22 14:50:54 -04001606static void
1607lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1608{
1609 struct lpfc_board_event_header board_event;
1610 struct Scsi_Host *shost;
1611
1612 board_event.event_type = FC_REG_BOARD_EVENT;
1613 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1614 shost = lpfc_shost_from_vport(phba->pport);
1615 fc_host_post_vendor_event(shost, fc_get_event_number(),
1616 sizeof(board_event),
1617 (char *) &board_event,
1618 LPFC_NL_VENDOR_ID);
1619}
1620
James Smarta257bf92009-04-06 18:48:10 -04001621/**
James Smart3772a992009-05-22 14:50:54 -04001622 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001623 * @phba: pointer to lpfc hba data structure.
1624 *
1625 * This routine is invoked to handle the following HBA hardware error
1626 * conditions:
1627 * 1 - HBA error attention interrupt
1628 * 2 - DMA ring index out of range
1629 * 3 - Mailbox command came back as unknown
1630 **/
James Smart3772a992009-05-22 14:50:54 -04001631static void
1632lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001633{
James Smart2e0fef82007-06-17 19:56:36 -05001634 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001635 struct lpfc_sli *psli = &phba->sli;
James Smartd2873e42006-08-18 17:46:43 -04001636 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001637 unsigned long temperature;
1638 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001639 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001640
Linas Vepstas8d63f372007-02-14 14:28:36 -06001641 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001642 * since we cannot communicate with the pci card anyway.
1643 */
1644 if (pci_channel_offline(phba->pcidev)) {
1645 spin_lock_irq(&phba->hbalock);
1646 phba->hba_flag &= ~DEFER_ERATT;
1647 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001648 return;
James Smart3772a992009-05-22 14:50:54 -04001649 }
1650
James Smart13815c82008-01-11 01:52:48 -05001651 /* If resets are disabled then leave the HBA alone and return */
1652 if (!phba->cfg_enable_hba_reset)
1653 return;
dea31012005-04-17 16:05:31 -05001654
James Smartea2151b2008-09-07 11:52:10 -04001655 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001656 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001657
James Smarta257bf92009-04-06 18:48:10 -04001658 if (phba->hba_flag & DEFER_ERATT)
1659 lpfc_handle_deferred_eratt(phba);
1660
James Smartdcf2a4e2010-09-29 11:18:53 -04001661 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1662 if (phba->work_hs & HS_FFER6)
1663 /* Re-establishing Link */
1664 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1665 "1301 Re-establishing Link "
1666 "Data: x%x x%x x%x\n",
1667 phba->work_hs, phba->work_status[0],
1668 phba->work_status[1]);
1669 if (phba->work_hs & HS_FFER8)
1670 /* Device Zeroization */
1671 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1672 "2861 Host Authentication device "
1673 "zeroization Data:x%x x%x x%x\n",
1674 phba->work_hs, phba->work_status[0],
1675 phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001676
James Smart92d7f7b2007-06-17 19:56:38 -05001677 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001678 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001679 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001680
1681 /*
1682 * Firmware stops when it triggled erratt with HS_FFER6.
1683 * That could cause the I/Os dropped by the firmware.
1684 * Error iocb (I/O) on txcmplq and let the SCSI layer
1685 * retry it after re-establishing link.
1686 */
James Smartdb55fba2014-04-04 13:52:02 -04001687 lpfc_sli_abort_fcp_rings(phba);
dea31012005-04-17 16:05:31 -05001688
dea31012005-04-17 16:05:31 -05001689 /*
1690 * There was a firmware error. Take the hba offline and then
1691 * attempt to restart it.
1692 */
James Smart618a5232012-06-12 13:54:36 -04001693 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
dea31012005-04-17 16:05:31 -05001694 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001695 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001696 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001697 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001698 return;
1699 }
James Smart46fa3112007-04-25 09:51:45 -04001700 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001701 } else if (phba->work_hs & HS_CRIT_TEMP) {
1702 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1703 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1704 temp_event_data.event_code = LPFC_CRIT_TEMP;
1705 temp_event_data.data = (uint32_t)temperature;
1706
1707 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001708 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001709 "(%ld), taking this port offline "
1710 "Data: x%x x%x x%x\n",
1711 temperature, phba->work_hs,
1712 phba->work_status[0], phba->work_status[1]);
1713
1714 shost = lpfc_shost_from_vport(phba->pport);
1715 fc_host_post_vendor_event(shost, fc_get_event_number(),
1716 sizeof(temp_event_data),
1717 (char *) &temp_event_data,
1718 SCSI_NL_VID_TYPE_PCI
1719 | PCI_VENDOR_ID_EMULEX);
1720
James Smart7af67052007-10-27 13:38:11 -04001721 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001722 phba->over_temp_state = HBA_OVER_TEMP;
1723 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001724 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001725
dea31012005-04-17 16:05:31 -05001726 } else {
1727 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001728 * failure is a value other than FFER6. Do not call the offline
1729 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001730 */
1731 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001732 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001733 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001734 phba->work_hs,
dea31012005-04-17 16:05:31 -05001735 phba->work_status[0], phba->work_status[1]);
1736
James Smartd2873e42006-08-18 17:46:43 -04001737 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001738 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001739 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001740 sizeof(event_data), (char *) &event_data,
1741 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1742
James Smart09372822008-01-11 01:52:54 -05001743 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001744 }
James Smart93996272008-08-24 21:50:30 -04001745 return;
dea31012005-04-17 16:05:31 -05001746}
1747
James Smarte59058c2008-08-24 21:49:00 -04001748/**
James Smart618a5232012-06-12 13:54:36 -04001749 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1750 * @phba: pointer to lpfc hba data structure.
1751 * @mbx_action: flag for mailbox shutdown action.
1752 *
1753 * This routine is invoked to perform an SLI4 port PCI function reset in
1754 * response to port status register polling attention. It waits for port
1755 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1756 * During this process, interrupt vectors are freed and later requested
1757 * for handling possible port resource change.
1758 **/
1759static int
James Smarte10b2022014-02-20 09:57:43 -05001760lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1761 bool en_rn_msg)
James Smart618a5232012-06-12 13:54:36 -04001762{
1763 int rc;
1764 uint32_t intr_mode;
1765
James Smart27d6ac02018-02-22 08:18:42 -08001766 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
James Smart65791f12016-07-06 12:35:56 -07001767 LPFC_SLI_INTF_IF_TYPE_2) {
1768 /*
1769 * On error status condition, driver need to wait for port
1770 * ready before performing reset.
1771 */
1772 rc = lpfc_sli4_pdev_status_reg_wait(phba);
James Smart0e916ee2016-07-06 12:36:06 -07001773 if (rc)
James Smart65791f12016-07-06 12:35:56 -07001774 return rc;
James Smart618a5232012-06-12 13:54:36 -04001775 }
James Smart0e916ee2016-07-06 12:36:06 -07001776
James Smart65791f12016-07-06 12:35:56 -07001777 /* need reset: attempt for port recovery */
1778 if (en_rn_msg)
1779 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1780 "2887 Reset Needed: Attempting Port "
1781 "Recovery...\n");
1782 lpfc_offline_prep(phba, mbx_action);
1783 lpfc_offline(phba);
1784 /* release interrupt for possible resource change */
1785 lpfc_sli4_disable_intr(phba);
1786 lpfc_sli_brdrestart(phba);
1787 /* request and enable interrupt */
1788 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1789 if (intr_mode == LPFC_INTR_ERROR) {
1790 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1791 "3175 Failed to enable interrupt\n");
1792 return -EIO;
1793 }
1794 phba->intr_mode = intr_mode;
1795 rc = lpfc_online(phba);
1796 if (rc == 0)
1797 lpfc_unblock_mgmt_io(phba);
1798
James Smart618a5232012-06-12 13:54:36 -04001799 return rc;
1800}
1801
1802/**
James Smartda0436e2009-05-22 14:51:39 -04001803 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1804 * @phba: pointer to lpfc hba data structure.
1805 *
1806 * This routine is invoked to handle the SLI4 HBA hardware error attention
1807 * conditions.
1808 **/
1809static void
1810lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1811{
1812 struct lpfc_vport *vport = phba->pport;
1813 uint32_t event_data;
1814 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001815 uint32_t if_type;
James Smart2e90f4b2011-12-13 13:22:37 -05001816 struct lpfc_register portstat_reg = {0};
1817 uint32_t reg_err1, reg_err2;
1818 uint32_t uerrlo_reg, uemasklo_reg;
James Smart65791f12016-07-06 12:35:56 -07001819 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
James Smarte10b2022014-02-20 09:57:43 -05001820 bool en_rn_msg = true;
James Smart946727d2015-04-07 15:07:09 -04001821 struct temp_event temp_event_data;
James Smart65791f12016-07-06 12:35:56 -07001822 struct lpfc_register portsmphr_reg;
1823 int rc, i;
James Smartda0436e2009-05-22 14:51:39 -04001824
1825 /* If the pci channel is offline, ignore possible errors, since
1826 * we cannot communicate with the pci card anyway.
1827 */
1828 if (pci_channel_offline(phba->pcidev))
1829 return;
James Smartda0436e2009-05-22 14:51:39 -04001830
James Smart65791f12016-07-06 12:35:56 -07001831 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
James Smart2fcee4b2010-12-15 17:57:46 -05001832 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1833 switch (if_type) {
1834 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart2e90f4b2011-12-13 13:22:37 -05001835 pci_rd_rc1 = lpfc_readl(
1836 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1837 &uerrlo_reg);
1838 pci_rd_rc2 = lpfc_readl(
1839 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1840 &uemasklo_reg);
1841 /* consider PCI bus read error as pci_channel_offline */
1842 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1843 return;
James Smart65791f12016-07-06 12:35:56 -07001844 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
1845 lpfc_sli4_offline_eratt(phba);
1846 return;
1847 }
1848 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1849 "7623 Checking UE recoverable");
1850
1851 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
1852 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1853 &portsmphr_reg.word0))
1854 continue;
1855
1856 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
1857 &portsmphr_reg);
1858 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1859 LPFC_PORT_SEM_UE_RECOVERABLE)
1860 break;
1861 /*Sleep for 1Sec, before checking SEMAPHORE */
1862 msleep(1000);
1863 }
1864
1865 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1866 "4827 smphr_port_status x%x : Waited %dSec",
1867 smphr_port_status, i);
1868
1869 /* Recoverable UE, reset the HBA device */
1870 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1871 LPFC_PORT_SEM_UE_RECOVERABLE) {
1872 for (i = 0; i < 20; i++) {
1873 msleep(1000);
1874 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1875 &portsmphr_reg.word0) &&
1876 (LPFC_POST_STAGE_PORT_READY ==
1877 bf_get(lpfc_port_smphr_port_status,
1878 &portsmphr_reg))) {
1879 rc = lpfc_sli4_port_sta_fn_reset(phba,
1880 LPFC_MBX_NO_WAIT, en_rn_msg);
1881 if (rc == 0)
1882 return;
1883 lpfc_printf_log(phba,
1884 KERN_ERR, LOG_INIT,
1885 "4215 Failed to recover UE");
1886 break;
1887 }
1888 }
1889 }
1890 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1891 "7624 Firmware not ready: Failing UE recovery,"
1892 " waited %dSec", i);
James Smart2fcee4b2010-12-15 17:57:46 -05001893 lpfc_sli4_offline_eratt(phba);
1894 break;
James Smart946727d2015-04-07 15:07:09 -04001895
James Smart2fcee4b2010-12-15 17:57:46 -05001896 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08001897 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2e90f4b2011-12-13 13:22:37 -05001898 pci_rd_rc1 = lpfc_readl(
1899 phba->sli4_hba.u.if_type2.STATUSregaddr,
1900 &portstat_reg.word0);
1901 /* consider PCI bus read error as pci_channel_offline */
James Smart6b5151f2012-01-18 16:24:06 -05001902 if (pci_rd_rc1 == -EIO) {
1903 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1904 "3151 PCI bus read access failure: x%x\n",
1905 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
James Smart2e90f4b2011-12-13 13:22:37 -05001906 return;
James Smart6b5151f2012-01-18 16:24:06 -05001907 }
James Smart2e90f4b2011-12-13 13:22:37 -05001908 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1909 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
James Smart2fcee4b2010-12-15 17:57:46 -05001910 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
James Smart2fcee4b2010-12-15 17:57:46 -05001911 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1912 "2889 Port Overtemperature event, "
James Smart946727d2015-04-07 15:07:09 -04001913 "taking port offline Data: x%x x%x\n",
1914 reg_err1, reg_err2);
1915
James Smart310429e2016-07-06 12:35:54 -07001916 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04001917 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1918 temp_event_data.event_code = LPFC_CRIT_TEMP;
1919 temp_event_data.data = 0xFFFFFFFF;
1920
1921 shost = lpfc_shost_from_vport(phba->pport);
1922 fc_host_post_vendor_event(shost, fc_get_event_number(),
1923 sizeof(temp_event_data),
1924 (char *)&temp_event_data,
1925 SCSI_NL_VID_TYPE_PCI
1926 | PCI_VENDOR_ID_EMULEX);
1927
James Smart2fcee4b2010-12-15 17:57:46 -05001928 spin_lock_irq(&phba->hbalock);
1929 phba->over_temp_state = HBA_OVER_TEMP;
1930 spin_unlock_irq(&phba->hbalock);
1931 lpfc_sli4_offline_eratt(phba);
James Smart946727d2015-04-07 15:07:09 -04001932 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001933 }
James Smart2e90f4b2011-12-13 13:22:37 -05001934 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smarte10b2022014-02-20 09:57:43 -05001935 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
James Smart2e90f4b2011-12-13 13:22:37 -05001936 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte10b2022014-02-20 09:57:43 -05001937 "3143 Port Down: Firmware Update "
1938 "Detected\n");
1939 en_rn_msg = false;
1940 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smart2e90f4b2011-12-13 13:22:37 -05001941 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1942 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1943 "3144 Port Down: Debug Dump\n");
1944 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1945 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1946 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1947 "3145 Port Down: Provisioning\n");
James Smart618a5232012-06-12 13:54:36 -04001948
James Smart946727d2015-04-07 15:07:09 -04001949 /* If resets are disabled then leave the HBA alone and return */
1950 if (!phba->cfg_enable_hba_reset)
1951 return;
1952
James Smart618a5232012-06-12 13:54:36 -04001953 /* Check port status register for function reset */
James Smarte10b2022014-02-20 09:57:43 -05001954 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1955 en_rn_msg);
James Smart618a5232012-06-12 13:54:36 -04001956 if (rc == 0) {
1957 /* don't report event on forced debug dump */
1958 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1959 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1960 return;
1961 else
1962 break;
James Smart2fcee4b2010-12-15 17:57:46 -05001963 }
James Smart618a5232012-06-12 13:54:36 -04001964 /* fall through for not able to recover */
James Smart6b5151f2012-01-18 16:24:06 -05001965 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1966 "3152 Unrecoverable error, bring the port "
1967 "offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05001968 lpfc_sli4_offline_eratt(phba);
1969 break;
1970 case LPFC_SLI_INTF_IF_TYPE_1:
1971 default:
1972 break;
1973 }
James Smart2e90f4b2011-12-13 13:22:37 -05001974 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1975 "3123 Report dump event to upper layer\n");
1976 /* Send an internal error event to mgmt application */
1977 lpfc_board_errevt_to_mgmt(phba);
1978
1979 event_data = FC_REG_DUMP_EVENT;
1980 shost = lpfc_shost_from_vport(vport);
1981 fc_host_post_vendor_event(shost, fc_get_event_number(),
1982 sizeof(event_data), (char *) &event_data,
1983 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
James Smartda0436e2009-05-22 14:51:39 -04001984}
1985
1986/**
1987 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1988 * @phba: pointer to lpfc HBA data structure.
1989 *
1990 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1991 * routine from the API jump table function pointer from the lpfc_hba struct.
1992 *
1993 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001994 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001995 * Any other value - error.
1996 **/
1997void
1998lpfc_handle_eratt(struct lpfc_hba *phba)
1999{
2000 (*phba->lpfc_handle_eratt)(phba);
2001}
2002
2003/**
James Smart3621a712009-04-06 18:47:14 -04002004 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04002005 * @phba: pointer to lpfc hba data structure.
2006 *
2007 * This routine is invoked from the worker thread to handle a HBA host
James Smart895427b2017-02-12 13:52:30 -08002008 * attention link event. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002009 **/
dea31012005-04-17 16:05:31 -05002010void
James Smart2e0fef82007-06-17 19:56:36 -05002011lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002012{
James Smart2e0fef82007-06-17 19:56:36 -05002013 struct lpfc_vport *vport = phba->pport;
2014 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05002015 LPFC_MBOXQ_t *pmb;
2016 volatile uint32_t control;
2017 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05002018 int rc = 0;
dea31012005-04-17 16:05:31 -05002019
2020 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05002021 if (!pmb) {
2022 rc = 1;
dea31012005-04-17 16:05:31 -05002023 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05002024 }
dea31012005-04-17 16:05:31 -05002025
2026 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05002027 if (!mp) {
2028 rc = 2;
dea31012005-04-17 16:05:31 -05002029 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05002030 }
dea31012005-04-17 16:05:31 -05002031
2032 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05002033 if (!mp->virt) {
2034 rc = 3;
dea31012005-04-17 16:05:31 -05002035 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05002036 }
dea31012005-04-17 16:05:31 -05002037
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05002038 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04002039 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05002040
2041 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05002042 lpfc_read_topology(phba, pmb, mp);
2043 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05002044 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04002045 /* Block ELS IOCBs until we have processed this mbox command */
James Smart895427b2017-02-12 13:52:30 -08002046 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04002047 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05002048 if (rc == MBX_NOT_FINISHED) {
2049 rc = 4;
James Smart14691152006-12-02 13:34:28 -05002050 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05002051 }
dea31012005-04-17 16:05:31 -05002052
2053 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05002054 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002055 writel(HA_LATT, phba->HAregaddr);
2056 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05002057 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002058
2059 return;
2060
James Smart14691152006-12-02 13:34:28 -05002061lpfc_handle_latt_free_mbuf:
James Smart895427b2017-02-12 13:52:30 -08002062 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05002063 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05002064lpfc_handle_latt_free_mp:
2065 kfree(mp);
2066lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04002067 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002068lpfc_handle_latt_err_exit:
2069 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05002070 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002071 psli->sli_flag |= LPFC_PROCESS_LA;
2072 control = readl(phba->HCregaddr);
2073 control |= HC_LAINT_ENA;
2074 writel(control, phba->HCregaddr);
2075 readl(phba->HCregaddr); /* flush */
2076
2077 /* Clear Link Attention in HA REG */
2078 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 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002082 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002083
James Smart09372822008-01-11 01:52:54 -05002084 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
2085 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05002086
2087 return;
2088}
2089
James Smarte59058c2008-08-24 21:49:00 -04002090/**
James Smart3621a712009-04-06 18:47:14 -04002091 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04002092 * @phba: pointer to lpfc hba data structure.
2093 * @vpd: pointer to the vital product data.
2094 * @len: length of the vital product data in bytes.
2095 *
2096 * This routine parses the Vital Product Data (VPD). The VPD is treated as
2097 * an array of characters. In this routine, the ModelName, ProgramType, and
2098 * ModelDesc, etc. fields of the phba data structure will be populated.
2099 *
2100 * Return codes
2101 * 0 - pointer to the VPD passed in is NULL
2102 * 1 - success
2103 **/
James Smart3772a992009-05-22 14:50:54 -04002104int
James Smart2e0fef82007-06-17 19:56:36 -05002105lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05002106{
2107 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05002108 int Length;
dea31012005-04-17 16:05:31 -05002109 int i, j;
2110 int finished = 0;
2111 int index = 0;
2112
2113 if (!vpd)
2114 return 0;
2115
2116 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05002117 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002118 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05002119 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
2120 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002121 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05002122 switch (vpd[index]) {
2123 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002124 case 0x91:
dea31012005-04-17 16:05:31 -05002125 index += 1;
2126 lenlo = vpd[index];
2127 index += 1;
2128 lenhi = vpd[index];
2129 index += 1;
2130 i = ((((unsigned short)lenhi) << 8) + lenlo);
2131 index += i;
2132 break;
2133 case 0x90:
2134 index += 1;
2135 lenlo = vpd[index];
2136 index += 1;
2137 lenhi = vpd[index];
2138 index += 1;
2139 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002140 if (Length > len - index)
2141 Length = len - index;
dea31012005-04-17 16:05:31 -05002142 while (Length > 0) {
2143 /* Look for Serial Number */
2144 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
2145 index += 2;
2146 i = vpd[index];
2147 index += 1;
2148 j = 0;
2149 Length -= (3+i);
2150 while(i--) {
2151 phba->SerialNumber[j++] = vpd[index++];
2152 if (j == 31)
2153 break;
2154 }
2155 phba->SerialNumber[j] = 0;
2156 continue;
2157 }
2158 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
2159 phba->vpd_flag |= VPD_MODEL_DESC;
2160 index += 2;
2161 i = vpd[index];
2162 index += 1;
2163 j = 0;
2164 Length -= (3+i);
2165 while(i--) {
2166 phba->ModelDesc[j++] = vpd[index++];
2167 if (j == 255)
2168 break;
2169 }
2170 phba->ModelDesc[j] = 0;
2171 continue;
2172 }
2173 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
2174 phba->vpd_flag |= VPD_MODEL_NAME;
2175 index += 2;
2176 i = vpd[index];
2177 index += 1;
2178 j = 0;
2179 Length -= (3+i);
2180 while(i--) {
2181 phba->ModelName[j++] = vpd[index++];
2182 if (j == 79)
2183 break;
2184 }
2185 phba->ModelName[j] = 0;
2186 continue;
2187 }
2188 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2189 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2190 index += 2;
2191 i = vpd[index];
2192 index += 1;
2193 j = 0;
2194 Length -= (3+i);
2195 while(i--) {
2196 phba->ProgramType[j++] = vpd[index++];
2197 if (j == 255)
2198 break;
2199 }
2200 phba->ProgramType[j] = 0;
2201 continue;
2202 }
2203 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2204 phba->vpd_flag |= VPD_PORT;
2205 index += 2;
2206 i = vpd[index];
2207 index += 1;
2208 j = 0;
2209 Length -= (3+i);
2210 while(i--) {
James Smartcd1c8302011-10-10 21:33:25 -04002211 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2212 (phba->sli4_hba.pport_name_sta ==
2213 LPFC_SLI4_PPNAME_GET)) {
2214 j++;
2215 index++;
2216 } else
2217 phba->Port[j++] = vpd[index++];
2218 if (j == 19)
2219 break;
dea31012005-04-17 16:05:31 -05002220 }
James Smartcd1c8302011-10-10 21:33:25 -04002221 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2222 (phba->sli4_hba.pport_name_sta ==
2223 LPFC_SLI4_PPNAME_NON))
2224 phba->Port[j] = 0;
dea31012005-04-17 16:05:31 -05002225 continue;
2226 }
2227 else {
2228 index += 2;
2229 i = vpd[index];
2230 index += 1;
2231 index += i;
2232 Length -= (3 + i);
2233 }
2234 }
2235 finished = 0;
2236 break;
2237 case 0x78:
2238 finished = 1;
2239 break;
2240 default:
2241 index ++;
2242 break;
2243 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002244 }
dea31012005-04-17 16:05:31 -05002245
2246 return(1);
2247}
2248
James Smarte59058c2008-08-24 21:49:00 -04002249/**
James Smart3621a712009-04-06 18:47:14 -04002250 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04002251 * @phba: pointer to lpfc hba data structure.
2252 * @mdp: pointer to the data structure to hold the derived model name.
2253 * @descp: pointer to the data structure to hold the derived description.
2254 *
2255 * This routine retrieves HBA's description based on its registered PCI device
2256 * ID. The @descp passed into this function points to an array of 256 chars. It
2257 * shall be returned with the model name, maximum speed, and the host bus type.
2258 * The @mdp passed into this function points to an array of 80 chars. When the
2259 * function returns, the @mdp will be filled with the model name.
2260 **/
dea31012005-04-17 16:05:31 -05002261static void
James Smart2e0fef82007-06-17 19:56:36 -05002262lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05002263{
2264 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05002265 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002266 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04002267 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04002268 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002269 struct {
James Smarta747c9c2009-11-18 15:41:10 -05002270 char *name;
2271 char *bus;
2272 char *function;
2273 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002274
2275 if (mdp && mdp[0] != '\0'
2276 && descp && descp[0] != '\0')
2277 return;
2278
James Smartfbd8a6b2018-02-22 08:18:45 -08002279 if (phba->lmt & LMT_64Gb)
2280 max_speed = 64;
2281 else if (phba->lmt & LMT_32Gb)
James Smartd38dd522015-08-31 16:48:17 -04002282 max_speed = 32;
2283 else if (phba->lmt & LMT_16Gb)
James Smartc0c11512011-05-24 11:41:34 -04002284 max_speed = 16;
2285 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002286 max_speed = 10;
2287 else if (phba->lmt & LMT_8Gb)
2288 max_speed = 8;
2289 else if (phba->lmt & LMT_4Gb)
2290 max_speed = 4;
2291 else if (phba->lmt & LMT_2Gb)
2292 max_speed = 2;
James Smart4169d862012-09-29 11:32:09 -04002293 else if (phba->lmt & LMT_1Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002294 max_speed = 1;
James Smart4169d862012-09-29 11:32:09 -04002295 else
2296 max_speed = 0;
dea31012005-04-17 16:05:31 -05002297
2298 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05002299
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002300 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002301 case PCI_DEVICE_ID_FIREFLY:
James Smart12222f42014-05-21 08:05:19 -04002302 m = (typeof(m)){"LP6000", "PCI",
2303 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002304 break;
dea31012005-04-17 16:05:31 -05002305 case PCI_DEVICE_ID_SUPERFLY:
2306 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart12222f42014-05-21 08:05:19 -04002307 m = (typeof(m)){"LP7000", "PCI", ""};
dea31012005-04-17 16:05:31 -05002308 else
James Smart12222f42014-05-21 08:05:19 -04002309 m = (typeof(m)){"LP7000E", "PCI", ""};
2310 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002311 break;
2312 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002313 m = (typeof(m)){"LP8000", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002314 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002315 break;
2316 case PCI_DEVICE_ID_CENTAUR:
2317 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart12222f42014-05-21 08:05:19 -04002318 m = (typeof(m)){"LP9002", "PCI", ""};
dea31012005-04-17 16:05:31 -05002319 else
James Smart12222f42014-05-21 08:05:19 -04002320 m = (typeof(m)){"LP9000", "PCI", ""};
2321 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002322 break;
2323 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002324 m = (typeof(m)){"LP952", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002325 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002326 break;
2327 case PCI_DEVICE_ID_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05002328 m = (typeof(m)){"LP9802", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002329 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002330 break;
2331 case PCI_DEVICE_ID_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05002332 m = (typeof(m)){"LP10000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002333 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002334 break;
2335 case PCI_DEVICE_ID_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05002336 m = (typeof(m)){"LPX1000", "PCI-X",
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_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002340 m = (typeof(m)){"LP982", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002341 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002342 break;
2343 case PCI_DEVICE_ID_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002344 m = (typeof(m)){"LP1050", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002345 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002346 break;
2347 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05002348 m = (typeof(m)){"LP11000", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002349 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002350 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002351 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002352 m = (typeof(m)){"LP11000-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002353 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002354 break;
2355 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002356 m = (typeof(m)){"LP11002-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002357 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002358 break;
2359 case PCI_DEVICE_ID_NEPTUNE:
James Smart12222f42014-05-21 08:05:19 -04002360 m = (typeof(m)){"LPe1000", "PCIe",
2361 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002362 break;
2363 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart12222f42014-05-21 08:05:19 -04002364 m = (typeof(m)){"LPe1000-SP", "PCIe",
2365 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002366 break;
2367 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart12222f42014-05-21 08:05:19 -04002368 m = (typeof(m)){"LPe1002-SP", "PCIe",
2369 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002370 break;
dea31012005-04-17 16:05:31 -05002371 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05002372 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002373 break;
2374 case PCI_DEVICE_ID_BSMB:
James Smart12222f42014-05-21 08:05:19 -04002375 m = (typeof(m)){"LP111", "PCI-X2",
2376 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002377 break;
2378 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05002379 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002380 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002381 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002382 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002383 break;
2384 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002385 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04002386 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002387 break;
dea31012005-04-17 16:05:31 -05002388 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05002389 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002390 break;
2391 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05002392 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002393 break;
2394 case PCI_DEVICE_ID_LP101:
James Smart12222f42014-05-21 08:05:19 -04002395 m = (typeof(m)){"LP101", "PCI-X",
2396 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002397 break;
2398 case PCI_DEVICE_ID_LP10000S:
James Smart12222f42014-05-21 08:05:19 -04002399 m = (typeof(m)){"LP10000-S", "PCI",
2400 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002401 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002402 case PCI_DEVICE_ID_LP11000S:
James Smart12222f42014-05-21 08:05:19 -04002403 m = (typeof(m)){"LP11000-S", "PCI-X2",
2404 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05002405 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002406 case PCI_DEVICE_ID_LPE11000S:
James Smart12222f42014-05-21 08:05:19 -04002407 m = (typeof(m)){"LPe11000-S", "PCIe",
2408 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002409 break;
James Smartb87eab32007-04-25 09:53:28 -04002410 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05002411 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002412 break;
2413 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05002414 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002415 break;
2416 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05002417 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002418 break;
2419 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002420 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002421 break;
2422 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002423 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002424 break;
2425 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05002426 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002427 break;
James Smart84774a42008-08-24 21:50:06 -04002428 case PCI_DEVICE_ID_HORNET:
James Smart12222f42014-05-21 08:05:19 -04002429 m = (typeof(m)){"LP21000", "PCIe",
2430 "Obsolete, Unsupported FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002431 GE = 1;
2432 break;
2433 case PCI_DEVICE_ID_PROTEUS_VF:
James Smarta747c9c2009-11-18 15:41:10 -05002434 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002435 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002436 break;
2437 case PCI_DEVICE_ID_PROTEUS_PF:
James Smarta747c9c2009-11-18 15:41:10 -05002438 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002439 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002440 break;
2441 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05002442 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002443 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002444 break;
James Smartda0436e2009-05-22 14:51:39 -04002445 case PCI_DEVICE_ID_TIGERSHARK:
2446 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002447 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04002448 break;
James Smarta747c9c2009-11-18 15:41:10 -05002449 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04002450 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002451 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2452 break;
2453 case PCI_DEVICE_ID_FALCON:
2454 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2455 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04002456 break;
James Smart98fc5dd2010-06-07 15:24:29 -04002457 case PCI_DEVICE_ID_BALIUS:
2458 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
James Smart12222f42014-05-21 08:05:19 -04002459 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart98fc5dd2010-06-07 15:24:29 -04002460 break;
James Smart085c6472010-11-20 23:11:37 -05002461 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04002462 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05002463 break;
James Smart12222f42014-05-21 08:05:19 -04002464 case PCI_DEVICE_ID_LANCER_FC_VF:
2465 m = (typeof(m)){"LPe16000", "PCIe",
2466 "Obsolete, Unsupported Fibre Channel Adapter"};
2467 break;
James Smart085c6472010-11-20 23:11:37 -05002468 case PCI_DEVICE_ID_LANCER_FCOE:
2469 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04002470 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05002471 break;
James Smart12222f42014-05-21 08:05:19 -04002472 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2473 oneConnect = 1;
2474 m = (typeof(m)){"OCe15100", "PCIe",
2475 "Obsolete, Unsupported FCoE"};
2476 break;
James Smartd38dd522015-08-31 16:48:17 -04002477 case PCI_DEVICE_ID_LANCER_G6_FC:
2478 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2479 break;
James Smartc238b9b2018-02-22 08:18:44 -08002480 case PCI_DEVICE_ID_LANCER_G7_FC:
2481 m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"};
2482 break;
James Smartf8cafd32012-08-03 12:42:51 -04002483 case PCI_DEVICE_ID_SKYHAWK:
2484 case PCI_DEVICE_ID_SKYHAWK_VF:
2485 oneConnect = 1;
2486 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2487 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002488 default:
James Smarta747c9c2009-11-18 15:41:10 -05002489 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002490 break;
dea31012005-04-17 16:05:31 -05002491 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002492
2493 if (mdp && mdp[0] == '\0')
2494 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04002495 /*
2496 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04002497 * and we put the port number on the end
2498 */
2499 if (descp && descp[0] == '\0') {
2500 if (oneConnect)
2501 snprintf(descp, 255,
James Smart4169d862012-09-29 11:32:09 -04002502 "Emulex OneConnect %s, %s Initiator %s",
James Smarta747c9c2009-11-18 15:41:10 -05002503 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04002504 phba->Port);
James Smart4169d862012-09-29 11:32:09 -04002505 else if (max_speed == 0)
2506 snprintf(descp, 255,
Sebastian Herbszt290237d2015-08-31 16:48:08 -04002507 "Emulex %s %s %s",
James Smart4169d862012-09-29 11:32:09 -04002508 m.name, m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002509 else
2510 snprintf(descp, 255,
2511 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05002512 m.name, max_speed, (GE) ? "GE" : "Gb",
2513 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002514 }
dea31012005-04-17 16:05:31 -05002515}
2516
James Smarte59058c2008-08-24 21:49:00 -04002517/**
James Smart3621a712009-04-06 18:47:14 -04002518 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04002519 * @phba: pointer to lpfc hba data structure.
2520 * @pring: pointer to a IOCB ring.
2521 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2522 *
2523 * This routine posts a given number of IOCBs with the associated DMA buffer
2524 * descriptors specified by the cnt argument to the given IOCB ring.
2525 *
2526 * Return codes
2527 * The number of IOCBs NOT able to be posted to the IOCB ring.
2528 **/
dea31012005-04-17 16:05:31 -05002529int
James Smart495a7142008-06-14 22:52:59 -04002530lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002531{
2532 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002533 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002534 struct lpfc_dmabuf *mp1, *mp2;
2535
2536 cnt += pring->missbufcnt;
2537
2538 /* While there are buffers to post */
2539 while (cnt > 0) {
2540 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002541 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002542 if (iocb == NULL) {
2543 pring->missbufcnt = cnt;
2544 return cnt;
2545 }
dea31012005-04-17 16:05:31 -05002546 icmd = &iocb->iocb;
2547
2548 /* 2 buffers can be posted per command */
2549 /* Allocate buffer to post */
2550 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2551 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002552 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2553 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002554 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002555 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002556 pring->missbufcnt = cnt;
2557 return cnt;
2558 }
2559
2560 INIT_LIST_HEAD(&mp1->list);
2561 /* Allocate buffer to post */
2562 if (cnt > 1) {
2563 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2564 if (mp2)
2565 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2566 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002567 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002568 kfree(mp2);
dea31012005-04-17 16:05:31 -05002569 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2570 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002571 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002572 pring->missbufcnt = cnt;
2573 return cnt;
2574 }
2575
2576 INIT_LIST_HEAD(&mp2->list);
2577 } else {
2578 mp2 = NULL;
2579 }
2580
2581 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2582 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2583 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2584 icmd->ulpBdeCount = 1;
2585 cnt--;
2586 if (mp2) {
2587 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2588 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2589 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2590 cnt--;
2591 icmd->ulpBdeCount = 2;
2592 }
2593
2594 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2595 icmd->ulpLe = 1;
2596
James Smart3772a992009-05-22 14:50:54 -04002597 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2598 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002599 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2600 kfree(mp1);
2601 cnt++;
2602 if (mp2) {
2603 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2604 kfree(mp2);
2605 cnt++;
2606 }
James Bottomley604a3e32005-10-29 10:28:33 -05002607 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002608 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002609 return cnt;
2610 }
dea31012005-04-17 16:05:31 -05002611 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002612 if (mp2)
dea31012005-04-17 16:05:31 -05002613 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002614 }
2615 pring->missbufcnt = 0;
2616 return 0;
2617}
2618
James Smarte59058c2008-08-24 21:49:00 -04002619/**
James Smart3621a712009-04-06 18:47:14 -04002620 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002621 * @phba: pointer to lpfc hba data structure.
2622 *
2623 * This routine posts initial receive IOCB buffers to the ELS ring. The
2624 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
James Smart895427b2017-02-12 13:52:30 -08002625 * set to 64 IOCBs. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002626 *
2627 * Return codes
2628 * 0 - success (currently always success)
2629 **/
dea31012005-04-17 16:05:31 -05002630static int
James Smart2e0fef82007-06-17 19:56:36 -05002631lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002632{
2633 struct lpfc_sli *psli = &phba->sli;
2634
2635 /* Ring 0, ELS / CT buffers */
James Smart895427b2017-02-12 13:52:30 -08002636 lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002637 /* Ring 2 - FCP no buffers needed */
2638
2639 return 0;
2640}
2641
2642#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2643
James Smarte59058c2008-08-24 21:49:00 -04002644/**
James Smart3621a712009-04-06 18:47:14 -04002645 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002646 * @HashResultPointer: pointer to an array as hash table.
2647 *
2648 * This routine sets up the initial values to the array of hash table entries
2649 * for the LC HBAs.
2650 **/
dea31012005-04-17 16:05:31 -05002651static void
2652lpfc_sha_init(uint32_t * HashResultPointer)
2653{
2654 HashResultPointer[0] = 0x67452301;
2655 HashResultPointer[1] = 0xEFCDAB89;
2656 HashResultPointer[2] = 0x98BADCFE;
2657 HashResultPointer[3] = 0x10325476;
2658 HashResultPointer[4] = 0xC3D2E1F0;
2659}
2660
James Smarte59058c2008-08-24 21:49:00 -04002661/**
James Smart3621a712009-04-06 18:47:14 -04002662 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002663 * @HashResultPointer: pointer to an initial/result hash table.
2664 * @HashWorkingPointer: pointer to an working hash table.
2665 *
2666 * This routine iterates an initial hash table pointed by @HashResultPointer
2667 * with the values from the working hash table pointeed by @HashWorkingPointer.
2668 * The results are putting back to the initial hash table, returned through
2669 * the @HashResultPointer as the result hash table.
2670 **/
dea31012005-04-17 16:05:31 -05002671static void
2672lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2673{
2674 int t;
2675 uint32_t TEMP;
2676 uint32_t A, B, C, D, E;
2677 t = 16;
2678 do {
2679 HashWorkingPointer[t] =
2680 S(1,
2681 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2682 8] ^
2683 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2684 } while (++t <= 79);
2685 t = 0;
2686 A = HashResultPointer[0];
2687 B = HashResultPointer[1];
2688 C = HashResultPointer[2];
2689 D = HashResultPointer[3];
2690 E = HashResultPointer[4];
2691
2692 do {
2693 if (t < 20) {
2694 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2695 } else if (t < 40) {
2696 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2697 } else if (t < 60) {
2698 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2699 } else {
2700 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2701 }
2702 TEMP += S(5, A) + E + HashWorkingPointer[t];
2703 E = D;
2704 D = C;
2705 C = S(30, B);
2706 B = A;
2707 A = TEMP;
2708 } while (++t <= 79);
2709
2710 HashResultPointer[0] += A;
2711 HashResultPointer[1] += B;
2712 HashResultPointer[2] += C;
2713 HashResultPointer[3] += D;
2714 HashResultPointer[4] += E;
2715
2716}
2717
James Smarte59058c2008-08-24 21:49:00 -04002718/**
James Smart3621a712009-04-06 18:47:14 -04002719 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002720 * @RandomChallenge: pointer to the entry of host challenge random number array.
2721 * @HashWorking: pointer to the entry of the working hash array.
2722 *
2723 * This routine calculates the working hash array referred by @HashWorking
2724 * from the challenge random numbers associated with the host, referred by
2725 * @RandomChallenge. The result is put into the entry of the working hash
2726 * array and returned by reference through @HashWorking.
2727 **/
dea31012005-04-17 16:05:31 -05002728static void
2729lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2730{
2731 *HashWorking = (*RandomChallenge ^ *HashWorking);
2732}
2733
James Smarte59058c2008-08-24 21:49:00 -04002734/**
James Smart3621a712009-04-06 18:47:14 -04002735 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002736 * @phba: pointer to lpfc hba data structure.
2737 * @hbainit: pointer to an array of unsigned 32-bit integers.
2738 *
2739 * This routine performs the special handling for LC HBA initialization.
2740 **/
dea31012005-04-17 16:05:31 -05002741void
2742lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2743{
2744 int t;
2745 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002746 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002747
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002748 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002749 if (!HashWorking)
2750 return;
2751
dea31012005-04-17 16:05:31 -05002752 HashWorking[0] = HashWorking[78] = *pwwnn++;
2753 HashWorking[1] = HashWorking[79] = *pwwnn;
2754
2755 for (t = 0; t < 7; t++)
2756 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2757
2758 lpfc_sha_init(hbainit);
2759 lpfc_sha_iterate(hbainit, HashWorking);
2760 kfree(HashWorking);
2761}
2762
James Smarte59058c2008-08-24 21:49:00 -04002763/**
James Smart3621a712009-04-06 18:47:14 -04002764 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002765 * @vport: pointer to a virtual N_Port data structure.
2766 *
2767 * This routine performs the necessary cleanups before deleting the @vport.
2768 * It invokes the discovery state machine to perform necessary state
2769 * transitions and to release the ndlps associated with the @vport. Note,
2770 * the physical port is treated as @vport 0.
2771 **/
James Smart87af33f2007-10-27 13:37:43 -04002772void
James Smart2e0fef82007-06-17 19:56:36 -05002773lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002774{
James Smart87af33f2007-10-27 13:37:43 -04002775 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002776 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002777 int i = 0;
dea31012005-04-17 16:05:31 -05002778
James Smart87af33f2007-10-27 13:37:43 -04002779 if (phba->link_state > LPFC_LINK_DOWN)
2780 lpfc_port_link_failure(vport);
2781
2782 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002783 if (!NLP_CHK_NODE_ACT(ndlp)) {
2784 ndlp = lpfc_enable_node(vport, ndlp,
2785 NLP_STE_UNUSED_NODE);
2786 if (!ndlp)
2787 continue;
2788 spin_lock_irq(&phba->ndlp_lock);
2789 NLP_SET_FREE_REQ(ndlp);
2790 spin_unlock_irq(&phba->ndlp_lock);
2791 /* Trigger the release of the ndlp memory */
2792 lpfc_nlp_put(ndlp);
2793 continue;
2794 }
2795 spin_lock_irq(&phba->ndlp_lock);
2796 if (NLP_CHK_FREE_REQ(ndlp)) {
2797 /* The ndlp should not be in memory free mode already */
2798 spin_unlock_irq(&phba->ndlp_lock);
2799 continue;
2800 } else
2801 /* Indicate request for freeing ndlp memory */
2802 NLP_SET_FREE_REQ(ndlp);
2803 spin_unlock_irq(&phba->ndlp_lock);
2804
James Smart58da1ff2008-04-07 10:15:56 -04002805 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2806 ndlp->nlp_DID == Fabric_DID) {
2807 /* Just free up ndlp with Fabric_DID for vports */
2808 lpfc_nlp_put(ndlp);
2809 continue;
2810 }
2811
James Smarteff4a012012-01-18 16:25:25 -05002812 /* take care of nodes in unused state before the state
2813 * machine taking action.
2814 */
2815 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2816 lpfc_nlp_put(ndlp);
2817 continue;
2818 }
2819
James Smart87af33f2007-10-27 13:37:43 -04002820 if (ndlp->nlp_type & NLP_FABRIC)
2821 lpfc_disc_state_machine(vport, ndlp, NULL,
2822 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002823
James Smart87af33f2007-10-27 13:37:43 -04002824 lpfc_disc_state_machine(vport, ndlp, NULL,
2825 NLP_EVT_DEVICE_RM);
2826 }
2827
James Smarta8adb832007-10-27 13:37:53 -04002828 /* At this point, ALL ndlp's should be gone
2829 * because of the previous NLP_EVT_DEVICE_RM.
2830 * Lets wait for this to happen, if needed.
2831 */
James Smart87af33f2007-10-27 13:37:43 -04002832 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002833 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04002834 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04002835 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002836 list_for_each_entry_safe(ndlp, next_ndlp,
2837 &vport->fc_nodes, nlp_listp) {
2838 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2839 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04002840 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05002841 "usgmap:x%x refcnt:%d\n",
2842 ndlp->nlp_DID, (void *)ndlp,
2843 ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01002844 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05002845 }
James Smarta8adb832007-10-27 13:37:53 -04002846 break;
James Smart87af33f2007-10-27 13:37:43 -04002847 }
James Smarta8adb832007-10-27 13:37:53 -04002848
2849 /* Wait for any activity on ndlps to settle */
2850 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002851 }
James Smart1151e3e2011-02-16 12:39:35 -05002852 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002853}
2854
James Smarte59058c2008-08-24 21:49:00 -04002855/**
James Smart3621a712009-04-06 18:47:14 -04002856 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002857 * @vport: pointer to a virtual N_Port data structure.
2858 *
2859 * This routine stops all the timers associated with a @vport. This function
2860 * is invoked before disabling or deleting a @vport. Note that the physical
2861 * port is treated as @vport 0.
2862 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002863void
2864lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002865{
James Smart92d7f7b2007-06-17 19:56:38 -05002866 del_timer_sync(&vport->els_tmofunc);
James Smart92494142011-02-16 12:39:44 -05002867 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002868 lpfc_can_disctmo(vport);
2869 return;
dea31012005-04-17 16:05:31 -05002870}
2871
James Smarte59058c2008-08-24 21:49:00 -04002872/**
James Smartecfd03c2010-02-12 14:41:27 -05002873 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2874 * @phba: pointer to lpfc hba data structure.
2875 *
2876 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2877 * caller of this routine should already hold the host lock.
2878 **/
2879void
2880__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2881{
James Smart5ac6b302010-10-22 11:05:36 -04002882 /* Clear pending FCF rediscovery wait flag */
2883 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2884
James Smartecfd03c2010-02-12 14:41:27 -05002885 /* Now, try to stop the timer */
2886 del_timer(&phba->fcf.redisc_wait);
2887}
2888
2889/**
2890 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2891 * @phba: pointer to lpfc hba data structure.
2892 *
2893 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2894 * checks whether the FCF rediscovery wait timer is pending with the host
2895 * lock held before proceeding with disabling the timer and clearing the
2896 * wait timer pendig flag.
2897 **/
2898void
2899lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2900{
2901 spin_lock_irq(&phba->hbalock);
2902 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2903 /* FCF rediscovery timer already fired or stopped */
2904 spin_unlock_irq(&phba->hbalock);
2905 return;
2906 }
2907 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002908 /* Clear failover in progress flags */
2909 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002910 spin_unlock_irq(&phba->hbalock);
2911}
2912
2913/**
James Smart3772a992009-05-22 14:50:54 -04002914 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002915 * @phba: pointer to lpfc hba data structure.
2916 *
2917 * This routine stops all the timers associated with a HBA. This function is
2918 * invoked before either putting a HBA offline or unloading the driver.
2919 **/
James Smart3772a992009-05-22 14:50:54 -04002920void
2921lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002922{
James Smart51ef4c22007-08-02 11:10:31 -04002923 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05002924 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002925 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002926 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002927 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002928 if (phba->sli_rev == LPFC_SLI_REV4) {
2929 del_timer_sync(&phba->rrq_tmr);
2930 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2931 }
James Smart3772a992009-05-22 14:50:54 -04002932 phba->hb_outstanding = 0;
2933
2934 switch (phba->pci_dev_grp) {
2935 case LPFC_PCI_DEV_LP:
2936 /* Stop any LightPulse device specific driver timers */
2937 del_timer_sync(&phba->fcp_poll_timer);
2938 break;
2939 case LPFC_PCI_DEV_OC:
2940 /* Stop any OneConnect device sepcific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002941 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002942 break;
2943 default:
2944 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2945 "0297 Invalid device group (x%x)\n",
2946 phba->pci_dev_grp);
2947 break;
2948 }
James Smart2e0fef82007-06-17 19:56:36 -05002949 return;
dea31012005-04-17 16:05:31 -05002950}
2951
James Smarte59058c2008-08-24 21:49:00 -04002952/**
James Smart3621a712009-04-06 18:47:14 -04002953 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002954 * @phba: pointer to lpfc hba data structure.
2955 *
2956 * This routine marks a HBA's management interface as blocked. Once the HBA's
2957 * management interface is marked as blocked, all the user space access to
2958 * the HBA, whether they are from sysfs interface or libdfc interface will
2959 * all be blocked. The HBA is set to block the management interface when the
2960 * driver prepares the HBA interface for online or offline.
2961 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01002962static void
James Smart618a5232012-06-12 13:54:36 -04002963lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
Adrian Bunka6ababd2007-11-05 18:07:33 +01002964{
2965 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04002966 uint8_t actcmd = MBX_HEARTBEAT;
2967 unsigned long timeout;
2968
Adrian Bunka6ababd2007-11-05 18:07:33 +01002969 spin_lock_irqsave(&phba->hbalock, iflag);
2970 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart618a5232012-06-12 13:54:36 -04002971 spin_unlock_irqrestore(&phba->hbalock, iflag);
2972 if (mbx_action == LPFC_MBX_NO_WAIT)
2973 return;
2974 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2975 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002976 if (phba->sli.mbox_active) {
James Smart6e7288d2010-06-07 15:23:35 -04002977 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
James Smarta183a152011-10-10 21:32:43 -04002978 /* Determine how long we might wait for the active mailbox
2979 * command to be gracefully completed by firmware.
2980 */
2981 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
2982 phba->sli.mbox_active) * 1000) + jiffies;
2983 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002984 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002985
James Smart6e7288d2010-06-07 15:23:35 -04002986 /* Wait for the outstnading mailbox command to complete */
2987 while (phba->sli.mbox_active) {
2988 /* Check active mailbox complete status every 2ms */
2989 msleep(2);
2990 if (time_after(jiffies, timeout)) {
2991 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2992 "2813 Mgmt IO is Blocked %x "
2993 "- mbox cmd %x still active\n",
2994 phba->sli.sli_flag, actcmd);
2995 break;
2996 }
2997 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002998}
2999
James Smarte59058c2008-08-24 21:49:00 -04003000/**
James Smart6b5151f2012-01-18 16:24:06 -05003001 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
3002 * @phba: pointer to lpfc hba data structure.
3003 *
3004 * Allocate RPIs for all active remote nodes. This is needed whenever
3005 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
3006 * is to fixup the temporary rpi assignments.
3007 **/
3008void
3009lpfc_sli4_node_prep(struct lpfc_hba *phba)
3010{
3011 struct lpfc_nodelist *ndlp, *next_ndlp;
3012 struct lpfc_vport **vports;
James Smart9d3d3402017-04-21 16:05:00 -07003013 int i, rpi;
3014 unsigned long flags;
James Smart6b5151f2012-01-18 16:24:06 -05003015
3016 if (phba->sli_rev != LPFC_SLI_REV4)
3017 return;
3018
3019 vports = lpfc_create_vport_work_array(phba);
James Smart9d3d3402017-04-21 16:05:00 -07003020 if (vports == NULL)
3021 return;
James Smart6b5151f2012-01-18 16:24:06 -05003022
James Smart9d3d3402017-04-21 16:05:00 -07003023 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3024 if (vports[i]->load_flag & FC_UNLOADING)
3025 continue;
3026
3027 list_for_each_entry_safe(ndlp, next_ndlp,
3028 &vports[i]->fc_nodes,
3029 nlp_listp) {
3030 if (!NLP_CHK_NODE_ACT(ndlp))
3031 continue;
3032 rpi = lpfc_sli4_alloc_rpi(phba);
3033 if (rpi == LPFC_RPI_ALLOC_ERROR) {
3034 spin_lock_irqsave(&phba->ndlp_lock, flags);
3035 NLP_CLR_NODE_ACT(ndlp);
3036 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3037 continue;
James Smart6b5151f2012-01-18 16:24:06 -05003038 }
James Smart9d3d3402017-04-21 16:05:00 -07003039 ndlp->nlp_rpi = rpi;
3040 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3041 "0009 rpi:%x DID:%x "
3042 "flg:%x map:%x %p\n", ndlp->nlp_rpi,
3043 ndlp->nlp_DID, ndlp->nlp_flag,
3044 ndlp->nlp_usg_map, ndlp);
James Smart6b5151f2012-01-18 16:24:06 -05003045 }
3046 }
3047 lpfc_destroy_vport_work_array(phba, vports);
3048}
3049
3050/**
James Smart3621a712009-04-06 18:47:14 -04003051 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04003052 * @phba: pointer to lpfc hba data structure.
3053 *
3054 * This routine initializes the HBA and brings a HBA online. During this
3055 * process, the management interface is blocked to prevent user space access
3056 * to the HBA interfering with the driver initialization.
3057 *
3058 * Return codes
3059 * 0 - successful
3060 * 1 - failed
3061 **/
dea31012005-04-17 16:05:31 -05003062int
James Smart2e0fef82007-06-17 19:56:36 -05003063lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003064{
Julia Lawall372bd282008-12-16 16:15:08 +01003065 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04003066 struct lpfc_vport **vports;
Dick Kennedya145fda2017-08-23 16:55:44 -07003067 int i, error = 0;
James Smart16a3a202013-04-17 20:14:38 -04003068 bool vpis_cleared = false;
James Smart2e0fef82007-06-17 19:56:36 -05003069
dea31012005-04-17 16:05:31 -05003070 if (!phba)
3071 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01003072 vport = phba->pport;
dea31012005-04-17 16:05:31 -05003073
James Smart2e0fef82007-06-17 19:56:36 -05003074 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05003075 return 0;
3076
James Smarted957682007-06-17 19:56:37 -05003077 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003078 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05003079
James Smart618a5232012-06-12 13:54:36 -04003080 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05003081
James Smartda0436e2009-05-22 14:51:39 -04003082 if (phba->sli_rev == LPFC_SLI_REV4) {
3083 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
3084 lpfc_unblock_mgmt_io(phba);
3085 return 1;
3086 }
James Smart16a3a202013-04-17 20:14:38 -04003087 spin_lock_irq(&phba->hbalock);
3088 if (!phba->sli4_hba.max_cfg_param.vpi_used)
3089 vpis_cleared = true;
3090 spin_unlock_irq(&phba->hbalock);
Dick Kennedya145fda2017-08-23 16:55:44 -07003091
3092 /* Reestablish the local initiator port.
3093 * The offline process destroyed the previous lport.
3094 */
3095 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
3096 !phba->nvmet_support) {
3097 error = lpfc_nvme_create_localport(phba->pport);
3098 if (error)
3099 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3100 "6132 NVME restore reg failed "
3101 "on nvmei error x%x\n", error);
3102 }
James Smartda0436e2009-05-22 14:51:39 -04003103 } else {
James Smart895427b2017-02-12 13:52:30 -08003104 lpfc_sli_queue_init(phba);
James Smartda0436e2009-05-22 14:51:39 -04003105 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
3106 lpfc_unblock_mgmt_io(phba);
3107 return 1;
3108 }
James Smart46fa3112007-04-25 09:51:45 -04003109 }
dea31012005-04-17 16:05:31 -05003110
James Smart549e55c2007-08-02 11:09:51 -04003111 vports = lpfc_create_vport_work_array(phba);
Arnd Bergmannaeb66412016-03-14 15:29:44 +01003112 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003113 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003114 struct Scsi_Host *shost;
3115 shost = lpfc_shost_from_vport(vports[i]);
3116 spin_lock_irq(shost->host_lock);
3117 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
3118 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
3119 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart16a3a202013-04-17 20:14:38 -04003120 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart1c6834a2009-07-19 10:01:26 -04003121 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart16a3a202013-04-17 20:14:38 -04003122 if ((vpis_cleared) &&
3123 (vports[i]->port_type !=
3124 LPFC_PHYSICAL_PORT))
3125 vports[i]->vpi = 0;
3126 }
James Smart549e55c2007-08-02 11:09:51 -04003127 spin_unlock_irq(shost->host_lock);
3128 }
Arnd Bergmannaeb66412016-03-14 15:29:44 +01003129 }
3130 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003131
James Smart46fa3112007-04-25 09:51:45 -04003132 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05003133 return 0;
3134}
3135
James Smarte59058c2008-08-24 21:49:00 -04003136/**
James Smart3621a712009-04-06 18:47:14 -04003137 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04003138 * @phba: pointer to lpfc hba data structure.
3139 *
3140 * This routine marks a HBA's management interface as not blocked. Once the
3141 * HBA's management interface is marked as not blocked, all the user space
3142 * access to the HBA, whether they are from sysfs interface or libdfc
3143 * interface will be allowed. The HBA is set to block the management interface
3144 * when the driver prepares the HBA interface for online or offline and then
3145 * set to unblock the management interface afterwards.
3146 **/
James Smart46fa3112007-04-25 09:51:45 -04003147void
James Smart46fa3112007-04-25 09:51:45 -04003148lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
3149{
3150 unsigned long iflag;
3151
James Smart2e0fef82007-06-17 19:56:36 -05003152 spin_lock_irqsave(&phba->hbalock, iflag);
3153 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3154 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04003155}
3156
James Smarte59058c2008-08-24 21:49:00 -04003157/**
James Smart3621a712009-04-06 18:47:14 -04003158 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04003159 * @phba: pointer to lpfc hba data structure.
3160 *
3161 * This routine is invoked to prepare a HBA to be brought offline. It performs
3162 * unregistration login to all the nodes on all vports and flushes the mailbox
3163 * queue to make it ready to be brought offline.
3164 **/
James Smart46fa3112007-04-25 09:51:45 -04003165void
James Smart618a5232012-06-12 13:54:36 -04003166lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04003167{
James Smart2e0fef82007-06-17 19:56:36 -05003168 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04003169 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04003170 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05003171 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04003172 int i;
dea31012005-04-17 16:05:31 -05003173
James Smart2e0fef82007-06-17 19:56:36 -05003174 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003175 return;
dea31012005-04-17 16:05:31 -05003176
James Smart618a5232012-06-12 13:54:36 -04003177 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05003178
3179 lpfc_linkdown(phba);
3180
James Smart87af33f2007-10-27 13:37:43 -04003181 /* Issue an unreg_login to all nodes on all vports */
3182 vports = lpfc_create_vport_work_array(phba);
3183 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003184 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04003185 if (vports[i]->load_flag & FC_UNLOADING)
3186 continue;
James Smart72100cc2010-02-12 14:43:01 -05003187 shost = lpfc_shost_from_vport(vports[i]);
3188 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003189 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003190 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3191 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05003192 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05003193
James Smart87af33f2007-10-27 13:37:43 -04003194 shost = lpfc_shost_from_vport(vports[i]);
3195 list_for_each_entry_safe(ndlp, next_ndlp,
3196 &vports[i]->fc_nodes,
3197 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003198 if (!NLP_CHK_NODE_ACT(ndlp))
3199 continue;
James Smart87af33f2007-10-27 13:37:43 -04003200 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3201 continue;
3202 if (ndlp->nlp_type & NLP_FABRIC) {
3203 lpfc_disc_state_machine(vports[i], ndlp,
3204 NULL, NLP_EVT_DEVICE_RECOVERY);
3205 lpfc_disc_state_machine(vports[i], ndlp,
3206 NULL, NLP_EVT_DEVICE_RM);
3207 }
3208 spin_lock_irq(shost->host_lock);
3209 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart401ee0c2012-03-01 22:35:34 -05003210 spin_unlock_irq(shost->host_lock);
James Smart6b5151f2012-01-18 16:24:06 -05003211 /*
3212 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05003213 * RPI. Get a new RPI when the adapter port
3214 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05003215 */
James Smartbe6bb942015-04-07 15:07:22 -04003216 if (phba->sli_rev == LPFC_SLI_REV4) {
3217 lpfc_printf_vlog(ndlp->vport,
3218 KERN_INFO, LOG_NODE,
3219 "0011 lpfc_offline: "
3220 "ndlp:x%p did %x "
3221 "usgmap:x%x rpi:%x\n",
3222 ndlp, ndlp->nlp_DID,
3223 ndlp->nlp_usg_map,
3224 ndlp->nlp_rpi);
3225
James Smart6b5151f2012-01-18 16:24:06 -05003226 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smartbe6bb942015-04-07 15:07:22 -04003227 }
James Smart87af33f2007-10-27 13:37:43 -04003228 lpfc_unreg_rpi(vports[i], ndlp);
3229 }
3230 }
3231 }
James Smart09372822008-01-11 01:52:54 -05003232 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003233
James Smart618a5232012-06-12 13:54:36 -04003234 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
Dick Kennedyf485c182017-09-29 17:34:34 -07003235
3236 if (phba->wq)
3237 flush_workqueue(phba->wq);
James Smart46fa3112007-04-25 09:51:45 -04003238}
3239
James Smarte59058c2008-08-24 21:49:00 -04003240/**
James Smart3621a712009-04-06 18:47:14 -04003241 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04003242 * @phba: pointer to lpfc hba data structure.
3243 *
3244 * This routine actually brings a HBA offline. It stops all the timers
3245 * associated with the HBA, brings down the SLI layer, and eventually
3246 * marks the HBA as in offline state for the upper layer protocol.
3247 **/
James Smart46fa3112007-04-25 09:51:45 -04003248void
James Smart2e0fef82007-06-17 19:56:36 -05003249lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04003250{
James Smart549e55c2007-08-02 11:09:51 -04003251 struct Scsi_Host *shost;
3252 struct lpfc_vport **vports;
3253 int i;
James Smart46fa3112007-04-25 09:51:45 -04003254
James Smart549e55c2007-08-02 11:09:51 -04003255 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003256 return;
James Smart688a8862006-07-06 15:49:56 -04003257
James Smartda0436e2009-05-22 14:51:39 -04003258 /* stop port and all timers associated with this hba */
3259 lpfc_stop_port(phba);
Dick Kennedy4b40d022017-08-23 16:55:38 -07003260
3261 /* Tear down the local and target port registrations. The
3262 * nvme transports need to cleanup.
3263 */
3264 lpfc_nvmet_destroy_targetport(phba);
3265 lpfc_nvme_destroy_localport(phba->pport);
3266
James Smart51ef4c22007-08-02 11:10:31 -04003267 vports = lpfc_create_vport_work_array(phba);
3268 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003269 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04003270 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05003271 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05003272 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003273 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05003274 /* Bring down the SLI Layer and cleanup. The HBA is offline
3275 now. */
3276 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003277 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04003278 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003279 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04003280 vports = lpfc_create_vport_work_array(phba);
3281 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003282 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003283 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04003284 spin_lock_irq(shost->host_lock);
3285 vports[i]->work_port_events = 0;
3286 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3287 spin_unlock_irq(shost->host_lock);
3288 }
James Smart09372822008-01-11 01:52:54 -05003289 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003290}
3291
James Smarte59058c2008-08-24 21:49:00 -04003292/**
James Smart3621a712009-04-06 18:47:14 -04003293 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04003294 * @phba: pointer to lpfc hba data structure.
3295 *
3296 * This routine is to free all the SCSI buffers and IOCBs from the driver
3297 * list back to kernel. It is called from lpfc_pci_remove_one to free
3298 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04003299 **/
James Smart8a9d2e82012-05-09 21:16:12 -04003300static void
James Smart2e0fef82007-06-17 19:56:36 -05003301lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003302{
3303 struct lpfc_scsi_buf *sb, *sb_next;
dea31012005-04-17 16:05:31 -05003304
James Smart895427b2017-02-12 13:52:30 -08003305 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3306 return;
3307
James Smart2e0fef82007-06-17 19:56:36 -05003308 spin_lock_irq(&phba->hbalock);
James Smarta40fc5f2013-04-17 20:17:40 -04003309
dea31012005-04-17 16:05:31 -05003310 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smarta40fc5f2013-04-17 20:17:40 -04003311
3312 spin_lock(&phba->scsi_buf_list_put_lock);
3313 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3314 list) {
dea31012005-04-17 16:05:31 -05003315 list_del(&sb->list);
Romain Perier771db5c2017-07-06 10:13:05 +02003316 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05003317 sb->dma_handle);
dea31012005-04-17 16:05:31 -05003318 kfree(sb);
3319 phba->total_scsi_bufs--;
3320 }
James Smarta40fc5f2013-04-17 20:17:40 -04003321 spin_unlock(&phba->scsi_buf_list_put_lock);
3322
3323 spin_lock(&phba->scsi_buf_list_get_lock);
3324 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3325 list) {
3326 list_del(&sb->list);
Romain Perier771db5c2017-07-06 10:13:05 +02003327 dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smarta40fc5f2013-04-17 20:17:40 -04003328 sb->dma_handle);
3329 kfree(sb);
3330 phba->total_scsi_bufs--;
3331 }
3332 spin_unlock(&phba->scsi_buf_list_get_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003333 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003334}
James Smart8a9d2e82012-05-09 21:16:12 -04003335/**
James Smart895427b2017-02-12 13:52:30 -08003336 * lpfc_nvme_free - Free all the NVME buffers and IOCBs from driver lists
3337 * @phba: pointer to lpfc hba data structure.
3338 *
3339 * This routine is to free all the NVME buffers and IOCBs from the driver
3340 * list back to kernel. It is called from lpfc_pci_remove_one to free
3341 * the internal resources before the device is removed from the system.
3342 **/
3343static void
3344lpfc_nvme_free(struct lpfc_hba *phba)
3345{
3346 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
James Smart895427b2017-02-12 13:52:30 -08003347
3348 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3349 return;
3350
3351 spin_lock_irq(&phba->hbalock);
3352
3353 /* Release all the lpfc_nvme_bufs maintained by this host. */
3354 spin_lock(&phba->nvme_buf_list_put_lock);
3355 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3356 &phba->lpfc_nvme_buf_list_put, list) {
3357 list_del(&lpfc_ncmd->list);
James Smartcf1a1d32017-12-08 17:18:03 -08003358 phba->put_nvme_bufs--;
Romain Perier771db5c2017-07-06 10:13:05 +02003359 dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
James Smart895427b2017-02-12 13:52:30 -08003360 lpfc_ncmd->dma_handle);
3361 kfree(lpfc_ncmd);
3362 phba->total_nvme_bufs--;
3363 }
3364 spin_unlock(&phba->nvme_buf_list_put_lock);
3365
3366 spin_lock(&phba->nvme_buf_list_get_lock);
3367 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3368 &phba->lpfc_nvme_buf_list_get, list) {
3369 list_del(&lpfc_ncmd->list);
James Smartcf1a1d32017-12-08 17:18:03 -08003370 phba->get_nvme_bufs--;
Romain Perier771db5c2017-07-06 10:13:05 +02003371 dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
James Smart895427b2017-02-12 13:52:30 -08003372 lpfc_ncmd->dma_handle);
3373 kfree(lpfc_ncmd);
3374 phba->total_nvme_bufs--;
3375 }
3376 spin_unlock(&phba->nvme_buf_list_get_lock);
James Smart895427b2017-02-12 13:52:30 -08003377 spin_unlock_irq(&phba->hbalock);
3378}
3379/**
3380 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
James Smart8a9d2e82012-05-09 21:16:12 -04003381 * @phba: pointer to lpfc hba data structure.
3382 *
3383 * This routine first calculates the sizes of the current els and allocated
3384 * scsi sgl lists, and then goes through all sgls to updates the physical
3385 * XRIs assigned due to port function reset. During port initialization, the
3386 * current els and allocated scsi sgl lists are 0s.
3387 *
3388 * Return codes
3389 * 0 - successful (for now, it always returns 0)
3390 **/
3391int
James Smart895427b2017-02-12 13:52:30 -08003392lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
James Smart8a9d2e82012-05-09 21:16:12 -04003393{
3394 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
James Smart895427b2017-02-12 13:52:30 -08003395 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart8a9d2e82012-05-09 21:16:12 -04003396 LIST_HEAD(els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003397 int rc;
3398
3399 /*
3400 * update on pci function's els xri-sgl list
3401 */
3402 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart895427b2017-02-12 13:52:30 -08003403
James Smart8a9d2e82012-05-09 21:16:12 -04003404 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3405 /* els xri-sgl expanded */
3406 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3407 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3408 "3157 ELS xri-sgl count increased from "
3409 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3410 els_xri_cnt);
3411 /* allocate the additional els sgls */
3412 for (i = 0; i < xri_cnt; i++) {
3413 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3414 GFP_KERNEL);
3415 if (sglq_entry == NULL) {
3416 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3417 "2562 Failure to allocate an "
3418 "ELS sgl entry:%d\n", i);
3419 rc = -ENOMEM;
3420 goto out_free_mem;
3421 }
3422 sglq_entry->buff_type = GEN_BUFF_TYPE;
3423 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3424 &sglq_entry->phys);
3425 if (sglq_entry->virt == NULL) {
3426 kfree(sglq_entry);
3427 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3428 "2563 Failure to allocate an "
3429 "ELS mbuf:%d\n", i);
3430 rc = -ENOMEM;
3431 goto out_free_mem;
3432 }
3433 sglq_entry->sgl = sglq_entry->virt;
3434 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3435 sglq_entry->state = SGL_FREED;
3436 list_add_tail(&sglq_entry->list, &els_sgl_list);
3437 }
James Smart38c20672013-03-01 16:37:44 -05003438 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003439 spin_lock(&phba->sli4_hba.sgl_list_lock);
3440 list_splice_init(&els_sgl_list,
3441 &phba->sli4_hba.lpfc_els_sgl_list);
3442 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart38c20672013-03-01 16:37:44 -05003443 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003444 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3445 /* els xri-sgl shrinked */
3446 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3447 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3448 "3158 ELS xri-sgl count decreased from "
3449 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3450 els_xri_cnt);
3451 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003452 spin_lock(&phba->sli4_hba.sgl_list_lock);
3453 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
3454 &els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003455 /* release extra els sgls from list */
3456 for (i = 0; i < xri_cnt; i++) {
3457 list_remove_head(&els_sgl_list,
3458 sglq_entry, struct lpfc_sglq, list);
3459 if (sglq_entry) {
James Smart895427b2017-02-12 13:52:30 -08003460 __lpfc_mbuf_free(phba, sglq_entry->virt,
3461 sglq_entry->phys);
James Smart8a9d2e82012-05-09 21:16:12 -04003462 kfree(sglq_entry);
3463 }
3464 }
James Smart895427b2017-02-12 13:52:30 -08003465 list_splice_init(&els_sgl_list,
3466 &phba->sli4_hba.lpfc_els_sgl_list);
3467 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003468 spin_unlock_irq(&phba->hbalock);
3469 } else
3470 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3471 "3163 ELS xri-sgl count unchanged: %d\n",
3472 els_xri_cnt);
3473 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3474
3475 /* update xris to els sgls on the list */
3476 sglq_entry = NULL;
3477 sglq_entry_next = NULL;
3478 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
James Smart895427b2017-02-12 13:52:30 -08003479 &phba->sli4_hba.lpfc_els_sgl_list, list) {
James Smart8a9d2e82012-05-09 21:16:12 -04003480 lxri = lpfc_sli4_next_xritag(phba);
3481 if (lxri == NO_XRI) {
3482 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3483 "2400 Failed to allocate xri for "
3484 "ELS sgl\n");
3485 rc = -ENOMEM;
3486 goto out_free_mem;
3487 }
3488 sglq_entry->sli4_lxritag = lxri;
3489 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3490 }
James Smart895427b2017-02-12 13:52:30 -08003491 return 0;
3492
3493out_free_mem:
3494 lpfc_free_els_sgl_list(phba);
3495 return rc;
3496}
3497
3498/**
James Smartf358dd02017-02-12 13:52:34 -08003499 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
3500 * @phba: pointer to lpfc hba data structure.
3501 *
3502 * This routine first calculates the sizes of the current els and allocated
3503 * scsi sgl lists, and then goes through all sgls to updates the physical
3504 * XRIs assigned due to port function reset. During port initialization, the
3505 * current els and allocated scsi sgl lists are 0s.
3506 *
3507 * Return codes
3508 * 0 - successful (for now, it always returns 0)
3509 **/
3510int
3511lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
3512{
3513 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3514 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart6c621a22017-05-15 15:20:45 -07003515 uint16_t nvmet_xri_cnt;
James Smartf358dd02017-02-12 13:52:34 -08003516 LIST_HEAD(nvmet_sgl_list);
3517 int rc;
3518
3519 /*
3520 * update on pci function's nvmet xri-sgl list
3521 */
3522 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart61f3d4b2017-05-15 15:20:41 -07003523
James Smart6c621a22017-05-15 15:20:45 -07003524 /* For NVMET, ALL remaining XRIs are dedicated for IO processing */
3525 nvmet_xri_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
James Smartf358dd02017-02-12 13:52:34 -08003526 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
3527 /* els xri-sgl expanded */
3528 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
3529 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3530 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
3531 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
3532 /* allocate the additional nvmet sgls */
3533 for (i = 0; i < xri_cnt; i++) {
3534 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3535 GFP_KERNEL);
3536 if (sglq_entry == NULL) {
3537 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3538 "6303 Failure to allocate an "
3539 "NVMET sgl entry:%d\n", i);
3540 rc = -ENOMEM;
3541 goto out_free_mem;
3542 }
3543 sglq_entry->buff_type = NVMET_BUFF_TYPE;
3544 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
3545 &sglq_entry->phys);
3546 if (sglq_entry->virt == NULL) {
3547 kfree(sglq_entry);
3548 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3549 "6304 Failure to allocate an "
3550 "NVMET buf:%d\n", i);
3551 rc = -ENOMEM;
3552 goto out_free_mem;
3553 }
3554 sglq_entry->sgl = sglq_entry->virt;
3555 memset(sglq_entry->sgl, 0,
3556 phba->cfg_sg_dma_buf_size);
3557 sglq_entry->state = SGL_FREED;
3558 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
3559 }
3560 spin_lock_irq(&phba->hbalock);
3561 spin_lock(&phba->sli4_hba.sgl_list_lock);
3562 list_splice_init(&nvmet_sgl_list,
3563 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3564 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3565 spin_unlock_irq(&phba->hbalock);
3566 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
3567 /* nvmet xri-sgl shrunk */
3568 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
3569 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3570 "6305 NVMET xri-sgl count decreased from "
3571 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
3572 nvmet_xri_cnt);
3573 spin_lock_irq(&phba->hbalock);
3574 spin_lock(&phba->sli4_hba.sgl_list_lock);
3575 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
3576 &nvmet_sgl_list);
3577 /* release extra nvmet sgls from list */
3578 for (i = 0; i < xri_cnt; i++) {
3579 list_remove_head(&nvmet_sgl_list,
3580 sglq_entry, struct lpfc_sglq, list);
3581 if (sglq_entry) {
3582 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
3583 sglq_entry->phys);
3584 kfree(sglq_entry);
3585 }
3586 }
3587 list_splice_init(&nvmet_sgl_list,
3588 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3589 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3590 spin_unlock_irq(&phba->hbalock);
3591 } else
3592 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3593 "6306 NVMET xri-sgl count unchanged: %d\n",
3594 nvmet_xri_cnt);
3595 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
3596
3597 /* update xris to nvmet sgls on the list */
3598 sglq_entry = NULL;
3599 sglq_entry_next = NULL;
3600 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3601 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
3602 lxri = lpfc_sli4_next_xritag(phba);
3603 if (lxri == NO_XRI) {
3604 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3605 "6307 Failed to allocate xri for "
3606 "NVMET sgl\n");
3607 rc = -ENOMEM;
3608 goto out_free_mem;
3609 }
3610 sglq_entry->sli4_lxritag = lxri;
3611 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3612 }
3613 return 0;
3614
3615out_free_mem:
3616 lpfc_free_nvmet_sgl_list(phba);
3617 return rc;
3618}
3619
3620/**
James Smart895427b2017-02-12 13:52:30 -08003621 * lpfc_sli4_scsi_sgl_update - update xri-sgl sizing and mapping
3622 * @phba: pointer to lpfc hba data structure.
3623 *
3624 * This routine first calculates the sizes of the current els and allocated
3625 * scsi sgl lists, and then goes through all sgls to updates the physical
3626 * XRIs assigned due to port function reset. During port initialization, the
3627 * current els and allocated scsi sgl lists are 0s.
3628 *
3629 * Return codes
3630 * 0 - successful (for now, it always returns 0)
3631 **/
3632int
3633lpfc_sli4_scsi_sgl_update(struct lpfc_hba *phba)
3634{
3635 struct lpfc_scsi_buf *psb, *psb_next;
3636 uint16_t i, lxri, els_xri_cnt, scsi_xri_cnt;
3637 LIST_HEAD(scsi_sgl_list);
3638 int rc;
3639
3640 /*
3641 * update on pci function's els xri-sgl list
3642 */
3643 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3644 phba->total_scsi_bufs = 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003645
3646 /*
3647 * update on pci function's allocated scsi xri-sgl list
3648 */
James Smart8a9d2e82012-05-09 21:16:12 -04003649 /* maximum number of xris available for scsi buffers */
3650 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3651 els_xri_cnt;
3652
James Smart895427b2017-02-12 13:52:30 -08003653 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3654 return 0;
3655
3656 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3657 phba->sli4_hba.scsi_xri_max = /* Split them up */
3658 (phba->sli4_hba.scsi_xri_max *
3659 phba->cfg_xri_split) / 100;
James Smart8a9d2e82012-05-09 21:16:12 -04003660
James Smarta40fc5f2013-04-17 20:17:40 -04003661 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003662 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003663 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3664 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
James Smart164cecd2013-09-06 12:22:38 -04003665 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003666 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003667
James Smarte8c0a772017-04-21 16:04:49 -07003668 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3669 "6060 Current allocated SCSI xri-sgl count:%d, "
3670 "maximum SCSI xri count:%d (split:%d)\n",
3671 phba->sli4_hba.scsi_xri_cnt,
3672 phba->sli4_hba.scsi_xri_max, phba->cfg_xri_split);
3673
James Smart8a9d2e82012-05-09 21:16:12 -04003674 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3675 /* max scsi xri shrinked below the allocated scsi buffers */
3676 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3677 phba->sli4_hba.scsi_xri_max;
3678 /* release the extra allocated scsi buffers */
3679 for (i = 0; i < scsi_xri_cnt; i++) {
3680 list_remove_head(&scsi_sgl_list, psb,
3681 struct lpfc_scsi_buf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04003682 if (psb) {
Romain Perier771db5c2017-07-06 10:13:05 +02003683 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
James Smarta2fc4aef2014-09-03 12:57:55 -04003684 psb->data, psb->dma_handle);
3685 kfree(psb);
3686 }
James Smart8a9d2e82012-05-09 21:16:12 -04003687 }
James Smarta40fc5f2013-04-17 20:17:40 -04003688 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003689 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
James Smarta40fc5f2013-04-17 20:17:40 -04003690 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003691 }
3692
3693 /* update xris associated to remaining allocated scsi buffers */
3694 psb = NULL;
3695 psb_next = NULL;
3696 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3697 lxri = lpfc_sli4_next_xritag(phba);
3698 if (lxri == NO_XRI) {
3699 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3700 "2560 Failed to allocate xri for "
3701 "scsi buffer\n");
3702 rc = -ENOMEM;
3703 goto out_free_mem;
3704 }
3705 psb->cur_iocbq.sli4_lxritag = lxri;
3706 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3707 }
James Smarta40fc5f2013-04-17 20:17:40 -04003708 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003709 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003710 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3711 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
James Smart164cecd2013-09-06 12:22:38 -04003712 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003713 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
dea31012005-04-17 16:05:31 -05003714 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003715
3716out_free_mem:
James Smart8a9d2e82012-05-09 21:16:12 -04003717 lpfc_scsi_free(phba);
3718 return rc;
dea31012005-04-17 16:05:31 -05003719}
3720
James Smart96418b52017-03-04 09:30:31 -08003721static uint64_t
3722lpfc_get_wwpn(struct lpfc_hba *phba)
3723{
3724 uint64_t wwn;
3725 int rc;
3726 LPFC_MBOXQ_t *mboxq;
3727 MAILBOX_t *mb;
3728
James Smart96418b52017-03-04 09:30:31 -08003729 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
3730 GFP_KERNEL);
3731 if (!mboxq)
3732 return (uint64_t)-1;
3733
3734 /* First get WWN of HBA instance */
3735 lpfc_read_nv(phba, mboxq);
3736 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
3737 if (rc != MBX_SUCCESS) {
3738 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3739 "6019 Mailbox failed , mbxCmd x%x "
3740 "READ_NV, mbxStatus x%x\n",
3741 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
3742 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
3743 mempool_free(mboxq, phba->mbox_mem_pool);
3744 return (uint64_t) -1;
3745 }
3746 mb = &mboxq->u.mb;
3747 memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
3748 /* wwn is WWPN of HBA instance */
3749 mempool_free(mboxq, phba->mbox_mem_pool);
3750 if (phba->sli_rev == LPFC_SLI_REV4)
3751 return be64_to_cpu(wwn);
3752 else
Maurizio Lombardi286871a2017-08-23 16:55:48 -07003753 return rol64(wwn, 32);
James Smart96418b52017-03-04 09:30:31 -08003754}
3755
James Smarte59058c2008-08-24 21:49:00 -04003756/**
James Smart895427b2017-02-12 13:52:30 -08003757 * lpfc_sli4_nvme_sgl_update - update xri-sgl sizing and mapping
3758 * @phba: pointer to lpfc hba data structure.
3759 *
3760 * This routine first calculates the sizes of the current els and allocated
3761 * scsi sgl lists, and then goes through all sgls to updates the physical
3762 * XRIs assigned due to port function reset. During port initialization, the
3763 * current els and allocated scsi sgl lists are 0s.
3764 *
3765 * Return codes
3766 * 0 - successful (for now, it always returns 0)
3767 **/
3768int
3769lpfc_sli4_nvme_sgl_update(struct lpfc_hba *phba)
3770{
3771 struct lpfc_nvme_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
3772 uint16_t i, lxri, els_xri_cnt;
3773 uint16_t nvme_xri_cnt, nvme_xri_max;
3774 LIST_HEAD(nvme_sgl_list);
James Smartcf1a1d32017-12-08 17:18:03 -08003775 int rc, cnt;
James Smart895427b2017-02-12 13:52:30 -08003776
3777 phba->total_nvme_bufs = 0;
James Smartcf1a1d32017-12-08 17:18:03 -08003778 phba->get_nvme_bufs = 0;
3779 phba->put_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08003780
3781 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3782 return 0;
3783 /*
3784 * update on pci function's allocated nvme xri-sgl list
3785 */
3786
3787 /* maximum number of xris available for nvme buffers */
3788 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3789 nvme_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3790 phba->sli4_hba.nvme_xri_max = nvme_xri_max;
3791 phba->sli4_hba.nvme_xri_max -= phba->sli4_hba.scsi_xri_max;
3792
3793 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3794 "6074 Current allocated NVME xri-sgl count:%d, "
3795 "maximum NVME xri count:%d\n",
3796 phba->sli4_hba.nvme_xri_cnt,
3797 phba->sli4_hba.nvme_xri_max);
3798
3799 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3800 spin_lock(&phba->nvme_buf_list_put_lock);
3801 list_splice_init(&phba->lpfc_nvme_buf_list_get, &nvme_sgl_list);
3802 list_splice(&phba->lpfc_nvme_buf_list_put, &nvme_sgl_list);
James Smartcf1a1d32017-12-08 17:18:03 -08003803 cnt = phba->get_nvme_bufs + phba->put_nvme_bufs;
3804 phba->get_nvme_bufs = 0;
3805 phba->put_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08003806 spin_unlock(&phba->nvme_buf_list_put_lock);
3807 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3808
3809 if (phba->sli4_hba.nvme_xri_cnt > phba->sli4_hba.nvme_xri_max) {
3810 /* max nvme xri shrunk below the allocated nvme buffers */
3811 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3812 nvme_xri_cnt = phba->sli4_hba.nvme_xri_cnt -
3813 phba->sli4_hba.nvme_xri_max;
3814 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3815 /* release the extra allocated nvme buffers */
3816 for (i = 0; i < nvme_xri_cnt; i++) {
3817 list_remove_head(&nvme_sgl_list, lpfc_ncmd,
3818 struct lpfc_nvme_buf, list);
3819 if (lpfc_ncmd) {
Romain Perier771db5c2017-07-06 10:13:05 +02003820 dma_pool_free(phba->lpfc_sg_dma_buf_pool,
James Smart895427b2017-02-12 13:52:30 -08003821 lpfc_ncmd->data,
3822 lpfc_ncmd->dma_handle);
3823 kfree(lpfc_ncmd);
3824 }
3825 }
3826 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3827 phba->sli4_hba.nvme_xri_cnt -= nvme_xri_cnt;
3828 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3829 }
3830
3831 /* update xris associated to remaining allocated nvme buffers */
3832 lpfc_ncmd = NULL;
3833 lpfc_ncmd_next = NULL;
3834 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3835 &nvme_sgl_list, list) {
3836 lxri = lpfc_sli4_next_xritag(phba);
3837 if (lxri == NO_XRI) {
3838 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3839 "6075 Failed to allocate xri for "
3840 "nvme buffer\n");
3841 rc = -ENOMEM;
3842 goto out_free_mem;
3843 }
3844 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
3845 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3846 }
3847 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3848 spin_lock(&phba->nvme_buf_list_put_lock);
3849 list_splice_init(&nvme_sgl_list, &phba->lpfc_nvme_buf_list_get);
James Smartcf1a1d32017-12-08 17:18:03 -08003850 phba->get_nvme_bufs = cnt;
James Smart895427b2017-02-12 13:52:30 -08003851 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
3852 spin_unlock(&phba->nvme_buf_list_put_lock);
3853 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3854 return 0;
3855
3856out_free_mem:
3857 lpfc_nvme_free(phba);
3858 return rc;
3859}
3860
3861/**
James Smart3621a712009-04-06 18:47:14 -04003862 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04003863 * @phba: pointer to lpfc hba data structure.
3864 * @instance: a unique integer ID to this FC port.
3865 * @dev: pointer to the device data structure.
3866 *
3867 * This routine creates a FC port for the upper layer protocol. The FC port
3868 * can be created on top of either a physical port or a virtual port provided
3869 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3870 * and associates the FC port created before adding the shost into the SCSI
3871 * layer.
3872 *
3873 * Return codes
3874 * @vport - pointer to the virtual N_Port data structure.
3875 * NULL - port create failed.
3876 **/
James Smart2e0fef82007-06-17 19:56:36 -05003877struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04003878lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04003879{
James Smart2e0fef82007-06-17 19:56:36 -05003880 struct lpfc_vport *vport;
James Smart895427b2017-02-12 13:52:30 -08003881 struct Scsi_Host *shost = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003882 int error = 0;
James Smart96418b52017-03-04 09:30:31 -08003883 int i;
3884 uint64_t wwn;
3885 bool use_no_reset_hba = false;
James Smart56bc8022017-06-15 22:56:43 -07003886 int rc;
James Smart96418b52017-03-04 09:30:31 -08003887
James Smart56bc8022017-06-15 22:56:43 -07003888 if (lpfc_no_hba_reset_cnt) {
3889 if (phba->sli_rev < LPFC_SLI_REV4 &&
3890 dev == &phba->pcidev->dev) {
3891 /* Reset the port first */
3892 lpfc_sli_brdrestart(phba);
3893 rc = lpfc_sli_chipset_init(phba);
3894 if (rc)
3895 return NULL;
3896 }
3897 wwn = lpfc_get_wwpn(phba);
3898 }
James Smart96418b52017-03-04 09:30:31 -08003899
3900 for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
3901 if (wwn == lpfc_no_hba_reset[i]) {
3902 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3903 "6020 Setting use_no_reset port=%llx\n",
3904 wwn);
3905 use_no_reset_hba = true;
3906 break;
3907 }
3908 }
James Smart47a86172007-04-25 09:53:22 -04003909
James Smart895427b2017-02-12 13:52:30 -08003910 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
3911 if (dev != &phba->pcidev->dev) {
3912 shost = scsi_host_alloc(&lpfc_vport_template,
3913 sizeof(struct lpfc_vport));
3914 } else {
James Smart96418b52017-03-04 09:30:31 -08003915 if (!use_no_reset_hba)
James Smart895427b2017-02-12 13:52:30 -08003916 shost = scsi_host_alloc(&lpfc_template,
3917 sizeof(struct lpfc_vport));
3918 else
James Smart96418b52017-03-04 09:30:31 -08003919 shost = scsi_host_alloc(&lpfc_template_no_hr,
James Smart895427b2017-02-12 13:52:30 -08003920 sizeof(struct lpfc_vport));
3921 }
3922 } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
3923 shost = scsi_host_alloc(&lpfc_template_nvme,
James Smartea4142f2015-04-07 15:07:13 -04003924 sizeof(struct lpfc_vport));
3925 }
James Smart2e0fef82007-06-17 19:56:36 -05003926 if (!shost)
3927 goto out;
James Smart47a86172007-04-25 09:53:22 -04003928
James Smart2e0fef82007-06-17 19:56:36 -05003929 vport = (struct lpfc_vport *) shost->hostdata;
3930 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05003931 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05003932 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05003933 vport->fc_rscn_flush = 0;
James Smart3de2a652007-08-02 11:09:59 -04003934 lpfc_get_vport_cfgparam(vport);
James Smart895427b2017-02-12 13:52:30 -08003935
James Smart2e0fef82007-06-17 19:56:36 -05003936 shost->unique_id = instance;
3937 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04003938 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05003939 shost->this_id = -1;
3940 shost->max_cmd_len = 16;
James Smart8b0dff12015-05-22 10:42:38 -04003941 shost->nr_hw_queues = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04003942 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05003943 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04003944 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smartda0436e2009-05-22 14:51:39 -04003945 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
3946 }
James Smart81301a92008-12-04 22:39:46 -05003947
James Smart47a86172007-04-25 09:53:22 -04003948 /*
James Smart2e0fef82007-06-17 19:56:36 -05003949 * Set initial can_queue value since 0 is no longer supported and
3950 * scsi_add_host will fail. This will be adjusted later based on the
3951 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04003952 */
James Smart2e0fef82007-06-17 19:56:36 -05003953 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04003954 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05003955 shost->transportt = lpfc_vport_transport_template;
3956 vport->port_type = LPFC_NPIV_PORT;
3957 } else {
3958 shost->transportt = lpfc_transport_template;
3959 vport->port_type = LPFC_PHYSICAL_PORT;
3960 }
James Smart47a86172007-04-25 09:53:22 -04003961
James Smart2e0fef82007-06-17 19:56:36 -05003962 /* Initialize all internally managed lists. */
3963 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04003964 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05003965 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04003966
Kees Cookf22eb4d2017-09-06 20:24:26 -07003967 timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0);
James Smart47a86172007-04-25 09:53:22 -04003968
Kees Cookf22eb4d2017-09-06 20:24:26 -07003969 timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0);
James Smart92494142011-02-16 12:39:44 -05003970
Kees Cookf22eb4d2017-09-06 20:24:26 -07003971 timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0);
James Smart92494142011-02-16 12:39:44 -05003972
James Bottomleyd139b9b2009-11-05 13:33:12 -06003973 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05003974 if (error)
3975 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04003976
James Smart549e55c2007-08-02 11:09:51 -04003977 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003978 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04003979 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003980 return vport;
James Smart47a86172007-04-25 09:53:22 -04003981
James Smart2e0fef82007-06-17 19:56:36 -05003982out_put_shost:
3983 scsi_host_put(shost);
3984out:
3985 return NULL;
James Smart47a86172007-04-25 09:53:22 -04003986}
3987
James Smarte59058c2008-08-24 21:49:00 -04003988/**
James Smart3621a712009-04-06 18:47:14 -04003989 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04003990 * @vport: pointer to an lpfc virtual N_Port data structure.
3991 *
3992 * This routine destroys a FC port from the upper layer protocol. All the
3993 * resources associated with the port are released.
3994 **/
James Smart2e0fef82007-06-17 19:56:36 -05003995void
3996destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04003997{
James Smart92d7f7b2007-06-17 19:56:38 -05003998 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3999 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04004000
James Smart858c9f62007-06-17 19:56:39 -05004001 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05004002 fc_remove_host(shost);
4003 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04004004
James Smart92d7f7b2007-06-17 19:56:38 -05004005 spin_lock_irq(&phba->hbalock);
4006 list_del_init(&vport->listentry);
4007 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04004008
James Smart92d7f7b2007-06-17 19:56:38 -05004009 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04004010 return;
James Smart47a86172007-04-25 09:53:22 -04004011}
4012
James Smarte59058c2008-08-24 21:49:00 -04004013/**
James Smart3621a712009-04-06 18:47:14 -04004014 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04004015 *
4016 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
4017 * uses the kernel idr facility to perform the task.
4018 *
4019 * Return codes:
4020 * instance - a unique integer ID allocated as the new instance.
4021 * -1 - lpfc get instance failed.
4022 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004023int
4024lpfc_get_instance(void)
4025{
Tejun Heoab516032013-02-27 17:04:44 -08004026 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05004027
Tejun Heoab516032013-02-27 17:04:44 -08004028 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
4029 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05004030}
4031
James Smarte59058c2008-08-24 21:49:00 -04004032/**
James Smart3621a712009-04-06 18:47:14 -04004033 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04004034 * @shost: pointer to SCSI host data structure.
4035 * @time: elapsed time of the scan in jiffies.
4036 *
4037 * This routine is called by the SCSI layer with a SCSI host to determine
4038 * whether the scan host is finished.
4039 *
4040 * Note: there is no scan_start function as adapter initialization will have
4041 * asynchronously kicked off the link initialization.
4042 *
4043 * Return codes
4044 * 0 - SCSI host scan is not over yet.
4045 * 1 - SCSI host scan is over.
4046 **/
James Smart47a86172007-04-25 09:53:22 -04004047int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
4048{
James Smart2e0fef82007-06-17 19:56:36 -05004049 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4050 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05004051 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04004052
James Smart858c9f62007-06-17 19:56:39 -05004053 spin_lock_irq(shost->host_lock);
4054
James Smart51ef4c22007-08-02 11:10:31 -04004055 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05004056 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004057 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05004058 }
James Smart256ec0d2013-04-17 20:14:58 -04004059 if (time >= msecs_to_jiffies(30 * 1000)) {
James Smart2e0fef82007-06-17 19:56:36 -05004060 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004061 "0461 Scanning longer than 30 "
4062 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05004063 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004064 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004065 }
James Smart256ec0d2013-04-17 20:14:58 -04004066 if (time >= msecs_to_jiffies(15 * 1000) &&
4067 phba->link_state <= LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05004068 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04004069 "0465 Link down longer than 15 "
4070 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05004071 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05004072 goto finished;
James Smart47a86172007-04-25 09:53:22 -04004073 }
4074
James Smart2e0fef82007-06-17 19:56:36 -05004075 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05004076 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004077 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05004078 goto finished;
James Smart256ec0d2013-04-17 20:14:58 -04004079 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
James Smart858c9f62007-06-17 19:56:39 -05004080 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05004081 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05004082 goto finished;
4083
4084 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04004085
4086finished:
James Smart858c9f62007-06-17 19:56:39 -05004087 spin_unlock_irq(shost->host_lock);
4088 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05004089}
4090
James Smarte59058c2008-08-24 21:49:00 -04004091/**
James Smart3621a712009-04-06 18:47:14 -04004092 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04004093 * @shost: pointer to SCSI host data structure.
4094 *
4095 * This routine initializes a given SCSI host attributes on a FC port. The
4096 * SCSI host can be either on top of a physical port or a virtual port.
4097 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004098void lpfc_host_attrib_init(struct Scsi_Host *shost)
4099{
4100 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4101 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04004102 /*
James Smart2e0fef82007-06-17 19:56:36 -05004103 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04004104 */
4105
James Smart2e0fef82007-06-17 19:56:36 -05004106 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
4107 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04004108 fc_host_supported_classes(shost) = FC_COS_CLASS3;
4109
4110 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05004111 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04004112 fc_host_supported_fc4s(shost)[2] = 1;
4113 fc_host_supported_fc4s(shost)[7] = 1;
4114
James Smart92d7f7b2007-06-17 19:56:38 -05004115 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
4116 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04004117
4118 fc_host_supported_speeds(shost) = 0;
James Smartfbd8a6b2018-02-22 08:18:45 -08004119 if (phba->lmt & LMT_64Gb)
4120 fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT;
James Smartd38dd522015-08-31 16:48:17 -04004121 if (phba->lmt & LMT_32Gb)
4122 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
James Smart88a2cfb2011-07-22 18:36:33 -04004123 if (phba->lmt & LMT_16Gb)
4124 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
James Smart47a86172007-04-25 09:53:22 -04004125 if (phba->lmt & LMT_10Gb)
4126 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04004127 if (phba->lmt & LMT_8Gb)
4128 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04004129 if (phba->lmt & LMT_4Gb)
4130 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
4131 if (phba->lmt & LMT_2Gb)
4132 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
4133 if (phba->lmt & LMT_1Gb)
4134 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
4135
4136 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05004137 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
4138 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04004139
Mike Christie0af5d702010-09-15 16:52:31 -05004140 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
4141
James Smart47a86172007-04-25 09:53:22 -04004142 /* This value is also unchanging */
4143 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05004144 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04004145 fc_host_active_fc4s(shost)[2] = 1;
4146 fc_host_active_fc4s(shost)[7] = 1;
4147
James Smart92d7f7b2007-06-17 19:56:38 -05004148 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04004149 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04004150 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04004151 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04004152}
dea31012005-04-17 16:05:31 -05004153
James Smarte59058c2008-08-24 21:49:00 -04004154/**
James Smartda0436e2009-05-22 14:51:39 -04004155 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04004156 * @phba: pointer to lpfc hba data structure.
4157 *
James Smartda0436e2009-05-22 14:51:39 -04004158 * This routine is invoked to stop an SLI3 device port, it stops the device
4159 * from generating interrupts and stops the device driver's timers for the
4160 * device.
James Smarte59058c2008-08-24 21:49:00 -04004161 **/
James Smartdb2378e2008-02-08 18:49:51 -05004162static void
James Smartda0436e2009-05-22 14:51:39 -04004163lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05004164{
James Smartda0436e2009-05-22 14:51:39 -04004165 /* Clear all interrupt enable conditions */
4166 writel(0, phba->HCregaddr);
4167 readl(phba->HCregaddr); /* flush */
4168 /* Clear all pending interrupts */
4169 writel(0xffffffff, phba->HAregaddr);
4170 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04004171
James Smartda0436e2009-05-22 14:51:39 -04004172 /* Reset some HBA SLI setup states */
4173 lpfc_stop_hba_timers(phba);
4174 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05004175}
4176
James Smarte59058c2008-08-24 21:49:00 -04004177/**
James Smartda0436e2009-05-22 14:51:39 -04004178 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05004179 * @phba: pointer to lpfc hba data structure.
4180 *
James Smartda0436e2009-05-22 14:51:39 -04004181 * This routine is invoked to stop an SLI4 device port, it stops the device
4182 * from generating interrupts and stops the device driver's timers for the
4183 * device.
4184 **/
4185static void
4186lpfc_stop_port_s4(struct lpfc_hba *phba)
4187{
4188 /* Reset some HBA SLI4 setup states */
4189 lpfc_stop_hba_timers(phba);
4190 phba->pport->work_port_events = 0;
4191 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04004192}
4193
4194/**
4195 * lpfc_stop_port - Wrapper function for stopping hba port
4196 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05004197 *
James Smartda0436e2009-05-22 14:51:39 -04004198 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
4199 * the API jump table function pointer from the lpfc_hba struct.
4200 **/
4201void
4202lpfc_stop_port(struct lpfc_hba *phba)
4203{
4204 phba->lpfc_stop_port(phba);
Dick Kennedyf485c182017-09-29 17:34:34 -07004205
4206 if (phba->wq)
4207 flush_workqueue(phba->wq);
James Smartda0436e2009-05-22 14:51:39 -04004208}
4209
4210/**
James Smartecfd03c2010-02-12 14:41:27 -05004211 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
4212 * @phba: Pointer to hba for which this call is being executed.
4213 *
4214 * This routine starts the timer waiting for the FCF rediscovery to complete.
4215 **/
4216void
4217lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
4218{
4219 unsigned long fcf_redisc_wait_tmo =
4220 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
4221 /* Start fcf rediscovery wait period timer */
4222 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
4223 spin_lock_irq(&phba->hbalock);
4224 /* Allow action to new fcf asynchronous event */
4225 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
4226 /* Mark the FCF rediscovery pending state */
4227 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
4228 spin_unlock_irq(&phba->hbalock);
4229}
4230
4231/**
4232 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
4233 * @ptr: Map to lpfc_hba data structure pointer.
4234 *
4235 * This routine is invoked when waiting for FCF table rediscover has been
4236 * timed out. If new FCF record(s) has (have) been discovered during the
4237 * wait period, a new FCF event shall be added to the FCOE async event
4238 * list, and then worker thread shall be waked up for processing from the
4239 * worker thread context.
4240 **/
Rashika Kheriae399b222014-09-03 12:55:28 -04004241static void
Kees Cookf22eb4d2017-09-06 20:24:26 -07004242lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t)
James Smartecfd03c2010-02-12 14:41:27 -05004243{
Kees Cookf22eb4d2017-09-06 20:24:26 -07004244 struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait);
James Smartecfd03c2010-02-12 14:41:27 -05004245
4246 /* Don't send FCF rediscovery event if timer cancelled */
4247 spin_lock_irq(&phba->hbalock);
4248 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
4249 spin_unlock_irq(&phba->hbalock);
4250 return;
4251 }
4252 /* Clear FCF rediscovery timer pending flag */
4253 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
4254 /* FCF rediscovery event to worker thread */
4255 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
4256 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004257 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04004258 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05004259 /* wake up worker thread */
4260 lpfc_worker_wake_up(phba);
4261}
4262
4263/**
James Smartda0436e2009-05-22 14:51:39 -04004264 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
4265 * @phba: pointer to lpfc hba data structure.
4266 * @acqe_link: pointer to the async link completion queue entry.
4267 *
4268 * This routine is to parse the SLI4 link-attention link fault code and
4269 * translate it into the base driver's read link attention mailbox command
4270 * status.
4271 *
4272 * Return: Link-attention status in terms of base driver's coding.
4273 **/
4274static uint16_t
4275lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
4276 struct lpfc_acqe_link *acqe_link)
4277{
4278 uint16_t latt_fault;
4279
4280 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
4281 case LPFC_ASYNC_LINK_FAULT_NONE:
4282 case LPFC_ASYNC_LINK_FAULT_LOCAL:
4283 case LPFC_ASYNC_LINK_FAULT_REMOTE:
4284 latt_fault = 0;
4285 break;
4286 default:
4287 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4288 "0398 Invalid link fault code: x%x\n",
4289 bf_get(lpfc_acqe_link_fault, acqe_link));
4290 latt_fault = MBXERR_ERROR;
4291 break;
4292 }
4293 return latt_fault;
4294}
4295
4296/**
4297 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
4298 * @phba: pointer to lpfc hba data structure.
4299 * @acqe_link: pointer to the async link completion queue entry.
4300 *
4301 * This routine is to parse the SLI4 link attention type and translate it
4302 * into the base driver's link attention type coding.
4303 *
4304 * Return: Link attention type in terms of base driver's coding.
4305 **/
4306static uint8_t
4307lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
4308 struct lpfc_acqe_link *acqe_link)
4309{
4310 uint8_t att_type;
4311
4312 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
4313 case LPFC_ASYNC_LINK_STATUS_DOWN:
4314 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05004315 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04004316 break;
4317 case LPFC_ASYNC_LINK_STATUS_UP:
4318 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05004319 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004320 break;
4321 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05004322 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04004323 break;
4324 default:
4325 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4326 "0399 Invalid link attention type: x%x\n",
4327 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05004328 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004329 break;
4330 }
4331 return att_type;
4332}
4333
4334/**
James Smart8b68cd52012-09-29 11:32:37 -04004335 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
4336 * @phba: pointer to lpfc hba data structure.
4337 *
4338 * This routine is to get an SLI3 FC port's link speed in Mbps.
4339 *
4340 * Return: link speed in terms of Mbps.
4341 **/
4342uint32_t
4343lpfc_sli_port_speed_get(struct lpfc_hba *phba)
4344{
4345 uint32_t link_speed;
4346
4347 if (!lpfc_is_link_up(phba))
4348 return 0;
4349
James Smarta085e872015-12-16 18:12:02 -05004350 if (phba->sli_rev <= LPFC_SLI_REV3) {
4351 switch (phba->fc_linkspeed) {
4352 case LPFC_LINK_SPEED_1GHZ:
4353 link_speed = 1000;
4354 break;
4355 case LPFC_LINK_SPEED_2GHZ:
4356 link_speed = 2000;
4357 break;
4358 case LPFC_LINK_SPEED_4GHZ:
4359 link_speed = 4000;
4360 break;
4361 case LPFC_LINK_SPEED_8GHZ:
4362 link_speed = 8000;
4363 break;
4364 case LPFC_LINK_SPEED_10GHZ:
4365 link_speed = 10000;
4366 break;
4367 case LPFC_LINK_SPEED_16GHZ:
4368 link_speed = 16000;
4369 break;
4370 default:
4371 link_speed = 0;
4372 }
4373 } else {
4374 if (phba->sli4_hba.link_state.logical_speed)
4375 link_speed =
4376 phba->sli4_hba.link_state.logical_speed;
4377 else
4378 link_speed = phba->sli4_hba.link_state.speed;
James Smart8b68cd52012-09-29 11:32:37 -04004379 }
4380 return link_speed;
4381}
4382
4383/**
4384 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
4385 * @phba: pointer to lpfc hba data structure.
4386 * @evt_code: asynchronous event code.
4387 * @speed_code: asynchronous event link speed code.
4388 *
4389 * This routine is to parse the giving SLI4 async event link speed code into
4390 * value of Mbps for the link speed.
4391 *
4392 * Return: link speed in terms of Mbps.
4393 **/
4394static uint32_t
4395lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
4396 uint8_t speed_code)
4397{
4398 uint32_t port_speed;
4399
4400 switch (evt_code) {
4401 case LPFC_TRAILER_CODE_LINK:
4402 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004403 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smart8b68cd52012-09-29 11:32:37 -04004404 port_speed = 0;
4405 break;
James Smart26d830e2015-04-07 15:07:17 -04004406 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004407 port_speed = 10;
4408 break;
James Smart26d830e2015-04-07 15:07:17 -04004409 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004410 port_speed = 100;
4411 break;
James Smart26d830e2015-04-07 15:07:17 -04004412 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004413 port_speed = 1000;
4414 break;
James Smart26d830e2015-04-07 15:07:17 -04004415 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004416 port_speed = 10000;
4417 break;
James Smart26d830e2015-04-07 15:07:17 -04004418 case LPFC_ASYNC_LINK_SPEED_20GBPS:
4419 port_speed = 20000;
4420 break;
4421 case LPFC_ASYNC_LINK_SPEED_25GBPS:
4422 port_speed = 25000;
4423 break;
4424 case LPFC_ASYNC_LINK_SPEED_40GBPS:
4425 port_speed = 40000;
4426 break;
James Smart8b68cd52012-09-29 11:32:37 -04004427 default:
4428 port_speed = 0;
4429 }
4430 break;
4431 case LPFC_TRAILER_CODE_FC:
4432 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004433 case LPFC_FC_LA_SPEED_UNKNOWN:
James Smart8b68cd52012-09-29 11:32:37 -04004434 port_speed = 0;
4435 break;
James Smart26d830e2015-04-07 15:07:17 -04004436 case LPFC_FC_LA_SPEED_1G:
James Smart8b68cd52012-09-29 11:32:37 -04004437 port_speed = 1000;
4438 break;
James Smart26d830e2015-04-07 15:07:17 -04004439 case LPFC_FC_LA_SPEED_2G:
James Smart8b68cd52012-09-29 11:32:37 -04004440 port_speed = 2000;
4441 break;
James Smart26d830e2015-04-07 15:07:17 -04004442 case LPFC_FC_LA_SPEED_4G:
James Smart8b68cd52012-09-29 11:32:37 -04004443 port_speed = 4000;
4444 break;
James Smart26d830e2015-04-07 15:07:17 -04004445 case LPFC_FC_LA_SPEED_8G:
James Smart8b68cd52012-09-29 11:32:37 -04004446 port_speed = 8000;
4447 break;
James Smart26d830e2015-04-07 15:07:17 -04004448 case LPFC_FC_LA_SPEED_10G:
James Smart8b68cd52012-09-29 11:32:37 -04004449 port_speed = 10000;
4450 break;
James Smart26d830e2015-04-07 15:07:17 -04004451 case LPFC_FC_LA_SPEED_16G:
James Smart8b68cd52012-09-29 11:32:37 -04004452 port_speed = 16000;
4453 break;
James Smartd38dd522015-08-31 16:48:17 -04004454 case LPFC_FC_LA_SPEED_32G:
4455 port_speed = 32000;
4456 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08004457 case LPFC_FC_LA_SPEED_64G:
4458 port_speed = 64000;
4459 break;
James Smart8b68cd52012-09-29 11:32:37 -04004460 default:
4461 port_speed = 0;
4462 }
4463 break;
4464 default:
4465 port_speed = 0;
4466 }
4467 return port_speed;
4468}
4469
4470/**
James Smart70f3c072010-12-15 17:57:33 -05004471 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04004472 * @phba: pointer to lpfc hba data structure.
4473 * @acqe_link: pointer to the async link completion queue entry.
4474 *
James Smart70f3c072010-12-15 17:57:33 -05004475 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04004476 **/
4477static void
4478lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
4479 struct lpfc_acqe_link *acqe_link)
4480{
4481 struct lpfc_dmabuf *mp;
4482 LPFC_MBOXQ_t *pmb;
4483 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05004484 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04004485 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05004486 int rc;
James Smartda0436e2009-05-22 14:51:39 -04004487
4488 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05004489 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04004490 return;
James Smart32b97932009-07-19 10:01:21 -04004491 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004492 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4493 if (!pmb) {
4494 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4495 "0395 The mboxq allocation failed\n");
4496 return;
4497 }
4498 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4499 if (!mp) {
4500 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4501 "0396 The lpfc_dmabuf allocation failed\n");
4502 goto out_free_pmb;
4503 }
4504 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4505 if (!mp->virt) {
4506 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4507 "0397 The mbuf allocation failed\n");
4508 goto out_free_dmabuf;
4509 }
4510
4511 /* Cleanup any outstanding ELS commands */
4512 lpfc_els_flush_all_cmd(phba);
4513
4514 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004515 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smartda0436e2009-05-22 14:51:39 -04004516
4517 /* Update link event statistics */
4518 phba->sli.slistat.link_event++;
4519
James Smart76a95d72010-11-20 23:11:48 -05004520 /* Create lpfc_handle_latt mailbox command from link ACQE */
4521 lpfc_read_topology(phba, pmb, mp);
4522 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04004523 pmb->vport = phba->pport;
4524
James Smartda0436e2009-05-22 14:51:39 -04004525 /* Keep the link status for extra SLI4 state machine reference */
4526 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004527 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
4528 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04004529 phba->sli4_hba.link_state.duplex =
4530 bf_get(lpfc_acqe_link_duplex, acqe_link);
4531 phba->sli4_hba.link_state.status =
4532 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05004533 phba->sli4_hba.link_state.type =
4534 bf_get(lpfc_acqe_link_type, acqe_link);
4535 phba->sli4_hba.link_state.number =
4536 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04004537 phba->sli4_hba.link_state.fault =
4538 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05004539 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004540 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
4541
James Smart70f3c072010-12-15 17:57:33 -05004542 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04004543 "2900 Async FC/FCoE Link event - Speed:%dGBit "
4544 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
4545 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05004546 phba->sli4_hba.link_state.speed,
4547 phba->sli4_hba.link_state.topology,
4548 phba->sli4_hba.link_state.status,
4549 phba->sli4_hba.link_state.type,
4550 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004551 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004552 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05004553 /*
4554 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
4555 * topology info. Note: Optional for non FC-AL ports.
4556 */
4557 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
4558 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4559 if (rc == MBX_NOT_FINISHED)
4560 goto out_free_dmabuf;
4561 return;
4562 }
4563 /*
4564 * For FCoE Mode: fill in all the topology information we need and call
4565 * the READ_TOPOLOGY completion routine to continue without actually
4566 * sending the READ_TOPOLOGY mailbox command to the port.
4567 */
4568 /* Parse and translate status field */
4569 mb = &pmb->u.mb;
4570 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
4571
4572 /* Parse and translate link attention fields */
4573 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
4574 la->eventTag = acqe_link->event_tag;
4575 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
4576 bf_set(lpfc_mbx_read_top_link_spd, la,
James Smarta085e872015-12-16 18:12:02 -05004577 (bf_get(lpfc_acqe_link_speed, acqe_link)));
James Smart76a95d72010-11-20 23:11:48 -05004578
4579 /* Fake the the following irrelvant fields */
4580 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
4581 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
4582 bf_set(lpfc_mbx_read_top_il, la, 0);
4583 bf_set(lpfc_mbx_read_top_pb, la, 0);
4584 bf_set(lpfc_mbx_read_top_fa, la, 0);
4585 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04004586
4587 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05004588 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04004589
4590 return;
4591
4592out_free_dmabuf:
4593 kfree(mp);
4594out_free_pmb:
4595 mempool_free(pmb, phba->mbox_mem_pool);
4596}
4597
4598/**
James Smart70f3c072010-12-15 17:57:33 -05004599 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
4600 * @phba: pointer to lpfc hba data structure.
4601 * @acqe_fc: pointer to the async fc completion queue entry.
4602 *
4603 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
4604 * that the event was received and then issue a read_topology mailbox command so
4605 * that the rest of the driver will treat it the same as SLI3.
4606 **/
4607static void
4608lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
4609{
4610 struct lpfc_dmabuf *mp;
4611 LPFC_MBOXQ_t *pmb;
James Smart7bdedb32016-07-06 12:36:00 -07004612 MAILBOX_t *mb;
4613 struct lpfc_mbx_read_top *la;
James Smart70f3c072010-12-15 17:57:33 -05004614 int rc;
4615
4616 if (bf_get(lpfc_trailer_type, acqe_fc) !=
4617 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
4618 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4619 "2895 Non FC link Event detected.(%d)\n",
4620 bf_get(lpfc_trailer_type, acqe_fc));
4621 return;
4622 }
4623 /* Keep the link status for extra SLI4 state machine reference */
4624 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004625 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
4626 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05004627 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
4628 phba->sli4_hba.link_state.topology =
4629 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
4630 phba->sli4_hba.link_state.status =
4631 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
4632 phba->sli4_hba.link_state.type =
4633 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
4634 phba->sli4_hba.link_state.number =
4635 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
4636 phba->sli4_hba.link_state.fault =
4637 bf_get(lpfc_acqe_link_fault, acqe_fc);
4638 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004639 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart70f3c072010-12-15 17:57:33 -05004640 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4641 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4642 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4643 "%dMbps Fault:%d\n",
4644 phba->sli4_hba.link_state.speed,
4645 phba->sli4_hba.link_state.topology,
4646 phba->sli4_hba.link_state.status,
4647 phba->sli4_hba.link_state.type,
4648 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004649 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004650 phba->sli4_hba.link_state.fault);
4651 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4652 if (!pmb) {
4653 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4654 "2897 The mboxq allocation failed\n");
4655 return;
4656 }
4657 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4658 if (!mp) {
4659 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4660 "2898 The lpfc_dmabuf allocation failed\n");
4661 goto out_free_pmb;
4662 }
4663 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4664 if (!mp->virt) {
4665 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4666 "2899 The mbuf allocation failed\n");
4667 goto out_free_dmabuf;
4668 }
4669
4670 /* Cleanup any outstanding ELS commands */
4671 lpfc_els_flush_all_cmd(phba);
4672
4673 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004674 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smart70f3c072010-12-15 17:57:33 -05004675
4676 /* Update link event statistics */
4677 phba->sli.slistat.link_event++;
4678
4679 /* Create lpfc_handle_latt mailbox command from link ACQE */
4680 lpfc_read_topology(phba, pmb, mp);
4681 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4682 pmb->vport = phba->pport;
4683
James Smart7bdedb32016-07-06 12:36:00 -07004684 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
James Smartae9e28f2017-05-15 15:20:51 -07004685 phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK);
4686
4687 switch (phba->sli4_hba.link_state.status) {
4688 case LPFC_FC_LA_TYPE_MDS_LINK_DOWN:
4689 phba->link_flag |= LS_MDS_LINK_DOWN;
4690 break;
4691 case LPFC_FC_LA_TYPE_MDS_LOOPBACK:
4692 phba->link_flag |= LS_MDS_LOOPBACK;
4693 break;
4694 default:
4695 break;
4696 }
4697
James Smart7bdedb32016-07-06 12:36:00 -07004698 /* Parse and translate status field */
4699 mb = &pmb->u.mb;
4700 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba,
4701 (void *)acqe_fc);
4702
4703 /* Parse and translate link attention fields */
4704 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
4705 la->eventTag = acqe_fc->event_tag;
James Smart7bdedb32016-07-06 12:36:00 -07004706
James Smartaeb3c812017-04-21 16:05:02 -07004707 if (phba->sli4_hba.link_state.status ==
4708 LPFC_FC_LA_TYPE_UNEXP_WWPN) {
4709 bf_set(lpfc_mbx_read_top_att_type, la,
4710 LPFC_FC_LA_TYPE_UNEXP_WWPN);
4711 } else {
4712 bf_set(lpfc_mbx_read_top_att_type, la,
4713 LPFC_FC_LA_TYPE_LINK_DOWN);
4714 }
James Smart7bdedb32016-07-06 12:36:00 -07004715 /* Invoke the mailbox command callback function */
4716 lpfc_mbx_cmpl_read_topology(phba, pmb);
4717
4718 return;
4719 }
4720
James Smart70f3c072010-12-15 17:57:33 -05004721 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4722 if (rc == MBX_NOT_FINISHED)
4723 goto out_free_dmabuf;
4724 return;
4725
4726out_free_dmabuf:
4727 kfree(mp);
4728out_free_pmb:
4729 mempool_free(pmb, phba->mbox_mem_pool);
4730}
4731
4732/**
4733 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4734 * @phba: pointer to lpfc hba data structure.
4735 * @acqe_fc: pointer to the async SLI completion queue entry.
4736 *
4737 * This routine is to handle the SLI4 asynchronous SLI events.
4738 **/
4739static void
4740lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
4741{
James Smart4b8bae02012-06-12 13:55:07 -04004742 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04004743 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04004744 uint8_t status;
James Smart946727d2015-04-07 15:07:09 -04004745 uint8_t evt_type;
James Smart448193b2015-12-16 18:12:05 -05004746 uint8_t operational = 0;
James Smart946727d2015-04-07 15:07:09 -04004747 struct temp_event temp_event_data;
James Smart4b8bae02012-06-12 13:55:07 -04004748 struct lpfc_acqe_misconfigured_event *misconfigured;
James Smart946727d2015-04-07 15:07:09 -04004749 struct Scsi_Host *shost;
James Smart4b8bae02012-06-12 13:55:07 -04004750
James Smart946727d2015-04-07 15:07:09 -04004751 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
4752
James Smart448193b2015-12-16 18:12:05 -05004753 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4754 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4755 "x%08x SLI Event Type:%d\n",
4756 acqe_sli->event_data1, acqe_sli->event_data2,
4757 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004758
4759 port_name = phba->Port[0];
4760 if (port_name == 0x00)
4761 port_name = '?'; /* get port name is empty */
4762
James Smart946727d2015-04-07 15:07:09 -04004763 switch (evt_type) {
4764 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
4765 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4766 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
4767 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4768
4769 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4770 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4771 acqe_sli->event_data1, port_name);
4772
James Smart310429e2016-07-06 12:35:54 -07004773 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04004774 shost = lpfc_shost_from_vport(phba->pport);
4775 fc_host_post_vendor_event(shost, fc_get_event_number(),
4776 sizeof(temp_event_data),
4777 (char *)&temp_event_data,
4778 SCSI_NL_VID_TYPE_PCI
4779 | PCI_VENDOR_ID_EMULEX);
4780 break;
4781 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
4782 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4783 temp_event_data.event_code = LPFC_NORMAL_TEMP;
4784 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4785
4786 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4787 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4788 acqe_sli->event_data1, port_name);
4789
4790 shost = lpfc_shost_from_vport(phba->pport);
4791 fc_host_post_vendor_event(shost, fc_get_event_number(),
4792 sizeof(temp_event_data),
4793 (char *)&temp_event_data,
4794 SCSI_NL_VID_TYPE_PCI
4795 | PCI_VENDOR_ID_EMULEX);
4796 break;
4797 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
4798 misconfigured = (struct lpfc_acqe_misconfigured_event *)
James Smart4b8bae02012-06-12 13:55:07 -04004799 &acqe_sli->event_data1;
4800
James Smart946727d2015-04-07 15:07:09 -04004801 /* fetch the status for this port */
4802 switch (phba->sli4_hba.lnk_info.lnk_no) {
4803 case LPFC_LINK_NUMBER_0:
James Smart448193b2015-12-16 18:12:05 -05004804 status = bf_get(lpfc_sli_misconfigured_port0_state,
4805 &misconfigured->theEvent);
4806 operational = bf_get(lpfc_sli_misconfigured_port0_op,
James Smart4b8bae02012-06-12 13:55:07 -04004807 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004808 break;
4809 case LPFC_LINK_NUMBER_1:
James Smart448193b2015-12-16 18:12:05 -05004810 status = bf_get(lpfc_sli_misconfigured_port1_state,
4811 &misconfigured->theEvent);
4812 operational = bf_get(lpfc_sli_misconfigured_port1_op,
James Smart4b8bae02012-06-12 13:55:07 -04004813 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004814 break;
4815 case LPFC_LINK_NUMBER_2:
James Smart448193b2015-12-16 18:12:05 -05004816 status = bf_get(lpfc_sli_misconfigured_port2_state,
4817 &misconfigured->theEvent);
4818 operational = bf_get(lpfc_sli_misconfigured_port2_op,
James Smart4b8bae02012-06-12 13:55:07 -04004819 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004820 break;
4821 case LPFC_LINK_NUMBER_3:
James Smart448193b2015-12-16 18:12:05 -05004822 status = bf_get(lpfc_sli_misconfigured_port3_state,
4823 &misconfigured->theEvent);
4824 operational = bf_get(lpfc_sli_misconfigured_port3_op,
James Smart4b8bae02012-06-12 13:55:07 -04004825 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004826 break;
4827 default:
James Smart448193b2015-12-16 18:12:05 -05004828 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4829 "3296 "
4830 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
4831 "event: Invalid link %d",
4832 phba->sli4_hba.lnk_info.lnk_no);
4833 return;
James Smart946727d2015-04-07 15:07:09 -04004834 }
James Smart4b8bae02012-06-12 13:55:07 -04004835
James Smart448193b2015-12-16 18:12:05 -05004836 /* Skip if optic state unchanged */
4837 if (phba->sli4_hba.lnk_info.optic_state == status)
4838 return;
4839
James Smart946727d2015-04-07 15:07:09 -04004840 switch (status) {
4841 case LPFC_SLI_EVENT_STATUS_VALID:
James Smart448193b2015-12-16 18:12:05 -05004842 sprintf(message, "Physical Link is functional");
4843 break;
James Smart946727d2015-04-07 15:07:09 -04004844 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
4845 sprintf(message, "Optics faulted/incorrectly "
4846 "installed/not installed - Reseat optics, "
4847 "if issue not resolved, replace.");
4848 break;
4849 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
4850 sprintf(message,
4851 "Optics of two types installed - Remove one "
4852 "optic or install matching pair of optics.");
4853 break;
4854 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
4855 sprintf(message, "Incompatible optics - Replace with "
James Smart292098b2012-09-29 11:31:41 -04004856 "compatible optics for card to function.");
James Smart946727d2015-04-07 15:07:09 -04004857 break;
James Smart448193b2015-12-16 18:12:05 -05004858 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
4859 sprintf(message, "Unqualified optics - Replace with "
4860 "Avago optics for Warranty and Technical "
4861 "Support - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08004862 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05004863 break;
4864 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
4865 sprintf(message, "Uncertified optics - Replace with "
4866 "Avago-certified optics to enable link "
4867 "operation - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08004868 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05004869 break;
James Smart946727d2015-04-07 15:07:09 -04004870 default:
4871 /* firmware is reporting a status we don't know about */
4872 sprintf(message, "Unknown event status x%02x", status);
4873 break;
4874 }
James Smart448193b2015-12-16 18:12:05 -05004875 phba->sli4_hba.lnk_info.optic_state = status;
James Smart946727d2015-04-07 15:07:09 -04004876 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart448193b2015-12-16 18:12:05 -05004877 "3176 Port Name %c %s\n", port_name, message);
James Smart946727d2015-04-07 15:07:09 -04004878 break;
4879 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
4880 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4881 "3192 Remote DPort Test Initiated - "
4882 "Event Data1:x%08x Event Data2: x%08x\n",
4883 acqe_sli->event_data1, acqe_sli->event_data2);
James Smart4b8bae02012-06-12 13:55:07 -04004884 break;
4885 default:
James Smart946727d2015-04-07 15:07:09 -04004886 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4887 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
4888 "x%08x SLI Event Type:%d\n",
4889 acqe_sli->event_data1, acqe_sli->event_data2,
4890 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004891 break;
4892 }
James Smart70f3c072010-12-15 17:57:33 -05004893}
4894
4895/**
James Smartfc2b9892010-02-26 14:15:29 -05004896 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
4897 * @vport: pointer to vport data structure.
4898 *
4899 * This routine is to perform Clear Virtual Link (CVL) on a vport in
4900 * response to a CVL event.
4901 *
4902 * Return the pointer to the ndlp with the vport if successful, otherwise
4903 * return NULL.
4904 **/
4905static struct lpfc_nodelist *
4906lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
4907{
4908 struct lpfc_nodelist *ndlp;
4909 struct Scsi_Host *shost;
4910 struct lpfc_hba *phba;
4911
4912 if (!vport)
4913 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05004914 phba = vport->phba;
4915 if (!phba)
4916 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04004917 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4918 if (!ndlp) {
4919 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07004920 ndlp = lpfc_nlp_init(vport, Fabric_DID);
James Smart78730cf2010-04-06 15:06:30 -04004921 if (!ndlp)
4922 return 0;
James Smart78730cf2010-04-06 15:06:30 -04004923 /* Set the node type */
4924 ndlp->nlp_type |= NLP_FABRIC;
4925 /* Put ndlp onto node list */
4926 lpfc_enqueue_node(vport, ndlp);
4927 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4928 /* re-setup ndlp without removing from node list */
4929 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4930 if (!ndlp)
4931 return 0;
4932 }
James Smart63e801c2010-11-20 23:14:19 -05004933 if ((phba->pport->port_state < LPFC_FLOGI) &&
4934 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004935 return NULL;
4936 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05004937 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
4938 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004939 return NULL;
4940 shost = lpfc_shost_from_vport(vport);
4941 if (!shost)
4942 return NULL;
4943 lpfc_linkdown_port(vport);
4944 lpfc_cleanup_pending_mbox(vport);
4945 spin_lock_irq(shost->host_lock);
4946 vport->fc_flag |= FC_VPORT_CVL_RCVD;
4947 spin_unlock_irq(shost->host_lock);
4948
4949 return ndlp;
4950}
4951
4952/**
4953 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4954 * @vport: pointer to lpfc hba data structure.
4955 *
4956 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4957 * response to a FCF dead event.
4958 **/
4959static void
4960lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
4961{
4962 struct lpfc_vport **vports;
4963 int i;
4964
4965 vports = lpfc_create_vport_work_array(phba);
4966 if (vports)
4967 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4968 lpfc_sli4_perform_vport_cvl(vports[i]);
4969 lpfc_destroy_vport_work_array(phba, vports);
4970}
4971
4972/**
James Smart76a95d72010-11-20 23:11:48 -05004973 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04004974 * @phba: pointer to lpfc hba data structure.
4975 * @acqe_link: pointer to the async fcoe completion queue entry.
4976 *
4977 * This routine is to handle the SLI4 asynchronous fcoe event.
4978 **/
4979static void
James Smart76a95d72010-11-20 23:11:48 -05004980lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05004981 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04004982{
James Smart70f3c072010-12-15 17:57:33 -05004983 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004984 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04004985 struct lpfc_vport *vport;
4986 struct lpfc_nodelist *ndlp;
4987 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05004988 int active_vlink_present;
4989 struct lpfc_vport **vports;
4990 int i;
James Smartda0436e2009-05-22 14:51:39 -04004991
James Smart70f3c072010-12-15 17:57:33 -05004992 phba->fc_eventTag = acqe_fip->event_tag;
4993 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004994 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05004995 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
4996 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
4997 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04004998 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4999 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005000 "2546 New FCF event, evt_tag:x%x, "
5001 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005002 acqe_fip->event_tag,
5003 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04005004 else
5005 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
5006 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005007 "2788 FCF param modified event, "
5008 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005009 acqe_fip->event_tag,
5010 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04005011 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05005012 /*
5013 * During period of FCF discovery, read the FCF
5014 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04005015 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05005016 */
5017 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5018 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005019 "2779 Read FCF (x%x) for updating "
5020 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05005021 acqe_fip->index);
5022 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05005023 }
James Smart38b92ef2010-08-04 16:11:39 -04005024
5025 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04005026 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04005027 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04005028 spin_unlock_irq(&phba->hbalock);
5029 break;
5030 }
5031 /* If fast FCF failover rescan event is pending, do nothing */
5032 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
5033 spin_unlock_irq(&phba->hbalock);
5034 break;
5035 }
5036
James Smartc2b97122013-05-31 17:05:36 -04005037 /* If the FCF has been in discovered state, do nothing. */
5038 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
James Smart3804dc82010-07-14 15:31:37 -04005039 spin_unlock_irq(&phba->hbalock);
5040 break;
5041 }
5042 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04005043
James Smart0c9ab6f2010-02-26 14:15:57 -05005044 /* Otherwise, scan the entire FCF table and re-discover SAN */
5045 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005046 "2770 Start FCF table scan per async FCF "
5047 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005048 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05005049 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
5050 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04005051 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05005052 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5053 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04005054 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04005055 break;
5056
James Smart70f3c072010-12-15 17:57:33 -05005057 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04005058 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04005059 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05005060 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
5061 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04005062 break;
5063
James Smart70f3c072010-12-15 17:57:33 -05005064 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05005065 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05005066 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005067 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05005068 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04005069 /*
5070 * If we are in the middle of FCF failover process, clear
5071 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04005072 */
James Smartfc2b9892010-02-26 14:15:29 -05005073 spin_lock_irq(&phba->hbalock);
James Smarta1cadfe2016-07-06 12:36:02 -07005074 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
5075 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
James Smartfc2b9892010-02-26 14:15:29 -05005076 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005077 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05005078 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05005079 break;
5080 }
James Smart38b92ef2010-08-04 16:11:39 -04005081 spin_unlock_irq(&phba->hbalock);
5082
5083 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05005084 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04005085 break;
5086
5087 /*
5088 * Otherwise, request the port to rediscover the entire FCF
5089 * table for a fast recovery from case that the current FCF
5090 * is no longer valid as we are not in the middle of FCF
5091 * failover process already.
5092 */
James Smartc2b97122013-05-31 17:05:36 -04005093 spin_lock_irq(&phba->hbalock);
5094 /* Mark the fast failover process in progress */
5095 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
5096 spin_unlock_irq(&phba->hbalock);
5097
5098 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
5099 "2771 Start FCF fast failover process due to "
5100 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
5101 "\n", acqe_fip->event_tag, acqe_fip->index);
5102 rc = lpfc_sli4_redisc_fcf_table(phba);
5103 if (rc) {
5104 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5105 LOG_DISCOVERY,
5106 "2772 Issue FCF rediscover mabilbox "
5107 "command failed, fail through to FCF "
5108 "dead event\n");
5109 spin_lock_irq(&phba->hbalock);
5110 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
5111 spin_unlock_irq(&phba->hbalock);
5112 /*
5113 * Last resort will fail over by treating this
5114 * as a link down to FCF registration.
5115 */
5116 lpfc_sli4_fcf_dead_failthrough(phba);
5117 } else {
5118 /* Reset FCF roundrobin bmask for new discovery */
5119 lpfc_sli4_clear_fcf_rr_bmask(phba);
5120 /*
5121 * Handling fast FCF failover to a DEAD FCF event is
5122 * considered equalivant to receiving CVL to all vports.
5123 */
5124 lpfc_sli4_perform_all_vport_cvl(phba);
5125 }
James Smartda0436e2009-05-22 14:51:39 -04005126 break;
James Smart70f3c072010-12-15 17:57:33 -05005127 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05005128 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05005129 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04005130 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05005131 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04005132
James Smart6669f9b2009-10-02 15:16:45 -04005133 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04005134 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05005135 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04005136 if (!ndlp)
5137 break;
James Smart695a8142010-01-26 23:08:03 -05005138 active_vlink_present = 0;
5139
5140 vports = lpfc_create_vport_work_array(phba);
5141 if (vports) {
5142 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
5143 i++) {
5144 if ((!(vports[i]->fc_flag &
5145 FC_VPORT_CVL_RCVD)) &&
5146 (vports[i]->port_state > LPFC_FDISC)) {
5147 active_vlink_present = 1;
5148 break;
5149 }
5150 }
5151 lpfc_destroy_vport_work_array(phba, vports);
5152 }
5153
James Smartcc823552015-05-21 13:55:26 -04005154 /*
5155 * Don't re-instantiate if vport is marked for deletion.
5156 * If we are here first then vport_delete is going to wait
5157 * for discovery to complete.
5158 */
5159 if (!(vport->load_flag & FC_UNLOADING) &&
5160 active_vlink_present) {
James Smart695a8142010-01-26 23:08:03 -05005161 /*
5162 * If there are other active VLinks present,
5163 * re-instantiate the Vlink using FDISC.
5164 */
James Smart256ec0d2013-04-17 20:14:58 -04005165 mod_timer(&ndlp->nlp_delayfunc,
5166 jiffies + msecs_to_jiffies(1000));
James Smartfc2b9892010-02-26 14:15:29 -05005167 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04005168 spin_lock_irq(shost->host_lock);
5169 ndlp->nlp_flag |= NLP_DELAY_TMO;
5170 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05005171 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
5172 vport->port_state = LPFC_FDISC;
5173 } else {
James Smartecfd03c2010-02-12 14:41:27 -05005174 /*
5175 * Otherwise, we request port to rediscover
5176 * the entire FCF table for a fast recovery
5177 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05005178 * is no longer valid if we are not already
5179 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05005180 */
James Smartfc2b9892010-02-26 14:15:29 -05005181 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005182 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05005183 spin_unlock_irq(&phba->hbalock);
5184 break;
5185 }
5186 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05005187 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05005188 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005189 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5190 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005191 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05005192 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05005193 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05005194 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05005195 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5196 LOG_DISCOVERY,
5197 "2774 Issue FCF rediscover "
5198 "mabilbox command failed, "
5199 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05005200 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005201 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05005202 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05005203 /*
5204 * Last resort will be re-try on the
5205 * the current registered FCF entry.
5206 */
5207 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04005208 } else
5209 /*
5210 * Reset FCF roundrobin bmask for new
5211 * discovery.
5212 */
James Smart7d791df2011-07-22 18:37:52 -04005213 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04005214 }
5215 break;
James Smartda0436e2009-05-22 14:51:39 -04005216 default:
5217 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5218 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05005219 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04005220 break;
5221 }
5222}
5223
5224/**
5225 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
5226 * @phba: pointer to lpfc hba data structure.
5227 * @acqe_link: pointer to the async dcbx completion queue entry.
5228 *
5229 * This routine is to handle the SLI4 asynchronous dcbx event.
5230 **/
5231static void
5232lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
5233 struct lpfc_acqe_dcbx *acqe_dcbx)
5234{
James Smart4d9ab992009-10-02 15:16:39 -04005235 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04005236 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5237 "0290 The SLI4 DCBX asynchronous event is not "
5238 "handled yet\n");
5239}
5240
5241/**
James Smartb19a0612010-04-06 14:48:51 -04005242 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
5243 * @phba: pointer to lpfc hba data structure.
5244 * @acqe_link: pointer to the async grp5 completion queue entry.
5245 *
5246 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
5247 * is an asynchronous notified of a logical link speed change. The Port
5248 * reports the logical link speed in units of 10Mbps.
5249 **/
5250static void
5251lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
5252 struct lpfc_acqe_grp5 *acqe_grp5)
5253{
5254 uint16_t prev_ll_spd;
5255
5256 phba->fc_eventTag = acqe_grp5->event_tag;
5257 phba->fcoe_eventtag = acqe_grp5->event_tag;
5258 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
5259 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04005260 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04005261 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5262 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04005263 "from %dMbps to %dMbps\n", prev_ll_spd,
5264 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04005265}
5266
5267/**
James Smartda0436e2009-05-22 14:51:39 -04005268 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
5269 * @phba: pointer to lpfc hba data structure.
5270 *
5271 * This routine is invoked by the worker thread to process all the pending
5272 * SLI4 asynchronous events.
5273 **/
5274void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
5275{
5276 struct lpfc_cq_event *cq_event;
5277
5278 /* First, declare the async event has been handled */
5279 spin_lock_irq(&phba->hbalock);
5280 phba->hba_flag &= ~ASYNC_EVENT;
5281 spin_unlock_irq(&phba->hbalock);
5282 /* Now, handle all the async events */
5283 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
5284 /* Get the first event from the head of the event queue */
5285 spin_lock_irq(&phba->hbalock);
5286 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
5287 cq_event, struct lpfc_cq_event, list);
5288 spin_unlock_irq(&phba->hbalock);
5289 /* Process the asynchronous event */
5290 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
5291 case LPFC_TRAILER_CODE_LINK:
5292 lpfc_sli4_async_link_evt(phba,
5293 &cq_event->cqe.acqe_link);
5294 break;
5295 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05005296 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04005297 break;
5298 case LPFC_TRAILER_CODE_DCBX:
5299 lpfc_sli4_async_dcbx_evt(phba,
5300 &cq_event->cqe.acqe_dcbx);
5301 break;
James Smartb19a0612010-04-06 14:48:51 -04005302 case LPFC_TRAILER_CODE_GRP5:
5303 lpfc_sli4_async_grp5_evt(phba,
5304 &cq_event->cqe.acqe_grp5);
5305 break;
James Smart70f3c072010-12-15 17:57:33 -05005306 case LPFC_TRAILER_CODE_FC:
5307 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
5308 break;
5309 case LPFC_TRAILER_CODE_SLI:
5310 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
5311 break;
James Smartda0436e2009-05-22 14:51:39 -04005312 default:
5313 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5314 "1804 Invalid asynchrous event code: "
5315 "x%x\n", bf_get(lpfc_trailer_code,
5316 &cq_event->cqe.mcqe_cmpl));
5317 break;
5318 }
5319 /* Free the completion event processed to the free pool */
5320 lpfc_sli4_cq_event_release(phba, cq_event);
5321 }
5322}
5323
5324/**
James Smartecfd03c2010-02-12 14:41:27 -05005325 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
5326 * @phba: pointer to lpfc hba data structure.
5327 *
5328 * This routine is invoked by the worker thread to process FCF table
5329 * rediscovery pending completion event.
5330 **/
5331void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
5332{
5333 int rc;
5334
5335 spin_lock_irq(&phba->hbalock);
5336 /* Clear FCF rediscovery timeout event */
5337 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
5338 /* Clear driver fast failover FCF record flag */
5339 phba->fcf.failover_rec.flag = 0;
5340 /* Set state for FCF fast failover */
5341 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
5342 spin_unlock_irq(&phba->hbalock);
5343
5344 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05005345 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005346 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05005347 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05005348 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05005349 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5350 "2747 Issue FCF scan read FCF mailbox "
5351 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05005352}
5353
5354/**
James Smartda0436e2009-05-22 14:51:39 -04005355 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
5356 * @phba: pointer to lpfc hba data structure.
5357 * @dev_grp: The HBA PCI-Device group number.
5358 *
5359 * This routine is invoked to set up the per HBA PCI-Device group function
5360 * API jump table entries.
5361 *
5362 * Return: 0 if success, otherwise -ENODEV
5363 **/
5364int
5365lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05005366{
5367 int rc;
5368
James Smartda0436e2009-05-22 14:51:39 -04005369 /* Set up lpfc PCI-device group */
5370 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05005371
James Smartda0436e2009-05-22 14:51:39 -04005372 /* The LPFC_PCI_DEV_OC uses SLI4 */
5373 if (dev_grp == LPFC_PCI_DEV_OC)
5374 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05005375
James Smartda0436e2009-05-22 14:51:39 -04005376 /* Set up device INIT API function jump table */
5377 rc = lpfc_init_api_table_setup(phba, dev_grp);
5378 if (rc)
5379 return -ENODEV;
5380 /* Set up SCSI API function jump table */
5381 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
5382 if (rc)
5383 return -ENODEV;
5384 /* Set up SLI API function jump table */
5385 rc = lpfc_sli_api_table_setup(phba, dev_grp);
5386 if (rc)
5387 return -ENODEV;
5388 /* Set up MBOX API function jump table */
5389 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
5390 if (rc)
5391 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05005392
James Smartda0436e2009-05-22 14:51:39 -04005393 return 0;
James Smart5b75da22008-12-04 22:39:35 -05005394}
5395
5396/**
James Smart3621a712009-04-06 18:47:14 -04005397 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05005398 * @phba: pointer to lpfc hba data structure.
5399 * @intr_mode: active interrupt mode adopted.
5400 *
5401 * This routine it invoked to log the currently used active interrupt mode
5402 * to the device.
James Smart3772a992009-05-22 14:50:54 -04005403 **/
5404static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05005405{
5406 switch (intr_mode) {
5407 case 0:
5408 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5409 "0470 Enable INTx interrupt mode.\n");
5410 break;
5411 case 1:
5412 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5413 "0481 Enabled MSI interrupt mode.\n");
5414 break;
5415 case 2:
5416 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5417 "0480 Enabled MSI-X interrupt mode.\n");
5418 break;
5419 default:
5420 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5421 "0482 Illegal interrupt mode.\n");
5422 break;
5423 }
5424 return;
5425}
5426
James Smart5b75da22008-12-04 22:39:35 -05005427/**
James Smart3772a992009-05-22 14:50:54 -04005428 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05005429 * @phba: pointer to lpfc hba data structure.
5430 *
James Smart3772a992009-05-22 14:50:54 -04005431 * This routine is invoked to enable the PCI device that is common to all
5432 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05005433 *
5434 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005435 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005436 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05005437 **/
James Smart3772a992009-05-22 14:50:54 -04005438static int
5439lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05005440{
James Smart3772a992009-05-22 14:50:54 -04005441 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05005442
James Smart3772a992009-05-22 14:50:54 -04005443 /* Obtain PCI device reference */
5444 if (!phba->pcidev)
5445 goto out_error;
5446 else
5447 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04005448 /* Enable PCI device */
5449 if (pci_enable_device_mem(pdev))
5450 goto out_error;
5451 /* Request PCI resource for the device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005452 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
James Smart3772a992009-05-22 14:50:54 -04005453 goto out_disable_device;
5454 /* Set up device as PCI master and save state for EEH */
5455 pci_set_master(pdev);
5456 pci_try_set_mwi(pdev);
5457 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05005458
James Smart05580562011-05-24 11:40:48 -04005459 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
Jon Mason453193e2013-09-11 15:38:13 -07005460 if (pci_is_pcie(pdev))
James Smart05580562011-05-24 11:40:48 -04005461 pdev->needs_freset = 1;
5462
James Smart3772a992009-05-22 14:50:54 -04005463 return 0;
James Smart5b75da22008-12-04 22:39:35 -05005464
James Smart3772a992009-05-22 14:50:54 -04005465out_disable_device:
5466 pci_disable_device(pdev);
5467out_error:
James Smart079b5c92011-08-21 21:48:49 -04005468 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005469 "1401 Failed to enable pci device\n");
James Smart3772a992009-05-22 14:50:54 -04005470 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05005471}
5472
5473/**
James Smart3772a992009-05-22 14:50:54 -04005474 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05005475 * @phba: pointer to lpfc hba data structure.
5476 *
James Smart3772a992009-05-22 14:50:54 -04005477 * This routine is invoked to disable the PCI device that is common to all
5478 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05005479 **/
5480static void
James Smart3772a992009-05-22 14:50:54 -04005481lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05005482{
James Smart3772a992009-05-22 14:50:54 -04005483 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05005484
James Smart3772a992009-05-22 14:50:54 -04005485 /* Obtain PCI device reference */
5486 if (!phba->pcidev)
5487 return;
5488 else
5489 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04005490 /* Release PCI resource and disable PCI device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005491 pci_release_mem_regions(pdev);
James Smart3772a992009-05-22 14:50:54 -04005492 pci_disable_device(pdev);
James Smart5b75da22008-12-04 22:39:35 -05005493
5494 return;
5495}
5496
5497/**
James Smart3772a992009-05-22 14:50:54 -04005498 * lpfc_reset_hba - Reset a hba
5499 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04005500 *
James Smart3772a992009-05-22 14:50:54 -04005501 * This routine is invoked to reset a hba device. It brings the HBA
5502 * offline, performs a board restart, and then brings the board back
5503 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
5504 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04005505 **/
James Smart3772a992009-05-22 14:50:54 -04005506void
5507lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05005508{
James Smart3772a992009-05-22 14:50:54 -04005509 /* If resets are disabled then set error state and return. */
5510 if (!phba->cfg_enable_hba_reset) {
5511 phba->link_state = LPFC_HBA_ERROR;
5512 return;
5513 }
James Smartee620212014-04-04 13:51:53 -04005514 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
5515 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
5516 else
5517 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart3772a992009-05-22 14:50:54 -04005518 lpfc_offline(phba);
5519 lpfc_sli_brdrestart(phba);
5520 lpfc_online(phba);
5521 lpfc_unblock_mgmt_io(phba);
5522}
dea31012005-04-17 16:05:31 -05005523
James Smart3772a992009-05-22 14:50:54 -04005524/**
James Smart0a96e972011-07-22 18:37:28 -04005525 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
5526 * @phba: pointer to lpfc hba data structure.
5527 *
5528 * This function enables the PCI SR-IOV virtual functions to a physical
5529 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5530 * enable the number of virtual functions to the physical function. As
5531 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5532 * API call does not considered as an error condition for most of the device.
5533 **/
5534uint16_t
5535lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
5536{
5537 struct pci_dev *pdev = phba->pcidev;
5538 uint16_t nr_virtfn;
5539 int pos;
5540
James Smart0a96e972011-07-22 18:37:28 -04005541 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
5542 if (pos == 0)
5543 return 0;
5544
5545 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
5546 return nr_virtfn;
5547}
5548
5549/**
James Smart912e3ac2011-05-24 11:42:11 -04005550 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
5551 * @phba: pointer to lpfc hba data structure.
5552 * @nr_vfn: number of virtual functions to be enabled.
5553 *
5554 * This function enables the PCI SR-IOV virtual functions to a physical
5555 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5556 * enable the number of virtual functions to the physical function. As
5557 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5558 * API call does not considered as an error condition for most of the device.
5559 **/
5560int
5561lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
5562{
5563 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04005564 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04005565 int rc;
5566
James Smart0a96e972011-07-22 18:37:28 -04005567 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
5568 if (nr_vfn > max_nr_vfn) {
5569 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5570 "3057 Requested vfs (%d) greater than "
5571 "supported vfs (%d)", nr_vfn, max_nr_vfn);
5572 return -EINVAL;
5573 }
5574
James Smart912e3ac2011-05-24 11:42:11 -04005575 rc = pci_enable_sriov(pdev, nr_vfn);
5576 if (rc) {
5577 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5578 "2806 Failed to enable sriov on this device "
5579 "with vfn number nr_vf:%d, rc:%d\n",
5580 nr_vfn, rc);
5581 } else
5582 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5583 "2807 Successful enable sriov on this device "
5584 "with vfn number nr_vf:%d\n", nr_vfn);
5585 return rc;
5586}
5587
5588/**
James Smart895427b2017-02-12 13:52:30 -08005589 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
James Smart3772a992009-05-22 14:50:54 -04005590 * @phba: pointer to lpfc hba data structure.
5591 *
James Smart895427b2017-02-12 13:52:30 -08005592 * This routine is invoked to set up the driver internal resources before the
5593 * device specific resource setup to support the HBA device it attached to.
James Smart3772a992009-05-22 14:50:54 -04005594 *
5595 * Return codes
James Smart895427b2017-02-12 13:52:30 -08005596 * 0 - successful
5597 * other values - error
James Smart3772a992009-05-22 14:50:54 -04005598 **/
5599static int
James Smart895427b2017-02-12 13:52:30 -08005600lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
James Smart3772a992009-05-22 14:50:54 -04005601{
James Smart895427b2017-02-12 13:52:30 -08005602 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05005603
James Smart3772a992009-05-22 14:50:54 -04005604 /*
James Smart895427b2017-02-12 13:52:30 -08005605 * Driver resources common to all SLI revisions
James Smart3772a992009-05-22 14:50:54 -04005606 */
James Smart895427b2017-02-12 13:52:30 -08005607 atomic_set(&phba->fast_event_count, 0);
5608 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005609
James Smart895427b2017-02-12 13:52:30 -08005610 /* Initialize ndlp management spinlock */
5611 spin_lock_init(&phba->ndlp_lock);
James Smart3772a992009-05-22 14:50:54 -04005612
James Smart895427b2017-02-12 13:52:30 -08005613 INIT_LIST_HEAD(&phba->port_list);
5614 INIT_LIST_HEAD(&phba->work_list);
5615 init_waitqueue_head(&phba->wait_4_mlo_m_q);
5616
5617 /* Initialize the wait queue head for the kernel thread */
5618 init_waitqueue_head(&phba->work_waitq);
5619
5620 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartf358dd02017-02-12 13:52:34 -08005621 "1403 Protocols supported %s %s %s\n",
James Smart895427b2017-02-12 13:52:30 -08005622 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
5623 "SCSI" : " "),
5624 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
James Smartf358dd02017-02-12 13:52:34 -08005625 "NVME" : " "),
5626 (phba->nvmet_support ? "NVMET" : " "));
James Smart895427b2017-02-12 13:52:30 -08005627
5628 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5629 /* Initialize the scsi buffer list used by driver for scsi IO */
5630 spin_lock_init(&phba->scsi_buf_list_get_lock);
5631 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5632 spin_lock_init(&phba->scsi_buf_list_put_lock);
5633 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
5634 }
5635
5636 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
5637 (phba->nvmet_support == 0)) {
5638 /* Initialize the NVME buffer list used by driver for NVME IO */
5639 spin_lock_init(&phba->nvme_buf_list_get_lock);
5640 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_get);
James Smartcf1a1d32017-12-08 17:18:03 -08005641 phba->get_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08005642 spin_lock_init(&phba->nvme_buf_list_put_lock);
5643 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
James Smartcf1a1d32017-12-08 17:18:03 -08005644 phba->put_nvme_bufs = 0;
James Smart895427b2017-02-12 13:52:30 -08005645 }
5646
5647 /* Initialize the fabric iocb list */
5648 INIT_LIST_HEAD(&phba->fabric_iocb_list);
5649
5650 /* Initialize list to save ELS buffers */
5651 INIT_LIST_HEAD(&phba->elsbuf);
5652
5653 /* Initialize FCF connection rec list */
5654 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
5655
5656 /* Initialize OAS configuration list */
5657 spin_lock_init(&phba->devicelock);
5658 INIT_LIST_HEAD(&phba->luns);
5659
James Smart3772a992009-05-22 14:50:54 -04005660 /* MBOX heartbeat timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005661 timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04005662 /* Fabric block timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005663 timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04005664 /* EA polling mode timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005665 timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0);
James Smart895427b2017-02-12 13:52:30 -08005666 /* Heartbeat timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005667 timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0);
James Smart895427b2017-02-12 13:52:30 -08005668
5669 return 0;
5670}
5671
5672/**
5673 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
5674 * @phba: pointer to lpfc hba data structure.
5675 *
5676 * This routine is invoked to set up the driver internal resources specific to
5677 * support the SLI-3 HBA device it attached to.
5678 *
5679 * Return codes
5680 * 0 - successful
5681 * other values - error
5682 **/
5683static int
5684lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
5685{
5686 int rc;
5687
5688 /*
5689 * Initialize timers used by driver
5690 */
5691
5692 /* FCP polling mode timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005693 timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0);
James Smart3772a992009-05-22 14:50:54 -04005694
5695 /* Host attention work mask setup */
5696 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
5697 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
5698
5699 /* Get all the module params for configuring this host */
5700 lpfc_get_cfgparam(phba);
James Smart895427b2017-02-12 13:52:30 -08005701 /* Set up phase-1 common device driver resources */
5702
5703 rc = lpfc_setup_driver_resource_phase1(phba);
5704 if (rc)
5705 return -ENODEV;
5706
James Smart49198b32010-04-06 15:04:33 -04005707 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
5708 phba->menlo_flag |= HBA_MENLO_SUPPORT;
5709 /* check for menlo minimum sg count */
5710 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
5711 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
5712 }
5713
James Smart895427b2017-02-12 13:52:30 -08005714 if (!phba->sli.sli3_ring)
5715 phba->sli.sli3_ring = kzalloc(LPFC_SLI3_MAX_RING *
James Smart2a76a282012-08-03 12:35:54 -04005716 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
James Smart895427b2017-02-12 13:52:30 -08005717 if (!phba->sli.sli3_ring)
James Smart2a76a282012-08-03 12:35:54 -04005718 return -ENOMEM;
5719
James Smart3772a992009-05-22 14:50:54 -04005720 /*
James Smart96f70772013-04-17 20:16:15 -04005721 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smart3772a992009-05-22 14:50:54 -04005722 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart3772a992009-05-22 14:50:54 -04005723 */
James Smart3772a992009-05-22 14:50:54 -04005724
James Smart96f70772013-04-17 20:16:15 -04005725 /* Initialize the host templates the configured values. */
James Smart3772a992009-05-22 14:50:54 -04005726 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart96418b52017-03-04 09:30:31 -08005727 lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt;
5728 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart3772a992009-05-22 14:50:54 -04005729
James Smart96f70772013-04-17 20:16:15 -04005730 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
5731 if (phba->cfg_enable_bg) {
5732 /*
5733 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5734 * the FCP rsp, and a BDE for each. Sice we have no control
5735 * over how many protection data segments the SCSI Layer
5736 * will hand us (ie: there could be one for every block
5737 * in the IO), we just allocate enough BDEs to accomidate
5738 * our max amount and we need to limit lpfc_sg_seg_cnt to
5739 * minimize the risk of running out.
5740 */
5741 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5742 sizeof(struct fcp_rsp) +
5743 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
5744
5745 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
5746 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
5747
5748 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
5749 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
5750 } else {
5751 /*
5752 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5753 * the FCP rsp, a BDE for each, and a BDE for up to
5754 * cfg_sg_seg_cnt data segments.
5755 */
5756 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5757 sizeof(struct fcp_rsp) +
5758 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
5759
5760 /* Total BDEs in BPL for scsi_sg_list */
5761 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5762 }
5763
5764 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5765 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
5766 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5767 phba->cfg_total_seg_cnt);
5768
James Smart3772a992009-05-22 14:50:54 -04005769 phba->max_vpi = LPFC_MAX_VPI;
5770 /* This will be set to correct value after config_port mbox */
5771 phba->max_vports = 0;
5772
5773 /*
5774 * Initialize the SLI Layer to run with lpfc HBAs.
5775 */
5776 lpfc_sli_setup(phba);
James Smart895427b2017-02-12 13:52:30 -08005777 lpfc_sli_queue_init(phba);
James Smart3772a992009-05-22 14:50:54 -04005778
5779 /* Allocate device driver memory */
5780 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
5781 return -ENOMEM;
5782
James Smart912e3ac2011-05-24 11:42:11 -04005783 /*
5784 * Enable sr-iov virtual functions if supported and configured
5785 * through the module parameter.
5786 */
5787 if (phba->cfg_sriov_nr_virtfn > 0) {
5788 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5789 phba->cfg_sriov_nr_virtfn);
5790 if (rc) {
5791 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5792 "2808 Requested number of SR-IOV "
5793 "virtual functions (%d) is not "
5794 "supported\n",
5795 phba->cfg_sriov_nr_virtfn);
5796 phba->cfg_sriov_nr_virtfn = 0;
5797 }
5798 }
5799
James Smart3772a992009-05-22 14:50:54 -04005800 return 0;
5801}
5802
5803/**
5804 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
5805 * @phba: pointer to lpfc hba data structure.
5806 *
5807 * This routine is invoked to unset the driver internal resources set up
5808 * specific for supporting the SLI-3 HBA device it attached to.
5809 **/
5810static void
5811lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
5812{
5813 /* Free device driver memory allocated */
5814 lpfc_mem_free_all(phba);
5815
5816 return;
5817}
5818
5819/**
James Smartda0436e2009-05-22 14:51:39 -04005820 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
5821 * @phba: pointer to lpfc hba data structure.
5822 *
5823 * This routine is invoked to set up the driver internal resources specific to
5824 * support the SLI-4 HBA device it attached to.
5825 *
5826 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005827 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04005828 * other values - error
5829 **/
5830static int
5831lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5832{
James Smart28baac72010-02-12 14:42:03 -05005833 LPFC_MBOXQ_t *mboxq;
James Smartf358dd02017-02-12 13:52:34 -08005834 MAILBOX_t *mb;
James Smart895427b2017-02-12 13:52:30 -08005835 int rc, i, max_buf_size;
James Smart28baac72010-02-12 14:42:03 -05005836 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
5837 struct lpfc_mqe *mqe;
James Smart09294d42013-04-17 20:16:05 -04005838 int longs;
James Smart1ba981f2014-02-20 09:56:45 -05005839 int fof_vectors = 0;
James Smart81e6a632017-11-20 16:00:43 -08005840 int extra;
James Smartf358dd02017-02-12 13:52:34 -08005841 uint64_t wwn;
James Smartda0436e2009-05-22 14:51:39 -04005842
James Smart895427b2017-02-12 13:52:30 -08005843 phba->sli4_hba.num_online_cpu = num_online_cpus();
5844 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
5845 phba->sli4_hba.curr_disp_cpu = 0;
5846
James Smart716d3bc2013-09-06 12:18:28 -04005847 /* Get all the module params for configuring this host */
5848 lpfc_get_cfgparam(phba);
5849
James Smart895427b2017-02-12 13:52:30 -08005850 /* Set up phase-1 common device driver resources */
5851 rc = lpfc_setup_driver_resource_phase1(phba);
5852 if (rc)
5853 return -ENODEV;
5854
James Smartda0436e2009-05-22 14:51:39 -04005855 /* Before proceed, wait for POST done and device ready */
5856 rc = lpfc_sli4_post_status_check(phba);
5857 if (rc)
5858 return -ENODEV;
5859
5860 /*
5861 * Initialize timers used by driver
5862 */
5863
Kees Cookf22eb4d2017-09-06 20:24:26 -07005864 timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0);
James Smartda0436e2009-05-22 14:51:39 -04005865
James Smartecfd03c2010-02-12 14:41:27 -05005866 /* FCF rediscover timer */
Kees Cookf22eb4d2017-09-06 20:24:26 -07005867 timer_setup(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo, 0);
James Smartecfd03c2010-02-12 14:41:27 -05005868
James Smartda0436e2009-05-22 14:51:39 -04005869 /*
James Smart7ad20aa2011-05-24 11:44:28 -04005870 * Control structure for handling external multi-buffer mailbox
5871 * command pass-through.
5872 */
5873 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
5874 sizeof(struct lpfc_mbox_ext_buf_ctx));
5875 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
5876
James Smartda0436e2009-05-22 14:51:39 -04005877 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04005878
James Smartda0436e2009-05-22 14:51:39 -04005879 /* This will be set to correct value after the read_config mbox */
5880 phba->max_vports = 0;
5881
5882 /* Program the default value of vlan_id and fc_map */
5883 phba->valid_vlan = 0;
5884 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5885 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5886 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5887
5888 /*
James Smart2a76a282012-08-03 12:35:54 -04005889 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
James Smart895427b2017-02-12 13:52:30 -08005890 * we will associate a new ring, for each EQ/CQ/WQ tuple.
5891 * The WQ create will allocate the ring.
James Smart2a76a282012-08-03 12:35:54 -04005892 */
James Smart085c6472010-11-20 23:11:37 -05005893
James Smart09294d42013-04-17 20:16:05 -04005894 /*
James Smart81e6a632017-11-20 16:00:43 -08005895 * 1 for cmd, 1 for rsp, NVME adds an extra one
5896 * for boundary conditions in its max_sgl_segment template.
5897 */
5898 extra = 2;
5899 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
5900 extra++;
5901
5902 /*
James Smart09294d42013-04-17 20:16:05 -04005903 * It doesn't matter what family our adapter is in, we are
5904 * limited to 2 Pages, 512 SGEs, for our SGL.
5905 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
5906 */
5907 max_buf_size = (2 * SLI4_PAGE_SIZE);
James Smart81e6a632017-11-20 16:00:43 -08005908 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - extra)
5909 phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - extra;
James Smart09294d42013-04-17 20:16:05 -04005910
James Smartda0436e2009-05-22 14:51:39 -04005911 /*
James Smart895427b2017-02-12 13:52:30 -08005912 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
5913 * used to create the sg_dma_buf_pool must be calculated.
James Smart28baac72010-02-12 14:42:03 -05005914 */
James Smart96f70772013-04-17 20:16:15 -04005915 if (phba->cfg_enable_bg) {
5916 /*
James Smart895427b2017-02-12 13:52:30 -08005917 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
5918 * the FCP rsp, and a SGE. Sice we have no control
5919 * over how many protection segments the SCSI Layer
James Smart96f70772013-04-17 20:16:15 -04005920 * will hand us (ie: there could be one for every block
James Smart895427b2017-02-12 13:52:30 -08005921 * in the IO), just allocate enough SGEs to accomidate
5922 * our max amount and we need to limit lpfc_sg_seg_cnt
5923 * to minimize the risk of running out.
James Smart96f70772013-04-17 20:16:15 -04005924 */
5925 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08005926 sizeof(struct fcp_rsp) + max_buf_size;
James Smart96f70772013-04-17 20:16:15 -04005927
5928 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
5929 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
5930
5931 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
James Smart895427b2017-02-12 13:52:30 -08005932 phba->cfg_sg_seg_cnt =
5933 LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
James Smart96f70772013-04-17 20:16:15 -04005934 } else {
5935 /*
James Smart895427b2017-02-12 13:52:30 -08005936 * The scsi_buf for a regular I/O holds the FCP cmnd,
James Smart96f70772013-04-17 20:16:15 -04005937 * the FCP rsp, a SGE for each, and a SGE for up to
5938 * cfg_sg_seg_cnt data segments.
5939 */
5940 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08005941 sizeof(struct fcp_rsp) +
James Smart81e6a632017-11-20 16:00:43 -08005942 ((phba->cfg_sg_seg_cnt + extra) *
James Smart895427b2017-02-12 13:52:30 -08005943 sizeof(struct sli4_sge));
James Smart96f70772013-04-17 20:16:15 -04005944
5945 /* Total SGEs for scsi_sg_list */
James Smart81e6a632017-11-20 16:00:43 -08005946 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra;
James Smart895427b2017-02-12 13:52:30 -08005947
James Smart96f70772013-04-17 20:16:15 -04005948 /*
James Smart81e6a632017-11-20 16:00:43 -08005949 * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only
James Smart895427b2017-02-12 13:52:30 -08005950 * need to post 1 page for the SGL.
James Smart96f70772013-04-17 20:16:15 -04005951 */
James Smart085c6472010-11-20 23:11:37 -05005952 }
James Smartacd68592012-01-18 16:25:09 -05005953
James Smart96f70772013-04-17 20:16:15 -04005954 /* Initialize the host templates with the updated values. */
5955 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5956 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart96418b52017-03-04 09:30:31 -08005957 lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart96f70772013-04-17 20:16:15 -04005958
5959 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
5960 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
5961 else
5962 phba->cfg_sg_dma_buf_size =
5963 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
5964
5965 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5966 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
5967 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5968 phba->cfg_total_seg_cnt);
James Smartda0436e2009-05-22 14:51:39 -04005969
5970 /* Initialize buffer queue management fields */
James Smart895427b2017-02-12 13:52:30 -08005971 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
James Smartda0436e2009-05-22 14:51:39 -04005972 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
5973 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
5974
5975 /*
5976 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
5977 */
James Smart895427b2017-02-12 13:52:30 -08005978 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5979 /* Initialize the Abort scsi buffer list used by driver */
5980 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
5981 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
5982 }
5983
5984 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
5985 /* Initialize the Abort nvme buffer list used by driver */
5986 spin_lock_init(&phba->sli4_hba.abts_nvme_buf_list_lock);
5987 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
James Smart86c67372017-04-21 16:05:04 -07005988 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
James Smarta8cf5df2017-05-15 15:20:46 -07005989 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list);
James Smart895427b2017-02-12 13:52:30 -08005990 }
5991
James Smartda0436e2009-05-22 14:51:39 -04005992 /* This abort list used by worker thread */
James Smart895427b2017-02-12 13:52:30 -08005993 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
James Smarta8cf5df2017-05-15 15:20:46 -07005994 spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock);
James Smartda0436e2009-05-22 14:51:39 -04005995
5996 /*
James Smart6d368e52011-05-24 11:44:12 -04005997 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04005998 */
5999
6000 /* Driver internel slow-path CQ Event pool */
6001 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
6002 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04006003 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04006004 /* Asynchronous event CQ Event work queue list */
6005 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
6006 /* Fast-path XRI aborted CQ Event work queue list */
6007 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
6008 /* Slow-path XRI aborted CQ Event work queue list */
6009 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
6010 /* Receive queue CQ Event work queue list */
6011 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
6012
James Smart6d368e52011-05-24 11:44:12 -04006013 /* Initialize extent block lists. */
6014 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
6015 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
6016 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
6017 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
6018
James Smartd1f525a2017-04-21 16:04:55 -07006019 /* Initialize mboxq lists. If the early init routines fail
6020 * these lists need to be correctly initialized.
6021 */
6022 INIT_LIST_HEAD(&phba->sli.mboxq);
6023 INIT_LIST_HEAD(&phba->sli.mboxq_cmpl);
6024
James Smart448193b2015-12-16 18:12:05 -05006025 /* initialize optic_state to 0xFF */
6026 phba->sli4_hba.lnk_info.optic_state = 0xff;
6027
James Smartda0436e2009-05-22 14:51:39 -04006028 /* Allocate device driver memory */
6029 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
6030 if (rc)
6031 return -ENOMEM;
6032
James Smart2fcee4b2010-12-15 17:57:46 -05006033 /* IF Type 2 ports get initialized now. */
James Smart27d6ac02018-02-22 08:18:42 -08006034 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
James Smart2fcee4b2010-12-15 17:57:46 -05006035 LPFC_SLI_INTF_IF_TYPE_2) {
6036 rc = lpfc_pci_function_reset(phba);
James Smart895427b2017-02-12 13:52:30 -08006037 if (unlikely(rc)) {
6038 rc = -ENODEV;
6039 goto out_free_mem;
6040 }
James Smart946727d2015-04-07 15:07:09 -04006041 phba->temp_sensor_support = 1;
James Smart2fcee4b2010-12-15 17:57:46 -05006042 }
6043
James Smartda0436e2009-05-22 14:51:39 -04006044 /* Create the bootstrap mailbox command */
6045 rc = lpfc_create_bootstrap_mbox(phba);
6046 if (unlikely(rc))
6047 goto out_free_mem;
6048
6049 /* Set up the host's endian order with the device. */
6050 rc = lpfc_setup_endian_order(phba);
6051 if (unlikely(rc))
6052 goto out_free_bsmbx;
6053
6054 /* Set up the hba's configuration parameters. */
6055 rc = lpfc_sli4_read_config(phba);
6056 if (unlikely(rc))
6057 goto out_free_bsmbx;
James Smartcff261f2013-12-17 20:29:47 -05006058 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
6059 if (unlikely(rc))
6060 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04006061
James Smart2fcee4b2010-12-15 17:57:46 -05006062 /* IF Type 0 ports get initialized now. */
6063 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
6064 LPFC_SLI_INTF_IF_TYPE_0) {
6065 rc = lpfc_pci_function_reset(phba);
6066 if (unlikely(rc))
6067 goto out_free_bsmbx;
6068 }
James Smartda0436e2009-05-22 14:51:39 -04006069
James Smartcb5172e2010-03-15 11:25:07 -04006070 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
6071 GFP_KERNEL);
6072 if (!mboxq) {
6073 rc = -ENOMEM;
6074 goto out_free_bsmbx;
6075 }
6076
James Smartf358dd02017-02-12 13:52:34 -08006077 /* Check for NVMET being configured */
James Smart895427b2017-02-12 13:52:30 -08006078 phba->nvmet_support = 0;
James Smartf358dd02017-02-12 13:52:34 -08006079 if (lpfc_enable_nvmet_cnt) {
6080
6081 /* First get WWN of HBA instance */
6082 lpfc_read_nv(phba, mboxq);
6083 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
6084 if (rc != MBX_SUCCESS) {
6085 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6086 "6016 Mailbox failed , mbxCmd x%x "
6087 "READ_NV, mbxStatus x%x\n",
6088 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
6089 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
James Smartd1f525a2017-04-21 16:04:55 -07006090 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartf358dd02017-02-12 13:52:34 -08006091 rc = -EIO;
6092 goto out_free_bsmbx;
6093 }
6094 mb = &mboxq->u.mb;
6095 memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
6096 sizeof(uint64_t));
6097 wwn = cpu_to_be64(wwn);
6098 phba->sli4_hba.wwnn.u.name = wwn;
6099 memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
6100 sizeof(uint64_t));
6101 /* wwn is WWPN of HBA instance */
6102 wwn = cpu_to_be64(wwn);
6103 phba->sli4_hba.wwpn.u.name = wwn;
6104
6105 /* Check to see if it matches any module parameter */
6106 for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
6107 if (wwn == lpfc_enable_nvmet[i]) {
James Smart7d708032017-03-08 14:36:01 -08006108#if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
James Smart3c603be2017-05-15 15:20:44 -07006109 if (lpfc_nvmet_mem_alloc(phba))
6110 break;
6111
6112 phba->nvmet_support = 1; /* a match */
6113
James Smartf358dd02017-02-12 13:52:34 -08006114 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6115 "6017 NVME Target %016llx\n",
6116 wwn);
James Smart7d708032017-03-08 14:36:01 -08006117#else
6118 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6119 "6021 Can't enable NVME Target."
6120 " NVME_TARGET_FC infrastructure"
6121 " is not in kernel\n");
6122#endif
James Smart3c603be2017-05-15 15:20:44 -07006123 break;
James Smartf358dd02017-02-12 13:52:34 -08006124 }
6125 }
6126 }
James Smart895427b2017-02-12 13:52:30 -08006127
6128 lpfc_nvme_mod_param_dep(phba);
6129
James Smartfedd3b72011-02-16 12:39:24 -05006130 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04006131 lpfc_supported_pages(mboxq);
6132 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05006133 if (!rc) {
6134 mqe = &mboxq->u.mqe;
6135 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
6136 LPFC_MAX_SUPPORTED_PAGES);
6137 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
6138 switch (pn_page[i]) {
6139 case LPFC_SLI4_PARAMETERS:
6140 phba->sli4_hba.pc_sli4_params.supported = 1;
6141 break;
6142 default:
6143 break;
6144 }
6145 }
6146 /* Read the port's SLI4 Parameters capabilities if supported. */
6147 if (phba->sli4_hba.pc_sli4_params.supported)
6148 rc = lpfc_pc_sli4_params_get(phba, mboxq);
6149 if (rc) {
6150 mempool_free(mboxq, phba->mbox_mem_pool);
6151 rc = -EIO;
6152 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04006153 }
6154 }
James Smart65791f12016-07-06 12:35:56 -07006155
James Smartfedd3b72011-02-16 12:39:24 -05006156 /*
6157 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04006158 * If this call fails, it isn't critical unless the SLI4 parameters come
6159 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05006160 */
James Smart6d368e52011-05-24 11:44:12 -04006161 rc = lpfc_get_sli4_parameters(phba, mboxq);
6162 if (rc) {
6163 if (phba->sli4_hba.extents_in_use &&
6164 phba->sli4_hba.rpi_hdrs_in_use) {
6165 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6166 "2999 Unsupported SLI4 Parameters "
6167 "Extents and RPI headers enabled.\n");
James Smart6d368e52011-05-24 11:44:12 -04006168 }
James Smart895427b2017-02-12 13:52:30 -08006169 mempool_free(mboxq, phba->mbox_mem_pool);
Stefano Brivio5c756062017-09-06 11:02:56 +02006170 rc = -EIO;
James Smart895427b2017-02-12 13:52:30 -08006171 goto out_free_bsmbx;
James Smart6d368e52011-05-24 11:44:12 -04006172 }
James Smart895427b2017-02-12 13:52:30 -08006173
James Smartcb5172e2010-03-15 11:25:07 -04006174 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -05006175
6176 /* Verify OAS is supported */
6177 lpfc_sli4_oas_verify(phba);
6178 if (phba->cfg_fof)
6179 fof_vectors = 1;
6180
James Smart5350d872011-10-10 21:33:49 -04006181 /* Verify all the SLI4 queues */
6182 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04006183 if (rc)
6184 goto out_free_bsmbx;
6185
6186 /* Create driver internal CQE event pool */
6187 rc = lpfc_sli4_cq_event_pool_create(phba);
6188 if (rc)
James Smart5350d872011-10-10 21:33:49 -04006189 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04006190
James Smart8a9d2e82012-05-09 21:16:12 -04006191 /* Initialize sgl lists per host */
6192 lpfc_init_sgl_list(phba);
6193
6194 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04006195 rc = lpfc_init_active_sgl_array(phba);
6196 if (rc) {
6197 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6198 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04006199 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04006200 }
James Smartda0436e2009-05-22 14:51:39 -04006201 rc = lpfc_sli4_init_rpi_hdrs(phba);
6202 if (rc) {
6203 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6204 "1432 Failed to initialize rpi headers.\n");
6205 goto out_free_active_sgl;
6206 }
6207
James Smarta93ff372010-10-22 11:06:08 -04006208 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05006209 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
6210 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
6211 GFP_KERNEL);
6212 if (!phba->fcf.fcf_rr_bmask) {
6213 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6214 "2759 Failed allocate memory for FCF round "
6215 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04006216 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05006217 goto out_remove_rpi_hdrs;
6218 }
6219
James Smart895427b2017-02-12 13:52:30 -08006220 phba->sli4_hba.hba_eq_hdl = kcalloc(fof_vectors + phba->io_channel_irqs,
6221 sizeof(struct lpfc_hba_eq_hdl),
6222 GFP_KERNEL);
6223 if (!phba->sli4_hba.hba_eq_hdl) {
James Smart67d12732012-08-03 12:36:13 -04006224 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6225 "2572 Failed allocate memory for "
6226 "fast-path per-EQ handle array\n");
6227 rc = -ENOMEM;
6228 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04006229 }
6230
James Smart895427b2017-02-12 13:52:30 -08006231 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_present_cpu,
6232 sizeof(struct lpfc_vector_map_info),
6233 GFP_KERNEL);
James Smart7bb03bb2013-04-17 20:19:16 -04006234 if (!phba->sli4_hba.cpu_map) {
6235 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6236 "3327 Failed allocate memory for msi-x "
6237 "interrupt vector mapping\n");
6238 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08006239 goto out_free_hba_eq_hdl;
James Smart7bb03bb2013-04-17 20:19:16 -04006240 }
James Smartb246de12013-05-31 17:03:07 -04006241 if (lpfc_used_cpu == NULL) {
James Smart895427b2017-02-12 13:52:30 -08006242 lpfc_used_cpu = kcalloc(lpfc_present_cpu, sizeof(uint16_t),
6243 GFP_KERNEL);
James Smartb246de12013-05-31 17:03:07 -04006244 if (!lpfc_used_cpu) {
6245 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6246 "3335 Failed allocate memory for msi-x "
6247 "interrupt vector mapping\n");
6248 kfree(phba->sli4_hba.cpu_map);
6249 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08006250 goto out_free_hba_eq_hdl;
James Smartb246de12013-05-31 17:03:07 -04006251 }
6252 for (i = 0; i < lpfc_present_cpu; i++)
6253 lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
6254 }
6255
James Smart912e3ac2011-05-24 11:42:11 -04006256 /*
6257 * Enable sr-iov virtual functions if supported and configured
6258 * through the module parameter.
6259 */
6260 if (phba->cfg_sriov_nr_virtfn > 0) {
6261 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
6262 phba->cfg_sriov_nr_virtfn);
6263 if (rc) {
6264 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6265 "3020 Requested number of SR-IOV "
6266 "virtual functions (%d) is not "
6267 "supported\n",
6268 phba->cfg_sriov_nr_virtfn);
6269 phba->cfg_sriov_nr_virtfn = 0;
6270 }
6271 }
6272
James Smart5248a742011-07-22 18:37:06 -04006273 return 0;
James Smartda0436e2009-05-22 14:51:39 -04006274
James Smart895427b2017-02-12 13:52:30 -08006275out_free_hba_eq_hdl:
6276 kfree(phba->sli4_hba.hba_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05006277out_free_fcf_rr_bmask:
6278 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04006279out_remove_rpi_hdrs:
6280 lpfc_sli4_remove_rpi_hdrs(phba);
6281out_free_active_sgl:
6282 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04006283out_destroy_cq_event_pool:
6284 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04006285out_free_bsmbx:
6286 lpfc_destroy_bootstrap_mbox(phba);
6287out_free_mem:
6288 lpfc_mem_free(phba);
6289 return rc;
6290}
6291
6292/**
6293 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
6294 * @phba: pointer to lpfc hba data structure.
6295 *
6296 * This routine is invoked to unset the driver internal resources set up
6297 * specific for supporting the SLI-4 HBA device it attached to.
6298 **/
6299static void
6300lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
6301{
6302 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6303
James Smart7bb03bb2013-04-17 20:19:16 -04006304 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
6305 kfree(phba->sli4_hba.cpu_map);
6306 phba->sli4_hba.num_present_cpu = 0;
6307 phba->sli4_hba.num_online_cpu = 0;
James Smart76fd07a2014-02-20 09:57:18 -05006308 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04006309
James Smartda0436e2009-05-22 14:51:39 -04006310 /* Free memory allocated for fast-path work queue handles */
James Smart895427b2017-02-12 13:52:30 -08006311 kfree(phba->sli4_hba.hba_eq_hdl);
James Smartda0436e2009-05-22 14:51:39 -04006312
6313 /* Free the allocated rpi headers. */
6314 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04006315 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04006316
James Smart0c9ab6f2010-02-26 14:15:57 -05006317 /* Free eligible FCF index bmask */
6318 kfree(phba->fcf.fcf_rr_bmask);
6319
James Smartda0436e2009-05-22 14:51:39 -04006320 /* Free the ELS sgl list */
6321 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04006322 lpfc_free_els_sgl_list(phba);
James Smartf358dd02017-02-12 13:52:34 -08006323 lpfc_free_nvmet_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04006324
James Smartda0436e2009-05-22 14:51:39 -04006325 /* Free the completion queue EQ event pool */
6326 lpfc_sli4_cq_event_release_all(phba);
6327 lpfc_sli4_cq_event_pool_destroy(phba);
6328
James Smart6d368e52011-05-24 11:44:12 -04006329 /* Release resource identifiers. */
6330 lpfc_sli4_dealloc_resource_identifiers(phba);
6331
James Smartda0436e2009-05-22 14:51:39 -04006332 /* Free the bsmbx region. */
6333 lpfc_destroy_bootstrap_mbox(phba);
6334
6335 /* Free the SLI Layer memory with SLI4 HBAs */
6336 lpfc_mem_free_all(phba);
6337
6338 /* Free the current connect table */
6339 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04006340 &phba->fcf_conn_rec_list, list) {
6341 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04006342 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04006343 }
James Smartda0436e2009-05-22 14:51:39 -04006344
6345 return;
6346}
6347
6348/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006349 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04006350 * @phba: The hba struct for which this call is being executed.
6351 * @dev_grp: The HBA PCI-Device group number.
6352 *
6353 * This routine sets up the device INIT interface API function jump table
6354 * in @phba struct.
6355 *
6356 * Returns: 0 - success, -ENODEV - failure.
6357 **/
6358int
6359lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
6360{
James Smart84d1b002010-02-12 14:42:33 -05006361 phba->lpfc_hba_init_link = lpfc_hba_init_link;
6362 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05006363 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04006364 switch (dev_grp) {
6365 case LPFC_PCI_DEV_LP:
6366 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
6367 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
6368 phba->lpfc_stop_port = lpfc_stop_port_s3;
6369 break;
James Smartda0436e2009-05-22 14:51:39 -04006370 case LPFC_PCI_DEV_OC:
6371 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
6372 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
6373 phba->lpfc_stop_port = lpfc_stop_port_s4;
6374 break;
James Smart3772a992009-05-22 14:50:54 -04006375 default:
6376 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6377 "1431 Invalid HBA PCI-device group: 0x%x\n",
6378 dev_grp);
6379 return -ENODEV;
6380 break;
6381 }
6382 return 0;
6383}
6384
6385/**
James Smart3772a992009-05-22 14:50:54 -04006386 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
6387 * @phba: pointer to lpfc hba data structure.
6388 *
6389 * This routine is invoked to set up the driver internal resources after the
6390 * device specific resource setup to support the HBA device it attached to.
6391 *
6392 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006393 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006394 * other values - error
6395 **/
6396static int
6397lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
6398{
6399 int error;
6400
6401 /* Startup the kernel thread for this host adapter. */
6402 phba->worker_thread = kthread_run(lpfc_do_work, phba,
6403 "lpfc_worker_%d", phba->brd_no);
6404 if (IS_ERR(phba->worker_thread)) {
6405 error = PTR_ERR(phba->worker_thread);
6406 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006407 }
6408
Dick Kennedyf485c182017-09-29 17:34:34 -07006409 /* workqueue for deferred irq use */
6410 phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0);
6411
James Smart3772a992009-05-22 14:50:54 -04006412 return 0;
6413}
6414
6415/**
6416 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
6417 * @phba: pointer to lpfc hba data structure.
6418 *
6419 * This routine is invoked to unset the driver internal resources set up after
6420 * the device specific resource setup for supporting the HBA device it
6421 * attached to.
6422 **/
6423static void
6424lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
6425{
Dick Kennedyf485c182017-09-29 17:34:34 -07006426 if (phba->wq) {
6427 flush_workqueue(phba->wq);
6428 destroy_workqueue(phba->wq);
6429 phba->wq = NULL;
6430 }
6431
James Smart3772a992009-05-22 14:50:54 -04006432 /* Stop kernel worker thread */
6433 kthread_stop(phba->worker_thread);
6434}
6435
6436/**
6437 * lpfc_free_iocb_list - Free iocb list.
6438 * @phba: pointer to lpfc hba data structure.
6439 *
6440 * This routine is invoked to free the driver's IOCB list and memory.
6441 **/
James Smart6c621a22017-05-15 15:20:45 -07006442void
James Smart3772a992009-05-22 14:50:54 -04006443lpfc_free_iocb_list(struct lpfc_hba *phba)
6444{
6445 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
6446
6447 spin_lock_irq(&phba->hbalock);
6448 list_for_each_entry_safe(iocbq_entry, iocbq_next,
6449 &phba->lpfc_iocb_list, list) {
6450 list_del(&iocbq_entry->list);
6451 kfree(iocbq_entry);
6452 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006453 }
James Smart3772a992009-05-22 14:50:54 -04006454 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006455
James Smart3772a992009-05-22 14:50:54 -04006456 return;
6457}
dea31012005-04-17 16:05:31 -05006458
James Smart3772a992009-05-22 14:50:54 -04006459/**
6460 * lpfc_init_iocb_list - Allocate and initialize iocb list.
6461 * @phba: pointer to lpfc hba data structure.
6462 *
6463 * This routine is invoked to allocate and initizlize the driver's IOCB
6464 * list and set up the IOCB tag array accordingly.
6465 *
6466 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006467 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006468 * other values - error
6469 **/
James Smart6c621a22017-05-15 15:20:45 -07006470int
James Smart3772a992009-05-22 14:50:54 -04006471lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
6472{
6473 struct lpfc_iocbq *iocbq_entry = NULL;
6474 uint16_t iotag;
6475 int i;
dea31012005-04-17 16:05:31 -05006476
6477 /* Initialize and populate the iocb list per host. */
6478 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04006479 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07006480 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05006481 if (iocbq_entry == NULL) {
6482 printk(KERN_ERR "%s: only allocated %d iocbs of "
6483 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07006484 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05006485 goto out_free_iocbq;
6486 }
6487
James Bottomley604a3e32005-10-29 10:28:33 -05006488 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
6489 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04006490 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05006491 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04006492 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05006493 goto out_free_iocbq;
6494 }
James Smart6d368e52011-05-24 11:44:12 -04006495 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04006496 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05006497
6498 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006499 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
6500 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05006501 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006502 }
6503
James Smart3772a992009-05-22 14:50:54 -04006504 return 0;
6505
6506out_free_iocbq:
6507 lpfc_free_iocb_list(phba);
6508
6509 return -ENOMEM;
6510}
6511
6512/**
James Smart8a9d2e82012-05-09 21:16:12 -04006513 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04006514 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04006515 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04006516 *
James Smart8a9d2e82012-05-09 21:16:12 -04006517 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04006518 **/
James Smart8a9d2e82012-05-09 21:16:12 -04006519void
6520lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04006521{
6522 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04006523
6524 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
6525 list_del(&sglq_entry->list);
6526 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
6527 kfree(sglq_entry);
6528 }
6529}
6530
6531/**
6532 * lpfc_free_els_sgl_list - Free els sgl list.
6533 * @phba: pointer to lpfc hba data structure.
6534 *
6535 * This routine is invoked to free the driver's els sgl list and memory.
6536 **/
6537static void
6538lpfc_free_els_sgl_list(struct lpfc_hba *phba)
6539{
James Smartda0436e2009-05-22 14:51:39 -04006540 LIST_HEAD(sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04006541
James Smart8a9d2e82012-05-09 21:16:12 -04006542 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04006543 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08006544 spin_lock(&phba->sli4_hba.sgl_list_lock);
6545 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
6546 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04006547 spin_unlock_irq(&phba->hbalock);
6548
James Smart8a9d2e82012-05-09 21:16:12 -04006549 /* Now free the sgl list */
6550 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04006551}
6552
6553/**
James Smartf358dd02017-02-12 13:52:34 -08006554 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
6555 * @phba: pointer to lpfc hba data structure.
6556 *
6557 * This routine is invoked to free the driver's nvmet sgl list and memory.
6558 **/
6559static void
6560lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
6561{
6562 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6563 LIST_HEAD(sglq_list);
6564
6565 /* Retrieve all nvmet sgls from driver list */
6566 spin_lock_irq(&phba->hbalock);
6567 spin_lock(&phba->sli4_hba.sgl_list_lock);
6568 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
6569 spin_unlock(&phba->sli4_hba.sgl_list_lock);
6570 spin_unlock_irq(&phba->hbalock);
6571
6572 /* Now free the sgl list */
6573 list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
6574 list_del(&sglq_entry->list);
6575 lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
6576 kfree(sglq_entry);
6577 }
Dick Kennedy4b40d022017-08-23 16:55:38 -07006578
6579 /* Update the nvmet_xri_cnt to reflect no current sgls.
6580 * The next initialization cycle sets the count and allocates
6581 * the sgls over again.
6582 */
6583 phba->sli4_hba.nvmet_xri_cnt = 0;
James Smartf358dd02017-02-12 13:52:34 -08006584}
6585
6586/**
James Smartda0436e2009-05-22 14:51:39 -04006587 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
6588 * @phba: pointer to lpfc hba data structure.
6589 *
6590 * This routine is invoked to allocate the driver's active sgl memory.
6591 * This array will hold the sglq_entry's for active IOs.
6592 **/
6593static int
6594lpfc_init_active_sgl_array(struct lpfc_hba *phba)
6595{
6596 int size;
6597 size = sizeof(struct lpfc_sglq *);
6598 size *= phba->sli4_hba.max_cfg_param.max_xri;
6599
6600 phba->sli4_hba.lpfc_sglq_active_list =
6601 kzalloc(size, GFP_KERNEL);
6602 if (!phba->sli4_hba.lpfc_sglq_active_list)
6603 return -ENOMEM;
6604 return 0;
6605}
6606
6607/**
6608 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
6609 * @phba: pointer to lpfc hba data structure.
6610 *
6611 * This routine is invoked to walk through the array of active sglq entries
6612 * and free all of the resources.
6613 * This is just a place holder for now.
6614 **/
6615static void
6616lpfc_free_active_sgl(struct lpfc_hba *phba)
6617{
6618 kfree(phba->sli4_hba.lpfc_sglq_active_list);
6619}
6620
6621/**
6622 * lpfc_init_sgl_list - Allocate and initialize sgl list.
6623 * @phba: pointer to lpfc hba data structure.
6624 *
6625 * This routine is invoked to allocate and initizlize the driver's sgl
6626 * list and set up the sgl xritag tag array accordingly.
6627 *
James Smartda0436e2009-05-22 14:51:39 -04006628 **/
James Smart8a9d2e82012-05-09 21:16:12 -04006629static void
James Smartda0436e2009-05-22 14:51:39 -04006630lpfc_init_sgl_list(struct lpfc_hba *phba)
6631{
James Smartda0436e2009-05-22 14:51:39 -04006632 /* Initialize and populate the sglq list per host/VF. */
James Smart895427b2017-02-12 13:52:30 -08006633 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
James Smartda0436e2009-05-22 14:51:39 -04006634 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -08006635 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
James Smart86c67372017-04-21 16:05:04 -07006636 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
James Smartda0436e2009-05-22 14:51:39 -04006637
James Smart8a9d2e82012-05-09 21:16:12 -04006638 /* els xri-sgl book keeping */
6639 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04006640
James Smart8a9d2e82012-05-09 21:16:12 -04006641 /* scsi xri-buffer book keeping */
James Smartda0436e2009-05-22 14:51:39 -04006642 phba->sli4_hba.scsi_xri_cnt = 0;
James Smart895427b2017-02-12 13:52:30 -08006643
6644 /* nvme xri-buffer book keeping */
6645 phba->sli4_hba.nvme_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04006646}
6647
6648/**
6649 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
6650 * @phba: pointer to lpfc hba data structure.
6651 *
6652 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04006653 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04006654 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04006655 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
6656 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04006657 *
6658 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006659 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04006660 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04006661 **/
6662int
6663lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
6664{
6665 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04006666 struct lpfc_rpi_hdr *rpi_hdr;
6667
6668 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05006669 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04006670 return rc;
James Smart6d368e52011-05-24 11:44:12 -04006671 if (phba->sli4_hba.extents_in_use)
6672 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04006673
6674 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
6675 if (!rpi_hdr) {
6676 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6677 "0391 Error during rpi post operation\n");
6678 lpfc_sli4_remove_rpis(phba);
6679 rc = -ENODEV;
6680 }
6681
6682 return rc;
6683}
6684
6685/**
6686 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
6687 * @phba: pointer to lpfc hba data structure.
6688 *
6689 * This routine is invoked to allocate a single 4KB memory region to
6690 * support rpis and stores them in the phba. This single region
6691 * provides support for up to 64 rpis. The region is used globally
6692 * by the device.
6693 *
6694 * Returns:
6695 * A valid rpi hdr on success.
6696 * A NULL pointer on any failure.
6697 **/
6698struct lpfc_rpi_hdr *
6699lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
6700{
6701 uint16_t rpi_limit, curr_rpi_range;
6702 struct lpfc_dmabuf *dmabuf;
6703 struct lpfc_rpi_hdr *rpi_hdr;
6704
James Smart6d368e52011-05-24 11:44:12 -04006705 /*
6706 * If the SLI4 port supports extents, posting the rpi header isn't
6707 * required. Set the expected maximum count and let the actual value
6708 * get set when extents are fully allocated.
6709 */
6710 if (!phba->sli4_hba.rpi_hdrs_in_use)
6711 return NULL;
6712 if (phba->sli4_hba.extents_in_use)
6713 return NULL;
6714
6715 /* The limit on the logical index is just the max_rpi count. */
James Smart845d9e82017-05-15 15:20:38 -07006716 rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi;
James Smartda0436e2009-05-22 14:51:39 -04006717
6718 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006719 /*
6720 * Establish the starting RPI in this header block. The starting
6721 * rpi is normalized to a zero base because the physical rpi is
6722 * port based.
6723 */
James Smart97f2ecf2012-03-01 22:35:23 -05006724 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04006725 spin_unlock_irq(&phba->hbalock);
6726
James Smart845d9e82017-05-15 15:20:38 -07006727 /* Reached full RPI range */
6728 if (curr_rpi_range == rpi_limit)
James Smart6d368e52011-05-24 11:44:12 -04006729 return NULL;
James Smart845d9e82017-05-15 15:20:38 -07006730
James Smartda0436e2009-05-22 14:51:39 -04006731 /*
6732 * First allocate the protocol header region for the port. The
6733 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
6734 */
6735 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6736 if (!dmabuf)
6737 return NULL;
6738
Joe Perches1aee3832014-09-03 12:56:12 -04006739 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
6740 LPFC_HDR_TEMPLATE_SIZE,
6741 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04006742 if (!dmabuf->virt) {
6743 rpi_hdr = NULL;
6744 goto err_free_dmabuf;
6745 }
6746
James Smartda0436e2009-05-22 14:51:39 -04006747 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
6748 rpi_hdr = NULL;
6749 goto err_free_coherent;
6750 }
6751
6752 /* Save the rpi header data for cleanup later. */
6753 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
6754 if (!rpi_hdr)
6755 goto err_free_coherent;
6756
6757 rpi_hdr->dmabuf = dmabuf;
6758 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
6759 rpi_hdr->page_count = 1;
6760 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006761
6762 /* The rpi_hdr stores the logical index only. */
6763 rpi_hdr->start_rpi = curr_rpi_range;
James Smart845d9e82017-05-15 15:20:38 -07006764 rpi_hdr->next_rpi = phba->sli4_hba.next_rpi + LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04006765 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
6766
James Smartda0436e2009-05-22 14:51:39 -04006767 spin_unlock_irq(&phba->hbalock);
6768 return rpi_hdr;
6769
6770 err_free_coherent:
6771 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
6772 dmabuf->virt, dmabuf->phys);
6773 err_free_dmabuf:
6774 kfree(dmabuf);
6775 return NULL;
6776}
6777
6778/**
6779 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
6780 * @phba: pointer to lpfc hba data structure.
6781 *
6782 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04006783 * to support rpis for SLI4 ports not supporting extents. This routine
6784 * presumes the caller has released all rpis consumed by fabric or port
6785 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04006786 **/
6787void
6788lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
6789{
6790 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
6791
James Smart6d368e52011-05-24 11:44:12 -04006792 if (!phba->sli4_hba.rpi_hdrs_in_use)
6793 goto exit;
6794
James Smartda0436e2009-05-22 14:51:39 -04006795 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
6796 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
6797 list_del(&rpi_hdr->list);
6798 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
6799 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
6800 kfree(rpi_hdr->dmabuf);
6801 kfree(rpi_hdr);
6802 }
James Smart6d368e52011-05-24 11:44:12 -04006803 exit:
6804 /* There are no rpis available to the port now. */
6805 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04006806}
6807
6808/**
James Smart3772a992009-05-22 14:50:54 -04006809 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
6810 * @pdev: pointer to pci device data structure.
6811 *
6812 * This routine is invoked to allocate the driver hba data structure for an
6813 * HBA device. If the allocation is successful, the phba reference to the
6814 * PCI device data structure is set.
6815 *
6816 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006817 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04006818 * NULL - error
6819 **/
6820static struct lpfc_hba *
6821lpfc_hba_alloc(struct pci_dev *pdev)
6822{
6823 struct lpfc_hba *phba;
6824
6825 /* Allocate memory for HBA structure */
6826 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
6827 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02006828 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04006829 return NULL;
6830 }
6831
6832 /* Set reference to PCI device in HBA structure */
6833 phba->pcidev = pdev;
6834
6835 /* Assign an unused board number */
6836 phba->brd_no = lpfc_get_instance();
6837 if (phba->brd_no < 0) {
6838 kfree(phba);
6839 return NULL;
6840 }
James Smart65791f12016-07-06 12:35:56 -07006841 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
James Smart3772a992009-05-22 14:50:54 -04006842
James Smart4fede782010-01-26 23:08:55 -05006843 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04006844 INIT_LIST_HEAD(&phba->ct_ev_waiters);
6845
James Smart3772a992009-05-22 14:50:54 -04006846 return phba;
6847}
6848
6849/**
6850 * lpfc_hba_free - Free driver hba data structure with a device.
6851 * @phba: pointer to lpfc hba data structure.
6852 *
6853 * This routine is invoked to free the driver hba data structure with an
6854 * HBA device.
6855 **/
6856static void
6857lpfc_hba_free(struct lpfc_hba *phba)
6858{
6859 /* Release the driver assigned board number */
6860 idr_remove(&lpfc_hba_index, phba->brd_no);
6861
James Smart895427b2017-02-12 13:52:30 -08006862 /* Free memory allocated with sli3 rings */
6863 kfree(phba->sli.sli3_ring);
6864 phba->sli.sli3_ring = NULL;
James Smart2a76a282012-08-03 12:35:54 -04006865
James Smart3772a992009-05-22 14:50:54 -04006866 kfree(phba);
6867 return;
6868}
6869
6870/**
6871 * lpfc_create_shost - Create hba physical port with associated scsi host.
6872 * @phba: pointer to lpfc hba data structure.
6873 *
6874 * This routine is invoked to create HBA physical port and associate a SCSI
6875 * host with it.
6876 *
6877 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006878 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006879 * other values - error
6880 **/
6881static int
6882lpfc_create_shost(struct lpfc_hba *phba)
6883{
6884 struct lpfc_vport *vport;
6885 struct Scsi_Host *shost;
6886
6887 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05006888 phba->fc_edtov = FF_DEF_EDTOV;
6889 phba->fc_ratov = FF_DEF_RATOV;
6890 phba->fc_altov = FF_DEF_ALTOV;
6891 phba->fc_arbtov = FF_DEF_ARBTOV;
6892
James Smartd7c47992010-06-08 18:31:54 -04006893 atomic_set(&phba->sdev_cnt, 0);
James Smart2cee7802017-06-01 21:07:02 -07006894 atomic_set(&phba->fc4ScsiInputRequests, 0);
6895 atomic_set(&phba->fc4ScsiOutputRequests, 0);
6896 atomic_set(&phba->fc4ScsiControlRequests, 0);
6897 atomic_set(&phba->fc4ScsiIoCmpls, 0);
6898 atomic_set(&phba->fc4NvmeInputRequests, 0);
6899 atomic_set(&phba->fc4NvmeOutputRequests, 0);
6900 atomic_set(&phba->fc4NvmeControlRequests, 0);
6901 atomic_set(&phba->fc4NvmeIoCmpls, 0);
6902 atomic_set(&phba->fc4NvmeLsRequests, 0);
6903 atomic_set(&phba->fc4NvmeLsCmpls, 0);
James Smart3de2a652007-08-02 11:09:59 -04006904 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05006905 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04006906 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05006907
6908 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05006909 phba->pport = vport;
James Smart2ea259e2017-02-12 13:52:27 -08006910
James Smartf358dd02017-02-12 13:52:34 -08006911 if (phba->nvmet_support) {
6912 /* Only 1 vport (pport) will support NVME target */
6913 if (phba->txrdy_payload_pool == NULL) {
Romain Perier771db5c2017-07-06 10:13:05 +02006914 phba->txrdy_payload_pool = dma_pool_create(
6915 "txrdy_pool", &phba->pcidev->dev,
James Smartf358dd02017-02-12 13:52:34 -08006916 TXRDY_PAYLOAD_LEN, 16, 0);
6917 if (phba->txrdy_payload_pool) {
6918 phba->targetport = NULL;
6919 phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
6920 lpfc_printf_log(phba, KERN_INFO,
6921 LOG_INIT | LOG_NVME_DISC,
6922 "6076 NVME Target Found\n");
6923 }
6924 }
6925 }
6926
James Smart858c9f62007-06-17 19:56:39 -05006927 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04006928 /* Put reference to SCSI host to driver's device private data */
6929 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05006930
James Smart4258e982015-12-16 18:11:58 -05006931 /*
6932 * At this point we are fully registered with PSA. In addition,
6933 * any initial discovery should be completed.
6934 */
6935 vport->load_flag |= FC_ALLOW_FDMI;
James Smart8663cbb2016-03-31 14:12:33 -07006936 if (phba->cfg_enable_SmartSAN ||
6937 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -05006938
6939 /* Setup appropriate attribute masks */
6940 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -07006941 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -05006942 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
6943 else
6944 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
6945 }
James Smart3772a992009-05-22 14:50:54 -04006946 return 0;
6947}
dea31012005-04-17 16:05:31 -05006948
James Smart3772a992009-05-22 14:50:54 -04006949/**
6950 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
6951 * @phba: pointer to lpfc hba data structure.
6952 *
6953 * This routine is invoked to destroy HBA physical port and the associated
6954 * SCSI host.
6955 **/
6956static void
6957lpfc_destroy_shost(struct lpfc_hba *phba)
6958{
6959 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04006960
James Smart3772a992009-05-22 14:50:54 -04006961 /* Destroy physical port that associated with the SCSI host */
6962 destroy_port(vport);
6963
6964 return;
6965}
6966
6967/**
6968 * lpfc_setup_bg - Setup Block guard structures and debug areas.
6969 * @phba: pointer to lpfc hba data structure.
6970 * @shost: the shost to be used to detect Block guard settings.
6971 *
6972 * This routine sets up the local Block guard protocol settings for @shost.
6973 * This routine also allocates memory for debugging bg buffers.
6974 **/
6975static void
6976lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
6977{
James Smartbbeb79b2012-06-12 13:54:27 -04006978 uint32_t old_mask;
6979 uint32_t old_guard;
6980
James Smart3772a992009-05-22 14:50:54 -04006981 int pagecnt = 10;
James Smartb3b98b72016-10-13 15:06:06 -07006982 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
James Smart3772a992009-05-22 14:50:54 -04006983 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6984 "1478 Registering BlockGuard with the "
6985 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04006986
James Smartb3b98b72016-10-13 15:06:06 -07006987 old_mask = phba->cfg_prot_mask;
6988 old_guard = phba->cfg_prot_guard;
James Smartbbeb79b2012-06-12 13:54:27 -04006989
6990 /* Only allow supported values */
James Smartb3b98b72016-10-13 15:06:06 -07006991 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
James Smartbbeb79b2012-06-12 13:54:27 -04006992 SHOST_DIX_TYPE0_PROTECTION |
6993 SHOST_DIX_TYPE1_PROTECTION);
James Smartb3b98b72016-10-13 15:06:06 -07006994 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
6995 SHOST_DIX_GUARD_CRC);
James Smartbbeb79b2012-06-12 13:54:27 -04006996
6997 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
James Smartb3b98b72016-10-13 15:06:06 -07006998 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
6999 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
James Smartbbeb79b2012-06-12 13:54:27 -04007000
James Smartb3b98b72016-10-13 15:06:06 -07007001 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
7002 if ((old_mask != phba->cfg_prot_mask) ||
7003 (old_guard != phba->cfg_prot_guard))
James Smartbbeb79b2012-06-12 13:54:27 -04007004 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7005 "1475 Registering BlockGuard with the "
7006 "SCSI layer: mask %d guard %d\n",
James Smartb3b98b72016-10-13 15:06:06 -07007007 phba->cfg_prot_mask,
7008 phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04007009
James Smartb3b98b72016-10-13 15:06:06 -07007010 scsi_host_set_prot(shost, phba->cfg_prot_mask);
7011 scsi_host_set_guard(shost, phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04007012 } else
7013 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7014 "1479 Not Registering BlockGuard with the SCSI "
7015 "layer, Bad protection parameters: %d %d\n",
7016 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04007017 }
James Smartbbeb79b2012-06-12 13:54:27 -04007018
James Smart81301a92008-12-04 22:39:46 -05007019 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05007020 while (pagecnt) {
7021 spin_lock_init(&_dump_buf_lock);
7022 _dump_buf_data =
7023 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
7024 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04007025 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7026 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04007027 "_dump_buf_data at 0x%p\n",
7028 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05007029 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04007030 memset(_dump_buf_data, 0,
7031 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05007032 break;
James Smart3772a992009-05-22 14:50:54 -04007033 } else
James Smart81301a92008-12-04 22:39:46 -05007034 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05007035 }
James Smart81301a92008-12-04 22:39:46 -05007036 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04007037 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7038 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04007039 "memory for hexdump\n");
7040 } else
James Smart6a9c52c2009-10-02 15:16:51 -04007041 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7042 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05007043 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05007044 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05007045 while (pagecnt) {
7046 _dump_buf_dif =
7047 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
7048 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04007049 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7050 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04007051 "_dump_buf_dif at 0x%p\n",
7052 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05007053 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04007054 memset(_dump_buf_dif, 0,
7055 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05007056 break;
James Smart3772a992009-05-22 14:50:54 -04007057 } else
James Smart81301a92008-12-04 22:39:46 -05007058 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05007059 }
James Smart81301a92008-12-04 22:39:46 -05007060 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04007061 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7062 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04007063 "memory for hexdump\n");
7064 } else
James Smart6a9c52c2009-10-02 15:16:51 -04007065 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
7066 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04007067 _dump_buf_dif);
7068}
7069
7070/**
7071 * lpfc_post_init_setup - Perform necessary device post initialization setup.
7072 * @phba: pointer to lpfc hba data structure.
7073 *
7074 * This routine is invoked to perform all the necessary post initialization
7075 * setup for the device.
7076 **/
7077static void
7078lpfc_post_init_setup(struct lpfc_hba *phba)
7079{
7080 struct Scsi_Host *shost;
7081 struct lpfc_adapter_event_header adapter_event;
7082
7083 /* Get the default values for Model Name and Description */
7084 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
7085
7086 /*
7087 * hba setup may have changed the hba_queue_depth so we need to
7088 * adjust the value of can_queue.
7089 */
7090 shost = pci_get_drvdata(phba->pcidev);
7091 shost->can_queue = phba->cfg_hba_queue_depth - 10;
7092 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
7093 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05007094
7095 lpfc_host_attrib_init(shost);
7096
James Smart2e0fef82007-06-17 19:56:36 -05007097 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
7098 spin_lock_irq(shost->host_lock);
7099 lpfc_poll_start_timer(phba);
7100 spin_unlock_irq(shost->host_lock);
7101 }
James Smart8f6d98d2006-08-01 07:34:00 -04007102
James Smart93996272008-08-24 21:50:30 -04007103 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7104 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04007105 /* Send board arrival event to upper layer */
7106 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
7107 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
7108 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04007109 sizeof(adapter_event),
7110 (char *) &adapter_event,
7111 LPFC_NL_VENDOR_ID);
7112 return;
7113}
7114
7115/**
7116 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
7117 * @phba: pointer to lpfc hba data structure.
7118 *
7119 * This routine is invoked to set up the PCI device memory space for device
7120 * with SLI-3 interface spec.
7121 *
7122 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007123 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04007124 * other values - error
7125 **/
7126static int
7127lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
7128{
7129 struct pci_dev *pdev;
7130 unsigned long bar0map_len, bar2map_len;
7131 int i, hbq_count;
7132 void *ptr;
7133 int error = -ENODEV;
7134
7135 /* Obtain PCI device reference */
7136 if (!phba->pcidev)
7137 return error;
7138 else
7139 pdev = phba->pcidev;
7140
7141 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05007142 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
7143 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
7144 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
7145 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smart3772a992009-05-22 14:50:54 -04007146 return error;
Michael Reed8e685972009-09-18 12:02:05 -05007147 }
7148 }
James Smart3772a992009-05-22 14:50:54 -04007149
7150 /* Get the bus address of Bar0 and Bar2 and the number of bytes
7151 * required by each mapping.
7152 */
7153 phba->pci_bar0_map = pci_resource_start(pdev, 0);
7154 bar0map_len = pci_resource_len(pdev, 0);
7155
7156 phba->pci_bar2_map = pci_resource_start(pdev, 2);
7157 bar2map_len = pci_resource_len(pdev, 2);
7158
7159 /* Map HBA SLIM to a kernel virtual address. */
7160 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
7161 if (!phba->slim_memmap_p) {
7162 dev_printk(KERN_ERR, &pdev->dev,
7163 "ioremap failed for SLIM memory.\n");
7164 goto out;
7165 }
7166
7167 /* Map HBA Control Registers to a kernel virtual address. */
7168 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
7169 if (!phba->ctrl_regs_memmap_p) {
7170 dev_printk(KERN_ERR, &pdev->dev,
7171 "ioremap failed for HBA control registers.\n");
7172 goto out_iounmap_slim;
7173 }
7174
7175 /* Allocate memory for SLI-2 structures */
Joe Perches1aee3832014-09-03 12:56:12 -04007176 phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7177 &phba->slim2p.phys, GFP_KERNEL);
James Smart3772a992009-05-22 14:50:54 -04007178 if (!phba->slim2p.virt)
7179 goto out_iounmap;
7180
James Smart3772a992009-05-22 14:50:54 -04007181 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04007182 phba->mbox_ext = (phba->slim2p.virt +
7183 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04007184 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
7185 phba->IOCBs = (phba->slim2p.virt +
7186 offsetof(struct lpfc_sli2_slim, IOCBs));
7187
7188 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
7189 lpfc_sli_hbq_size(),
7190 &phba->hbqslimp.phys,
7191 GFP_KERNEL);
7192 if (!phba->hbqslimp.virt)
7193 goto out_free_slim;
7194
7195 hbq_count = lpfc_sli_hbq_count();
7196 ptr = phba->hbqslimp.virt;
7197 for (i = 0; i < hbq_count; ++i) {
7198 phba->hbqs[i].hbq_virt = ptr;
7199 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
7200 ptr += (lpfc_hbq_defs[i]->entry_count *
7201 sizeof(struct lpfc_hbq_entry));
7202 }
7203 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
7204 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
7205
7206 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
7207
James Smart3772a992009-05-22 14:50:54 -04007208 phba->MBslimaddr = phba->slim_memmap_p;
7209 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
7210 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
7211 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
7212 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04007213
dea31012005-04-17 16:05:31 -05007214 return 0;
7215
dea31012005-04-17 16:05:31 -05007216out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04007217 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7218 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05007219out_iounmap:
7220 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05007221out_iounmap_slim:
dea31012005-04-17 16:05:31 -05007222 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05007223out:
7224 return error;
7225}
7226
James Smarte59058c2008-08-24 21:49:00 -04007227/**
James Smart3772a992009-05-22 14:50:54 -04007228 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
7229 * @phba: pointer to lpfc hba data structure.
7230 *
7231 * This routine is invoked to unset the PCI device memory space for device
7232 * with SLI-3 interface spec.
7233 **/
7234static void
7235lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
7236{
7237 struct pci_dev *pdev;
7238
7239 /* Obtain PCI device reference */
7240 if (!phba->pcidev)
7241 return;
7242 else
7243 pdev = phba->pcidev;
7244
7245 /* Free coherent DMA memory allocated */
7246 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
7247 phba->hbqslimp.virt, phba->hbqslimp.phys);
7248 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7249 phba->slim2p.virt, phba->slim2p.phys);
7250
7251 /* I/O memory unmap */
7252 iounmap(phba->ctrl_regs_memmap_p);
7253 iounmap(phba->slim_memmap_p);
7254
7255 return;
7256}
7257
7258/**
James Smartda0436e2009-05-22 14:51:39 -04007259 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
7260 * @phba: pointer to lpfc hba data structure.
7261 *
7262 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
7263 * done and check status.
7264 *
7265 * Return 0 if successful, otherwise -ENODEV.
7266 **/
7267int
7268lpfc_sli4_post_status_check(struct lpfc_hba *phba)
7269{
James Smart2fcee4b2010-12-15 17:57:46 -05007270 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
7271 struct lpfc_register reg_data;
7272 int i, port_error = 0;
7273 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04007274
James Smart9940b972011-03-11 16:06:12 -05007275 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
7276 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05007277 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04007278 return -ENODEV;
7279
James Smartda0436e2009-05-22 14:51:39 -04007280 /* Wait up to 30 seconds for the SLI Port POST done and ready */
7281 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05007282 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
7283 &portsmphr_reg.word0) ||
7284 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007285 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04007286 port_error = -ENODEV;
7287 break;
7288 }
James Smart2fcee4b2010-12-15 17:57:46 -05007289 if (LPFC_POST_STAGE_PORT_READY ==
7290 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04007291 break;
James Smartda0436e2009-05-22 14:51:39 -04007292 msleep(10);
7293 }
7294
James Smart2fcee4b2010-12-15 17:57:46 -05007295 /*
7296 * If there was a port error during POST, then don't proceed with
7297 * other register reads as the data may not be valid. Just exit.
7298 */
7299 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04007300 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05007301 "1408 Port Failed POST - portsmphr=0x%x, "
7302 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
7303 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
7304 portsmphr_reg.word0,
7305 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
7306 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
7307 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
7308 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
7309 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
7310 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
7311 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
7312 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
7313 } else {
James Smart28baac72010-02-12 14:42:03 -05007314 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05007315 "2534 Device Info: SLIFamily=0x%x, "
7316 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
7317 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05007318 bf_get(lpfc_sli_intf_sli_family,
7319 &phba->sli4_hba.sli_intf),
7320 bf_get(lpfc_sli_intf_slirev,
7321 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05007322 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05007323 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05007324 bf_get(lpfc_sli_intf_sli_hint1,
7325 &phba->sli4_hba.sli_intf),
7326 bf_get(lpfc_sli_intf_sli_hint2,
7327 &phba->sli4_hba.sli_intf),
7328 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05007329 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05007330 /*
7331 * Check for other Port errors during the initialization
7332 * process. Fail the load if the port did not come up
7333 * correctly.
7334 */
7335 if_type = bf_get(lpfc_sli_intf_if_type,
7336 &phba->sli4_hba.sli_intf);
7337 switch (if_type) {
7338 case LPFC_SLI_INTF_IF_TYPE_0:
7339 phba->sli4_hba.ue_mask_lo =
7340 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
7341 phba->sli4_hba.ue_mask_hi =
7342 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
7343 uerrlo_reg.word0 =
7344 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
7345 uerrhi_reg.word0 =
7346 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
7347 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
7348 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
7349 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7350 "1422 Unrecoverable Error "
7351 "Detected during POST "
7352 "uerr_lo_reg=0x%x, "
7353 "uerr_hi_reg=0x%x, "
7354 "ue_mask_lo_reg=0x%x, "
7355 "ue_mask_hi_reg=0x%x\n",
7356 uerrlo_reg.word0,
7357 uerrhi_reg.word0,
7358 phba->sli4_hba.ue_mask_lo,
7359 phba->sli4_hba.ue_mask_hi);
7360 port_error = -ENODEV;
7361 }
7362 break;
7363 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08007364 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2fcee4b2010-12-15 17:57:46 -05007365 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05007366 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
7367 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04007368 (bf_get(lpfc_sliport_status_err, &reg_data) &&
7369 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007370 phba->work_status[0] =
7371 readl(phba->sli4_hba.u.if_type2.
7372 ERR1regaddr);
7373 phba->work_status[1] =
7374 readl(phba->sli4_hba.u.if_type2.
7375 ERR2regaddr);
7376 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05007377 "2888 Unrecoverable port error "
7378 "following POST: port status reg "
7379 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05007380 "error 1=0x%x, error 2=0x%x\n",
7381 reg_data.word0,
7382 portsmphr_reg.word0,
7383 phba->work_status[0],
7384 phba->work_status[1]);
7385 port_error = -ENODEV;
7386 }
7387 break;
7388 case LPFC_SLI_INTF_IF_TYPE_1:
7389 default:
7390 break;
7391 }
James Smart28baac72010-02-12 14:42:03 -05007392 }
James Smartda0436e2009-05-22 14:51:39 -04007393 return port_error;
7394}
7395
7396/**
7397 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
7398 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05007399 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04007400 *
7401 * This routine is invoked to set up SLI4 BAR0 PCI config space register
7402 * memory map.
7403 **/
7404static void
James Smart2fcee4b2010-12-15 17:57:46 -05007405lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04007406{
James Smart2fcee4b2010-12-15 17:57:46 -05007407 switch (if_type) {
7408 case LPFC_SLI_INTF_IF_TYPE_0:
7409 phba->sli4_hba.u.if_type0.UERRLOregaddr =
7410 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
7411 phba->sli4_hba.u.if_type0.UERRHIregaddr =
7412 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
7413 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
7414 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
7415 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
7416 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
7417 phba->sli4_hba.SLIINTFregaddr =
7418 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7419 break;
7420 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart0cf07f842017-06-01 21:07:10 -07007421 phba->sli4_hba.u.if_type2.EQDregaddr =
7422 phba->sli4_hba.conf_regs_memmap_p +
7423 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007424 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007425 phba->sli4_hba.conf_regs_memmap_p +
7426 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007427 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007428 phba->sli4_hba.conf_regs_memmap_p +
7429 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007430 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007431 phba->sli4_hba.conf_regs_memmap_p +
7432 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007433 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007434 phba->sli4_hba.conf_regs_memmap_p +
7435 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007436 phba->sli4_hba.SLIINTFregaddr =
7437 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7438 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007439 phba->sli4_hba.conf_regs_memmap_p +
7440 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007441 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05007442 phba->sli4_hba.conf_regs_memmap_p +
7443 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05007444 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05007445 phba->sli4_hba.conf_regs_memmap_p +
7446 LPFC_ULP0_WQ_DOORBELL;
James Smart9dd35422018-02-22 08:18:41 -08007447 phba->sli4_hba.CQDBregaddr =
James Smart2fcee4b2010-12-15 17:57:46 -05007448 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
James Smart9dd35422018-02-22 08:18:41 -08007449 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
James Smart2fcee4b2010-12-15 17:57:46 -05007450 phba->sli4_hba.MQDBregaddr =
7451 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
7452 phba->sli4_hba.BMBXregaddr =
7453 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
7454 break;
James Smart27d6ac02018-02-22 08:18:42 -08007455 case LPFC_SLI_INTF_IF_TYPE_6:
7456 phba->sli4_hba.u.if_type2.EQDregaddr =
7457 phba->sli4_hba.conf_regs_memmap_p +
7458 LPFC_CTL_PORT_EQ_DELAY_OFFSET;
7459 phba->sli4_hba.u.if_type2.ERR1regaddr =
7460 phba->sli4_hba.conf_regs_memmap_p +
7461 LPFC_CTL_PORT_ER1_OFFSET;
7462 phba->sli4_hba.u.if_type2.ERR2regaddr =
7463 phba->sli4_hba.conf_regs_memmap_p +
7464 LPFC_CTL_PORT_ER2_OFFSET;
7465 phba->sli4_hba.u.if_type2.CTRLregaddr =
7466 phba->sli4_hba.conf_regs_memmap_p +
7467 LPFC_CTL_PORT_CTL_OFFSET;
7468 phba->sli4_hba.u.if_type2.STATUSregaddr =
7469 phba->sli4_hba.conf_regs_memmap_p +
7470 LPFC_CTL_PORT_STA_OFFSET;
7471 phba->sli4_hba.PSMPHRregaddr =
7472 phba->sli4_hba.conf_regs_memmap_p +
7473 LPFC_CTL_PORT_SEM_OFFSET;
7474 phba->sli4_hba.BMBXregaddr =
7475 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
7476 break;
James Smart2fcee4b2010-12-15 17:57:46 -05007477 case LPFC_SLI_INTF_IF_TYPE_1:
7478 default:
7479 dev_printk(KERN_ERR, &phba->pcidev->dev,
7480 "FATAL - unsupported SLI4 interface type - %d\n",
7481 if_type);
7482 break;
7483 }
James Smartda0436e2009-05-22 14:51:39 -04007484}
7485
7486/**
7487 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
7488 * @phba: pointer to lpfc hba data structure.
7489 *
James Smart27d6ac02018-02-22 08:18:42 -08007490 * This routine is invoked to set up SLI4 BAR1 register memory map.
James Smartda0436e2009-05-22 14:51:39 -04007491 **/
7492static void
James Smart27d6ac02018-02-22 08:18:42 -08007493lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04007494{
James Smart27d6ac02018-02-22 08:18:42 -08007495 switch (if_type) {
7496 case LPFC_SLI_INTF_IF_TYPE_0:
7497 phba->sli4_hba.PSMPHRregaddr =
7498 phba->sli4_hba.ctrl_regs_memmap_p +
7499 LPFC_SLIPORT_IF0_SMPHR;
7500 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7501 LPFC_HST_ISR0;
7502 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7503 LPFC_HST_IMR0;
7504 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7505 LPFC_HST_ISCR0;
7506 break;
7507 case LPFC_SLI_INTF_IF_TYPE_6:
7508 phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7509 LPFC_IF6_RQ_DOORBELL;
7510 phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7511 LPFC_IF6_WQ_DOORBELL;
7512 phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7513 LPFC_IF6_CQ_DOORBELL;
7514 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7515 LPFC_IF6_EQ_DOORBELL;
7516 phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p +
7517 LPFC_IF6_MQ_DOORBELL;
7518 break;
7519 case LPFC_SLI_INTF_IF_TYPE_2:
7520 case LPFC_SLI_INTF_IF_TYPE_1:
7521 default:
7522 dev_err(&phba->pcidev->dev,
7523 "FATAL - unsupported SLI4 interface type - %d\n",
7524 if_type);
7525 break;
7526 }
James Smartda0436e2009-05-22 14:51:39 -04007527}
7528
7529/**
7530 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
7531 * @phba: pointer to lpfc hba data structure.
7532 * @vf: virtual function number
7533 *
7534 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
7535 * based on the given viftual function number, @vf.
7536 *
7537 * Return 0 if successful, otherwise -ENODEV.
7538 **/
7539static int
7540lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
7541{
7542 if (vf > LPFC_VIR_FUNC_MAX)
7543 return -ENODEV;
7544
7545 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05007546 vf * LPFC_VFR_PAGE_SIZE +
7547 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04007548 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05007549 vf * LPFC_VFR_PAGE_SIZE +
7550 LPFC_ULP0_WQ_DOORBELL);
James Smart9dd35422018-02-22 08:18:41 -08007551 phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7552 vf * LPFC_VFR_PAGE_SIZE +
7553 LPFC_EQCQ_DOORBELL);
7554 phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr;
James Smartda0436e2009-05-22 14:51:39 -04007555 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7556 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
7557 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7558 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
7559 return 0;
7560}
7561
7562/**
7563 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
7564 * @phba: pointer to lpfc hba data structure.
7565 *
7566 * This routine is invoked to create the bootstrap mailbox
7567 * region consistent with the SLI-4 interface spec. This
7568 * routine allocates all memory necessary to communicate
7569 * mailbox commands to the port and sets up all alignment
7570 * needs. No locks are expected to be held when calling
7571 * this routine.
7572 *
7573 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007574 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04007575 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04007576 **/
7577static int
7578lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
7579{
7580 uint32_t bmbx_size;
7581 struct lpfc_dmabuf *dmabuf;
7582 struct dma_address *dma_address;
7583 uint32_t pa_addr;
7584 uint64_t phys_addr;
7585
7586 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
7587 if (!dmabuf)
7588 return -ENOMEM;
7589
7590 /*
7591 * The bootstrap mailbox region is comprised of 2 parts
7592 * plus an alignment restriction of 16 bytes.
7593 */
7594 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
Joe Perches1aee3832014-09-03 12:56:12 -04007595 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
7596 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04007597 if (!dmabuf->virt) {
7598 kfree(dmabuf);
7599 return -ENOMEM;
7600 }
James Smartda0436e2009-05-22 14:51:39 -04007601
7602 /*
7603 * Initialize the bootstrap mailbox pointers now so that the register
7604 * operations are simple later. The mailbox dma address is required
7605 * to be 16-byte aligned. Also align the virtual memory as each
7606 * maibox is copied into the bmbx mailbox region before issuing the
7607 * command to the port.
7608 */
7609 phba->sli4_hba.bmbx.dmabuf = dmabuf;
7610 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
7611
7612 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
7613 LPFC_ALIGN_16_BYTE);
7614 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
7615 LPFC_ALIGN_16_BYTE);
7616
7617 /*
7618 * Set the high and low physical addresses now. The SLI4 alignment
7619 * requirement is 16 bytes and the mailbox is posted to the port
7620 * as two 30-bit addresses. The other data is a bit marking whether
7621 * the 30-bit address is the high or low address.
7622 * Upcast bmbx aphys to 64bits so shift instruction compiles
7623 * clean on 32 bit machines.
7624 */
7625 dma_address = &phba->sli4_hba.bmbx.dma_address;
7626 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
7627 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
7628 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
7629 LPFC_BMBX_BIT1_ADDR_HI);
7630
7631 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
7632 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
7633 LPFC_BMBX_BIT1_ADDR_LO);
7634 return 0;
7635}
7636
7637/**
7638 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
7639 * @phba: pointer to lpfc hba data structure.
7640 *
7641 * This routine is invoked to teardown the bootstrap mailbox
7642 * region and release all host resources. This routine requires
7643 * the caller to ensure all mailbox commands recovered, no
7644 * additional mailbox comands are sent, and interrupts are disabled
7645 * before calling this routine.
7646 *
7647 **/
7648static void
7649lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
7650{
7651 dma_free_coherent(&phba->pcidev->dev,
7652 phba->sli4_hba.bmbx.bmbx_size,
7653 phba->sli4_hba.bmbx.dmabuf->virt,
7654 phba->sli4_hba.bmbx.dmabuf->phys);
7655
7656 kfree(phba->sli4_hba.bmbx.dmabuf);
7657 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
7658}
7659
7660/**
7661 * lpfc_sli4_read_config - Get the config parameters.
7662 * @phba: pointer to lpfc hba data structure.
7663 *
7664 * This routine is invoked to read the configuration parameters from the HBA.
7665 * The configuration parameters are used to set the base and maximum values
7666 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
7667 * allocation for the port.
7668 *
7669 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007670 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007671 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007672 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007673 **/
James Smartff78d8f2011-12-13 13:21:35 -05007674int
James Smartda0436e2009-05-22 14:51:39 -04007675lpfc_sli4_read_config(struct lpfc_hba *phba)
7676{
7677 LPFC_MBOXQ_t *pmb;
7678 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04007679 union lpfc_sli4_cfg_shdr *shdr;
7680 uint32_t shdr_status, shdr_add_status;
7681 struct lpfc_mbx_get_func_cfg *get_func_cfg;
7682 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04007683 char *pdesc_0;
James Smartc6918162016-10-13 15:06:16 -07007684 uint16_t forced_link_speed;
7685 uint32_t if_type;
James Smart8aa134a2012-08-14 14:25:29 -04007686 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04007687
7688 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7689 if (!pmb) {
7690 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7691 "2011 Unable to allocate memory for issuing "
7692 "SLI_CONFIG_SPECIAL mailbox command\n");
7693 return -ENOMEM;
7694 }
7695
7696 lpfc_read_config(phba, pmb);
7697
7698 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
7699 if (rc != MBX_SUCCESS) {
7700 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7701 "2012 Mailbox failed , mbxCmd x%x "
7702 "READ_CONFIG, mbxStatus x%x\n",
7703 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7704 bf_get(lpfc_mqe_status, &pmb->u.mqe));
7705 rc = -EIO;
7706 } else {
7707 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05007708 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
7709 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
7710 phba->sli4_hba.lnk_info.lnk_tp =
7711 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
7712 phba->sli4_hba.lnk_info.lnk_no =
7713 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
7714 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7715 "3081 lnk_type:%d, lnk_numb:%d\n",
7716 phba->sli4_hba.lnk_info.lnk_tp,
7717 phba->sli4_hba.lnk_info.lnk_no);
7718 } else
7719 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
7720 "3082 Mailbox (x%x) returned ldv:x0\n",
7721 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart44fd7fe2017-08-23 16:55:47 -07007722 if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) {
7723 phba->bbcredit_support = 1;
7724 phba->sli4_hba.bbscn_params.word0 = rd_config->word8;
7725 }
7726
James Smart6d368e52011-05-24 11:44:12 -04007727 phba->sli4_hba.extents_in_use =
7728 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04007729 phba->sli4_hba.max_cfg_param.max_xri =
7730 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
7731 phba->sli4_hba.max_cfg_param.xri_base =
7732 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
7733 phba->sli4_hba.max_cfg_param.max_vpi =
7734 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
7735 phba->sli4_hba.max_cfg_param.vpi_base =
7736 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
7737 phba->sli4_hba.max_cfg_param.max_rpi =
7738 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
7739 phba->sli4_hba.max_cfg_param.rpi_base =
7740 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
7741 phba->sli4_hba.max_cfg_param.max_vfi =
7742 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
7743 phba->sli4_hba.max_cfg_param.vfi_base =
7744 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
7745 phba->sli4_hba.max_cfg_param.max_fcfi =
7746 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04007747 phba->sli4_hba.max_cfg_param.max_eq =
7748 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
7749 phba->sli4_hba.max_cfg_param.max_rq =
7750 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
7751 phba->sli4_hba.max_cfg_param.max_wq =
7752 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
7753 phba->sli4_hba.max_cfg_param.max_cq =
7754 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
7755 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
7756 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
7757 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
7758 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05007759 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
7760 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04007761 phba->max_vports = phba->max_vpi;
7762 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04007763 "2003 cfg params Extents? %d "
7764 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04007765 "VPI(B:%d M:%d) "
7766 "VFI(B:%d M:%d) "
7767 "RPI(B:%d M:%d) "
James Smart2ea259e2017-02-12 13:52:27 -08007768 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n",
James Smart6d368e52011-05-24 11:44:12 -04007769 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04007770 phba->sli4_hba.max_cfg_param.xri_base,
7771 phba->sli4_hba.max_cfg_param.max_xri,
7772 phba->sli4_hba.max_cfg_param.vpi_base,
7773 phba->sli4_hba.max_cfg_param.max_vpi,
7774 phba->sli4_hba.max_cfg_param.vfi_base,
7775 phba->sli4_hba.max_cfg_param.max_vfi,
7776 phba->sli4_hba.max_cfg_param.rpi_base,
7777 phba->sli4_hba.max_cfg_param.max_rpi,
James Smart2ea259e2017-02-12 13:52:27 -08007778 phba->sli4_hba.max_cfg_param.max_fcfi,
7779 phba->sli4_hba.max_cfg_param.max_eq,
7780 phba->sli4_hba.max_cfg_param.max_cq,
7781 phba->sli4_hba.max_cfg_param.max_wq,
7782 phba->sli4_hba.max_cfg_param.max_rq);
7783
James Smartda0436e2009-05-22 14:51:39 -04007784 }
James Smart912e3ac2011-05-24 11:42:11 -04007785
7786 if (rc)
7787 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04007788
James Smartc6918162016-10-13 15:06:16 -07007789 /* Update link speed if forced link speed is supported */
7790 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smart27d6ac02018-02-22 08:18:42 -08007791 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
James Smartc6918162016-10-13 15:06:16 -07007792 forced_link_speed =
7793 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
7794 if (forced_link_speed) {
7795 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
7796
7797 switch (forced_link_speed) {
7798 case LINK_SPEED_1G:
7799 phba->cfg_link_speed =
7800 LPFC_USER_LINK_SPEED_1G;
7801 break;
7802 case LINK_SPEED_2G:
7803 phba->cfg_link_speed =
7804 LPFC_USER_LINK_SPEED_2G;
7805 break;
7806 case LINK_SPEED_4G:
7807 phba->cfg_link_speed =
7808 LPFC_USER_LINK_SPEED_4G;
7809 break;
7810 case LINK_SPEED_8G:
7811 phba->cfg_link_speed =
7812 LPFC_USER_LINK_SPEED_8G;
7813 break;
7814 case LINK_SPEED_10G:
7815 phba->cfg_link_speed =
7816 LPFC_USER_LINK_SPEED_10G;
7817 break;
7818 case LINK_SPEED_16G:
7819 phba->cfg_link_speed =
7820 LPFC_USER_LINK_SPEED_16G;
7821 break;
7822 case LINK_SPEED_32G:
7823 phba->cfg_link_speed =
7824 LPFC_USER_LINK_SPEED_32G;
7825 break;
James Smartfbd8a6b2018-02-22 08:18:45 -08007826 case LINK_SPEED_64G:
7827 phba->cfg_link_speed =
7828 LPFC_USER_LINK_SPEED_64G;
7829 break;
James Smartc6918162016-10-13 15:06:16 -07007830 case 0xffff:
7831 phba->cfg_link_speed =
7832 LPFC_USER_LINK_SPEED_AUTO;
7833 break;
7834 default:
7835 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7836 "0047 Unrecognized link "
7837 "speed : %d\n",
7838 forced_link_speed);
7839 phba->cfg_link_speed =
7840 LPFC_USER_LINK_SPEED_AUTO;
7841 }
7842 }
7843 }
7844
James Smartda0436e2009-05-22 14:51:39 -04007845 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -04007846 length = phba->sli4_hba.max_cfg_param.max_xri -
7847 lpfc_sli4_get_els_iocb_cnt(phba);
7848 if (phba->cfg_hba_queue_depth > length) {
7849 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7850 "3361 HBA queue depth changed from %d to %d\n",
7851 phba->cfg_hba_queue_depth, length);
7852 phba->cfg_hba_queue_depth = length;
7853 }
James Smart912e3ac2011-05-24 11:42:11 -04007854
James Smart27d6ac02018-02-22 08:18:42 -08007855 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smart912e3ac2011-05-24 11:42:11 -04007856 LPFC_SLI_INTF_IF_TYPE_2)
7857 goto read_cfg_out;
7858
7859 /* get the pf# and vf# for SLI4 if_type 2 port */
7860 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
7861 sizeof(struct lpfc_sli4_cfg_mhdr));
7862 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
7863 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
7864 length, LPFC_SLI4_MBX_EMBED);
7865
James Smart8aa134a2012-08-14 14:25:29 -04007866 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04007867 shdr = (union lpfc_sli4_cfg_shdr *)
7868 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
7869 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7870 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04007871 if (rc2 || shdr_status || shdr_add_status) {
James Smart912e3ac2011-05-24 11:42:11 -04007872 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7873 "3026 Mailbox failed , mbxCmd x%x "
7874 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
7875 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7876 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04007877 goto read_cfg_out;
7878 }
7879
7880 /* search for fc_fcoe resrouce descriptor */
7881 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
James Smart912e3ac2011-05-24 11:42:11 -04007882
James Smart8aa134a2012-08-14 14:25:29 -04007883 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
7884 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
7885 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
7886 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
7887 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
7888 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
7889 goto read_cfg_out;
7890
James Smart912e3ac2011-05-24 11:42:11 -04007891 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04007892 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04007893 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04007894 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04007895 phba->sli4_hba.iov.pf_number =
7896 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
7897 phba->sli4_hba.iov.vf_number =
7898 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
7899 break;
7900 }
7901 }
7902
7903 if (i < LPFC_RSRC_DESC_MAX_NUM)
7904 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7905 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
7906 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
7907 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04007908 else
James Smart912e3ac2011-05-24 11:42:11 -04007909 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7910 "3028 GET_FUNCTION_CONFIG: failed to find "
7911 "Resrouce Descriptor:x%x\n",
7912 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04007913
7914read_cfg_out:
7915 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04007916 return rc;
7917}
7918
7919/**
James Smart2fcee4b2010-12-15 17:57:46 -05007920 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04007921 * @phba: pointer to lpfc hba data structure.
7922 *
James Smart2fcee4b2010-12-15 17:57:46 -05007923 * This routine is invoked to setup the port-side endian order when
7924 * the port if_type is 0. This routine has no function for other
7925 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04007926 *
7927 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007928 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007929 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007930 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007931 **/
7932static int
7933lpfc_setup_endian_order(struct lpfc_hba *phba)
7934{
7935 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05007936 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04007937 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
7938 HOST_ENDIAN_HIGH_WORD1};
7939
James Smart2fcee4b2010-12-15 17:57:46 -05007940 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7941 switch (if_type) {
7942 case LPFC_SLI_INTF_IF_TYPE_0:
7943 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7944 GFP_KERNEL);
7945 if (!mboxq) {
7946 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7947 "0492 Unable to allocate memory for "
7948 "issuing SLI_CONFIG_SPECIAL mailbox "
7949 "command\n");
7950 return -ENOMEM;
7951 }
James Smartda0436e2009-05-22 14:51:39 -04007952
James Smart2fcee4b2010-12-15 17:57:46 -05007953 /*
7954 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
7955 * two words to contain special data values and no other data.
7956 */
7957 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
7958 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
7959 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7960 if (rc != MBX_SUCCESS) {
7961 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7962 "0493 SLI_CONFIG_SPECIAL mailbox "
7963 "failed with status x%x\n",
7964 rc);
7965 rc = -EIO;
7966 }
7967 mempool_free(mboxq, phba->mbox_mem_pool);
7968 break;
James Smart27d6ac02018-02-22 08:18:42 -08007969 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2fcee4b2010-12-15 17:57:46 -05007970 case LPFC_SLI_INTF_IF_TYPE_2:
7971 case LPFC_SLI_INTF_IF_TYPE_1:
7972 default:
7973 break;
James Smartda0436e2009-05-22 14:51:39 -04007974 }
James Smartda0436e2009-05-22 14:51:39 -04007975 return rc;
7976}
7977
7978/**
James Smart895427b2017-02-12 13:52:30 -08007979 * lpfc_sli4_queue_verify - Verify and update EQ counts
James Smartda0436e2009-05-22 14:51:39 -04007980 * @phba: pointer to lpfc hba data structure.
7981 *
James Smart895427b2017-02-12 13:52:30 -08007982 * This routine is invoked to check the user settable queue counts for EQs.
7983 * After this routine is called the counts will be set to valid values that
James Smart5350d872011-10-10 21:33:49 -04007984 * adhere to the constraints of the system's interrupt vectors and the port's
7985 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04007986 *
7987 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007988 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007989 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007990 **/
7991static int
James Smart5350d872011-10-10 21:33:49 -04007992lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04007993{
James Smart895427b2017-02-12 13:52:30 -08007994 int io_channel;
James Smart1ba981f2014-02-20 09:56:45 -05007995 int fof_vectors = phba->cfg_fof ? 1 : 0;
James Smartda0436e2009-05-22 14:51:39 -04007996
7997 /*
James Smart67d12732012-08-03 12:36:13 -04007998 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04007999 * device parameters
8000 */
8001
James Smart67d12732012-08-03 12:36:13 -04008002 /* Sanity check on HBA EQ parameters */
James Smart895427b2017-02-12 13:52:30 -08008003 io_channel = phba->io_channel_irqs;
James Smartda0436e2009-05-22 14:51:39 -04008004
James Smart895427b2017-02-12 13:52:30 -08008005 if (phba->sli4_hba.num_online_cpu < io_channel) {
James Smart82c3e9b2012-09-29 11:29:50 -04008006 lpfc_printf_log(phba,
8007 KERN_ERR, LOG_INIT,
James Smart90695ee2012-08-14 14:25:36 -04008008 "3188 Reducing IO channels to match number of "
James Smart7bb03bb2013-04-17 20:19:16 -04008009 "online CPUs: from %d to %d\n",
James Smart895427b2017-02-12 13:52:30 -08008010 io_channel, phba->sli4_hba.num_online_cpu);
8011 io_channel = phba->sli4_hba.num_online_cpu;
James Smart90695ee2012-08-14 14:25:36 -04008012 }
8013
James Smart895427b2017-02-12 13:52:30 -08008014 if (io_channel + fof_vectors > phba->sli4_hba.max_cfg_param.max_eq) {
James Smart82c3e9b2012-09-29 11:29:50 -04008015 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8016 "2575 Reducing IO channels to match number of "
8017 "available EQs: from %d to %d\n",
James Smart895427b2017-02-12 13:52:30 -08008018 io_channel,
James Smart82c3e9b2012-09-29 11:29:50 -04008019 phba->sli4_hba.max_cfg_param.max_eq);
James Smart895427b2017-02-12 13:52:30 -08008020 io_channel = phba->sli4_hba.max_cfg_param.max_eq - fof_vectors;
James Smartda0436e2009-05-22 14:51:39 -04008021 }
James Smart67d12732012-08-03 12:36:13 -04008022
James Smart895427b2017-02-12 13:52:30 -08008023 /* The actual number of FCP / NVME event queues adopted */
8024 if (io_channel != phba->io_channel_irqs)
8025 phba->io_channel_irqs = io_channel;
8026 if (phba->cfg_fcp_io_channel > io_channel)
8027 phba->cfg_fcp_io_channel = io_channel;
8028 if (phba->cfg_nvme_io_channel > io_channel)
8029 phba->cfg_nvme_io_channel = io_channel;
James Smartbcb24f62017-11-20 16:00:36 -08008030 if (phba->nvmet_support) {
8031 if (phba->cfg_nvme_io_channel < phba->cfg_nvmet_mrq)
8032 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
8033 }
8034 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
8035 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
James Smart895427b2017-02-12 13:52:30 -08008036
8037 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2d7dbc42017-02-12 13:52:35 -08008038 "2574 IO channels: irqs %d fcp %d nvme %d MRQ: %d\n",
James Smart895427b2017-02-12 13:52:30 -08008039 phba->io_channel_irqs, phba->cfg_fcp_io_channel,
James Smart2d7dbc42017-02-12 13:52:35 -08008040 phba->cfg_nvme_io_channel, phba->cfg_nvmet_mrq);
James Smartda0436e2009-05-22 14:51:39 -04008041
James Smartda0436e2009-05-22 14:51:39 -04008042 /* Get EQ depth from module parameter, fake the default for now */
8043 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8044 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8045
James Smart5350d872011-10-10 21:33:49 -04008046 /* Get CQ depth from module parameter, fake the default for now */
8047 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8048 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart5350d872011-10-10 21:33:49 -04008049 return 0;
James Smart895427b2017-02-12 13:52:30 -08008050}
8051
8052static int
8053lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx)
8054{
8055 struct lpfc_queue *qdesc;
James Smart895427b2017-02-12 13:52:30 -08008056
James Smarta51e41b2017-12-08 17:18:06 -08008057 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
James Smart81b96ed2017-11-20 16:00:29 -08008058 phba->sli4_hba.cq_esize,
James Smarta51e41b2017-12-08 17:18:06 -08008059 LPFC_CQE_EXP_COUNT);
James Smart895427b2017-02-12 13:52:30 -08008060 if (!qdesc) {
8061 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8062 "0508 Failed allocate fast-path NVME CQ (%d)\n",
8063 wqidx);
8064 return 1;
8065 }
8066 phba->sli4_hba.nvme_cq[wqidx] = qdesc;
8067
James Smarta51e41b2017-12-08 17:18:06 -08008068 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8069 LPFC_WQE128_SIZE, LPFC_WQE_EXP_COUNT);
James Smart895427b2017-02-12 13:52:30 -08008070 if (!qdesc) {
8071 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8072 "0509 Failed allocate fast-path NVME WQ (%d)\n",
8073 wqidx);
8074 return 1;
8075 }
8076 phba->sli4_hba.nvme_wq[wqidx] = qdesc;
8077 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8078 return 0;
8079}
8080
8081static int
8082lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx)
8083{
8084 struct lpfc_queue *qdesc;
James Smartc176ffa2018-01-30 15:58:46 -08008085 uint32_t wqesize;
James Smart895427b2017-02-12 13:52:30 -08008086
8087 /* Create Fast Path FCP CQs */
James Smartc176ffa2018-01-30 15:58:46 -08008088 if (phba->enab_exp_wqcq_pages)
James Smarta51e41b2017-12-08 17:18:06 -08008089 /* Increase the CQ size when WQEs contain an embedded cdb */
8090 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
8091 phba->sli4_hba.cq_esize,
8092 LPFC_CQE_EXP_COUNT);
8093
8094 else
8095 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8096 phba->sli4_hba.cq_esize,
8097 phba->sli4_hba.cq_ecount);
James Smart895427b2017-02-12 13:52:30 -08008098 if (!qdesc) {
8099 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8100 "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx);
8101 return 1;
8102 }
8103 phba->sli4_hba.fcp_cq[wqidx] = qdesc;
8104
8105 /* Create Fast Path FCP WQs */
James Smartc176ffa2018-01-30 15:58:46 -08008106 if (phba->enab_exp_wqcq_pages) {
James Smarta51e41b2017-12-08 17:18:06 -08008107 /* Increase the WQ size when WQEs contain an embedded cdb */
James Smartc176ffa2018-01-30 15:58:46 -08008108 wqesize = (phba->fcp_embed_io) ?
8109 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
James Smarta51e41b2017-12-08 17:18:06 -08008110 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE,
James Smartc176ffa2018-01-30 15:58:46 -08008111 wqesize,
James Smarta51e41b2017-12-08 17:18:06 -08008112 LPFC_WQE_EXP_COUNT);
James Smartc176ffa2018-01-30 15:58:46 -08008113 } else
James Smarta51e41b2017-12-08 17:18:06 -08008114 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8115 phba->sli4_hba.wq_esize,
8116 phba->sli4_hba.wq_ecount);
James Smartc176ffa2018-01-30 15:58:46 -08008117
James Smart895427b2017-02-12 13:52:30 -08008118 if (!qdesc) {
8119 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8120 "0503 Failed allocate fast-path FCP WQ (%d)\n",
8121 wqidx);
8122 return 1;
8123 }
8124 phba->sli4_hba.fcp_wq[wqidx] = qdesc;
8125 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8126 return 0;
James Smart5350d872011-10-10 21:33:49 -04008127}
8128
8129/**
8130 * lpfc_sli4_queue_create - Create all the SLI4 queues
8131 * @phba: pointer to lpfc hba data structure.
8132 *
8133 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
8134 * operation. For each SLI4 queue type, the parameters such as queue entry
8135 * count (queue depth) shall be taken from the module parameter. For now,
8136 * we just use some constant number as place holder.
8137 *
8138 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07008139 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04008140 * -ENOMEM - No availble memory
8141 * -EIO - The mailbox failed to complete successfully.
8142 **/
8143int
8144lpfc_sli4_queue_create(struct lpfc_hba *phba)
8145{
8146 struct lpfc_queue *qdesc;
James Smartd1f525a2017-04-21 16:04:55 -07008147 int idx, io_channel;
James Smart5350d872011-10-10 21:33:49 -04008148
8149 /*
James Smart67d12732012-08-03 12:36:13 -04008150 * Create HBA Record arrays.
James Smart895427b2017-02-12 13:52:30 -08008151 * Both NVME and FCP will share that same vectors / EQs
James Smart5350d872011-10-10 21:33:49 -04008152 */
James Smart895427b2017-02-12 13:52:30 -08008153 io_channel = phba->io_channel_irqs;
8154 if (!io_channel)
James Smart67d12732012-08-03 12:36:13 -04008155 return -ERANGE;
James Smart5350d872011-10-10 21:33:49 -04008156
James Smart67d12732012-08-03 12:36:13 -04008157 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
8158 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
8159 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
8160 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
8161 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
8162 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
James Smart895427b2017-02-12 13:52:30 -08008163 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
8164 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
8165 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
8166 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart67d12732012-08-03 12:36:13 -04008167
James Smart895427b2017-02-12 13:52:30 -08008168 phba->sli4_hba.hba_eq = kcalloc(io_channel,
8169 sizeof(struct lpfc_queue *),
8170 GFP_KERNEL);
James Smart67d12732012-08-03 12:36:13 -04008171 if (!phba->sli4_hba.hba_eq) {
James Smartda0436e2009-05-22 14:51:39 -04008172 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04008173 "2576 Failed allocate memory for "
8174 "fast-path EQ record array\n");
James Smartda0436e2009-05-22 14:51:39 -04008175 goto out_error;
8176 }
James Smart67d12732012-08-03 12:36:13 -04008177
James Smart895427b2017-02-12 13:52:30 -08008178 if (phba->cfg_fcp_io_channel) {
8179 phba->sli4_hba.fcp_cq = kcalloc(phba->cfg_fcp_io_channel,
8180 sizeof(struct lpfc_queue *),
8181 GFP_KERNEL);
8182 if (!phba->sli4_hba.fcp_cq) {
8183 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8184 "2577 Failed allocate memory for "
8185 "fast-path CQ record array\n");
8186 goto out_error;
8187 }
8188 phba->sli4_hba.fcp_wq = kcalloc(phba->cfg_fcp_io_channel,
8189 sizeof(struct lpfc_queue *),
8190 GFP_KERNEL);
8191 if (!phba->sli4_hba.fcp_wq) {
8192 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8193 "2578 Failed allocate memory for "
8194 "fast-path FCP WQ record array\n");
8195 goto out_error;
8196 }
8197 /*
8198 * Since the first EQ can have multiple CQs associated with it,
8199 * this array is used to quickly see if we have a FCP fast-path
8200 * CQ match.
8201 */
8202 phba->sli4_hba.fcp_cq_map = kcalloc(phba->cfg_fcp_io_channel,
8203 sizeof(uint16_t),
8204 GFP_KERNEL);
8205 if (!phba->sli4_hba.fcp_cq_map) {
8206 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8207 "2545 Failed allocate memory for "
8208 "fast-path CQ map\n");
8209 goto out_error;
8210 }
James Smart67d12732012-08-03 12:36:13 -04008211 }
8212
James Smart895427b2017-02-12 13:52:30 -08008213 if (phba->cfg_nvme_io_channel) {
8214 phba->sli4_hba.nvme_cq = kcalloc(phba->cfg_nvme_io_channel,
8215 sizeof(struct lpfc_queue *),
8216 GFP_KERNEL);
8217 if (!phba->sli4_hba.nvme_cq) {
8218 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8219 "6077 Failed allocate memory for "
8220 "fast-path CQ record array\n");
8221 goto out_error;
8222 }
8223
James Smart895427b2017-02-12 13:52:30 -08008224 phba->sli4_hba.nvme_wq = kcalloc(phba->cfg_nvme_io_channel,
8225 sizeof(struct lpfc_queue *),
8226 GFP_KERNEL);
8227 if (!phba->sli4_hba.nvme_wq) {
8228 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8229 "2581 Failed allocate memory for "
8230 "fast-path NVME WQ record array\n");
8231 goto out_error;
8232 }
8233
8234 /*
8235 * Since the first EQ can have multiple CQs associated with it,
8236 * this array is used to quickly see if we have a NVME fast-path
8237 * CQ match.
8238 */
8239 phba->sli4_hba.nvme_cq_map = kcalloc(phba->cfg_nvme_io_channel,
8240 sizeof(uint16_t),
8241 GFP_KERNEL);
8242 if (!phba->sli4_hba.nvme_cq_map) {
8243 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8244 "6078 Failed allocate memory for "
8245 "fast-path CQ map\n");
8246 goto out_error;
8247 }
James Smart2d7dbc42017-02-12 13:52:35 -08008248
8249 if (phba->nvmet_support) {
8250 phba->sli4_hba.nvmet_cqset = kcalloc(
8251 phba->cfg_nvmet_mrq,
8252 sizeof(struct lpfc_queue *),
8253 GFP_KERNEL);
8254 if (!phba->sli4_hba.nvmet_cqset) {
8255 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8256 "3121 Fail allocate memory for "
8257 "fast-path CQ set array\n");
8258 goto out_error;
8259 }
8260 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
8261 phba->cfg_nvmet_mrq,
8262 sizeof(struct lpfc_queue *),
8263 GFP_KERNEL);
8264 if (!phba->sli4_hba.nvmet_mrq_hdr) {
8265 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8266 "3122 Fail allocate memory for "
8267 "fast-path RQ set hdr array\n");
8268 goto out_error;
8269 }
8270 phba->sli4_hba.nvmet_mrq_data = kcalloc(
8271 phba->cfg_nvmet_mrq,
8272 sizeof(struct lpfc_queue *),
8273 GFP_KERNEL);
8274 if (!phba->sli4_hba.nvmet_mrq_data) {
8275 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8276 "3124 Fail allocate memory for "
8277 "fast-path RQ set data array\n");
8278 goto out_error;
8279 }
8280 }
James Smart67d12732012-08-03 12:36:13 -04008281 }
James Smartda0436e2009-05-22 14:51:39 -04008282
James Smart895427b2017-02-12 13:52:30 -08008283 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
James Smart67d12732012-08-03 12:36:13 -04008284
James Smart895427b2017-02-12 13:52:30 -08008285 /* Create HBA Event Queues (EQs) */
8286 for (idx = 0; idx < io_channel; idx++) {
James Smart67d12732012-08-03 12:36:13 -04008287 /* Create EQs */
James Smart81b96ed2017-11-20 16:00:29 -08008288 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8289 phba->sli4_hba.eq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008290 phba->sli4_hba.eq_ecount);
8291 if (!qdesc) {
8292 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04008293 "0497 Failed allocate EQ (%d)\n", idx);
8294 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008295 }
James Smart67d12732012-08-03 12:36:13 -04008296 phba->sli4_hba.hba_eq[idx] = qdesc;
James Smartda0436e2009-05-22 14:51:39 -04008297 }
8298
James Smart895427b2017-02-12 13:52:30 -08008299 /* FCP and NVME io channels are not required to be balanced */
8300
8301 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
8302 if (lpfc_alloc_fcp_wq_cq(phba, idx))
8303 goto out_error;
8304
8305 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
8306 if (lpfc_alloc_nvme_wq_cq(phba, idx))
8307 goto out_error;
James Smart67d12732012-08-03 12:36:13 -04008308
James Smart2d7dbc42017-02-12 13:52:35 -08008309 if (phba->nvmet_support) {
8310 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8311 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08008312 LPFC_DEFAULT_PAGE_SIZE,
8313 phba->sli4_hba.cq_esize,
8314 phba->sli4_hba.cq_ecount);
James Smart2d7dbc42017-02-12 13:52:35 -08008315 if (!qdesc) {
8316 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8317 "3142 Failed allocate NVME "
8318 "CQ Set (%d)\n", idx);
8319 goto out_error;
8320 }
8321 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
8322 }
8323 }
8324
James Smartda0436e2009-05-22 14:51:39 -04008325 /*
James Smart67d12732012-08-03 12:36:13 -04008326 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04008327 */
8328
James Smartda0436e2009-05-22 14:51:39 -04008329 /* Create slow-path Mailbox Command Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008330 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8331 phba->sli4_hba.cq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008332 phba->sli4_hba.cq_ecount);
8333 if (!qdesc) {
8334 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8335 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04008336 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008337 }
8338 phba->sli4_hba.mbx_cq = qdesc;
8339
8340 /* Create slow-path ELS Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008341 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8342 phba->sli4_hba.cq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008343 phba->sli4_hba.cq_ecount);
8344 if (!qdesc) {
8345 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8346 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -04008347 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008348 }
8349 phba->sli4_hba.els_cq = qdesc;
8350
James Smartda0436e2009-05-22 14:51:39 -04008351
James Smart5350d872011-10-10 21:33:49 -04008352 /*
James Smart67d12732012-08-03 12:36:13 -04008353 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04008354 */
James Smartda0436e2009-05-22 14:51:39 -04008355
8356 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04008357
James Smart81b96ed2017-11-20 16:00:29 -08008358 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8359 phba->sli4_hba.mq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008360 phba->sli4_hba.mq_ecount);
8361 if (!qdesc) {
8362 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8363 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04008364 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008365 }
8366 phba->sli4_hba.mbx_wq = qdesc;
8367
8368 /*
James Smart67d12732012-08-03 12:36:13 -04008369 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04008370 */
James Smartda0436e2009-05-22 14:51:39 -04008371
8372 /* Create slow-path ELS Work Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008373 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8374 phba->sli4_hba.wq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008375 phba->sli4_hba.wq_ecount);
8376 if (!qdesc) {
8377 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8378 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04008379 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008380 }
8381 phba->sli4_hba.els_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08008382 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8383
8384 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8385 /* Create NVME LS Complete Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008386 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8387 phba->sli4_hba.cq_esize,
James Smart895427b2017-02-12 13:52:30 -08008388 phba->sli4_hba.cq_ecount);
8389 if (!qdesc) {
8390 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8391 "6079 Failed allocate NVME LS CQ\n");
8392 goto out_error;
8393 }
8394 phba->sli4_hba.nvmels_cq = qdesc;
8395
8396 /* Create NVME LS Work Queue */
James Smart81b96ed2017-11-20 16:00:29 -08008397 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8398 phba->sli4_hba.wq_esize,
James Smart895427b2017-02-12 13:52:30 -08008399 phba->sli4_hba.wq_ecount);
8400 if (!qdesc) {
8401 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8402 "6080 Failed allocate NVME LS WQ\n");
8403 goto out_error;
8404 }
8405 phba->sli4_hba.nvmels_wq = qdesc;
8406 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8407 }
James Smartda0436e2009-05-22 14:51:39 -04008408
James Smartda0436e2009-05-22 14:51:39 -04008409 /*
8410 * Create Receive Queue (RQ)
8411 */
James Smartda0436e2009-05-22 14:51:39 -04008412
8413 /* Create Receive Queue for header */
James Smart81b96ed2017-11-20 16:00:29 -08008414 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8415 phba->sli4_hba.rq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008416 phba->sli4_hba.rq_ecount);
8417 if (!qdesc) {
8418 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8419 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04008420 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008421 }
8422 phba->sli4_hba.hdr_rq = qdesc;
8423
8424 /* Create Receive Queue for data */
James Smart81b96ed2017-11-20 16:00:29 -08008425 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
8426 phba->sli4_hba.rq_esize,
James Smartda0436e2009-05-22 14:51:39 -04008427 phba->sli4_hba.rq_ecount);
8428 if (!qdesc) {
8429 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8430 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04008431 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008432 }
8433 phba->sli4_hba.dat_rq = qdesc;
8434
James Smart2d7dbc42017-02-12 13:52:35 -08008435 if (phba->nvmet_support) {
8436 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8437 /* Create NVMET Receive Queue for header */
8438 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08008439 LPFC_DEFAULT_PAGE_SIZE,
James Smart2d7dbc42017-02-12 13:52:35 -08008440 phba->sli4_hba.rq_esize,
James Smart61f3d4b2017-05-15 15:20:41 -07008441 LPFC_NVMET_RQE_DEF_COUNT);
James Smart2d7dbc42017-02-12 13:52:35 -08008442 if (!qdesc) {
8443 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8444 "3146 Failed allocate "
8445 "receive HRQ\n");
8446 goto out_error;
8447 }
8448 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
8449
8450 /* Only needed for header of RQ pair */
8451 qdesc->rqbp = kzalloc(sizeof(struct lpfc_rqb),
8452 GFP_KERNEL);
8453 if (qdesc->rqbp == NULL) {
8454 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8455 "6131 Failed allocate "
8456 "Header RQBP\n");
8457 goto out_error;
8458 }
8459
Dick Kennedy4b40d022017-08-23 16:55:38 -07008460 /* Put list in known state in case driver load fails. */
8461 INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list);
8462
James Smart2d7dbc42017-02-12 13:52:35 -08008463 /* Create NVMET Receive Queue for data */
8464 qdesc = lpfc_sli4_queue_alloc(phba,
James Smart81b96ed2017-11-20 16:00:29 -08008465 LPFC_DEFAULT_PAGE_SIZE,
James Smart2d7dbc42017-02-12 13:52:35 -08008466 phba->sli4_hba.rq_esize,
James Smart61f3d4b2017-05-15 15:20:41 -07008467 LPFC_NVMET_RQE_DEF_COUNT);
James Smart2d7dbc42017-02-12 13:52:35 -08008468 if (!qdesc) {
8469 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8470 "3156 Failed allocate "
8471 "receive DRQ\n");
8472 goto out_error;
8473 }
8474 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
8475 }
8476 }
8477
James Smart1ba981f2014-02-20 09:56:45 -05008478 /* Create the Queues needed for Flash Optimized Fabric operations */
8479 if (phba->cfg_fof)
8480 lpfc_fof_queue_create(phba);
James Smartda0436e2009-05-22 14:51:39 -04008481 return 0;
8482
James Smartda0436e2009-05-22 14:51:39 -04008483out_error:
James Smart67d12732012-08-03 12:36:13 -04008484 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04008485 return -ENOMEM;
8486}
8487
James Smart895427b2017-02-12 13:52:30 -08008488static inline void
8489__lpfc_sli4_release_queue(struct lpfc_queue **qp)
8490{
8491 if (*qp != NULL) {
8492 lpfc_sli4_queue_free(*qp);
8493 *qp = NULL;
8494 }
8495}
8496
8497static inline void
8498lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
8499{
8500 int idx;
8501
8502 if (*qs == NULL)
8503 return;
8504
8505 for (idx = 0; idx < max; idx++)
8506 __lpfc_sli4_release_queue(&(*qs)[idx]);
8507
8508 kfree(*qs);
8509 *qs = NULL;
8510}
8511
8512static inline void
8513lpfc_sli4_release_queue_map(uint16_t **qmap)
8514{
8515 if (*qmap != NULL) {
8516 kfree(*qmap);
8517 *qmap = NULL;
8518 }
8519}
8520
James Smartda0436e2009-05-22 14:51:39 -04008521/**
8522 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
8523 * @phba: pointer to lpfc hba data structure.
8524 *
8525 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
8526 * operation.
8527 *
8528 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008529 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008530 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008531 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008532 **/
James Smart5350d872011-10-10 21:33:49 -04008533void
James Smartda0436e2009-05-22 14:51:39 -04008534lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
8535{
James Smart1ba981f2014-02-20 09:56:45 -05008536 if (phba->cfg_fof)
8537 lpfc_fof_queue_destroy(phba);
8538
James Smart895427b2017-02-12 13:52:30 -08008539 /* Release HBA eqs */
8540 lpfc_sli4_release_queues(&phba->sli4_hba.hba_eq, phba->io_channel_irqs);
James Smart67d12732012-08-03 12:36:13 -04008541
James Smart895427b2017-02-12 13:52:30 -08008542 /* Release FCP cqs */
8543 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_cq,
James Smartd1f525a2017-04-21 16:04:55 -07008544 phba->cfg_fcp_io_channel);
James Smart67d12732012-08-03 12:36:13 -04008545
James Smart895427b2017-02-12 13:52:30 -08008546 /* Release FCP wqs */
8547 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_wq,
James Smartd1f525a2017-04-21 16:04:55 -07008548 phba->cfg_fcp_io_channel);
James Smart67d12732012-08-03 12:36:13 -04008549
8550 /* Release FCP CQ mapping array */
James Smart895427b2017-02-12 13:52:30 -08008551 lpfc_sli4_release_queue_map(&phba->sli4_hba.fcp_cq_map);
8552
8553 /* Release NVME cqs */
8554 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_cq,
8555 phba->cfg_nvme_io_channel);
8556
8557 /* Release NVME wqs */
8558 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_wq,
8559 phba->cfg_nvme_io_channel);
8560
8561 /* Release NVME CQ mapping array */
8562 lpfc_sli4_release_queue_map(&phba->sli4_hba.nvme_cq_map);
James Smartda0436e2009-05-22 14:51:39 -04008563
James Smartbcb24f62017-11-20 16:00:36 -08008564 if (phba->nvmet_support) {
8565 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
8566 phba->cfg_nvmet_mrq);
James Smart2d7dbc42017-02-12 13:52:35 -08008567
James Smartbcb24f62017-11-20 16:00:36 -08008568 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
8569 phba->cfg_nvmet_mrq);
8570 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
8571 phba->cfg_nvmet_mrq);
8572 }
James Smart2d7dbc42017-02-12 13:52:35 -08008573
James Smartda0436e2009-05-22 14:51:39 -04008574 /* Release mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08008575 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
James Smartda0436e2009-05-22 14:51:39 -04008576
8577 /* Release ELS work queue */
James Smart895427b2017-02-12 13:52:30 -08008578 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
8579
8580 /* Release ELS work queue */
8581 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
James Smartda0436e2009-05-22 14:51:39 -04008582
8583 /* Release unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08008584 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
8585 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
James Smartda0436e2009-05-22 14:51:39 -04008586
James Smartda0436e2009-05-22 14:51:39 -04008587 /* Release ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08008588 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
8589
8590 /* Release NVME LS complete queue */
8591 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
James Smartda0436e2009-05-22 14:51:39 -04008592
8593 /* Release mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08008594 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
8595
8596 /* Everything on this list has been freed */
8597 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
8598}
8599
8600int
James Smart895427b2017-02-12 13:52:30 -08008601lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
8602{
8603 struct lpfc_rqb *rqbp;
8604 struct lpfc_dmabuf *h_buf;
8605 struct rqb_dmabuf *rqb_buffer;
8606
8607 rqbp = rq->rqbp;
8608 while (!list_empty(&rqbp->rqb_buffer_list)) {
8609 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
8610 struct lpfc_dmabuf, list);
8611
8612 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
8613 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
8614 rqbp->buffer_count--;
8615 }
8616 return 1;
8617}
8618
8619static int
8620lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
8621 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
8622 int qidx, uint32_t qtype)
8623{
8624 struct lpfc_sli_ring *pring;
8625 int rc;
8626
8627 if (!eq || !cq || !wq) {
8628 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8629 "6085 Fast-path %s (%d) not allocated\n",
8630 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
8631 return -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04008632 }
James Smartda0436e2009-05-22 14:51:39 -04008633
James Smart895427b2017-02-12 13:52:30 -08008634 /* create the Cq first */
8635 rc = lpfc_cq_create(phba, cq, eq,
8636 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
8637 if (rc) {
8638 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8639 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
8640 qidx, (uint32_t)rc);
8641 return rc;
8642 }
James Smart81b96ed2017-11-20 16:00:29 -08008643 cq->chann = qidx;
James Smart895427b2017-02-12 13:52:30 -08008644
8645 if (qtype != LPFC_MBOX) {
8646 /* Setup nvme_cq_map for fast lookup */
8647 if (cq_map)
8648 *cq_map = cq->queue_id;
8649
8650 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8651 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
8652 qidx, cq->queue_id, qidx, eq->queue_id);
8653
8654 /* create the wq */
8655 rc = lpfc_wq_create(phba, wq, cq, qtype);
8656 if (rc) {
8657 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8658 "6123 Fail setup fastpath WQ (%d), rc = 0x%x\n",
8659 qidx, (uint32_t)rc);
8660 /* no need to tear down cq - caller will do so */
8661 return rc;
8662 }
James Smart81b96ed2017-11-20 16:00:29 -08008663 wq->chann = qidx;
James Smart895427b2017-02-12 13:52:30 -08008664
8665 /* Bind this CQ/WQ to the NVME ring */
8666 pring = wq->pring;
8667 pring->sli.sli4.wqp = (void *)wq;
8668 cq->pring = pring;
8669
8670 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8671 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
8672 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
8673 } else {
8674 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
8675 if (rc) {
8676 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8677 "0539 Failed setup of slow-path MQ: "
8678 "rc = 0x%x\n", rc);
8679 /* no need to tear down cq - caller will do so */
8680 return rc;
8681 }
8682
8683 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8684 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
8685 phba->sli4_hba.mbx_wq->queue_id,
8686 phba->sli4_hba.mbx_cq->queue_id);
8687 }
8688
8689 return 0;
James Smartda0436e2009-05-22 14:51:39 -04008690}
8691
8692/**
8693 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
8694 * @phba: pointer to lpfc hba data structure.
8695 *
8696 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
8697 * operation.
8698 *
8699 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008700 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008701 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008702 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008703 **/
8704int
8705lpfc_sli4_queue_setup(struct lpfc_hba *phba)
8706{
James Smart962bc512013-01-03 15:44:00 -05008707 uint32_t shdr_status, shdr_add_status;
8708 union lpfc_sli4_cfg_shdr *shdr;
8709 LPFC_MBOXQ_t *mboxq;
James Smart895427b2017-02-12 13:52:30 -08008710 int qidx;
8711 uint32_t length, io_channel;
8712 int rc = -ENOMEM;
James Smart962bc512013-01-03 15:44:00 -05008713
8714 /* Check for dual-ULP support */
8715 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8716 if (!mboxq) {
8717 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8718 "3249 Unable to allocate memory for "
8719 "QUERY_FW_CFG mailbox command\n");
8720 return -ENOMEM;
8721 }
8722 length = (sizeof(struct lpfc_mbx_query_fw_config) -
8723 sizeof(struct lpfc_sli4_cfg_mhdr));
8724 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8725 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
8726 length, LPFC_SLI4_MBX_EMBED);
8727
8728 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8729
8730 shdr = (union lpfc_sli4_cfg_shdr *)
8731 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
8732 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8733 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
8734 if (shdr_status || shdr_add_status || rc) {
8735 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8736 "3250 QUERY_FW_CFG mailbox failed with status "
8737 "x%x add_status x%x, mbx status x%x\n",
8738 shdr_status, shdr_add_status, rc);
8739 if (rc != MBX_TIMEOUT)
8740 mempool_free(mboxq, phba->mbox_mem_pool);
8741 rc = -ENXIO;
8742 goto out_error;
8743 }
8744
8745 phba->sli4_hba.fw_func_mode =
8746 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
8747 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
8748 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
James Smart8b017a32015-05-21 13:55:18 -04008749 phba->sli4_hba.physical_port =
8750 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
James Smart962bc512013-01-03 15:44:00 -05008751 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8752 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
8753 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
8754 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
8755
8756 if (rc != MBX_TIMEOUT)
8757 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04008758
8759 /*
James Smart67d12732012-08-03 12:36:13 -04008760 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04008761 */
James Smart895427b2017-02-12 13:52:30 -08008762 io_channel = phba->io_channel_irqs;
James Smartda0436e2009-05-22 14:51:39 -04008763
James Smart67d12732012-08-03 12:36:13 -04008764 /* Set up HBA event queue */
James Smart895427b2017-02-12 13:52:30 -08008765 if (io_channel && !phba->sli4_hba.hba_eq) {
James Smart2e90f4b2011-12-13 13:22:37 -05008766 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8767 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05008768 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04008769 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05008770 }
James Smart895427b2017-02-12 13:52:30 -08008771 for (qidx = 0; qidx < io_channel; qidx++) {
8772 if (!phba->sli4_hba.hba_eq[qidx]) {
James Smartda0436e2009-05-22 14:51:39 -04008773 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8774 "0522 Fast-path EQ (%d) not "
James Smart895427b2017-02-12 13:52:30 -08008775 "allocated\n", qidx);
James Smart1b511972011-12-13 13:23:09 -05008776 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008777 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008778 }
James Smart895427b2017-02-12 13:52:30 -08008779 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[qidx],
8780 phba->cfg_fcp_imax);
James Smartda0436e2009-05-22 14:51:39 -04008781 if (rc) {
8782 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8783 "0523 Failed setup of fast-path EQ "
James Smart895427b2017-02-12 13:52:30 -08008784 "(%d), rc = 0x%x\n", qidx,
James Smarta2fc4aef2014-09-03 12:57:55 -04008785 (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08008786 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008787 }
8788 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008789 "2584 HBA EQ setup: queue[%d]-id=%d\n",
8790 qidx, phba->sli4_hba.hba_eq[qidx]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04008791 }
8792
James Smart895427b2017-02-12 13:52:30 -08008793 if (phba->cfg_nvme_io_channel) {
8794 if (!phba->sli4_hba.nvme_cq || !phba->sli4_hba.nvme_wq) {
James Smart67d12732012-08-03 12:36:13 -04008795 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008796 "6084 Fast-path NVME %s array not allocated\n",
8797 (phba->sli4_hba.nvme_cq) ? "CQ" : "WQ");
James Smart67d12732012-08-03 12:36:13 -04008798 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008799 goto out_destroy;
James Smart67d12732012-08-03 12:36:13 -04008800 }
8801
James Smart895427b2017-02-12 13:52:30 -08008802 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
8803 rc = lpfc_create_wq_cq(phba,
8804 phba->sli4_hba.hba_eq[
8805 qidx % io_channel],
8806 phba->sli4_hba.nvme_cq[qidx],
8807 phba->sli4_hba.nvme_wq[qidx],
8808 &phba->sli4_hba.nvme_cq_map[qidx],
8809 qidx, LPFC_NVME);
8810 if (rc) {
8811 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8812 "6123 Failed to setup fastpath "
8813 "NVME WQ/CQ (%d), rc = 0x%x\n",
8814 qidx, (uint32_t)rc);
8815 goto out_destroy;
8816 }
8817 }
James Smart67d12732012-08-03 12:36:13 -04008818 }
8819
James Smart895427b2017-02-12 13:52:30 -08008820 if (phba->cfg_fcp_io_channel) {
8821 /* Set up fast-path FCP Response Complete Queue */
8822 if (!phba->sli4_hba.fcp_cq || !phba->sli4_hba.fcp_wq) {
James Smart67d12732012-08-03 12:36:13 -04008823 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008824 "3148 Fast-path FCP %s array not allocated\n",
8825 phba->sli4_hba.fcp_cq ? "WQ" : "CQ");
James Smart67d12732012-08-03 12:36:13 -04008826 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008827 goto out_destroy;
James Smart67d12732012-08-03 12:36:13 -04008828 }
8829
James Smart895427b2017-02-12 13:52:30 -08008830 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
8831 rc = lpfc_create_wq_cq(phba,
8832 phba->sli4_hba.hba_eq[
8833 qidx % io_channel],
8834 phba->sli4_hba.fcp_cq[qidx],
8835 phba->sli4_hba.fcp_wq[qidx],
8836 &phba->sli4_hba.fcp_cq_map[qidx],
8837 qidx, LPFC_FCP);
8838 if (rc) {
8839 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8840 "0535 Failed to setup fastpath "
8841 "FCP WQ/CQ (%d), rc = 0x%x\n",
8842 qidx, (uint32_t)rc);
8843 goto out_destroy;
8844 }
8845 }
James Smart67d12732012-08-03 12:36:13 -04008846 }
James Smartda0436e2009-05-22 14:51:39 -04008847
8848 /*
James Smart895427b2017-02-12 13:52:30 -08008849 * Set up Slow Path Complete Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04008850 */
8851
James Smart895427b2017-02-12 13:52:30 -08008852 /* Set up slow-path MBOX CQ/MQ */
8853
8854 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
James Smartda0436e2009-05-22 14:51:39 -04008855 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008856 "0528 %s not allocated\n",
8857 phba->sli4_hba.mbx_cq ?
James Smartd1f525a2017-04-21 16:04:55 -07008858 "Mailbox WQ" : "Mailbox CQ");
James Smart1b511972011-12-13 13:23:09 -05008859 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008860 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008861 }
James Smart895427b2017-02-12 13:52:30 -08008862
8863 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
James Smartd1f525a2017-04-21 16:04:55 -07008864 phba->sli4_hba.mbx_cq,
8865 phba->sli4_hba.mbx_wq,
8866 NULL, 0, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04008867 if (rc) {
8868 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008869 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
8870 (uint32_t)rc);
8871 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008872 }
James Smart2d7dbc42017-02-12 13:52:35 -08008873 if (phba->nvmet_support) {
8874 if (!phba->sli4_hba.nvmet_cqset) {
8875 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8876 "3165 Fast-path NVME CQ Set "
8877 "array not allocated\n");
8878 rc = -ENOMEM;
8879 goto out_destroy;
8880 }
8881 if (phba->cfg_nvmet_mrq > 1) {
8882 rc = lpfc_cq_create_set(phba,
8883 phba->sli4_hba.nvmet_cqset,
8884 phba->sli4_hba.hba_eq,
8885 LPFC_WCQ, LPFC_NVMET);
8886 if (rc) {
8887 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8888 "3164 Failed setup of NVME CQ "
8889 "Set, rc = 0x%x\n",
8890 (uint32_t)rc);
8891 goto out_destroy;
8892 }
8893 } else {
8894 /* Set up NVMET Receive Complete Queue */
8895 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
8896 phba->sli4_hba.hba_eq[0],
8897 LPFC_WCQ, LPFC_NVMET);
8898 if (rc) {
8899 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8900 "6089 Failed setup NVMET CQ: "
8901 "rc = 0x%x\n", (uint32_t)rc);
8902 goto out_destroy;
8903 }
James Smart81b96ed2017-11-20 16:00:29 -08008904 phba->sli4_hba.nvmet_cqset[0]->chann = 0;
8905
James Smart2d7dbc42017-02-12 13:52:35 -08008906 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8907 "6090 NVMET CQ setup: cq-id=%d, "
8908 "parent eq-id=%d\n",
8909 phba->sli4_hba.nvmet_cqset[0]->queue_id,
8910 phba->sli4_hba.hba_eq[0]->queue_id);
8911 }
8912 }
James Smartda0436e2009-05-22 14:51:39 -04008913
James Smart895427b2017-02-12 13:52:30 -08008914 /* Set up slow-path ELS WQ/CQ */
8915 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
James Smartda0436e2009-05-22 14:51:39 -04008916 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008917 "0530 ELS %s not allocated\n",
8918 phba->sli4_hba.els_cq ? "WQ" : "CQ");
James Smart1b511972011-12-13 13:23:09 -05008919 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008920 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008921 }
James Smart895427b2017-02-12 13:52:30 -08008922 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8923 phba->sli4_hba.els_cq,
8924 phba->sli4_hba.els_wq,
8925 NULL, 0, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04008926 if (rc) {
8927 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008928 "0529 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
8929 (uint32_t)rc);
8930 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008931 }
8932 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8933 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
8934 phba->sli4_hba.els_wq->queue_id,
8935 phba->sli4_hba.els_cq->queue_id);
8936
James Smart895427b2017-02-12 13:52:30 -08008937 if (phba->cfg_nvme_io_channel) {
8938 /* Set up NVME LS Complete Queue */
8939 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
8940 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8941 "6091 LS %s not allocated\n",
8942 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
8943 rc = -ENOMEM;
8944 goto out_destroy;
8945 }
8946 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8947 phba->sli4_hba.nvmels_cq,
8948 phba->sli4_hba.nvmels_wq,
8949 NULL, 0, LPFC_NVME_LS);
8950 if (rc) {
8951 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8952 "0529 Failed setup of NVVME LS WQ/CQ: "
8953 "rc = 0x%x\n", (uint32_t)rc);
8954 goto out_destroy;
8955 }
8956
8957 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8958 "6096 ELS WQ setup: wq-id=%d, "
8959 "parent cq-id=%d\n",
8960 phba->sli4_hba.nvmels_wq->queue_id,
8961 phba->sli4_hba.nvmels_cq->queue_id);
8962 }
8963
James Smart2d7dbc42017-02-12 13:52:35 -08008964 /*
8965 * Create NVMET Receive Queue (RQ)
8966 */
8967 if (phba->nvmet_support) {
8968 if ((!phba->sli4_hba.nvmet_cqset) ||
8969 (!phba->sli4_hba.nvmet_mrq_hdr) ||
8970 (!phba->sli4_hba.nvmet_mrq_data)) {
8971 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8972 "6130 MRQ CQ Queues not "
8973 "allocated\n");
8974 rc = -ENOMEM;
8975 goto out_destroy;
8976 }
8977 if (phba->cfg_nvmet_mrq > 1) {
8978 rc = lpfc_mrq_create(phba,
8979 phba->sli4_hba.nvmet_mrq_hdr,
8980 phba->sli4_hba.nvmet_mrq_data,
8981 phba->sli4_hba.nvmet_cqset,
8982 LPFC_NVMET);
8983 if (rc) {
8984 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8985 "6098 Failed setup of NVMET "
8986 "MRQ: rc = 0x%x\n",
8987 (uint32_t)rc);
8988 goto out_destroy;
8989 }
8990
8991 } else {
8992 rc = lpfc_rq_create(phba,
8993 phba->sli4_hba.nvmet_mrq_hdr[0],
8994 phba->sli4_hba.nvmet_mrq_data[0],
8995 phba->sli4_hba.nvmet_cqset[0],
8996 LPFC_NVMET);
8997 if (rc) {
8998 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8999 "6057 Failed setup of NVMET "
9000 "Receive Queue: rc = 0x%x\n",
9001 (uint32_t)rc);
9002 goto out_destroy;
9003 }
9004
9005 lpfc_printf_log(
9006 phba, KERN_INFO, LOG_INIT,
9007 "6099 NVMET RQ setup: hdr-rq-id=%d, "
9008 "dat-rq-id=%d parent cq-id=%d\n",
9009 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
9010 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
9011 phba->sli4_hba.nvmet_cqset[0]->queue_id);
9012
9013 }
9014 }
9015
James Smartda0436e2009-05-22 14:51:39 -04009016 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
9017 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9018 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05009019 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08009020 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009021 }
James Smart73d91e52011-10-10 21:32:10 -04009022
James Smartda0436e2009-05-22 14:51:39 -04009023 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04009024 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04009025 if (rc) {
9026 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9027 "0541 Failed setup of Receive Queue: "
James Smarta2fc4aef2014-09-03 12:57:55 -04009028 "rc = 0x%x\n", (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08009029 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04009030 }
James Smart73d91e52011-10-10 21:32:10 -04009031
James Smartda0436e2009-05-22 14:51:39 -04009032 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9033 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
9034 "parent cq-id=%d\n",
9035 phba->sli4_hba.hdr_rq->queue_id,
9036 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04009037 phba->sli4_hba.els_cq->queue_id);
James Smart1ba981f2014-02-20 09:56:45 -05009038
9039 if (phba->cfg_fof) {
9040 rc = lpfc_fof_queue_setup(phba);
9041 if (rc) {
9042 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9043 "0549 Failed setup of FOF Queues: "
9044 "rc = 0x%x\n", rc);
James Smart895427b2017-02-12 13:52:30 -08009045 goto out_destroy;
James Smart1ba981f2014-02-20 09:56:45 -05009046 }
9047 }
James Smart2c9c5a02015-04-07 15:07:15 -04009048
James Smart43140ca2017-03-04 09:30:34 -08009049 for (qidx = 0; qidx < io_channel; qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
James Smart0cf07f842017-06-01 21:07:10 -07009050 lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT,
9051 phba->cfg_fcp_imax);
James Smart43140ca2017-03-04 09:30:34 -08009052
James Smartda0436e2009-05-22 14:51:39 -04009053 return 0;
9054
James Smart895427b2017-02-12 13:52:30 -08009055out_destroy:
9056 lpfc_sli4_queue_unset(phba);
James Smartda0436e2009-05-22 14:51:39 -04009057out_error:
9058 return rc;
9059}
9060
9061/**
9062 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
9063 * @phba: pointer to lpfc hba data structure.
9064 *
9065 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
9066 * operation.
9067 *
9068 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009069 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009070 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009071 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009072 **/
9073void
9074lpfc_sli4_queue_unset(struct lpfc_hba *phba)
9075{
James Smart895427b2017-02-12 13:52:30 -08009076 int qidx;
James Smartda0436e2009-05-22 14:51:39 -04009077
James Smart1ba981f2014-02-20 09:56:45 -05009078 /* Unset the queues created for Flash Optimized Fabric operations */
9079 if (phba->cfg_fof)
9080 lpfc_fof_queue_destroy(phba);
James Smart895427b2017-02-12 13:52:30 -08009081
James Smartda0436e2009-05-22 14:51:39 -04009082 /* Unset mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08009083 if (phba->sli4_hba.mbx_wq)
9084 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
9085
9086 /* Unset NVME LS work queue */
9087 if (phba->sli4_hba.nvmels_wq)
9088 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
9089
James Smartda0436e2009-05-22 14:51:39 -04009090 /* Unset ELS work queue */
Colin Ian King019c0d62017-05-06 23:13:55 +01009091 if (phba->sli4_hba.els_wq)
James Smart895427b2017-02-12 13:52:30 -08009092 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
9093
James Smartda0436e2009-05-22 14:51:39 -04009094 /* Unset unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08009095 if (phba->sli4_hba.hdr_rq)
9096 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
9097 phba->sli4_hba.dat_rq);
9098
James Smartda0436e2009-05-22 14:51:39 -04009099 /* Unset FCP work queue */
James Smart895427b2017-02-12 13:52:30 -08009100 if (phba->sli4_hba.fcp_wq)
9101 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
9102 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[qidx]);
9103
9104 /* Unset NVME work queue */
9105 if (phba->sli4_hba.nvme_wq) {
9106 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
9107 lpfc_wq_destroy(phba, phba->sli4_hba.nvme_wq[qidx]);
James Smart67d12732012-08-03 12:36:13 -04009108 }
James Smart895427b2017-02-12 13:52:30 -08009109
James Smartda0436e2009-05-22 14:51:39 -04009110 /* Unset mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08009111 if (phba->sli4_hba.mbx_cq)
9112 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
9113
James Smartda0436e2009-05-22 14:51:39 -04009114 /* Unset ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08009115 if (phba->sli4_hba.els_cq)
9116 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
9117
9118 /* Unset NVME LS complete queue */
9119 if (phba->sli4_hba.nvmels_cq)
9120 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
9121
9122 /* Unset NVME response complete queue */
9123 if (phba->sli4_hba.nvme_cq)
9124 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
9125 lpfc_cq_destroy(phba, phba->sli4_hba.nvme_cq[qidx]);
9126
James Smartbcb24f62017-11-20 16:00:36 -08009127 if (phba->nvmet_support) {
9128 /* Unset NVMET MRQ queue */
9129 if (phba->sli4_hba.nvmet_mrq_hdr) {
9130 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9131 lpfc_rq_destroy(
9132 phba,
James Smart2d7dbc42017-02-12 13:52:35 -08009133 phba->sli4_hba.nvmet_mrq_hdr[qidx],
9134 phba->sli4_hba.nvmet_mrq_data[qidx]);
James Smartbcb24f62017-11-20 16:00:36 -08009135 }
James Smart2d7dbc42017-02-12 13:52:35 -08009136
James Smartbcb24f62017-11-20 16:00:36 -08009137 /* Unset NVMET CQ Set complete queue */
9138 if (phba->sli4_hba.nvmet_cqset) {
9139 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
9140 lpfc_cq_destroy(
9141 phba, phba->sli4_hba.nvmet_cqset[qidx]);
9142 }
James Smart2d7dbc42017-02-12 13:52:35 -08009143 }
9144
James Smartda0436e2009-05-22 14:51:39 -04009145 /* Unset FCP response complete queue */
James Smart895427b2017-02-12 13:52:30 -08009146 if (phba->sli4_hba.fcp_cq)
9147 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
9148 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[qidx]);
9149
James Smartda0436e2009-05-22 14:51:39 -04009150 /* Unset fast-path event queue */
James Smart895427b2017-02-12 13:52:30 -08009151 if (phba->sli4_hba.hba_eq)
9152 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++)
9153 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[qidx]);
James Smartda0436e2009-05-22 14:51:39 -04009154}
9155
9156/**
9157 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
9158 * @phba: pointer to lpfc hba data structure.
9159 *
9160 * This routine is invoked to allocate and set up a pool of completion queue
9161 * events. The body of the completion queue event is a completion queue entry
9162 * CQE. For now, this pool is used for the interrupt service routine to queue
9163 * the following HBA completion queue events for the worker thread to process:
9164 * - Mailbox asynchronous events
9165 * - Receive queue completion unsolicited events
9166 * Later, this can be used for all the slow-path events.
9167 *
9168 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009169 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009170 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04009171 **/
9172static int
9173lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
9174{
9175 struct lpfc_cq_event *cq_event;
9176 int i;
9177
9178 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
9179 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
9180 if (!cq_event)
9181 goto out_pool_create_fail;
9182 list_add_tail(&cq_event->list,
9183 &phba->sli4_hba.sp_cqe_event_pool);
9184 }
9185 return 0;
9186
9187out_pool_create_fail:
9188 lpfc_sli4_cq_event_pool_destroy(phba);
9189 return -ENOMEM;
9190}
9191
9192/**
9193 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
9194 * @phba: pointer to lpfc hba data structure.
9195 *
9196 * This routine is invoked to free the pool of completion queue events at
9197 * driver unload time. Note that, it is the responsibility of the driver
9198 * cleanup routine to free all the outstanding completion-queue events
9199 * allocated from this pool back into the pool before invoking this routine
9200 * to destroy the pool.
9201 **/
9202static void
9203lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
9204{
9205 struct lpfc_cq_event *cq_event, *next_cq_event;
9206
9207 list_for_each_entry_safe(cq_event, next_cq_event,
9208 &phba->sli4_hba.sp_cqe_event_pool, list) {
9209 list_del(&cq_event->list);
9210 kfree(cq_event);
9211 }
9212}
9213
9214/**
9215 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9216 * @phba: pointer to lpfc hba data structure.
9217 *
9218 * This routine is the lock free version of the API invoked to allocate a
9219 * completion-queue event from the free pool.
9220 *
9221 * Return: Pointer to the newly allocated completion-queue event if successful
9222 * NULL otherwise.
9223 **/
9224struct lpfc_cq_event *
9225__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9226{
9227 struct lpfc_cq_event *cq_event = NULL;
9228
9229 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
9230 struct lpfc_cq_event, list);
9231 return cq_event;
9232}
9233
9234/**
9235 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
9236 * @phba: pointer to lpfc hba data structure.
9237 *
9238 * This routine is the lock version of the API invoked to allocate a
9239 * completion-queue event from the free pool.
9240 *
9241 * Return: Pointer to the newly allocated completion-queue event if successful
9242 * NULL otherwise.
9243 **/
9244struct lpfc_cq_event *
9245lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
9246{
9247 struct lpfc_cq_event *cq_event;
9248 unsigned long iflags;
9249
9250 spin_lock_irqsave(&phba->hbalock, iflags);
9251 cq_event = __lpfc_sli4_cq_event_alloc(phba);
9252 spin_unlock_irqrestore(&phba->hbalock, iflags);
9253 return cq_event;
9254}
9255
9256/**
9257 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9258 * @phba: pointer to lpfc hba data structure.
9259 * @cq_event: pointer to the completion queue event to be freed.
9260 *
9261 * This routine is the lock free version of the API invoked to release a
9262 * completion-queue event back into the free pool.
9263 **/
9264void
9265__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9266 struct lpfc_cq_event *cq_event)
9267{
9268 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
9269}
9270
9271/**
9272 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9273 * @phba: pointer to lpfc hba data structure.
9274 * @cq_event: pointer to the completion queue event to be freed.
9275 *
9276 * This routine is the lock version of the API invoked to release a
9277 * completion-queue event back into the free pool.
9278 **/
9279void
9280lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9281 struct lpfc_cq_event *cq_event)
9282{
9283 unsigned long iflags;
9284 spin_lock_irqsave(&phba->hbalock, iflags);
9285 __lpfc_sli4_cq_event_release(phba, cq_event);
9286 spin_unlock_irqrestore(&phba->hbalock, iflags);
9287}
9288
9289/**
9290 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
9291 * @phba: pointer to lpfc hba data structure.
9292 *
9293 * This routine is to free all the pending completion-queue events to the
9294 * back into the free pool for device reset.
9295 **/
9296static void
9297lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
9298{
9299 LIST_HEAD(cqelist);
9300 struct lpfc_cq_event *cqe;
9301 unsigned long iflags;
9302
9303 /* Retrieve all the pending WCQEs from pending WCQE lists */
9304 spin_lock_irqsave(&phba->hbalock, iflags);
9305 /* Pending FCP XRI abort events */
9306 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
9307 &cqelist);
9308 /* Pending ELS XRI abort events */
9309 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
9310 &cqelist);
9311 /* Pending asynnc events */
9312 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
9313 &cqelist);
9314 spin_unlock_irqrestore(&phba->hbalock, iflags);
9315
9316 while (!list_empty(&cqelist)) {
9317 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
9318 lpfc_sli4_cq_event_release(phba, cqe);
9319 }
9320}
9321
9322/**
9323 * lpfc_pci_function_reset - Reset pci function.
9324 * @phba: pointer to lpfc hba data structure.
9325 *
9326 * This routine is invoked to request a PCI function reset. It will destroys
9327 * all resources assigned to the PCI function which originates this request.
9328 *
9329 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009330 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009331 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009332 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009333 **/
9334int
9335lpfc_pci_function_reset(struct lpfc_hba *phba)
9336{
9337 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05009338 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04009339 uint32_t shdr_status, shdr_add_status;
James Smart2f6fa2c2014-09-03 12:57:08 -04009340 uint32_t rdy_chk;
9341 uint32_t port_reset = 0;
James Smartda0436e2009-05-22 14:51:39 -04009342 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05009343 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -05009344 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -04009345
James Smart2fcee4b2010-12-15 17:57:46 -05009346 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9347 switch (if_type) {
9348 case LPFC_SLI_INTF_IF_TYPE_0:
9349 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
9350 GFP_KERNEL);
9351 if (!mboxq) {
9352 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9353 "0494 Unable to allocate memory for "
9354 "issuing SLI_FUNCTION_RESET mailbox "
9355 "command\n");
9356 return -ENOMEM;
9357 }
9358
9359 /* Setup PCI function reset mailbox-ioctl command */
9360 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9361 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
9362 LPFC_SLI4_MBX_EMBED);
9363 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9364 shdr = (union lpfc_sli4_cfg_shdr *)
9365 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
9366 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9367 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
9368 &shdr->response);
9369 if (rc != MBX_TIMEOUT)
9370 mempool_free(mboxq, phba->mbox_mem_pool);
9371 if (shdr_status || shdr_add_status || rc) {
9372 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9373 "0495 SLI_FUNCTION_RESET mailbox "
9374 "failed with status x%x add_status x%x,"
9375 " mbx status x%x\n",
9376 shdr_status, shdr_add_status, rc);
9377 rc = -ENXIO;
9378 }
9379 break;
9380 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart27d6ac02018-02-22 08:18:42 -08009381 case LPFC_SLI_INTF_IF_TYPE_6:
James Smart2f6fa2c2014-09-03 12:57:08 -04009382wait:
9383 /*
9384 * Poll the Port Status Register and wait for RDY for
9385 * up to 30 seconds. If the port doesn't respond, treat
9386 * it as an error.
9387 */
James Smart77d093f2015-04-07 15:07:08 -04009388 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
James Smart2f6fa2c2014-09-03 12:57:08 -04009389 if (lpfc_readl(phba->sli4_hba.u.if_type2.
9390 STATUSregaddr, &reg_data.word0)) {
9391 rc = -ENODEV;
9392 goto out;
9393 }
9394 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
9395 break;
9396 msleep(20);
9397 }
9398
9399 if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
9400 phba->work_status[0] = readl(
9401 phba->sli4_hba.u.if_type2.ERR1regaddr);
9402 phba->work_status[1] = readl(
9403 phba->sli4_hba.u.if_type2.ERR2regaddr);
9404 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9405 "2890 Port not ready, port status reg "
9406 "0x%x error 1=0x%x, error 2=0x%x\n",
9407 reg_data.word0,
9408 phba->work_status[0],
9409 phba->work_status[1]);
9410 rc = -ENODEV;
9411 goto out;
9412 }
9413
9414 if (!port_reset) {
9415 /*
9416 * Reset the port now
9417 */
James Smart2fcee4b2010-12-15 17:57:46 -05009418 reg_data.word0 = 0;
9419 bf_set(lpfc_sliport_ctrl_end, &reg_data,
9420 LPFC_SLIPORT_LITTLE_ENDIAN);
9421 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
9422 LPFC_SLIPORT_INIT_PORT);
9423 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
9424 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -05009425 /* flush */
James Smart2b81f942012-03-01 22:37:18 -05009426 pci_read_config_word(phba->pcidev,
9427 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -05009428
James Smart2f6fa2c2014-09-03 12:57:08 -04009429 port_reset = 1;
9430 msleep(20);
9431 goto wait;
9432 } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
9433 rc = -ENODEV;
9434 goto out;
James Smart2fcee4b2010-12-15 17:57:46 -05009435 }
9436 break;
James Smart2f6fa2c2014-09-03 12:57:08 -04009437
James Smart2fcee4b2010-12-15 17:57:46 -05009438 case LPFC_SLI_INTF_IF_TYPE_1:
9439 default:
9440 break;
James Smartda0436e2009-05-22 14:51:39 -04009441 }
9442
James Smart73d91e52011-10-10 21:32:10 -04009443out:
James Smart2fcee4b2010-12-15 17:57:46 -05009444 /* Catch the not-ready port failure after a port reset. */
James Smart2f6fa2c2014-09-03 12:57:08 -04009445 if (rc) {
James Smart229adb02013-04-17 20:16:51 -04009446 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9447 "3317 HBA not functional: IP Reset Failed "
James Smart2f6fa2c2014-09-03 12:57:08 -04009448 "try: echo fw_reset > board_mode\n");
James Smart2fcee4b2010-12-15 17:57:46 -05009449 rc = -ENODEV;
James Smart229adb02013-04-17 20:16:51 -04009450 }
James Smart2fcee4b2010-12-15 17:57:46 -05009451
James Smartda0436e2009-05-22 14:51:39 -04009452 return rc;
9453}
9454
9455/**
James Smartda0436e2009-05-22 14:51:39 -04009456 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
9457 * @phba: pointer to lpfc hba data structure.
9458 *
9459 * This routine is invoked to set up the PCI device memory space for device
9460 * with SLI-4 interface spec.
9461 *
9462 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009463 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009464 * other values - error
9465 **/
9466static int
9467lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
9468{
9469 struct pci_dev *pdev;
9470 unsigned long bar0map_len, bar1map_len, bar2map_len;
9471 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05009472 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04009473
9474 /* Obtain PCI device reference */
9475 if (!phba->pcidev)
9476 return error;
9477 else
9478 pdev = phba->pcidev;
9479
9480 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05009481 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
9482 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
9483 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
9484 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smartda0436e2009-05-22 14:51:39 -04009485 return error;
Michael Reed8e685972009-09-18 12:02:05 -05009486 }
9487 }
James Smartda0436e2009-05-22 14:51:39 -04009488
James Smart2fcee4b2010-12-15 17:57:46 -05009489 /*
9490 * The BARs and register set definitions and offset locations are
9491 * dependent on the if_type.
9492 */
9493 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
9494 &phba->sli4_hba.sli_intf.word0)) {
9495 return error;
9496 }
9497
9498 /* There is no SLI3 failback for SLI4 devices. */
9499 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
9500 LPFC_SLI_INTF_VALID) {
9501 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9502 "2894 SLI_INTF reg contents invalid "
9503 "sli_intf reg 0x%x\n",
9504 phba->sli4_hba.sli_intf.word0);
9505 return error;
9506 }
9507
9508 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9509 /*
9510 * Get the bus address of SLI4 device Bar regions and the
9511 * number of bytes required by each mapping. The mapping of the
9512 * particular PCI BARs regions is dependent on the type of
9513 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04009514 */
James Smartf5ca6f22013-09-06 12:21:09 -04009515 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
9516 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
9517 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
James Smart2fcee4b2010-12-15 17:57:46 -05009518
9519 /*
9520 * Map SLI4 PCI Config Space Register base to a kernel virtual
9521 * addr
9522 */
9523 phba->sli4_hba.conf_regs_memmap_p =
9524 ioremap(phba->pci_bar0_map, bar0map_len);
9525 if (!phba->sli4_hba.conf_regs_memmap_p) {
9526 dev_printk(KERN_ERR, &pdev->dev,
9527 "ioremap failed for SLI4 PCI config "
9528 "registers.\n");
9529 goto out;
9530 }
James Smartf5ca6f22013-09-06 12:21:09 -04009531 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05009532 /* Set up BAR0 PCI config space register memory map */
9533 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05009534 } else {
9535 phba->pci_bar0_map = pci_resource_start(pdev, 1);
9536 bar0map_len = pci_resource_len(pdev, 1);
James Smart27d6ac02018-02-22 08:18:42 -08009537 if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
James Smart2fcee4b2010-12-15 17:57:46 -05009538 dev_printk(KERN_ERR, &pdev->dev,
9539 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
9540 goto out;
9541 }
9542 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04009543 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05009544 if (!phba->sli4_hba.conf_regs_memmap_p) {
9545 dev_printk(KERN_ERR, &pdev->dev,
9546 "ioremap failed for SLI4 PCI config "
9547 "registers.\n");
9548 goto out;
9549 }
9550 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04009551 }
9552
James Smarte4b97942017-11-20 16:00:31 -08009553 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
9554 if (pci_resource_start(pdev, PCI_64BIT_BAR2)) {
9555 /*
9556 * Map SLI4 if type 0 HBA Control Register base to a
9557 * kernel virtual address and setup the registers.
9558 */
9559 phba->pci_bar1_map = pci_resource_start(pdev,
9560 PCI_64BIT_BAR2);
9561 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
9562 phba->sli4_hba.ctrl_regs_memmap_p =
9563 ioremap(phba->pci_bar1_map,
9564 bar1map_len);
9565 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
9566 dev_err(&pdev->dev,
9567 "ioremap failed for SLI4 HBA "
9568 "control registers.\n");
9569 error = -ENOMEM;
9570 goto out_iounmap_conf;
9571 }
9572 phba->pci_bar2_memmap_p =
9573 phba->sli4_hba.ctrl_regs_memmap_p;
James Smart27d6ac02018-02-22 08:18:42 -08009574 lpfc_sli4_bar1_register_memmap(phba, if_type);
James Smarte4b97942017-11-20 16:00:31 -08009575 } else {
9576 error = -ENOMEM;
James Smart2fcee4b2010-12-15 17:57:46 -05009577 goto out_iounmap_conf;
9578 }
James Smartda0436e2009-05-22 14:51:39 -04009579 }
9580
James Smart27d6ac02018-02-22 08:18:42 -08009581 if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) &&
9582 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
9583 /*
9584 * Map SLI4 if type 6 HBA Doorbell Register base to a kernel
9585 * virtual address and setup the registers.
9586 */
9587 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
9588 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
9589 phba->sli4_hba.drbl_regs_memmap_p =
9590 ioremap(phba->pci_bar1_map, bar1map_len);
9591 if (!phba->sli4_hba.drbl_regs_memmap_p) {
9592 dev_err(&pdev->dev,
9593 "ioremap failed for SLI4 HBA doorbell registers.\n");
9594 goto out_iounmap_conf;
9595 }
9596 phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
9597 lpfc_sli4_bar1_register_memmap(phba, if_type);
9598 }
9599
James Smarte4b97942017-11-20 16:00:31 -08009600 if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
9601 if (pci_resource_start(pdev, PCI_64BIT_BAR4)) {
9602 /*
9603 * Map SLI4 if type 0 HBA Doorbell Register base to
9604 * a kernel virtual address and setup the registers.
9605 */
9606 phba->pci_bar2_map = pci_resource_start(pdev,
9607 PCI_64BIT_BAR4);
9608 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
9609 phba->sli4_hba.drbl_regs_memmap_p =
9610 ioremap(phba->pci_bar2_map,
9611 bar2map_len);
9612 if (!phba->sli4_hba.drbl_regs_memmap_p) {
9613 dev_err(&pdev->dev,
9614 "ioremap failed for SLI4 HBA"
9615 " doorbell registers.\n");
9616 error = -ENOMEM;
9617 goto out_iounmap_ctrl;
9618 }
9619 phba->pci_bar4_memmap_p =
9620 phba->sli4_hba.drbl_regs_memmap_p;
9621 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
9622 if (error)
9623 goto out_iounmap_all;
9624 } else {
9625 error = -ENOMEM;
James Smart2fcee4b2010-12-15 17:57:46 -05009626 goto out_iounmap_all;
James Smarte4b97942017-11-20 16:00:31 -08009627 }
James Smartda0436e2009-05-22 14:51:39 -04009628 }
9629
James Smart1351e692018-02-22 08:18:43 -08009630 if (if_type == LPFC_SLI_INTF_IF_TYPE_6 &&
9631 pci_resource_start(pdev, PCI_64BIT_BAR4)) {
9632 /*
9633 * Map SLI4 if type 6 HBA DPP Register base to a kernel
9634 * virtual address and setup the registers.
9635 */
9636 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
9637 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
9638 phba->sli4_hba.dpp_regs_memmap_p =
9639 ioremap(phba->pci_bar2_map, bar2map_len);
9640 if (!phba->sli4_hba.dpp_regs_memmap_p) {
9641 dev_err(&pdev->dev,
9642 "ioremap failed for SLI4 HBA dpp registers.\n");
9643 goto out_iounmap_ctrl;
9644 }
9645 phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
9646 }
9647
James Smartb71413d2018-02-22 08:18:40 -08009648 /* Set up the EQ/CQ register handeling functions now */
James Smart27d6ac02018-02-22 08:18:42 -08009649 switch (if_type) {
9650 case LPFC_SLI_INTF_IF_TYPE_0:
9651 case LPFC_SLI_INTF_IF_TYPE_2:
James Smartb71413d2018-02-22 08:18:40 -08009652 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr;
9653 phba->sli4_hba.sli4_eq_release = lpfc_sli4_eq_release;
9654 phba->sli4_hba.sli4_cq_release = lpfc_sli4_cq_release;
James Smart27d6ac02018-02-22 08:18:42 -08009655 break;
9656 case LPFC_SLI_INTF_IF_TYPE_6:
9657 phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_if6_eq_clr_intr;
9658 phba->sli4_hba.sli4_eq_release = lpfc_sli4_if6_eq_release;
9659 phba->sli4_hba.sli4_cq_release = lpfc_sli4_if6_cq_release;
9660 break;
9661 default:
9662 break;
James Smartb71413d2018-02-22 08:18:40 -08009663 }
9664
James Smartda0436e2009-05-22 14:51:39 -04009665 return 0;
9666
9667out_iounmap_all:
9668 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9669out_iounmap_ctrl:
9670 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9671out_iounmap_conf:
9672 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9673out:
9674 return error;
9675}
9676
9677/**
9678 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
9679 * @phba: pointer to lpfc hba data structure.
9680 *
9681 * This routine is invoked to unset the PCI device memory space for device
9682 * with SLI-4 interface spec.
9683 **/
9684static void
9685lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
9686{
James Smart2e90f4b2011-12-13 13:22:37 -05009687 uint32_t if_type;
9688 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -04009689
James Smart2e90f4b2011-12-13 13:22:37 -05009690 switch (if_type) {
9691 case LPFC_SLI_INTF_IF_TYPE_0:
9692 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9693 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9694 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9695 break;
9696 case LPFC_SLI_INTF_IF_TYPE_2:
9697 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9698 break;
James Smart27d6ac02018-02-22 08:18:42 -08009699 case LPFC_SLI_INTF_IF_TYPE_6:
9700 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9701 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9702 break;
James Smart2e90f4b2011-12-13 13:22:37 -05009703 case LPFC_SLI_INTF_IF_TYPE_1:
9704 default:
9705 dev_printk(KERN_ERR, &phba->pcidev->dev,
9706 "FATAL - unsupported SLI4 interface type - %d\n",
9707 if_type);
9708 break;
9709 }
James Smartda0436e2009-05-22 14:51:39 -04009710}
9711
9712/**
James Smart3772a992009-05-22 14:50:54 -04009713 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
9714 * @phba: pointer to lpfc hba data structure.
9715 *
9716 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009717 * with SLI-3 interface specs.
James Smart3772a992009-05-22 14:50:54 -04009718 *
9719 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009720 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009721 * other values - error
9722 **/
9723static int
9724lpfc_sli_enable_msix(struct lpfc_hba *phba)
9725{
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009726 int rc;
James Smart3772a992009-05-22 14:50:54 -04009727 LPFC_MBOXQ_t *pmb;
9728
9729 /* Set up MSI-X multi-message vectors */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009730 rc = pci_alloc_irq_vectors(phba->pcidev,
9731 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
9732 if (rc < 0) {
James Smart3772a992009-05-22 14:50:54 -04009733 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9734 "0420 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009735 goto vec_fail_out;
James Smart3772a992009-05-22 14:50:54 -04009736 }
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009737
James Smart3772a992009-05-22 14:50:54 -04009738 /*
9739 * Assign MSI-X vectors to interrupt handlers
9740 */
9741
9742 /* vector-0 is associated to slow-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009743 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
James Smarted243d32015-05-21 13:55:25 -04009744 &lpfc_sli_sp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04009745 LPFC_SP_DRIVER_HANDLER_NAME, phba);
9746 if (rc) {
9747 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9748 "0421 MSI-X slow-path request_irq failed "
9749 "(%d)\n", rc);
9750 goto msi_fail_out;
9751 }
9752
9753 /* vector-1 is associated to fast-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009754 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
James Smarted243d32015-05-21 13:55:25 -04009755 &lpfc_sli_fp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04009756 LPFC_FP_DRIVER_HANDLER_NAME, phba);
9757
9758 if (rc) {
9759 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9760 "0429 MSI-X fast-path request_irq failed "
9761 "(%d)\n", rc);
9762 goto irq_fail_out;
9763 }
9764
9765 /*
9766 * Configure HBA MSI-X attention conditions to messages
9767 */
9768 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9769
9770 if (!pmb) {
9771 rc = -ENOMEM;
9772 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9773 "0474 Unable to allocate memory for issuing "
9774 "MBOX_CONFIG_MSI command\n");
9775 goto mem_fail_out;
9776 }
9777 rc = lpfc_config_msi(phba, pmb);
9778 if (rc)
9779 goto mbx_fail_out;
9780 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
9781 if (rc != MBX_SUCCESS) {
9782 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
9783 "0351 Config MSI mailbox command failed, "
9784 "mbxCmd x%x, mbxStatus x%x\n",
9785 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
9786 goto mbx_fail_out;
9787 }
9788
9789 /* Free memory allocated for mailbox command */
9790 mempool_free(pmb, phba->mbox_mem_pool);
9791 return rc;
9792
9793mbx_fail_out:
9794 /* Free memory allocated for mailbox command */
9795 mempool_free(pmb, phba->mbox_mem_pool);
9796
9797mem_fail_out:
9798 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009799 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
James Smart3772a992009-05-22 14:50:54 -04009800
9801irq_fail_out:
9802 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009803 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
James Smart3772a992009-05-22 14:50:54 -04009804
9805msi_fail_out:
9806 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009807 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009808
9809vec_fail_out:
James Smart3772a992009-05-22 14:50:54 -04009810 return rc;
9811}
9812
9813/**
James Smart3772a992009-05-22 14:50:54 -04009814 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
9815 * @phba: pointer to lpfc hba data structure.
9816 *
9817 * This routine is invoked to enable the MSI interrupt mode to device with
9818 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
9819 * enable the MSI vector. The device driver is responsible for calling the
9820 * request_irq() to register MSI vector with a interrupt the handler, which
9821 * is done in this function.
9822 *
9823 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009824 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009825 * other values - error
9826 */
9827static int
9828lpfc_sli_enable_msi(struct lpfc_hba *phba)
9829{
9830 int rc;
9831
9832 rc = pci_enable_msi(phba->pcidev);
9833 if (!rc)
9834 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9835 "0462 PCI enable MSI mode success.\n");
9836 else {
9837 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9838 "0471 PCI enable MSI mode failed (%d)\n", rc);
9839 return rc;
9840 }
9841
9842 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04009843 0, LPFC_DRIVER_NAME, phba);
James Smart3772a992009-05-22 14:50:54 -04009844 if (rc) {
9845 pci_disable_msi(phba->pcidev);
9846 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9847 "0478 MSI request_irq failed (%d)\n", rc);
9848 }
9849 return rc;
9850}
9851
9852/**
James Smart3772a992009-05-22 14:50:54 -04009853 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
9854 * @phba: pointer to lpfc hba data structure.
9855 *
9856 * This routine is invoked to enable device interrupt and associate driver's
9857 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
9858 * spec. Depends on the interrupt mode configured to the driver, the driver
9859 * will try to fallback from the configured interrupt mode to an interrupt
9860 * mode which is supported by the platform, kernel, and device in the order
9861 * of:
9862 * MSI-X -> MSI -> IRQ.
9863 *
9864 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009865 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009866 * other values - error
9867 **/
9868static uint32_t
9869lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9870{
9871 uint32_t intr_mode = LPFC_INTR_ERROR;
9872 int retval;
9873
9874 if (cfg_mode == 2) {
9875 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
9876 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
9877 if (!retval) {
9878 /* Now, try to enable MSI-X interrupt mode */
9879 retval = lpfc_sli_enable_msix(phba);
9880 if (!retval) {
9881 /* Indicate initialization to MSI-X mode */
9882 phba->intr_type = MSIX;
9883 intr_mode = 2;
9884 }
9885 }
9886 }
9887
9888 /* Fallback to MSI if MSI-X initialization failed */
9889 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9890 retval = lpfc_sli_enable_msi(phba);
9891 if (!retval) {
9892 /* Indicate initialization to MSI mode */
9893 phba->intr_type = MSI;
9894 intr_mode = 1;
9895 }
9896 }
9897
9898 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9899 if (phba->intr_type == NONE) {
9900 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
9901 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9902 if (!retval) {
9903 /* Indicate initialization to INTx mode */
9904 phba->intr_type = INTx;
9905 intr_mode = 0;
9906 }
9907 }
9908 return intr_mode;
9909}
9910
9911/**
9912 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
9913 * @phba: pointer to lpfc hba data structure.
9914 *
9915 * This routine is invoked to disable device interrupt and disassociate the
9916 * driver's interrupt handler(s) from interrupt vector(s) to device with
9917 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
9918 * release the interrupt vector(s) for the message signaled interrupt.
9919 **/
9920static void
9921lpfc_sli_disable_intr(struct lpfc_hba *phba)
9922{
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009923 int nr_irqs, i;
9924
James Smart3772a992009-05-22 14:50:54 -04009925 if (phba->intr_type == MSIX)
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009926 nr_irqs = LPFC_MSIX_VECTORS;
9927 else
9928 nr_irqs = 1;
9929
9930 for (i = 0; i < nr_irqs; i++)
9931 free_irq(pci_irq_vector(phba->pcidev, i), phba);
9932 pci_free_irq_vectors(phba->pcidev);
James Smart3772a992009-05-22 14:50:54 -04009933
9934 /* Reset interrupt management states */
9935 phba->intr_type = NONE;
9936 phba->sli.slistat.sli_intr = 0;
James Smart3772a992009-05-22 14:50:54 -04009937}
9938
9939/**
James Smart895427b2017-02-12 13:52:30 -08009940 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
James Smart7bb03bb2013-04-17 20:19:16 -04009941 * @phba: pointer to lpfc hba data structure.
James Smart895427b2017-02-12 13:52:30 -08009942 * @vectors: number of msix vectors allocated.
James Smart7bb03bb2013-04-17 20:19:16 -04009943 *
James Smart895427b2017-02-12 13:52:30 -08009944 * The routine will figure out the CPU affinity assignment for every
9945 * MSI-X vector allocated for the HBA. The hba_eq_hdl will be updated
9946 * with a pointer to the CPU mask that defines ALL the CPUs this vector
9947 * can be associated with. If the vector can be unquely associated with
9948 * a single CPU, that CPU will be recorded in hba_eq_hdl[index].cpu.
9949 * In addition, the CPU to IO channel mapping will be calculated
9950 * and the phba->sli4_hba.cpu_map array will reflect this.
James Smart7bb03bb2013-04-17 20:19:16 -04009951 */
James Smart895427b2017-02-12 13:52:30 -08009952static void
9953lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
James Smart7bb03bb2013-04-17 20:19:16 -04009954{
9955 struct lpfc_vector_map_info *cpup;
James Smart895427b2017-02-12 13:52:30 -08009956 int index = 0;
9957 int vec = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04009958 int cpu;
James Smart7bb03bb2013-04-17 20:19:16 -04009959#ifdef CONFIG_X86
9960 struct cpuinfo_x86 *cpuinfo;
9961#endif
James Smart7bb03bb2013-04-17 20:19:16 -04009962
9963 /* Init cpu_map array */
9964 memset(phba->sli4_hba.cpu_map, 0xff,
9965 (sizeof(struct lpfc_vector_map_info) *
James Smart895427b2017-02-12 13:52:30 -08009966 phba->sli4_hba.num_present_cpu));
James Smart7bb03bb2013-04-17 20:19:16 -04009967
9968 /* Update CPU map with physical id and core id of each CPU */
9969 cpup = phba->sli4_hba.cpu_map;
9970 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
9971#ifdef CONFIG_X86
9972 cpuinfo = &cpu_data(cpu);
9973 cpup->phys_id = cpuinfo->phys_proc_id;
9974 cpup->core_id = cpuinfo->cpu_core_id;
9975#else
9976 /* No distinction between CPUs for other platforms */
9977 cpup->phys_id = 0;
9978 cpup->core_id = 0;
9979#endif
James Smart895427b2017-02-12 13:52:30 -08009980 cpup->channel_id = index; /* For now round robin */
9981 cpup->irq = pci_irq_vector(phba->pcidev, vec);
9982 vec++;
9983 if (vec >= vectors)
9984 vec = 0;
9985 index++;
9986 if (index >= phba->cfg_fcp_io_channel)
9987 index = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04009988 cpup++;
9989 }
James Smart7bb03bb2013-04-17 20:19:16 -04009990}
9991
9992
9993/**
James Smartda0436e2009-05-22 14:51:39 -04009994 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
9995 * @phba: pointer to lpfc hba data structure.
9996 *
9997 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009998 * with SLI-4 interface spec.
James Smartda0436e2009-05-22 14:51:39 -04009999 *
10000 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010001 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040010002 * other values - error
10003 **/
10004static int
10005lpfc_sli4_enable_msix(struct lpfc_hba *phba)
10006{
James Smart75baf692010-06-08 18:31:21 -040010007 int vectors, rc, index;
James Smartb83d0052017-06-01 21:07:05 -070010008 char *name;
James Smartda0436e2009-05-22 14:51:39 -040010009
10010 /* Set up MSI-X multi-message vectors */
James Smart895427b2017-02-12 13:52:30 -080010011 vectors = phba->io_channel_irqs;
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010012 if (phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -050010013 vectors++;
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010014
James Smartf358dd02017-02-12 13:52:34 -080010015 rc = pci_alloc_irq_vectors(phba->pcidev,
10016 (phba->nvmet_support) ? 1 : 2,
10017 vectors, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY);
Alexander Gordeev4f871e12014-09-03 12:56:29 -040010018 if (rc < 0) {
James Smartda0436e2009-05-22 14:51:39 -040010019 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10020 "0484 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +020010021 goto vec_fail_out;
James Smartda0436e2009-05-22 14:51:39 -040010022 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -040010023 vectors = rc;
James Smart75baf692010-06-08 18:31:21 -040010024
James Smart7bb03bb2013-04-17 20:19:16 -040010025 /* Assign MSI-X vectors to interrupt handlers */
James Smart67d12732012-08-03 12:36:13 -040010026 for (index = 0; index < vectors; index++) {
James Smartb83d0052017-06-01 21:07:05 -070010027 name = phba->sli4_hba.hba_eq_hdl[index].handler_name;
10028 memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ);
10029 snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ,
James Smart4305f182012-08-03 12:36:33 -040010030 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -040010031
James Smart895427b2017-02-12 13:52:30 -080010032 phba->sli4_hba.hba_eq_hdl[index].idx = index;
10033 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
10034 atomic_set(&phba->sli4_hba.hba_eq_hdl[index].hba_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -050010035 if (phba->cfg_fof && (index == (vectors - 1)))
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010036 rc = request_irq(pci_irq_vector(phba->pcidev, index),
James Smarted243d32015-05-21 13:55:25 -040010037 &lpfc_sli4_fof_intr_handler, 0,
James Smartb83d0052017-06-01 21:07:05 -070010038 name,
James Smart895427b2017-02-12 13:52:30 -080010039 &phba->sli4_hba.hba_eq_hdl[index]);
James Smart1ba981f2014-02-20 09:56:45 -050010040 else
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010041 rc = request_irq(pci_irq_vector(phba->pcidev, index),
James Smarted243d32015-05-21 13:55:25 -040010042 &lpfc_sli4_hba_intr_handler, 0,
James Smartb83d0052017-06-01 21:07:05 -070010043 name,
James Smart895427b2017-02-12 13:52:30 -080010044 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -040010045 if (rc) {
10046 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10047 "0486 MSI-X fast-path (%d) "
10048 "request_irq failed (%d)\n", index, rc);
10049 goto cfg_fail_out;
10050 }
10051 }
10052
James Smart1ba981f2014-02-20 09:56:45 -050010053 if (phba->cfg_fof)
10054 vectors--;
10055
James Smart895427b2017-02-12 13:52:30 -080010056 if (vectors != phba->io_channel_irqs) {
James Smart82c3e9b2012-09-29 11:29:50 -040010057 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10058 "3238 Reducing IO channels to match number of "
10059 "MSI-X vectors, requested %d got %d\n",
James Smart895427b2017-02-12 13:52:30 -080010060 phba->io_channel_irqs, vectors);
10061 if (phba->cfg_fcp_io_channel > vectors)
10062 phba->cfg_fcp_io_channel = vectors;
10063 if (phba->cfg_nvme_io_channel > vectors)
10064 phba->cfg_nvme_io_channel = vectors;
10065 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
10066 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
10067 else
10068 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
James Smart82c3e9b2012-09-29 11:29:50 -040010069 }
James Smart895427b2017-02-12 13:52:30 -080010070 lpfc_cpu_affinity_check(phba, vectors);
James Smart7bb03bb2013-04-17 20:19:16 -040010071
James Smartda0436e2009-05-22 14:51:39 -040010072 return rc;
10073
10074cfg_fail_out:
10075 /* free the irq already requested */
James Smart895427b2017-02-12 13:52:30 -080010076 for (--index; index >= 0; index--)
10077 free_irq(pci_irq_vector(phba->pcidev, index),
10078 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -040010079
James Smartda0436e2009-05-22 14:51:39 -040010080 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010081 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +020010082
10083vec_fail_out:
James Smartda0436e2009-05-22 14:51:39 -040010084 return rc;
10085}
10086
10087/**
James Smartda0436e2009-05-22 14:51:39 -040010088 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
10089 * @phba: pointer to lpfc hba data structure.
10090 *
10091 * This routine is invoked to enable the MSI interrupt mode to device with
10092 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
10093 * to enable the MSI vector. The device driver is responsible for calling
10094 * the request_irq() to register MSI vector with a interrupt the handler,
10095 * which is done in this function.
10096 *
10097 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010098 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040010099 * other values - error
10100 **/
10101static int
10102lpfc_sli4_enable_msi(struct lpfc_hba *phba)
10103{
10104 int rc, index;
10105
10106 rc = pci_enable_msi(phba->pcidev);
10107 if (!rc)
10108 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10109 "0487 PCI enable MSI mode success.\n");
10110 else {
10111 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10112 "0488 PCI enable MSI mode failed (%d)\n", rc);
10113 return rc;
10114 }
10115
10116 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
James Smarted243d32015-05-21 13:55:25 -040010117 0, LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -040010118 if (rc) {
10119 pci_disable_msi(phba->pcidev);
10120 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
10121 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -040010122 return rc;
James Smartda0436e2009-05-22 14:51:39 -040010123 }
10124
James Smart895427b2017-02-12 13:52:30 -080010125 for (index = 0; index < phba->io_channel_irqs; index++) {
10126 phba->sli4_hba.hba_eq_hdl[index].idx = index;
10127 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smartda0436e2009-05-22 14:51:39 -040010128 }
10129
James Smart1ba981f2014-02-20 09:56:45 -050010130 if (phba->cfg_fof) {
James Smart895427b2017-02-12 13:52:30 -080010131 phba->sli4_hba.hba_eq_hdl[index].idx = index;
10132 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smart1ba981f2014-02-20 09:56:45 -050010133 }
James Smart75baf692010-06-08 18:31:21 -040010134 return 0;
James Smartda0436e2009-05-22 14:51:39 -040010135}
10136
10137/**
James Smartda0436e2009-05-22 14:51:39 -040010138 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
10139 * @phba: pointer to lpfc hba data structure.
10140 *
10141 * This routine is invoked to enable device interrupt and associate driver's
10142 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
10143 * interface spec. Depends on the interrupt mode configured to the driver,
10144 * the driver will try to fallback from the configured interrupt mode to an
10145 * interrupt mode which is supported by the platform, kernel, and device in
10146 * the order of:
10147 * MSI-X -> MSI -> IRQ.
10148 *
10149 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020010150 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -040010151 * other values - error
10152 **/
10153static uint32_t
10154lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
10155{
10156 uint32_t intr_mode = LPFC_INTR_ERROR;
James Smart895427b2017-02-12 13:52:30 -080010157 int retval, idx;
James Smartda0436e2009-05-22 14:51:39 -040010158
10159 if (cfg_mode == 2) {
10160 /* Preparation before conf_msi mbox cmd */
10161 retval = 0;
10162 if (!retval) {
10163 /* Now, try to enable MSI-X interrupt mode */
10164 retval = lpfc_sli4_enable_msix(phba);
10165 if (!retval) {
10166 /* Indicate initialization to MSI-X mode */
10167 phba->intr_type = MSIX;
10168 intr_mode = 2;
10169 }
10170 }
10171 }
10172
10173 /* Fallback to MSI if MSI-X initialization failed */
10174 if (cfg_mode >= 1 && phba->intr_type == NONE) {
10175 retval = lpfc_sli4_enable_msi(phba);
10176 if (!retval) {
10177 /* Indicate initialization to MSI mode */
10178 phba->intr_type = MSI;
10179 intr_mode = 1;
10180 }
10181 }
10182
10183 /* Fallback to INTx if both MSI-X/MSI initalization failed */
10184 if (phba->intr_type == NONE) {
10185 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
10186 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
10187 if (!retval) {
James Smart895427b2017-02-12 13:52:30 -080010188 struct lpfc_hba_eq_hdl *eqhdl;
10189
James Smartda0436e2009-05-22 14:51:39 -040010190 /* Indicate initialization to INTx mode */
10191 phba->intr_type = INTx;
10192 intr_mode = 0;
James Smart895427b2017-02-12 13:52:30 -080010193
10194 for (idx = 0; idx < phba->io_channel_irqs; idx++) {
10195 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
10196 eqhdl->idx = idx;
10197 eqhdl->phba = phba;
10198 atomic_set(&eqhdl->hba_eq_in_use, 1);
James Smartda0436e2009-05-22 14:51:39 -040010199 }
James Smart1ba981f2014-02-20 09:56:45 -050010200 if (phba->cfg_fof) {
James Smart895427b2017-02-12 13:52:30 -080010201 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
10202 eqhdl->idx = idx;
10203 eqhdl->phba = phba;
10204 atomic_set(&eqhdl->hba_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -050010205 }
James Smartda0436e2009-05-22 14:51:39 -040010206 }
10207 }
10208 return intr_mode;
10209}
10210
10211/**
10212 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
10213 * @phba: pointer to lpfc hba data structure.
10214 *
10215 * This routine is invoked to disable device interrupt and disassociate
10216 * the driver's interrupt handler(s) from interrupt vector(s) to device
10217 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
10218 * will release the interrupt vector(s) for the message signaled interrupt.
10219 **/
10220static void
10221lpfc_sli4_disable_intr(struct lpfc_hba *phba)
10222{
10223 /* Disable the currently initialized interrupt mode */
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010224 if (phba->intr_type == MSIX) {
10225 int index;
10226
10227 /* Free up MSI-X multi-message vectors */
James Smart895427b2017-02-12 13:52:30 -080010228 for (index = 0; index < phba->io_channel_irqs; index++)
10229 free_irq(pci_irq_vector(phba->pcidev, index),
10230 &phba->sli4_hba.hba_eq_hdl[index]);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010231
10232 if (phba->cfg_fof)
James Smart895427b2017-02-12 13:52:30 -080010233 free_irq(pci_irq_vector(phba->pcidev, index),
10234 &phba->sli4_hba.hba_eq_hdl[index]);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010235 } else {
James Smartda0436e2009-05-22 14:51:39 -040010236 free_irq(phba->pcidev->irq, phba);
Christoph Hellwig45ffac12017-02-12 13:52:26 -080010237 }
10238
10239 pci_free_irq_vectors(phba->pcidev);
James Smartda0436e2009-05-22 14:51:39 -040010240
10241 /* Reset interrupt management states */
10242 phba->intr_type = NONE;
10243 phba->sli.slistat.sli_intr = 0;
James Smartda0436e2009-05-22 14:51:39 -040010244}
10245
10246/**
James Smart3772a992009-05-22 14:50:54 -040010247 * lpfc_unset_hba - Unset SLI3 hba device initialization
10248 * @phba: pointer to lpfc hba data structure.
10249 *
10250 * This routine is invoked to unset the HBA device initialization steps to
10251 * a device with SLI-3 interface spec.
10252 **/
10253static void
10254lpfc_unset_hba(struct lpfc_hba *phba)
10255{
10256 struct lpfc_vport *vport = phba->pport;
10257 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
10258
10259 spin_lock_irq(shost->host_lock);
10260 vport->load_flag |= FC_UNLOADING;
10261 spin_unlock_irq(shost->host_lock);
10262
James Smart72859902012-01-18 16:25:38 -050010263 kfree(phba->vpi_bmask);
10264 kfree(phba->vpi_ids);
10265
James Smart3772a992009-05-22 14:50:54 -040010266 lpfc_stop_hba_timers(phba);
10267
10268 phba->pport->work_port_events = 0;
10269
10270 lpfc_sli_hba_down(phba);
10271
10272 lpfc_sli_brdrestart(phba);
10273
10274 lpfc_sli_disable_intr(phba);
10275
10276 return;
10277}
10278
10279/**
James Smart5af5eee2010-10-22 11:06:38 -040010280 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
10281 * @phba: Pointer to HBA context object.
10282 *
10283 * This function is called in the SLI4 code path to wait for completion
10284 * of device's XRIs exchange busy. It will check the XRI exchange busy
10285 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
10286 * that, it will check the XRI exchange busy on outstanding FCP and ELS
10287 * I/Os every 30 seconds, log error message, and wait forever. Only when
10288 * all XRI exchange busy complete, the driver unload shall proceed with
10289 * invoking the function reset ioctl mailbox command to the CNA and the
10290 * the rest of the driver unload resource release.
10291 **/
10292static void
10293lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
10294{
10295 int wait_time = 0;
James Smart895427b2017-02-12 13:52:30 -080010296 int nvme_xri_cmpl = 1;
James Smart86c67372017-04-21 16:05:04 -070010297 int nvmet_xri_cmpl = 1;
James Smart895427b2017-02-12 13:52:30 -080010298 int fcp_xri_cmpl = 1;
James Smart5af5eee2010-10-22 11:06:38 -040010299 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
10300
James Smartc3725bd2017-11-20 16:00:42 -080010301 /* Driver just aborted IOs during the hba_unset process. Pause
10302 * here to give the HBA time to complete the IO and get entries
10303 * into the abts lists.
10304 */
10305 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5);
10306
10307 /* Wait for NVME pending IO to flush back to transport. */
10308 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
10309 lpfc_nvme_wait_for_io_drain(phba);
10310
James Smart895427b2017-02-12 13:52:30 -080010311 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
10312 fcp_xri_cmpl =
10313 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
James Smart86c67372017-04-21 16:05:04 -070010314 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -080010315 nvme_xri_cmpl =
10316 list_empty(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
James Smart86c67372017-04-21 16:05:04 -070010317 nvmet_xri_cmpl =
10318 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
10319 }
James Smart895427b2017-02-12 13:52:30 -080010320
James Smartf358dd02017-02-12 13:52:34 -080010321 while (!fcp_xri_cmpl || !els_xri_cmpl || !nvme_xri_cmpl ||
10322 !nvmet_xri_cmpl) {
James Smart5af5eee2010-10-22 11:06:38 -040010323 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
James Smart895427b2017-02-12 13:52:30 -080010324 if (!nvme_xri_cmpl)
10325 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10326 "6100 NVME XRI exchange busy "
10327 "wait time: %d seconds.\n",
10328 wait_time/1000);
James Smart5af5eee2010-10-22 11:06:38 -040010329 if (!fcp_xri_cmpl)
10330 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10331 "2877 FCP XRI exchange busy "
10332 "wait time: %d seconds.\n",
10333 wait_time/1000);
10334 if (!els_xri_cmpl)
10335 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10336 "2878 ELS XRI exchange busy "
10337 "wait time: %d seconds.\n",
10338 wait_time/1000);
10339 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
10340 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
10341 } else {
10342 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
10343 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
10344 }
James Smart86c67372017-04-21 16:05:04 -070010345 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -080010346 nvme_xri_cmpl = list_empty(
10347 &phba->sli4_hba.lpfc_abts_nvme_buf_list);
James Smart86c67372017-04-21 16:05:04 -070010348 nvmet_xri_cmpl = list_empty(
10349 &phba->sli4_hba.lpfc_abts_nvmet_ctx_list);
10350 }
James Smart895427b2017-02-12 13:52:30 -080010351
10352 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
10353 fcp_xri_cmpl = list_empty(
10354 &phba->sli4_hba.lpfc_abts_scsi_buf_list);
10355
James Smart5af5eee2010-10-22 11:06:38 -040010356 els_xri_cmpl =
10357 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -080010358
James Smart5af5eee2010-10-22 11:06:38 -040010359 }
10360}
10361
10362/**
James Smartda0436e2009-05-22 14:51:39 -040010363 * lpfc_sli4_hba_unset - Unset the fcoe hba
10364 * @phba: Pointer to HBA context object.
10365 *
10366 * This function is called in the SLI4 code path to reset the HBA's FCoE
10367 * function. The caller is not required to hold any lock. This routine
10368 * issues PCI function reset mailbox command to reset the FCoE function.
10369 * At the end of the function, it calls lpfc_hba_down_post function to
10370 * free any pending commands.
10371 **/
10372static void
10373lpfc_sli4_hba_unset(struct lpfc_hba *phba)
10374{
10375 int wait_cnt = 0;
10376 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -040010377 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -040010378
10379 lpfc_stop_hba_timers(phba);
10380 phba->sli4_hba.intr_enable = 0;
10381
10382 /*
10383 * Gracefully wait out the potential current outstanding asynchronous
10384 * mailbox command.
10385 */
10386
10387 /* First, block any pending async mailbox command from posted */
10388 spin_lock_irq(&phba->hbalock);
10389 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
10390 spin_unlock_irq(&phba->hbalock);
10391 /* Now, trying to wait it out if we can */
10392 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
10393 msleep(10);
10394 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
10395 break;
10396 }
10397 /* Forcefully release the outstanding mailbox command if timed out */
10398 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
10399 spin_lock_irq(&phba->hbalock);
10400 mboxq = phba->sli.mbox_active;
10401 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
10402 __lpfc_mbox_cmpl_put(phba, mboxq);
10403 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
10404 phba->sli.mbox_active = NULL;
10405 spin_unlock_irq(&phba->hbalock);
10406 }
10407
James Smart5af5eee2010-10-22 11:06:38 -040010408 /* Abort all iocbs associated with the hba */
10409 lpfc_sli_hba_iocb_abort(phba);
10410
10411 /* Wait for completion of device XRI exchange busy */
10412 lpfc_sli4_xri_exchange_busy_wait(phba);
10413
James Smartda0436e2009-05-22 14:51:39 -040010414 /* Disable PCI subsystem interrupt */
10415 lpfc_sli4_disable_intr(phba);
10416
James Smart912e3ac2011-05-24 11:42:11 -040010417 /* Disable SR-IOV if enabled */
10418 if (phba->cfg_sriov_nr_virtfn)
10419 pci_disable_sriov(pdev);
10420
James Smartda0436e2009-05-22 14:51:39 -040010421 /* Stop kthread signal shall trigger work_done one more time */
10422 kthread_stop(phba->worker_thread);
10423
James Smartd1f525a2017-04-21 16:04:55 -070010424 /* Unset the queues shared with the hardware then release all
10425 * allocated resources.
10426 */
10427 lpfc_sli4_queue_unset(phba);
10428 lpfc_sli4_queue_destroy(phba);
10429
James Smart3677a3a2010-09-29 11:19:14 -040010430 /* Reset SLI4 HBA FCoE function */
10431 lpfc_pci_function_reset(phba);
10432
James Smartda0436e2009-05-22 14:51:39 -040010433 /* Stop the SLI4 device port */
10434 phba->pport->work_port_events = 0;
10435}
10436
James Smart28baac72010-02-12 14:42:03 -050010437 /**
10438 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
10439 * @phba: Pointer to HBA context object.
10440 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10441 *
10442 * This function is called in the SLI4 code path to read the port's
10443 * sli4 capabilities.
10444 *
10445 * This function may be be called from any context that can block-wait
10446 * for the completion. The expectation is that this routine is called
10447 * typically from probe_one or from the online routine.
10448 **/
10449int
10450lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10451{
10452 int rc;
10453 struct lpfc_mqe *mqe;
10454 struct lpfc_pc_sli4_params *sli4_params;
10455 uint32_t mbox_tmo;
10456
10457 rc = 0;
10458 mqe = &mboxq->u.mqe;
10459
10460 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -050010461 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -050010462 if (!phba->sli4_hba.intr_enable)
10463 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10464 else {
James Smarta183a152011-10-10 21:32:43 -040010465 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -050010466 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10467 }
10468
10469 if (unlikely(rc))
10470 return 1;
10471
10472 sli4_params = &phba->sli4_hba.pc_sli4_params;
10473 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
10474 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
10475 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
10476 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
10477 &mqe->un.sli4_params);
10478 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
10479 &mqe->un.sli4_params);
10480 sli4_params->proto_types = mqe->un.sli4_params.word3;
10481 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
10482 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
10483 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
10484 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
10485 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
10486 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
10487 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
10488 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
10489 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
10490 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
10491 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
10492 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
10493 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
10494 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
10495 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
10496 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
10497 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
10498 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
10499 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
10500 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -040010501
10502 /* Make sure that sge_supp_len can be handled by the driver */
10503 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10504 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10505
James Smart28baac72010-02-12 14:42:03 -050010506 return rc;
10507}
10508
James Smartda0436e2009-05-22 14:51:39 -040010509/**
James Smartfedd3b72011-02-16 12:39:24 -050010510 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
10511 * @phba: Pointer to HBA context object.
10512 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10513 *
10514 * This function is called in the SLI4 code path to read the port's
10515 * sli4 capabilities.
10516 *
10517 * This function may be be called from any context that can block-wait
10518 * for the completion. The expectation is that this routine is called
10519 * typically from probe_one or from the online routine.
10520 **/
10521int
10522lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10523{
10524 int rc;
10525 struct lpfc_mqe *mqe = &mboxq->u.mqe;
10526 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -040010527 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -050010528 int length;
10529 struct lpfc_sli4_parameters *mbx_sli4_parameters;
10530
James Smart6d368e52011-05-24 11:44:12 -040010531 /*
10532 * By default, the driver assumes the SLI4 port requires RPI
10533 * header postings. The SLI4_PARAM response will correct this
10534 * assumption.
10535 */
10536 phba->sli4_hba.rpi_hdrs_in_use = 1;
10537
James Smartfedd3b72011-02-16 12:39:24 -050010538 /* Read the port's SLI4 Config Parameters */
10539 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
10540 sizeof(struct lpfc_sli4_cfg_mhdr));
10541 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
10542 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
10543 length, LPFC_SLI4_MBX_EMBED);
10544 if (!phba->sli4_hba.intr_enable)
10545 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -040010546 else {
10547 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
10548 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10549 }
James Smartfedd3b72011-02-16 12:39:24 -050010550 if (unlikely(rc))
10551 return rc;
10552 sli4_params = &phba->sli4_hba.pc_sli4_params;
10553 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
10554 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
10555 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
10556 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
10557 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
10558 mbx_sli4_parameters);
10559 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
10560 mbx_sli4_parameters);
10561 if (bf_get(cfg_phwq, mbx_sli4_parameters))
10562 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
10563 else
10564 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
10565 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
10566 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
James Smart1ba981f2014-02-20 09:56:45 -050010567 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010568 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
10569 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
10570 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
10571 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
James Smart0c651872013-07-15 18:33:23 -040010572 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010573 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
10574 mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080010575 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010576 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
10577 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -040010578 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
10579 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080010580 phba->nvme_support = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
10581 bf_get(cfg_xib, mbx_sli4_parameters));
10582
10583 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) ||
10584 !phba->nvme_support) {
10585 phba->nvme_support = 0;
10586 phba->nvmet_support = 0;
James Smartbcb24f62017-11-20 16:00:36 -080010587 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_OFF;
James Smart895427b2017-02-12 13:52:30 -080010588 phba->cfg_nvme_io_channel = 0;
10589 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
10590 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
10591 "6101 Disabling NVME support: "
10592 "Not supported by firmware: %d %d\n",
10593 bf_get(cfg_nvme, mbx_sli4_parameters),
10594 bf_get(cfg_xib, mbx_sli4_parameters));
10595
10596 /* If firmware doesn't support NVME, just use SCSI support */
10597 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
10598 return -ENODEV;
10599 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
10600 }
James Smart05580562011-05-24 11:40:48 -040010601
James Smart20aefac2018-01-30 15:58:58 -080010602 /*
10603 * To support Suppress Response feature we must satisfy 3 conditions.
10604 * lpfc_suppress_rsp module parameter must be set (default).
10605 * In SLI4-Parameters Descriptor:
10606 * Extended Inline Buffers (XIB) must be supported.
10607 * Suppress Response IU Not Supported (SRIUNS) must NOT be supported
10608 * (double negative).
10609 */
10610 if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) &&
10611 !(bf_get(cfg_nosr, mbx_sli4_parameters)))
James Smartf358dd02017-02-12 13:52:34 -080010612 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
James Smart20aefac2018-01-30 15:58:58 -080010613 else
10614 phba->cfg_suppress_rsp = 0;
James Smartf358dd02017-02-12 13:52:34 -080010615
James Smart0cf07f842017-06-01 21:07:10 -070010616 if (bf_get(cfg_eqdr, mbx_sli4_parameters))
10617 phba->sli.sli_flag |= LPFC_SLI_USE_EQDR;
10618
James Smart05580562011-05-24 11:40:48 -040010619 /* Make sure that sge_supp_len can be handled by the driver */
10620 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10621 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10622
James Smartb5c53952016-03-31 14:12:30 -070010623 /*
James Smartc176ffa2018-01-30 15:58:46 -080010624 * Check whether the adapter supports an embedded copy of the
10625 * FCP CMD IU within the WQE for FCP_Ixxx commands. In order
10626 * to use this option, 128-byte WQEs must be used.
James Smartb5c53952016-03-31 14:12:30 -070010627 */
10628 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
10629 phba->fcp_embed_io = 1;
10630 else
10631 phba->fcp_embed_io = 0;
James Smart7bdedb32016-07-06 12:36:00 -070010632
James Smartc176ffa2018-01-30 15:58:46 -080010633 if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) &&
10634 (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) &&
10635 (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT))
10636 phba->enab_exp_wqcq_pages = 1;
10637 else
10638 phba->enab_exp_wqcq_pages = 0;
James Smart7bdedb32016-07-06 12:36:00 -070010639 /*
10640 * Check if the SLI port supports MDS Diagnostics
10641 */
10642 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
10643 phba->mds_diags_support = 1;
10644 else
10645 phba->mds_diags_support = 0;
James Smartfedd3b72011-02-16 12:39:24 -050010646 return 0;
10647}
10648
10649/**
James Smart3772a992009-05-22 14:50:54 -040010650 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
10651 * @pdev: pointer to PCI device
10652 * @pid: pointer to PCI device identifier
10653 *
10654 * This routine is to be called to attach a device with SLI-3 interface spec
10655 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10656 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10657 * information of the device and driver to see if the driver state that it can
10658 * support this kind of device. If the match is successful, the driver core
10659 * invokes this routine. If this routine determines it can claim the HBA, it
10660 * does all the initialization that it needs to do to handle the HBA properly.
10661 *
10662 * Return code
10663 * 0 - driver can claim the device
10664 * negative value - driver can not claim the device
10665 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010666static int
James Smart3772a992009-05-22 14:50:54 -040010667lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
10668{
10669 struct lpfc_hba *phba;
10670 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040010671 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -040010672 int error;
10673 uint32_t cfg_mode, intr_mode;
10674
10675 /* Allocate memory for HBA structure */
10676 phba = lpfc_hba_alloc(pdev);
10677 if (!phba)
10678 return -ENOMEM;
10679
10680 /* Perform generic PCI device enabling operation */
10681 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040010682 if (error)
James Smart3772a992009-05-22 14:50:54 -040010683 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -040010684
10685 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
10686 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
10687 if (error)
10688 goto out_disable_pci_dev;
10689
10690 /* Set up SLI-3 specific device PCI memory space */
10691 error = lpfc_sli_pci_mem_setup(phba);
10692 if (error) {
10693 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10694 "1402 Failed to set up pci memory space.\n");
10695 goto out_disable_pci_dev;
10696 }
10697
James Smart3772a992009-05-22 14:50:54 -040010698 /* Set up SLI-3 specific device driver resources */
10699 error = lpfc_sli_driver_resource_setup(phba);
10700 if (error) {
10701 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10702 "1404 Failed to set up driver resource.\n");
10703 goto out_unset_pci_mem_s3;
10704 }
10705
10706 /* Initialize and populate the iocb list per host */
James Smartd1f525a2017-04-21 16:04:55 -070010707
James Smart3772a992009-05-22 14:50:54 -040010708 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
10709 if (error) {
10710 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10711 "1405 Failed to initialize iocb list.\n");
10712 goto out_unset_driver_resource_s3;
10713 }
10714
10715 /* Set up common device driver resources */
10716 error = lpfc_setup_driver_resource_phase2(phba);
10717 if (error) {
10718 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10719 "1406 Failed to set up driver resource.\n");
10720 goto out_free_iocb_list;
10721 }
10722
James Smart079b5c92011-08-21 21:48:49 -040010723 /* Get the default values for Model Name and Description */
10724 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
10725
James Smart3772a992009-05-22 14:50:54 -040010726 /* Create SCSI host to the physical port */
10727 error = lpfc_create_shost(phba);
10728 if (error) {
10729 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10730 "1407 Failed to create scsi host.\n");
10731 goto out_unset_driver_resource;
10732 }
10733
10734 /* Configure sysfs attributes */
10735 vport = phba->pport;
10736 error = lpfc_alloc_sysfs_attr(vport);
10737 if (error) {
10738 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10739 "1476 Failed to allocate sysfs attr\n");
10740 goto out_destroy_shost;
10741 }
10742
James Smart6669f9b2009-10-02 15:16:45 -040010743 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -040010744 /* Now, trying to enable interrupt and bring up the device */
10745 cfg_mode = phba->cfg_use_msi;
10746 while (true) {
10747 /* Put device to a known state before enabling interrupt */
10748 lpfc_stop_port(phba);
10749 /* Configure and enable interrupt */
10750 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
10751 if (intr_mode == LPFC_INTR_ERROR) {
10752 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10753 "0431 Failed to enable interrupt.\n");
10754 error = -ENODEV;
10755 goto out_free_sysfs_attr;
10756 }
10757 /* SLI-3 HBA setup */
10758 if (lpfc_sli_hba_setup(phba)) {
10759 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10760 "1477 Failed to set up hba\n");
10761 error = -ENODEV;
10762 goto out_remove_device;
10763 }
10764
10765 /* Wait 50ms for the interrupts of previous mailbox commands */
10766 msleep(50);
10767 /* Check active interrupts on message signaled interrupts */
10768 if (intr_mode == 0 ||
10769 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
10770 /* Log the current active interrupt mode */
10771 phba->intr_mode = intr_mode;
10772 lpfc_log_intr_mode(phba, intr_mode);
10773 break;
10774 } else {
10775 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10776 "0447 Configure interrupt mode (%d) "
10777 "failed active interrupt test.\n",
10778 intr_mode);
10779 /* Disable the current interrupt mode */
10780 lpfc_sli_disable_intr(phba);
10781 /* Try next level of interrupt mode */
10782 cfg_mode = --intr_mode;
10783 }
10784 }
10785
10786 /* Perform post initialization setup */
10787 lpfc_post_init_setup(phba);
10788
10789 /* Check if there are static vports to be created. */
10790 lpfc_create_static_vport(phba);
10791
10792 return 0;
10793
10794out_remove_device:
10795 lpfc_unset_hba(phba);
10796out_free_sysfs_attr:
10797 lpfc_free_sysfs_attr(vport);
10798out_destroy_shost:
10799 lpfc_destroy_shost(phba);
10800out_unset_driver_resource:
10801 lpfc_unset_driver_resource_phase2(phba);
10802out_free_iocb_list:
10803 lpfc_free_iocb_list(phba);
10804out_unset_driver_resource_s3:
10805 lpfc_sli_driver_resource_unset(phba);
10806out_unset_pci_mem_s3:
10807 lpfc_sli_pci_mem_unset(phba);
10808out_disable_pci_dev:
10809 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040010810 if (shost)
10811 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -040010812out_free_phba:
10813 lpfc_hba_free(phba);
10814 return error;
10815}
10816
10817/**
10818 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -040010819 * @pdev: pointer to PCI device
10820 *
James Smart3772a992009-05-22 14:50:54 -040010821 * This routine is to be called to disattach a device with SLI-3 interface
10822 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10823 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10824 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -040010825 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010826static void
James Smart3772a992009-05-22 14:50:54 -040010827lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -050010828{
James Smart2e0fef82007-06-17 19:56:36 -050010829 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10830 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -050010831 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -050010832 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -050010833 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -050010834
James Smart549e55c2007-08-02 11:09:51 -040010835 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -040010836 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -040010837 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -050010838
James Smart858c9f62007-06-17 19:56:39 -050010839 lpfc_free_sysfs_attr(vport);
10840
James Smarteada2722008-12-04 22:39:13 -050010841 /* Release all the vports against this physical port */
10842 vports = lpfc_create_vport_work_array(phba);
10843 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040010844 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10845 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
10846 continue;
James Smarteada2722008-12-04 22:39:13 -050010847 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040010848 }
James Smarteada2722008-12-04 22:39:13 -050010849 lpfc_destroy_vport_work_array(phba, vports);
10850
10851 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -050010852 fc_remove_host(shost);
10853 scsi_remove_host(shost);
James Smartd613b6a2017-02-12 13:52:37 -080010854
James Smart87af33f2007-10-27 13:37:43 -040010855 lpfc_cleanup(vport);
10856
James Smart2e0fef82007-06-17 19:56:36 -050010857 /*
10858 * Bring down the SLI Layer. This step disable all interrupts,
10859 * clears the rings, discards all mailbox commands, and resets
10860 * the HBA.
10861 */
James Smarta257bf92009-04-06 18:48:10 -040010862
Justin P. Mattock48e34d02010-12-30 15:07:58 -080010863 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -050010864 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -040010865 /* Stop kthread signal shall trigger work_done one more time */
10866 kthread_stop(phba->worker_thread);
10867 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -050010868 lpfc_sli_brdrestart(phba);
10869
James Smart72859902012-01-18 16:25:38 -050010870 kfree(phba->vpi_bmask);
10871 kfree(phba->vpi_ids);
10872
James Smart3772a992009-05-22 14:50:54 -040010873 lpfc_stop_hba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -050010874 spin_lock_irq(&phba->hbalock);
10875 list_del_init(&vport->listentry);
10876 spin_unlock_irq(&phba->hbalock);
10877
James Smart858c9f62007-06-17 19:56:39 -050010878 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -050010879
James Smart912e3ac2011-05-24 11:42:11 -040010880 /* Disable SR-IOV if enabled */
10881 if (phba->cfg_sriov_nr_virtfn)
10882 pci_disable_sriov(pdev);
10883
James Smart5b75da22008-12-04 22:39:35 -050010884 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -040010885 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -050010886
James Smart858c9f62007-06-17 19:56:39 -050010887 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -050010888
10889 /*
10890 * Call scsi_free before mem_free since scsi bufs are released to their
10891 * corresponding pools here.
10892 */
10893 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -040010894 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -050010895
James Smart34b02dc2008-08-24 21:49:55 -040010896 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
10897 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -050010898
James Smart2e0fef82007-06-17 19:56:36 -050010899 /* Free resources associated with SLI2 interface */
10900 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -040010901 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -050010902
10903 /* unmap adapter SLIM and Control Registers */
10904 iounmap(phba->ctrl_regs_memmap_p);
10905 iounmap(phba->slim_memmap_p);
10906
James Smart3772a992009-05-22 14:50:54 -040010907 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -050010908
Johannes Thumshirne0c04832016-06-07 09:44:03 +020010909 pci_release_mem_regions(pdev);
James Smart2e0fef82007-06-17 19:56:36 -050010910 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -050010911}
10912
Linas Vepstas8d63f372007-02-14 14:28:36 -060010913/**
James Smart3772a992009-05-22 14:50:54 -040010914 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050010915 * @pdev: pointer to PCI device
10916 * @msg: power management message
10917 *
James Smart3772a992009-05-22 14:50:54 -040010918 * This routine is to be called from the kernel's PCI subsystem to support
10919 * system Power Management (PM) to device with SLI-3 interface spec. When
10920 * PM invokes this method, it quiesces the device by stopping the driver's
10921 * worker thread for the device, turning off device's interrupt and DMA,
10922 * and bring the device offline. Note that as the driver implements the
10923 * minimum PM requirements to a power-aware driver's PM support for the
10924 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10925 * to the suspend() method call will be treated as SUSPEND and the driver will
10926 * fully reinitialize its device during resume() method call, the driver will
10927 * set device to PCI_D3hot state in PCI config space instead of setting it
10928 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -050010929 *
10930 * Return code
James Smart3772a992009-05-22 14:50:54 -040010931 * 0 - driver suspended the device
10932 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050010933 **/
10934static int
James Smart3772a992009-05-22 14:50:54 -040010935lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -050010936{
10937 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10938 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10939
10940 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10941 "0473 PCI device Power Management suspend.\n");
10942
10943 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040010944 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -050010945 lpfc_offline(phba);
10946 kthread_stop(phba->worker_thread);
10947
10948 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -040010949 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -050010950
10951 /* Save device state to PCI config space */
10952 pci_save_state(pdev);
10953 pci_set_power_state(pdev, PCI_D3hot);
10954
10955 return 0;
10956}
10957
10958/**
James Smart3772a992009-05-22 14:50:54 -040010959 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050010960 * @pdev: pointer to PCI device
10961 *
James Smart3772a992009-05-22 14:50:54 -040010962 * This routine is to be called from the kernel's PCI subsystem to support
10963 * system Power Management (PM) to device with SLI-3 interface spec. When PM
10964 * invokes this method, it restores the device's PCI config space state and
10965 * fully reinitializes the device and brings it online. Note that as the
10966 * driver implements the minimum PM requirements to a power-aware driver's
10967 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
10968 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
10969 * driver will fully reinitialize its device during resume() method call,
10970 * the device will be set to PCI_D0 directly in PCI config space before
10971 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -050010972 *
10973 * Return code
James Smart3772a992009-05-22 14:50:54 -040010974 * 0 - driver suspended the device
10975 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050010976 **/
10977static int
James Smart3772a992009-05-22 14:50:54 -040010978lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -050010979{
10980 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10981 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -050010982 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050010983 int error;
10984
10985 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10986 "0452 PCI device Power Management resume.\n");
10987
10988 /* Restore device state from PCI config space */
10989 pci_set_power_state(pdev, PCI_D0);
10990 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -040010991
James Smart1dfb5a42010-02-12 14:40:50 -050010992 /*
10993 * As the new kernel behavior of pci_restore_state() API call clears
10994 * device saved_state flag, need to save the restored state again.
10995 */
10996 pci_save_state(pdev);
10997
James Smart3a55b532008-12-04 22:38:54 -050010998 if (pdev->is_busmaster)
10999 pci_set_master(pdev);
11000
11001 /* Startup the kernel thread for this host adapter. */
11002 phba->worker_thread = kthread_run(lpfc_do_work, phba,
11003 "lpfc_worker_%d", phba->brd_no);
11004 if (IS_ERR(phba->worker_thread)) {
11005 error = PTR_ERR(phba->worker_thread);
11006 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11007 "0434 PM resume failed to start worker "
11008 "thread: error=x%x.\n", error);
11009 return error;
11010 }
11011
James Smart5b75da22008-12-04 22:39:35 -050011012 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040011013 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050011014 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -050011015 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -050011016 "0430 PM resume Failed to enable interrupt\n");
11017 return -EIO;
11018 } else
11019 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050011020
11021 /* Restart HBA and bring it online */
11022 lpfc_sli_brdrestart(phba);
11023 lpfc_online(phba);
11024
James Smart5b75da22008-12-04 22:39:35 -050011025 /* Log the current active interrupt mode */
11026 lpfc_log_intr_mode(phba, phba->intr_mode);
11027
James Smart3a55b532008-12-04 22:38:54 -050011028 return 0;
11029}
11030
11031/**
James Smart891478a2009-11-18 15:40:23 -050011032 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
11033 * @phba: pointer to lpfc hba data structure.
11034 *
11035 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -040011036 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -050011037 **/
11038static void
11039lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
11040{
11041 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11042 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -040011043
11044 /*
11045 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
11046 * and let the SCSI mid-layer to retry them to recover.
11047 */
James Smartdb55fba2014-04-04 13:52:02 -040011048 lpfc_sli_abort_fcp_rings(phba);
James Smart891478a2009-11-18 15:40:23 -050011049}
11050
11051/**
James Smart0d878412009-10-02 15:16:56 -040011052 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
11053 * @phba: pointer to lpfc hba data structure.
11054 *
11055 * This routine is called to prepare the SLI3 device for PCI slot reset. It
11056 * disables the device interrupt and pci device, and aborts the internal FCP
11057 * pending I/Os.
11058 **/
11059static void
11060lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
11061{
James Smart0d878412009-10-02 15:16:56 -040011062 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050011063 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -040011064
James Smart75baf692010-06-08 18:31:21 -040011065 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040011066 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040011067
James Smarte2af0d22010-03-15 11:25:32 -040011068 /* Block all SCSI devices' I/Os on the host */
11069 lpfc_scsi_dev_block(phba);
11070
James Smartea714f32013-04-17 20:18:47 -040011071 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
11072 lpfc_sli_flush_fcp_rings(phba);
11073
James Smarte2af0d22010-03-15 11:25:32 -040011074 /* stop all timers */
11075 lpfc_stop_hba_timers(phba);
11076
James Smart0d878412009-10-02 15:16:56 -040011077 /* Disable interrupt and pci device */
11078 lpfc_sli_disable_intr(phba);
11079 pci_disable_device(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -040011080}
11081
11082/**
11083 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
11084 * @phba: pointer to lpfc hba data structure.
11085 *
11086 * This routine is called to prepare the SLI3 device for PCI slot permanently
11087 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
11088 * pending I/Os.
11089 **/
11090static void
James Smart75baf692010-06-08 18:31:21 -040011091lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -040011092{
11093 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050011094 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -040011095 /* Block all SCSI devices' I/Os on the host */
11096 lpfc_scsi_dev_block(phba);
11097
11098 /* stop all timers */
11099 lpfc_stop_hba_timers(phba);
11100
James Smart0d878412009-10-02 15:16:56 -040011101 /* Clean up all driver's outstanding SCSI I/Os */
11102 lpfc_sli_flush_fcp_rings(phba);
11103}
11104
11105/**
James Smart3772a992009-05-22 14:50:54 -040011106 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -040011107 * @pdev: pointer to PCI device.
11108 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -060011109 *
James Smart3772a992009-05-22 14:50:54 -040011110 * This routine is called from the PCI subsystem for I/O error handling to
11111 * device with SLI-3 interface spec. This function is called by the PCI
11112 * subsystem after a PCI bus error affecting this device has been detected.
11113 * When this function is invoked, it will need to stop all the I/Os and
11114 * interrupt(s) to the device. Once that is done, it will return
11115 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
11116 * as desired.
James Smarte59058c2008-08-24 21:49:00 -040011117 *
11118 * Return codes
James Smart0d878412009-10-02 15:16:56 -040011119 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -040011120 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11121 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -040011122 **/
James Smart3772a992009-05-22 14:50:54 -040011123static pci_ers_result_t
11124lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -060011125{
James Smart51ef4c22007-08-02 11:10:31 -040011126 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11127 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011128
James Smart0d878412009-10-02 15:16:56 -040011129 switch (state) {
11130 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -050011131 /* Non-fatal error, prepare for recovery */
11132 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -040011133 return PCI_ERS_RESULT_CAN_RECOVER;
11134 case pci_channel_io_frozen:
11135 /* Fatal error, prepare for slot reset */
11136 lpfc_sli_prep_dev_for_reset(phba);
11137 return PCI_ERS_RESULT_NEED_RESET;
11138 case pci_channel_io_perm_failure:
11139 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -040011140 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011141 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -040011142 default:
11143 /* Unknown state, prepare and request slot reset */
11144 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11145 "0472 Unknown PCI error state: x%x\n", state);
11146 lpfc_sli_prep_dev_for_reset(phba);
11147 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -040011148 }
Linas Vepstas8d63f372007-02-14 14:28:36 -060011149}
11150
11151/**
James Smart3772a992009-05-22 14:50:54 -040011152 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -040011153 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -060011154 *
James Smart3772a992009-05-22 14:50:54 -040011155 * This routine is called from the PCI subsystem for error handling to
11156 * device with SLI-3 interface spec. This is called after PCI bus has been
11157 * reset to restart the PCI card from scratch, as if from a cold-boot.
11158 * During the PCI subsystem error recovery, after driver returns
11159 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
11160 * recovery and then call this routine before calling the .resume method
11161 * to recover the device. This function will initialize the HBA device,
11162 * enable the interrupt, but it will just put the HBA to offline state
11163 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -040011164 *
11165 * Return codes
James Smart3772a992009-05-22 14:50:54 -040011166 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11167 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -060011168 */
James Smart3772a992009-05-22 14:50:54 -040011169static pci_ers_result_t
11170lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060011171{
James Smart51ef4c22007-08-02 11:10:31 -040011172 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11173 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011174 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -050011175 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011176
11177 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +110011178 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -060011179 printk(KERN_ERR "lpfc: Cannot re-enable "
11180 "PCI device after reset.\n");
11181 return PCI_ERS_RESULT_DISCONNECT;
11182 }
11183
James Smart97207482008-12-04 22:39:19 -050011184 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050011185
11186 /*
11187 * As the new kernel behavior of pci_restore_state() API call clears
11188 * device saved_state flag, need to save the restored state again.
11189 */
11190 pci_save_state(pdev);
11191
James Smart97207482008-12-04 22:39:19 -050011192 if (pdev->is_busmaster)
11193 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011194
James Smart92d7f7b2007-06-17 19:56:38 -050011195 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040011196 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -050011197 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011198
James Smart5b75da22008-12-04 22:39:35 -050011199 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040011200 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050011201 if (intr_mode == LPFC_INTR_ERROR) {
11202 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11203 "0427 Cannot re-enable interrupt after "
11204 "slot reset.\n");
11205 return PCI_ERS_RESULT_DISCONNECT;
11206 } else
11207 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011208
James Smart75baf692010-06-08 18:31:21 -040011209 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -040011210 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011211 lpfc_offline(phba);
11212 lpfc_sli_brdrestart(phba);
11213
James Smart5b75da22008-12-04 22:39:35 -050011214 /* Log the current active interrupt mode */
11215 lpfc_log_intr_mode(phba, phba->intr_mode);
11216
Linas Vepstas8d63f372007-02-14 14:28:36 -060011217 return PCI_ERS_RESULT_RECOVERED;
11218}
11219
11220/**
James Smart3772a992009-05-22 14:50:54 -040011221 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -040011222 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -060011223 *
James Smart3772a992009-05-22 14:50:54 -040011224 * This routine is called from the PCI subsystem for error handling to device
11225 * with SLI-3 interface spec. It is called when kernel error recovery tells
11226 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
11227 * error recovery. After this call, traffic can start to flow from this device
11228 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -060011229 */
James Smart3772a992009-05-22 14:50:54 -040011230static void
11231lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060011232{
James Smart51ef4c22007-08-02 11:10:31 -040011233 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11234 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060011235
James Smarte2af0d22010-03-15 11:25:32 -040011236 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -040011237 lpfc_online(phba);
James Smart0d878412009-10-02 15:16:56 -040011238
11239 /* Clean up Advanced Error Reporting (AER) if needed */
11240 if (phba->hba_flag & HBA_AER_ENABLED)
11241 pci_cleanup_aer_uncorrect_error_status(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060011242}
11243
James Smart3772a992009-05-22 14:50:54 -040011244/**
James Smartda0436e2009-05-22 14:51:39 -040011245 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
11246 * @phba: pointer to lpfc hba data structure.
11247 *
11248 * returns the number of ELS/CT IOCBs to reserve
11249 **/
11250int
11251lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
11252{
11253 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
11254
James Smartf1126682009-06-10 17:22:44 -040011255 if (phba->sli_rev == LPFC_SLI_REV4) {
11256 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -040011257 return 10;
James Smartf1126682009-06-10 17:22:44 -040011258 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -040011259 return 25;
James Smartf1126682009-06-10 17:22:44 -040011260 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -040011261 return 50;
James Smartf1126682009-06-10 17:22:44 -040011262 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -040011263 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -040011264 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -040011265 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -040011266 else if (max_xri <= 2048)
11267 return 200;
11268 else
11269 return 250;
James Smartf1126682009-06-10 17:22:44 -040011270 } else
11271 return 0;
James Smartda0436e2009-05-22 14:51:39 -040011272}
11273
11274/**
James Smart895427b2017-02-12 13:52:30 -080011275 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
11276 * @phba: pointer to lpfc hba data structure.
11277 *
James Smartf358dd02017-02-12 13:52:34 -080011278 * returns the number of ELS/CT + NVMET IOCBs to reserve
James Smart895427b2017-02-12 13:52:30 -080011279 **/
11280int
11281lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
11282{
11283 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
11284
James Smartf358dd02017-02-12 13:52:34 -080011285 if (phba->nvmet_support)
11286 max_xri += LPFC_NVMET_BUF_POST;
James Smart895427b2017-02-12 13:52:30 -080011287 return max_xri;
11288}
11289
11290
11291/**
James Smart52d52442011-05-24 11:42:45 -040011292 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -040011293 * @fw: pointer to firmware image returned from request_firmware.
James Smartce396282012-09-29 11:30:56 -040011294 * @phba: pointer to lpfc hba data structure.
James Smart52d52442011-05-24 11:42:45 -040011295 *
James Smart52d52442011-05-24 11:42:45 -040011296 **/
James Smartce396282012-09-29 11:30:56 -040011297static void
11298lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -040011299{
James Smartce396282012-09-29 11:30:56 -040011300 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -050011301 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -040011302 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -040011303 struct list_head dma_buffer_list;
11304 int i, rc = 0;
11305 struct lpfc_dmabuf *dmabuf, *next;
11306 uint32_t offset = 0, temp_offset = 0;
James Smart6b6ef5d2016-10-13 15:06:17 -070011307 uint32_t magic_number, ftype, fid, fsize;
James Smart52d52442011-05-24 11:42:45 -040011308
James Smartc71ab862012-10-31 14:44:33 -040011309 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -040011310 if (!fw) {
11311 rc = -ENXIO;
11312 goto out;
11313 }
11314 image = (struct lpfc_grp_hdr *)fw->data;
11315
James Smart6b6ef5d2016-10-13 15:06:17 -070011316 magic_number = be32_to_cpu(image->magic_number);
11317 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
11318 fid = bf_get_be32(lpfc_grp_hdr_id, image),
11319 fsize = be32_to_cpu(image->size);
11320
James Smart52d52442011-05-24 11:42:45 -040011321 INIT_LIST_HEAD(&dma_buffer_list);
James Smart6b6ef5d2016-10-13 15:06:17 -070011322 if ((magic_number != LPFC_GROUP_OJECT_MAGIC_G5 &&
11323 magic_number != LPFC_GROUP_OJECT_MAGIC_G6) ||
11324 ftype != LPFC_FILE_TYPE_GROUP || fsize != fw->size) {
James Smart52d52442011-05-24 11:42:45 -040011325 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11326 "3022 Invalid FW image found. "
Arnd Bergmannefe583c2016-10-17 14:35:46 +020011327 "Magic:%x Type:%x ID:%x Size %d %zd\n",
James Smart6b6ef5d2016-10-13 15:06:17 -070011328 magic_number, ftype, fid, fsize, fw->size);
James Smartce396282012-09-29 11:30:56 -040011329 rc = -EINVAL;
11330 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040011331 }
11332 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -040011333 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -040011334 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartce396282012-09-29 11:30:56 -040011335 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -040011336 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -040011337 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -040011338 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
11339 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
11340 GFP_KERNEL);
11341 if (!dmabuf) {
11342 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040011343 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040011344 }
11345 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
11346 SLI4_PAGE_SIZE,
11347 &dmabuf->phys,
11348 GFP_KERNEL);
11349 if (!dmabuf->virt) {
11350 kfree(dmabuf);
11351 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040011352 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040011353 }
11354 list_add_tail(&dmabuf->list, &dma_buffer_list);
11355 }
11356 while (offset < fw->size) {
11357 temp_offset = offset;
11358 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -040011359 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -040011360 memcpy(dmabuf->virt,
11361 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -040011362 fw->size - temp_offset);
11363 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -040011364 break;
11365 }
James Smart52d52442011-05-24 11:42:45 -040011366 memcpy(dmabuf->virt, fw->data + temp_offset,
11367 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -040011368 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -040011369 }
11370 rc = lpfc_wr_object(phba, &dma_buffer_list,
11371 (fw->size - offset), &offset);
James Smartce396282012-09-29 11:30:56 -040011372 if (rc)
11373 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040011374 }
11375 rc = offset;
11376 }
James Smartce396282012-09-29 11:30:56 -040011377
11378release_out:
James Smart52d52442011-05-24 11:42:45 -040011379 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
11380 list_del(&dmabuf->list);
11381 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
11382 dmabuf->virt, dmabuf->phys);
11383 kfree(dmabuf);
11384 }
James Smartce396282012-09-29 11:30:56 -040011385 release_firmware(fw);
11386out:
11387 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc71ab862012-10-31 14:44:33 -040011388 "3024 Firmware update done: %d.\n", rc);
James Smartce396282012-09-29 11:30:56 -040011389 return;
James Smart52d52442011-05-24 11:42:45 -040011390}
11391
11392/**
James Smartc71ab862012-10-31 14:44:33 -040011393 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
11394 * @phba: pointer to lpfc hba data structure.
11395 *
11396 * This routine is called to perform Linux generic firmware upgrade on device
11397 * that supports such feature.
11398 **/
11399int
11400lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
11401{
11402 uint8_t file_name[ELX_MODEL_NAME_SIZE];
11403 int ret;
11404 const struct firmware *fw;
11405
11406 /* Only supported on SLI4 interface type 2 for now */
James Smart27d6ac02018-02-22 08:18:42 -080011407 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
James Smartc71ab862012-10-31 14:44:33 -040011408 LPFC_SLI_INTF_IF_TYPE_2)
11409 return -EPERM;
11410
11411 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
11412
11413 if (fw_upgrade == INT_FW_UPGRADE) {
11414 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
11415 file_name, &phba->pcidev->dev,
11416 GFP_KERNEL, (void *)phba,
11417 lpfc_write_firmware);
11418 } else if (fw_upgrade == RUN_FW_UPGRADE) {
11419 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
11420 if (!ret)
11421 lpfc_write_firmware(fw, (void *)phba);
11422 } else {
11423 ret = -EINVAL;
11424 }
11425
11426 return ret;
11427}
11428
11429/**
James Smartda0436e2009-05-22 14:51:39 -040011430 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
11431 * @pdev: pointer to PCI device
11432 * @pid: pointer to PCI device identifier
11433 *
11434 * This routine is called from the kernel's PCI subsystem to device with
11435 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11436 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
11437 * information of the device and driver to see if the driver state that it
11438 * can support this kind of device. If the match is successful, the driver
11439 * core invokes this routine. If this routine determines it can claim the HBA,
11440 * it does all the initialization that it needs to do to handle the HBA
11441 * properly.
11442 *
11443 * Return code
11444 * 0 - driver can claim the device
11445 * negative value - driver can not claim the device
11446 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011447static int
James Smartda0436e2009-05-22 14:51:39 -040011448lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
11449{
11450 struct lpfc_hba *phba;
11451 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040011452 struct Scsi_Host *shost = NULL;
James Smart6c621a22017-05-15 15:20:45 -070011453 int error;
James Smartda0436e2009-05-22 14:51:39 -040011454 uint32_t cfg_mode, intr_mode;
James Smartda0436e2009-05-22 14:51:39 -040011455
11456 /* Allocate memory for HBA structure */
11457 phba = lpfc_hba_alloc(pdev);
11458 if (!phba)
11459 return -ENOMEM;
11460
11461 /* Perform generic PCI device enabling operation */
11462 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040011463 if (error)
James Smartda0436e2009-05-22 14:51:39 -040011464 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -040011465
11466 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
11467 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
11468 if (error)
11469 goto out_disable_pci_dev;
11470
11471 /* Set up SLI-4 specific device PCI memory space */
11472 error = lpfc_sli4_pci_mem_setup(phba);
11473 if (error) {
11474 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11475 "1410 Failed to set up pci memory space.\n");
11476 goto out_disable_pci_dev;
11477 }
11478
James Smartda0436e2009-05-22 14:51:39 -040011479 /* Set up SLI-4 Specific device driver resources */
11480 error = lpfc_sli4_driver_resource_setup(phba);
11481 if (error) {
11482 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11483 "1412 Failed to set up driver resource.\n");
11484 goto out_unset_pci_mem_s4;
11485 }
11486
James Smart19ca7602010-11-20 23:11:55 -050011487 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -040011488 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -050011489
James Smartda0436e2009-05-22 14:51:39 -040011490 /* Set up common device driver resources */
11491 error = lpfc_setup_driver_resource_phase2(phba);
11492 if (error) {
11493 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11494 "1414 Failed to set up driver resource.\n");
James Smart6c621a22017-05-15 15:20:45 -070011495 goto out_unset_driver_resource_s4;
James Smartda0436e2009-05-22 14:51:39 -040011496 }
11497
James Smart079b5c92011-08-21 21:48:49 -040011498 /* Get the default values for Model Name and Description */
11499 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
11500
James Smartda0436e2009-05-22 14:51:39 -040011501 /* Create SCSI host to the physical port */
11502 error = lpfc_create_shost(phba);
11503 if (error) {
11504 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11505 "1415 Failed to create scsi host.\n");
11506 goto out_unset_driver_resource;
11507 }
11508
11509 /* Configure sysfs attributes */
11510 vport = phba->pport;
11511 error = lpfc_alloc_sysfs_attr(vport);
11512 if (error) {
11513 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11514 "1416 Failed to allocate sysfs attr\n");
11515 goto out_destroy_shost;
11516 }
11517
James Smart6669f9b2009-10-02 15:16:45 -040011518 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -040011519 /* Now, trying to enable interrupt and bring up the device */
11520 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -040011521
James Smart7b15db32013-01-03 15:43:29 -050011522 /* Put device to a known state before enabling interrupt */
11523 lpfc_stop_port(phba);
James Smart895427b2017-02-12 13:52:30 -080011524
James Smart7b15db32013-01-03 15:43:29 -050011525 /* Configure and enable interrupt */
11526 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
11527 if (intr_mode == LPFC_INTR_ERROR) {
11528 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11529 "0426 Failed to enable interrupt.\n");
11530 error = -ENODEV;
11531 goto out_free_sysfs_attr;
James Smartda0436e2009-05-22 14:51:39 -040011532 }
James Smart7b15db32013-01-03 15:43:29 -050011533 /* Default to single EQ for non-MSI-X */
James Smart895427b2017-02-12 13:52:30 -080011534 if (phba->intr_type != MSIX) {
11535 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
11536 phba->cfg_fcp_io_channel = 1;
James Smart2d7dbc42017-02-12 13:52:35 -080011537 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -080011538 phba->cfg_nvme_io_channel = 1;
James Smart2d7dbc42017-02-12 13:52:35 -080011539 if (phba->nvmet_support)
11540 phba->cfg_nvmet_mrq = 1;
11541 }
James Smart895427b2017-02-12 13:52:30 -080011542 phba->io_channel_irqs = 1;
11543 }
11544
James Smart7b15db32013-01-03 15:43:29 -050011545 /* Set up SLI-4 HBA */
11546 if (lpfc_sli4_hba_setup(phba)) {
11547 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11548 "1421 Failed to set up hba\n");
11549 error = -ENODEV;
11550 goto out_disable_intr;
11551 }
11552
11553 /* Log the current active interrupt mode */
11554 phba->intr_mode = intr_mode;
11555 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -040011556
11557 /* Perform post initialization setup */
11558 lpfc_post_init_setup(phba);
11559
James Smart01649562017-02-12 13:52:32 -080011560 /* NVME support in FW earlier in the driver load corrects the
11561 * FC4 type making a check for nvme_support unnecessary.
11562 */
11563 if ((phba->nvmet_support == 0) &&
11564 (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
11565 /* Create NVME binding with nvme_fc_transport. This
James Smartd1f525a2017-04-21 16:04:55 -070011566 * ensures the vport is initialized. If the localport
11567 * create fails, it should not unload the driver to
11568 * support field issues.
James Smart01649562017-02-12 13:52:32 -080011569 */
11570 error = lpfc_nvme_create_localport(vport);
11571 if (error) {
11572 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11573 "6004 NVME registration failed, "
11574 "error x%x\n",
11575 error);
James Smart01649562017-02-12 13:52:32 -080011576 }
11577 }
James Smart895427b2017-02-12 13:52:30 -080011578
James Smartc71ab862012-10-31 14:44:33 -040011579 /* check for firmware upgrade or downgrade */
11580 if (phba->cfg_request_firmware_upgrade)
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040011581 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -040011582
James Smart1c6834a2009-07-19 10:01:26 -040011583 /* Check if there are static vports to be created. */
11584 lpfc_create_static_vport(phba);
James Smartda0436e2009-05-22 14:51:39 -040011585 return 0;
11586
11587out_disable_intr:
11588 lpfc_sli4_disable_intr(phba);
11589out_free_sysfs_attr:
11590 lpfc_free_sysfs_attr(vport);
11591out_destroy_shost:
11592 lpfc_destroy_shost(phba);
11593out_unset_driver_resource:
11594 lpfc_unset_driver_resource_phase2(phba);
James Smartda0436e2009-05-22 14:51:39 -040011595out_unset_driver_resource_s4:
11596 lpfc_sli4_driver_resource_unset(phba);
11597out_unset_pci_mem_s4:
11598 lpfc_sli4_pci_mem_unset(phba);
11599out_disable_pci_dev:
11600 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040011601 if (shost)
11602 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -040011603out_free_phba:
11604 lpfc_hba_free(phba);
11605 return error;
11606}
11607
11608/**
11609 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
11610 * @pdev: pointer to PCI device
11611 *
11612 * This routine is called from the kernel's PCI subsystem to device with
11613 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11614 * removed from PCI bus, it performs all the necessary cleanup for the HBA
11615 * device to be removed from the PCI subsystem properly.
11616 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011617static void
James Smartda0436e2009-05-22 14:51:39 -040011618lpfc_pci_remove_one_s4(struct pci_dev *pdev)
11619{
11620 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11621 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
11622 struct lpfc_vport **vports;
11623 struct lpfc_hba *phba = vport->phba;
11624 int i;
11625
11626 /* Mark the device unloading flag */
11627 spin_lock_irq(&phba->hbalock);
11628 vport->load_flag |= FC_UNLOADING;
11629 spin_unlock_irq(&phba->hbalock);
11630
11631 /* Free the HBA sysfs attributes */
11632 lpfc_free_sysfs_attr(vport);
11633
11634 /* Release all the vports against this physical port */
11635 vports = lpfc_create_vport_work_array(phba);
11636 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040011637 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
11638 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
11639 continue;
James Smartda0436e2009-05-22 14:51:39 -040011640 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040011641 }
James Smartda0436e2009-05-22 14:51:39 -040011642 lpfc_destroy_vport_work_array(phba, vports);
11643
11644 /* Remove FC host and then SCSI host with the physical port */
11645 fc_remove_host(shost);
11646 scsi_remove_host(shost);
James Smartda0436e2009-05-22 14:51:39 -040011647
James Smartda0436e2009-05-22 14:51:39 -040011648 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
11649 * localports are destroyed after to cleanup all transport memory.
11650 */
11651 lpfc_cleanup(vport);
11652 lpfc_nvmet_destroy_targetport(phba);
11653 lpfc_nvme_destroy_localport(vport);
11654
James Smart281d6192018-01-30 15:58:47 -080011655 /*
11656 * Bring down the SLI Layer. This step disables all interrupts,
11657 * clears the rings, discards all mailbox commands, and resets
11658 * the HBA FCoE function.
11659 */
11660 lpfc_debugfs_terminate(vport);
11661 lpfc_sli4_hba_unset(phba);
James Smartda0436e2009-05-22 14:51:39 -040011662
Dick Kennedy19017622017-09-29 17:34:27 -070011663 lpfc_stop_hba_timers(phba);
James Smartda0436e2009-05-22 14:51:39 -040011664 spin_lock_irq(&phba->hbalock);
11665 list_del_init(&vport->listentry);
11666 spin_unlock_irq(&phba->hbalock);
11667
James Smart3677a3a2010-09-29 11:19:14 -040011668 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -040011669 * buffers are released to their corresponding pools here.
11670 */
11671 lpfc_scsi_free(phba);
James Smart895427b2017-02-12 13:52:30 -080011672 lpfc_nvme_free(phba);
James Smart01649562017-02-12 13:52:32 -080011673 lpfc_free_iocb_list(phba);
James Smart67d12732012-08-03 12:36:13 -040011674
James Smartda0436e2009-05-22 14:51:39 -040011675 lpfc_sli4_driver_resource_unset(phba);
11676
11677 /* Unmap adapter Control and Doorbell registers */
11678 lpfc_sli4_pci_mem_unset(phba);
11679
11680 /* Release PCI resources and disable device's PCI function */
11681 scsi_host_put(shost);
11682 lpfc_disable_pci_dev(phba);
11683
11684 /* Finally, free the driver's device data structure */
11685 lpfc_hba_free(phba);
11686
11687 return;
11688}
11689
11690/**
11691 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
11692 * @pdev: pointer to PCI device
11693 * @msg: power management message
11694 *
11695 * This routine is called from the kernel's PCI subsystem to support system
11696 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
11697 * this method, it quiesces the device by stopping the driver's worker
11698 * thread for the device, turning off device's interrupt and DMA, and bring
11699 * the device offline. Note that as the driver implements the minimum PM
11700 * requirements to a power-aware driver's PM support for suspend/resume -- all
11701 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
11702 * method call will be treated as SUSPEND and the driver will fully
11703 * reinitialize its device during resume() method call, the driver will set
11704 * device to PCI_D3hot state in PCI config space instead of setting it
11705 * according to the @msg provided by the PM.
11706 *
11707 * Return code
11708 * 0 - driver suspended the device
11709 * Error otherwise
11710 **/
11711static int
11712lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
11713{
11714 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11715 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11716
11717 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -040011718 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -040011719
11720 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040011721 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -040011722 lpfc_offline(phba);
11723 kthread_stop(phba->worker_thread);
11724
11725 /* Disable interrupt from device */
11726 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040011727 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040011728
11729 /* Save device state to PCI config space */
11730 pci_save_state(pdev);
11731 pci_set_power_state(pdev, PCI_D3hot);
11732
11733 return 0;
11734}
11735
11736/**
11737 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
11738 * @pdev: pointer to PCI device
11739 *
11740 * This routine is called from the kernel's PCI subsystem to support system
11741 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
11742 * this method, it restores the device's PCI config space state and fully
11743 * reinitializes the device and brings it online. Note that as the driver
11744 * implements the minimum PM requirements to a power-aware driver's PM for
11745 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
11746 * to the suspend() method call will be treated as SUSPEND and the driver
11747 * will fully reinitialize its device during resume() method call, the device
11748 * will be set to PCI_D0 directly in PCI config space before restoring the
11749 * state.
11750 *
11751 * Return code
11752 * 0 - driver suspended the device
11753 * Error otherwise
11754 **/
11755static int
11756lpfc_pci_resume_one_s4(struct pci_dev *pdev)
11757{
11758 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11759 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11760 uint32_t intr_mode;
11761 int error;
11762
11763 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11764 "0292 PCI device Power Management resume.\n");
11765
11766 /* Restore device state from PCI config space */
11767 pci_set_power_state(pdev, PCI_D0);
11768 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050011769
11770 /*
11771 * As the new kernel behavior of pci_restore_state() API call clears
11772 * device saved_state flag, need to save the restored state again.
11773 */
11774 pci_save_state(pdev);
11775
James Smartda0436e2009-05-22 14:51:39 -040011776 if (pdev->is_busmaster)
11777 pci_set_master(pdev);
11778
11779 /* Startup the kernel thread for this host adapter. */
11780 phba->worker_thread = kthread_run(lpfc_do_work, phba,
11781 "lpfc_worker_%d", phba->brd_no);
11782 if (IS_ERR(phba->worker_thread)) {
11783 error = PTR_ERR(phba->worker_thread);
11784 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11785 "0293 PM resume failed to start worker "
11786 "thread: error=x%x.\n", error);
11787 return error;
11788 }
11789
11790 /* Configure and enable interrupt */
11791 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
11792 if (intr_mode == LPFC_INTR_ERROR) {
11793 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11794 "0294 PM resume Failed to enable interrupt\n");
11795 return -EIO;
11796 } else
11797 phba->intr_mode = intr_mode;
11798
11799 /* Restart HBA and bring it online */
11800 lpfc_sli_brdrestart(phba);
11801 lpfc_online(phba);
11802
11803 /* Log the current active interrupt mode */
11804 lpfc_log_intr_mode(phba, phba->intr_mode);
11805
11806 return 0;
11807}
11808
11809/**
James Smart75baf692010-06-08 18:31:21 -040011810 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
11811 * @phba: pointer to lpfc hba data structure.
11812 *
11813 * This routine is called to prepare the SLI4 device for PCI slot recover. It
11814 * aborts all the outstanding SCSI I/Os to the pci device.
11815 **/
11816static void
11817lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
11818{
James Smart75baf692010-06-08 18:31:21 -040011819 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11820 "2828 PCI channel I/O abort preparing for recovery\n");
11821 /*
11822 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
11823 * and let the SCSI mid-layer to retry them to recover.
11824 */
James Smartdb55fba2014-04-04 13:52:02 -040011825 lpfc_sli_abort_fcp_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040011826}
11827
11828/**
11829 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
11830 * @phba: pointer to lpfc hba data structure.
11831 *
11832 * This routine is called to prepare the SLI4 device for PCI slot reset. It
11833 * disables the device interrupt and pci device, and aborts the internal FCP
11834 * pending I/Os.
11835 **/
11836static void
11837lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
11838{
11839 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11840 "2826 PCI channel disable preparing for reset\n");
11841
11842 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040011843 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -040011844
11845 /* Block all SCSI devices' I/Os on the host */
11846 lpfc_scsi_dev_block(phba);
11847
James Smartea714f32013-04-17 20:18:47 -040011848 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
11849 lpfc_sli_flush_fcp_rings(phba);
11850
James Smartc3725bd2017-11-20 16:00:42 -080011851 /* Flush the outstanding NVME IOs if fc4 type enabled. */
11852 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
11853 lpfc_sli_flush_nvme_rings(phba);
11854
James Smart75baf692010-06-08 18:31:21 -040011855 /* stop all timers */
11856 lpfc_stop_hba_timers(phba);
11857
11858 /* Disable interrupt and pci device */
11859 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040011860 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -040011861 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -040011862}
11863
11864/**
11865 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
11866 * @phba: pointer to lpfc hba data structure.
11867 *
11868 * This routine is called to prepare the SLI4 device for PCI slot permanently
11869 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
11870 * pending I/Os.
11871 **/
11872static void
11873lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
11874{
11875 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11876 "2827 PCI channel permanent disable for failure\n");
11877
11878 /* Block all SCSI devices' I/Os on the host */
11879 lpfc_scsi_dev_block(phba);
11880
11881 /* stop all timers */
11882 lpfc_stop_hba_timers(phba);
11883
11884 /* Clean up all driver's outstanding SCSI I/Os */
11885 lpfc_sli_flush_fcp_rings(phba);
James Smartc3725bd2017-11-20 16:00:42 -080011886
11887 /* Flush the outstanding NVME IOs if fc4 type enabled. */
11888 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
11889 lpfc_sli_flush_nvme_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040011890}
11891
11892/**
James Smartda0436e2009-05-22 14:51:39 -040011893 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
11894 * @pdev: pointer to PCI device.
11895 * @state: the current PCI connection state.
11896 *
11897 * This routine is called from the PCI subsystem for error handling to device
11898 * with SLI-4 interface spec. This function is called by the PCI subsystem
11899 * after a PCI bus error affecting this device has been detected. When this
11900 * function is invoked, it will need to stop all the I/Os and interrupt(s)
11901 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
11902 * for the PCI subsystem to perform proper recovery as desired.
11903 *
11904 * Return codes
11905 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11906 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11907 **/
11908static pci_ers_result_t
11909lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
11910{
James Smart75baf692010-06-08 18:31:21 -040011911 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11912 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11913
11914 switch (state) {
11915 case pci_channel_io_normal:
11916 /* Non-fatal error, prepare for recovery */
11917 lpfc_sli4_prep_dev_for_recover(phba);
11918 return PCI_ERS_RESULT_CAN_RECOVER;
11919 case pci_channel_io_frozen:
11920 /* Fatal error, prepare for slot reset */
11921 lpfc_sli4_prep_dev_for_reset(phba);
11922 return PCI_ERS_RESULT_NEED_RESET;
11923 case pci_channel_io_perm_failure:
11924 /* Permanent failure, prepare for device down */
11925 lpfc_sli4_prep_dev_for_perm_failure(phba);
11926 return PCI_ERS_RESULT_DISCONNECT;
11927 default:
11928 /* Unknown state, prepare and request slot reset */
11929 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11930 "2825 Unknown PCI error state: x%x\n", state);
11931 lpfc_sli4_prep_dev_for_reset(phba);
11932 return PCI_ERS_RESULT_NEED_RESET;
11933 }
James Smartda0436e2009-05-22 14:51:39 -040011934}
11935
11936/**
11937 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
11938 * @pdev: pointer to PCI device.
11939 *
11940 * This routine is called from the PCI subsystem for error handling to device
11941 * with SLI-4 interface spec. It is called after PCI bus has been reset to
11942 * restart the PCI card from scratch, as if from a cold-boot. During the
11943 * PCI subsystem error recovery, after the driver returns
11944 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
11945 * recovery and then call this routine before calling the .resume method to
11946 * recover the device. This function will initialize the HBA device, enable
11947 * the interrupt, but it will just put the HBA to offline state without
11948 * passing any I/O traffic.
11949 *
11950 * Return codes
11951 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11952 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11953 */
11954static pci_ers_result_t
11955lpfc_io_slot_reset_s4(struct pci_dev *pdev)
11956{
James Smart75baf692010-06-08 18:31:21 -040011957 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11958 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11959 struct lpfc_sli *psli = &phba->sli;
11960 uint32_t intr_mode;
11961
11962 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
11963 if (pci_enable_device_mem(pdev)) {
11964 printk(KERN_ERR "lpfc: Cannot re-enable "
11965 "PCI device after reset.\n");
11966 return PCI_ERS_RESULT_DISCONNECT;
11967 }
11968
11969 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040011970
11971 /*
11972 * As the new kernel behavior of pci_restore_state() API call clears
11973 * device saved_state flag, need to save the restored state again.
11974 */
11975 pci_save_state(pdev);
11976
James Smart75baf692010-06-08 18:31:21 -040011977 if (pdev->is_busmaster)
11978 pci_set_master(pdev);
11979
11980 spin_lock_irq(&phba->hbalock);
11981 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
11982 spin_unlock_irq(&phba->hbalock);
11983
11984 /* Configure and enable interrupt */
11985 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
11986 if (intr_mode == LPFC_INTR_ERROR) {
11987 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11988 "2824 Cannot re-enable interrupt after "
11989 "slot reset.\n");
11990 return PCI_ERS_RESULT_DISCONNECT;
11991 } else
11992 phba->intr_mode = intr_mode;
11993
11994 /* Log the current active interrupt mode */
11995 lpfc_log_intr_mode(phba, phba->intr_mode);
11996
James Smartda0436e2009-05-22 14:51:39 -040011997 return PCI_ERS_RESULT_RECOVERED;
11998}
11999
12000/**
12001 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
12002 * @pdev: pointer to PCI device
12003 *
12004 * This routine is called from the PCI subsystem for error handling to device
12005 * with SLI-4 interface spec. It is called when kernel error recovery tells
12006 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
12007 * error recovery. After this call, traffic can start to flow from this device
12008 * again.
12009 **/
12010static void
12011lpfc_io_resume_s4(struct pci_dev *pdev)
12012{
James Smart75baf692010-06-08 18:31:21 -040012013 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12014 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12015
12016 /*
12017 * In case of slot reset, as function reset is performed through
12018 * mailbox command which needs DMA to be enabled, this operation
12019 * has to be moved to the io resume phase. Taking device offline
12020 * will perform the necessary cleanup.
12021 */
12022 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
12023 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040012024 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040012025 lpfc_offline(phba);
12026 lpfc_sli_brdrestart(phba);
12027 /* Bring the device back online */
12028 lpfc_online(phba);
12029 }
12030
12031 /* Clean up Advanced Error Reporting (AER) if needed */
12032 if (phba->hba_flag & HBA_AER_ENABLED)
12033 pci_cleanup_aer_uncorrect_error_status(pdev);
James Smartda0436e2009-05-22 14:51:39 -040012034}
12035
12036/**
James Smart3772a992009-05-22 14:50:54 -040012037 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
12038 * @pdev: pointer to PCI device
12039 * @pid: pointer to PCI device identifier
12040 *
12041 * This routine is to be registered to the kernel's PCI subsystem. When an
12042 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
12043 * at PCI device-specific information of the device and driver to see if the
12044 * driver state that it can support this kind of device. If the match is
12045 * successful, the driver core invokes this routine. This routine dispatches
12046 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
12047 * do all the initialization that it needs to do to handle the HBA device
12048 * properly.
12049 *
12050 * Return code
12051 * 0 - driver can claim the device
12052 * negative value - driver can not claim the device
12053 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012054static int
James Smart3772a992009-05-22 14:50:54 -040012055lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
12056{
12057 int rc;
James Smart8fa38512009-07-19 10:01:03 -040012058 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040012059
James Smart28baac72010-02-12 14:42:03 -050012060 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040012061 return -ENODEV;
12062
James Smart8fa38512009-07-19 10:01:03 -040012063 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050012064 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040012065 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040012066 else
James Smart3772a992009-05-22 14:50:54 -040012067 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040012068
James Smart3772a992009-05-22 14:50:54 -040012069 return rc;
12070}
12071
12072/**
12073 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
12074 * @pdev: pointer to PCI device
12075 *
12076 * This routine is to be registered to the kernel's PCI subsystem. When an
12077 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
12078 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
12079 * remove routine, which will perform all the necessary cleanup for the
12080 * device to be removed from the PCI subsystem properly.
12081 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012082static void
James Smart3772a992009-05-22 14:50:54 -040012083lpfc_pci_remove_one(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
12088 switch (phba->pci_dev_grp) {
12089 case LPFC_PCI_DEV_LP:
12090 lpfc_pci_remove_one_s3(pdev);
12091 break;
James Smartda0436e2009-05-22 14:51:39 -040012092 case LPFC_PCI_DEV_OC:
12093 lpfc_pci_remove_one_s4(pdev);
12094 break;
James Smart3772a992009-05-22 14:50:54 -040012095 default:
12096 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12097 "1424 Invalid PCI device group: 0x%x\n",
12098 phba->pci_dev_grp);
12099 break;
12100 }
12101 return;
12102}
12103
12104/**
12105 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
12106 * @pdev: pointer to PCI device
12107 * @msg: power management message
12108 *
12109 * This routine is to be registered to the kernel's PCI subsystem to support
12110 * system Power Management (PM). When PM invokes this method, it dispatches
12111 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
12112 * suspend the device.
12113 *
12114 * Return code
12115 * 0 - driver suspended the device
12116 * Error otherwise
12117 **/
12118static int
12119lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
12120{
12121 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12122 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12123 int rc = -ENODEV;
12124
12125 switch (phba->pci_dev_grp) {
12126 case LPFC_PCI_DEV_LP:
12127 rc = lpfc_pci_suspend_one_s3(pdev, msg);
12128 break;
James Smartda0436e2009-05-22 14:51:39 -040012129 case LPFC_PCI_DEV_OC:
12130 rc = lpfc_pci_suspend_one_s4(pdev, msg);
12131 break;
James Smart3772a992009-05-22 14:50:54 -040012132 default:
12133 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12134 "1425 Invalid PCI device group: 0x%x\n",
12135 phba->pci_dev_grp);
12136 break;
12137 }
12138 return rc;
12139}
12140
12141/**
12142 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
12143 * @pdev: pointer to PCI device
12144 *
12145 * This routine is to be registered to the kernel's PCI subsystem to support
12146 * system Power Management (PM). When PM invokes this method, it dispatches
12147 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
12148 * resume the device.
12149 *
12150 * Return code
12151 * 0 - driver suspended the device
12152 * Error otherwise
12153 **/
12154static int
12155lpfc_pci_resume_one(struct pci_dev *pdev)
12156{
12157 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12158 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12159 int rc = -ENODEV;
12160
12161 switch (phba->pci_dev_grp) {
12162 case LPFC_PCI_DEV_LP:
12163 rc = lpfc_pci_resume_one_s3(pdev);
12164 break;
James Smartda0436e2009-05-22 14:51:39 -040012165 case LPFC_PCI_DEV_OC:
12166 rc = lpfc_pci_resume_one_s4(pdev);
12167 break;
James Smart3772a992009-05-22 14:50:54 -040012168 default:
12169 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12170 "1426 Invalid PCI device group: 0x%x\n",
12171 phba->pci_dev_grp);
12172 break;
12173 }
12174 return rc;
12175}
12176
12177/**
12178 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
12179 * @pdev: pointer to PCI device.
12180 * @state: the current PCI connection state.
12181 *
12182 * This routine is registered to the PCI subsystem for error handling. This
12183 * function is called by the PCI subsystem after a PCI bus error affecting
12184 * this device has been detected. When this routine is invoked, it dispatches
12185 * the action to the proper SLI-3 or SLI-4 device error detected handling
12186 * routine, which will perform the proper error detected operation.
12187 *
12188 * Return codes
12189 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
12190 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12191 **/
12192static pci_ers_result_t
12193lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
12194{
12195 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12196 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12197 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
12198
12199 switch (phba->pci_dev_grp) {
12200 case LPFC_PCI_DEV_LP:
12201 rc = lpfc_io_error_detected_s3(pdev, state);
12202 break;
James Smartda0436e2009-05-22 14:51:39 -040012203 case LPFC_PCI_DEV_OC:
12204 rc = lpfc_io_error_detected_s4(pdev, state);
12205 break;
James Smart3772a992009-05-22 14:50:54 -040012206 default:
12207 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12208 "1427 Invalid PCI device group: 0x%x\n",
12209 phba->pci_dev_grp);
12210 break;
12211 }
12212 return rc;
12213}
12214
12215/**
12216 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
12217 * @pdev: pointer to PCI device.
12218 *
12219 * This routine is registered to the PCI subsystem for error handling. This
12220 * function is called after PCI bus has been reset to restart the PCI card
12221 * from scratch, as if from a cold-boot. When this routine is invoked, it
12222 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
12223 * routine, which will perform the proper device reset.
12224 *
12225 * Return codes
12226 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
12227 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
12228 **/
12229static pci_ers_result_t
12230lpfc_io_slot_reset(struct pci_dev *pdev)
12231{
12232 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12233 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12234 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
12235
12236 switch (phba->pci_dev_grp) {
12237 case LPFC_PCI_DEV_LP:
12238 rc = lpfc_io_slot_reset_s3(pdev);
12239 break;
James Smartda0436e2009-05-22 14:51:39 -040012240 case LPFC_PCI_DEV_OC:
12241 rc = lpfc_io_slot_reset_s4(pdev);
12242 break;
James Smart3772a992009-05-22 14:50:54 -040012243 default:
12244 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12245 "1428 Invalid PCI device group: 0x%x\n",
12246 phba->pci_dev_grp);
12247 break;
12248 }
12249 return rc;
12250}
12251
12252/**
12253 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
12254 * @pdev: pointer to PCI device
12255 *
12256 * This routine is registered to the PCI subsystem for error handling. It
12257 * is called when kernel error recovery tells the lpfc driver that it is
12258 * OK to resume normal PCI operation after PCI bus error recovery. When
12259 * this routine is invoked, it dispatches the action to the proper SLI-3
12260 * or SLI-4 device io_resume routine, which will resume the device operation.
12261 **/
12262static void
12263lpfc_io_resume(struct pci_dev *pdev)
12264{
12265 struct Scsi_Host *shost = pci_get_drvdata(pdev);
12266 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
12267
12268 switch (phba->pci_dev_grp) {
12269 case LPFC_PCI_DEV_LP:
12270 lpfc_io_resume_s3(pdev);
12271 break;
James Smartda0436e2009-05-22 14:51:39 -040012272 case LPFC_PCI_DEV_OC:
12273 lpfc_io_resume_s4(pdev);
12274 break;
James Smart3772a992009-05-22 14:50:54 -040012275 default:
12276 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
12277 "1429 Invalid PCI device group: 0x%x\n",
12278 phba->pci_dev_grp);
12279 break;
12280 }
12281 return;
12282}
12283
James Smart1ba981f2014-02-20 09:56:45 -050012284/**
12285 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
12286 * @phba: pointer to lpfc hba data structure.
12287 *
12288 * This routine checks to see if OAS is supported for this adapter. If
12289 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
12290 * the enable oas flag is cleared and the pool created for OAS device data
12291 * is destroyed.
12292 *
12293 **/
12294void
12295lpfc_sli4_oas_verify(struct lpfc_hba *phba)
12296{
12297
12298 if (!phba->cfg_EnableXLane)
12299 return;
12300
12301 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
12302 phba->cfg_fof = 1;
12303 } else {
James Smartf38fa0b2014-04-04 13:52:21 -040012304 phba->cfg_fof = 0;
James Smart1ba981f2014-02-20 09:56:45 -050012305 if (phba->device_data_mem_pool)
12306 mempool_destroy(phba->device_data_mem_pool);
12307 phba->device_data_mem_pool = NULL;
12308 }
12309
12310 return;
12311}
12312
12313/**
12314 * lpfc_fof_queue_setup - Set up all the fof queues
12315 * @phba: pointer to lpfc hba data structure.
12316 *
12317 * This routine is invoked to set up all the fof queues for the FC HBA
12318 * operation.
12319 *
12320 * Return codes
12321 * 0 - successful
12322 * -ENOMEM - No available memory
12323 **/
12324int
12325lpfc_fof_queue_setup(struct lpfc_hba *phba)
12326{
James Smart895427b2017-02-12 13:52:30 -080012327 struct lpfc_sli_ring *pring;
James Smart1ba981f2014-02-20 09:56:45 -050012328 int rc;
12329
12330 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
12331 if (rc)
12332 return -ENOMEM;
12333
James Smartf38fa0b2014-04-04 13:52:21 -040012334 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050012335
12336 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
12337 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
12338 if (rc)
12339 goto out_oas_cq;
12340
12341 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
12342 phba->sli4_hba.oas_cq, LPFC_FCP);
12343 if (rc)
12344 goto out_oas_wq;
12345
James Smart895427b2017-02-12 13:52:30 -080012346 /* Bind this CQ/WQ to the NVME ring */
12347 pring = phba->sli4_hba.oas_wq->pring;
12348 pring->sli.sli4.wqp =
12349 (void *)phba->sli4_hba.oas_wq;
12350 phba->sli4_hba.oas_cq->pring = pring;
James Smart1ba981f2014-02-20 09:56:45 -050012351 }
12352
12353 return 0;
12354
12355out_oas_wq:
James Smartf38fa0b2014-04-04 13:52:21 -040012356 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
James Smart1ba981f2014-02-20 09:56:45 -050012357out_oas_cq:
12358 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
12359 return rc;
12360
12361}
12362
12363/**
12364 * lpfc_fof_queue_create - Create all the fof queues
12365 * @phba: pointer to lpfc hba data structure.
12366 *
12367 * This routine is invoked to allocate all the fof queues for the FC HBA
12368 * operation. For each SLI4 queue type, the parameters such as queue entry
12369 * count (queue depth) shall be taken from the module parameter. For now,
12370 * we just use some constant number as place holder.
12371 *
12372 * Return codes
12373 * 0 - successful
12374 * -ENOMEM - No availble memory
12375 * -EIO - The mailbox failed to complete successfully.
12376 **/
12377int
12378lpfc_fof_queue_create(struct lpfc_hba *phba)
12379{
12380 struct lpfc_queue *qdesc;
James Smartc176ffa2018-01-30 15:58:46 -080012381 uint32_t wqesize;
James Smart1ba981f2014-02-20 09:56:45 -050012382
12383 /* Create FOF EQ */
James Smart81b96ed2017-11-20 16:00:29 -080012384 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE,
12385 phba->sli4_hba.eq_esize,
James Smart1ba981f2014-02-20 09:56:45 -050012386 phba->sli4_hba.eq_ecount);
12387 if (!qdesc)
12388 goto out_error;
12389
12390 phba->sli4_hba.fof_eq = qdesc;
12391
James Smartf38fa0b2014-04-04 13:52:21 -040012392 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050012393
12394 /* Create OAS CQ */
James Smartc176ffa2018-01-30 15:58:46 -080012395 if (phba->enab_exp_wqcq_pages)
James Smarta51e41b2017-12-08 17:18:06 -080012396 qdesc = lpfc_sli4_queue_alloc(phba,
12397 LPFC_EXPANDED_PAGE_SIZE,
12398 phba->sli4_hba.cq_esize,
12399 LPFC_CQE_EXP_COUNT);
12400 else
12401 qdesc = lpfc_sli4_queue_alloc(phba,
12402 LPFC_DEFAULT_PAGE_SIZE,
12403 phba->sli4_hba.cq_esize,
12404 phba->sli4_hba.cq_ecount);
James Smart1ba981f2014-02-20 09:56:45 -050012405 if (!qdesc)
12406 goto out_error;
12407
12408 phba->sli4_hba.oas_cq = qdesc;
12409
12410 /* Create OAS WQ */
James Smartc176ffa2018-01-30 15:58:46 -080012411 if (phba->enab_exp_wqcq_pages) {
12412 wqesize = (phba->fcp_embed_io) ?
12413 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
James Smarta51e41b2017-12-08 17:18:06 -080012414 qdesc = lpfc_sli4_queue_alloc(phba,
12415 LPFC_EXPANDED_PAGE_SIZE,
James Smartc176ffa2018-01-30 15:58:46 -080012416 wqesize,
James Smarta51e41b2017-12-08 17:18:06 -080012417 LPFC_WQE_EXP_COUNT);
James Smartc176ffa2018-01-30 15:58:46 -080012418 } else
James Smarta51e41b2017-12-08 17:18:06 -080012419 qdesc = lpfc_sli4_queue_alloc(phba,
12420 LPFC_DEFAULT_PAGE_SIZE,
12421 phba->sli4_hba.wq_esize,
12422 phba->sli4_hba.wq_ecount);
James Smartc176ffa2018-01-30 15:58:46 -080012423
James Smart1ba981f2014-02-20 09:56:45 -050012424 if (!qdesc)
12425 goto out_error;
12426
12427 phba->sli4_hba.oas_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -080012428 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
James Smart1ba981f2014-02-20 09:56:45 -050012429
12430 }
12431 return 0;
12432
12433out_error:
12434 lpfc_fof_queue_destroy(phba);
12435 return -ENOMEM;
12436}
12437
12438/**
12439 * lpfc_fof_queue_destroy - Destroy all the fof queues
12440 * @phba: pointer to lpfc hba data structure.
12441 *
12442 * This routine is invoked to release all the SLI4 queues with the FC HBA
12443 * operation.
12444 *
12445 * Return codes
12446 * 0 - successful
12447 **/
12448int
12449lpfc_fof_queue_destroy(struct lpfc_hba *phba)
12450{
12451 /* Release FOF Event queue */
12452 if (phba->sli4_hba.fof_eq != NULL) {
12453 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
12454 phba->sli4_hba.fof_eq = NULL;
12455 }
12456
12457 /* Release OAS Completion queue */
12458 if (phba->sli4_hba.oas_cq != NULL) {
12459 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
12460 phba->sli4_hba.oas_cq = NULL;
12461 }
12462
12463 /* Release OAS Work queue */
12464 if (phba->sli4_hba.oas_wq != NULL) {
12465 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
12466 phba->sli4_hba.oas_wq = NULL;
12467 }
12468 return 0;
12469}
12470
dea31012005-04-17 16:05:31 -050012471MODULE_DEVICE_TABLE(pci, lpfc_id_table);
12472
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070012473static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060012474 .error_detected = lpfc_io_error_detected,
12475 .slot_reset = lpfc_io_slot_reset,
12476 .resume = lpfc_io_resume,
12477};
12478
dea31012005-04-17 16:05:31 -050012479static struct pci_driver lpfc_driver = {
12480 .name = LPFC_DRIVER_NAME,
12481 .id_table = lpfc_id_table,
12482 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012483 .remove = lpfc_pci_remove_one,
Anton Blanchard85e8a232017-02-13 08:49:20 +110012484 .shutdown = lpfc_pci_remove_one,
James Smart3a55b532008-12-04 22:38:54 -050012485 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040012486 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050012487 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050012488};
12489
James Smart3ef6d242012-01-18 16:23:48 -050012490static const struct file_operations lpfc_mgmt_fop = {
Al Viro858feac2013-04-14 22:39:37 -040012491 .owner = THIS_MODULE,
James Smart3ef6d242012-01-18 16:23:48 -050012492};
12493
12494static struct miscdevice lpfc_mgmt_dev = {
12495 .minor = MISC_DYNAMIC_MINOR,
12496 .name = "lpfcmgmt",
12497 .fops = &lpfc_mgmt_fop,
12498};
12499
James Smarte59058c2008-08-24 21:49:00 -040012500/**
James Smart3621a712009-04-06 18:47:14 -040012501 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040012502 *
12503 * This routine is to be invoked when the lpfc module is loaded into the
12504 * kernel. The special kernel macro module_init() is used to indicate the
12505 * role of this routine to the kernel as lpfc module entry point.
12506 *
12507 * Return codes
12508 * 0 - successful
12509 * -ENOMEM - FC attach transport failed
12510 * all others - failed
12511 */
dea31012005-04-17 16:05:31 -050012512static int __init
12513lpfc_init(void)
12514{
12515 int error = 0;
12516
12517 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012518 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050012519
James Smart3ef6d242012-01-18 16:23:48 -050012520 error = misc_register(&lpfc_mgmt_dev);
12521 if (error)
12522 printk(KERN_ERR "Could not register lpfcmgmt device, "
12523 "misc_register returned with status %d", error);
12524
James Smart458c0832016-07-06 12:36:07 -070012525 lpfc_transport_functions.vport_create = lpfc_vport_create;
12526 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
dea31012005-04-17 16:05:31 -050012527 lpfc_transport_template =
12528 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040012529 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050012530 return -ENOMEM;
James Smart458c0832016-07-06 12:36:07 -070012531 lpfc_vport_transport_template =
12532 fc_attach_transport(&lpfc_vport_transport_functions);
12533 if (lpfc_vport_transport_template == NULL) {
12534 fc_release_transport(lpfc_transport_template);
12535 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040012536 }
James Smart7bb03bb2013-04-17 20:19:16 -040012537
12538 /* Initialize in case vector mapping is needed */
James Smartb246de12013-05-31 17:03:07 -040012539 lpfc_used_cpu = NULL;
James Smart2ea259e2017-02-12 13:52:27 -080012540 lpfc_present_cpu = num_present_cpus();
James Smart7bb03bb2013-04-17 20:19:16 -040012541
dea31012005-04-17 16:05:31 -050012542 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050012543 if (error) {
dea31012005-04-17 16:05:31 -050012544 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070012545 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050012546 }
dea31012005-04-17 16:05:31 -050012547
12548 return error;
12549}
12550
James Smarte59058c2008-08-24 21:49:00 -040012551/**
James Smart3621a712009-04-06 18:47:14 -040012552 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040012553 *
12554 * This routine is invoked when the lpfc module is removed from the kernel.
12555 * The special kernel macro module_exit() is used to indicate the role of
12556 * this routine to the kernel as lpfc module exit point.
12557 */
dea31012005-04-17 16:05:31 -050012558static void __exit
12559lpfc_exit(void)
12560{
James Smart3ef6d242012-01-18 16:23:48 -050012561 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050012562 pci_unregister_driver(&lpfc_driver);
12563 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070012564 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050012565 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040012566 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
12567 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050012568 (1L << _dump_buf_data_order), _dump_buf_data);
12569 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
12570 }
12571
12572 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040012573 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
12574 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050012575 (1L << _dump_buf_dif_order), _dump_buf_dif);
12576 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
12577 }
James Smartb246de12013-05-31 17:03:07 -040012578 kfree(lpfc_used_cpu);
Johannes Thumshirn79739672015-08-31 16:48:11 -040012579 idr_destroy(&lpfc_hba_index);
dea31012005-04-17 16:05:31 -050012580}
12581
12582module_init(lpfc_init);
12583module_exit(lpfc_exit);
12584MODULE_LICENSE("GPL");
12585MODULE_DESCRIPTION(LPFC_MODULE_DESC);
James Smartd080abe2017-02-12 13:52:39 -080012586MODULE_AUTHOR("Broadcom");
dea31012005-04-17 16:05:31 -050012587MODULE_VERSION("0:" LPFC_DRIVER_VERSION);