blob: 4138d6155a4fd01836bcecd549b7921907e7bf95 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartd080abe2017-02-12 13:52:39 -08004 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
James Smart50611572016-03-31 14:12:34 -07006 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * EMULEX and SLI are trademarks of Emulex. *
James Smartd080abe2017-02-12 13:52:39 -08008 * www.broadcom.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04009 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -050010 * *
11 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
dea31012005-04-17 16:05:31 -050022 *******************************************************************/
23
dea31012005-04-17 16:05:31 -050024#include <linux/blkdev.h>
25#include <linux/delay.h>
26#include <linux/dma-mapping.h>
27#include <linux/idr.h>
28#include <linux/interrupt.h>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040029#include <linux/module.h>
dea31012005-04-17 16:05:31 -050030#include <linux/kthread.h>
31#include <linux/pci.h>
32#include <linux/spinlock.h>
James Smart92d7f7b2007-06-17 19:56:38 -050033#include <linux/ctype.h>
James Smart0d878412009-10-02 15:16:56 -040034#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
James Smart52d52442011-05-24 11:42:45 -040036#include <linux/firmware.h>
James Smart3ef6d242012-01-18 16:23:48 -050037#include <linux/miscdevice.h>
James Smart7bb03bb2013-04-17 20:19:16 -040038#include <linux/percpu.h>
James Smart895427b2017-02-12 13:52:30 -080039#include <linux/msi.h>
dea31012005-04-17 16:05:31 -050040
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040041#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050042#include <scsi/scsi_device.h>
43#include <scsi/scsi_host.h>
44#include <scsi/scsi_transport_fc.h>
45
James Smartda0436e2009-05-22 14:51:39 -040046#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050047#include "lpfc_hw.h"
48#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040049#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040050#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050051#include "lpfc_disc.h"
dea31012005-04-17 16:05:31 -050052#include "lpfc.h"
James Smart895427b2017-02-12 13:52:30 -080053#include "lpfc_scsi.h"
54#include "lpfc_nvme.h"
dea31012005-04-17 16:05:31 -050055#include "lpfc_logmsg.h"
56#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050057#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050058#include "lpfc_version.h"
James Smart12f44452016-07-06 12:36:03 -070059#include "lpfc_ids.h"
dea31012005-04-17 16:05:31 -050060
James Smart81301a92008-12-04 22:39:46 -050061char *_dump_buf_data;
62unsigned long _dump_buf_data_order;
63char *_dump_buf_dif;
64unsigned long _dump_buf_dif_order;
65spinlock_t _dump_buf_lock;
66
James Smart7bb03bb2013-04-17 20:19:16 -040067/* Used when mapping IRQ vectors in a driver centric manner */
James Smartb246de12013-05-31 17:03:07 -040068uint16_t *lpfc_used_cpu;
69uint32_t lpfc_present_cpu;
James Smart7bb03bb2013-04-17 20:19:16 -040070
dea31012005-04-17 16:05:31 -050071static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
72static int lpfc_post_rcv_buf(struct lpfc_hba *);
James Smart5350d872011-10-10 21:33:49 -040073static int lpfc_sli4_queue_verify(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040074static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
75static int lpfc_setup_endian_order(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040076static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040077static void lpfc_free_els_sgl_list(struct lpfc_hba *);
James Smartf358dd02017-02-12 13:52:34 -080078static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040079static void lpfc_init_sgl_list(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040080static int lpfc_init_active_sgl_array(struct lpfc_hba *);
81static void lpfc_free_active_sgl(struct lpfc_hba *);
82static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
83static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
84static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
85static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
86static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
James Smart618a5232012-06-12 13:54:36 -040087static void lpfc_sli4_disable_intr(struct lpfc_hba *);
88static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
James Smart1ba981f2014-02-20 09:56:45 -050089static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
dea31012005-04-17 16:05:31 -050090
91static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050092static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -050093static DEFINE_IDR(lpfc_hba_index);
James Smartf358dd02017-02-12 13:52:34 -080094#define LPFC_NVMET_BUF_POST 254
dea31012005-04-17 16:05:31 -050095
James Smarte59058c2008-08-24 21:49:00 -040096/**
James Smart3621a712009-04-06 18:47:14 -040097 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
James Smarte59058c2008-08-24 21:49:00 -040098 * @phba: pointer to lpfc hba data structure.
99 *
100 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
101 * mailbox command. It retrieves the revision information from the HBA and
102 * collects the Vital Product Data (VPD) about the HBA for preparing the
103 * configuration of the HBA.
104 *
105 * Return codes:
106 * 0 - success.
107 * -ERESTART - requests the SLI layer to reset the HBA and try again.
108 * Any other value - indicates an error.
109 **/
dea31012005-04-17 16:05:31 -0500110int
James Smart2e0fef82007-06-17 19:56:36 -0500111lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500112{
113 lpfc_vpd_t *vp = &phba->vpd;
114 int i = 0, rc;
115 LPFC_MBOXQ_t *pmb;
116 MAILBOX_t *mb;
117 char *lpfc_vpd_data = NULL;
118 uint16_t offset = 0;
119 static char licensed[56] =
120 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -0400121 static int init_key = 1;
dea31012005-04-17 16:05:31 -0500122
123 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
124 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500125 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500126 return -ENOMEM;
127 }
128
James Smart04c68492009-05-22 14:52:52 -0400129 mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -0500130 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -0500131
132 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -0400133 if (init_key) {
134 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -0500135
James Smart65a29c12006-07-06 15:50:50 -0400136 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
137 *ptext = cpu_to_be32(*ptext);
138 init_key = 0;
139 }
dea31012005-04-17 16:05:31 -0500140
141 lpfc_read_nv(phba, pmb);
142 memset((char*)mb->un.varRDnvp.rsvd3, 0,
143 sizeof (mb->un.varRDnvp.rsvd3));
144 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
145 sizeof (licensed));
146
147 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
148
149 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500150 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400151 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500152 "error, mbxCmd x%x READ_NVPARM, "
153 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500154 mb->mbxCommand, mb->mbxStatus);
155 mempool_free(pmb, phba->mbox_mem_pool);
156 return -ERESTART;
157 }
158 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500159 sizeof(phba->wwnn));
160 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
161 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500162 }
163
James Smart92d7f7b2007-06-17 19:56:38 -0500164 phba->sli3_options = 0x0;
165
dea31012005-04-17 16:05:31 -0500166 /* Setup and issue mailbox READ REV command */
167 lpfc_read_rev(phba, pmb);
168 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
169 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500170 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400171 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500172 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500173 mb->mbxCommand, mb->mbxStatus);
174 mempool_free( pmb, phba->mbox_mem_pool);
175 return -ERESTART;
176 }
177
James Smart92d7f7b2007-06-17 19:56:38 -0500178
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500179 /*
180 * The value of rr must be 1 since the driver set the cv field to 1.
181 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500182 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500183 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500184 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500185 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400186 "0440 Adapter failed to init, READ_REV has "
187 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500188 mempool_free(pmb, phba->mbox_mem_pool);
189 return -ERESTART;
dea31012005-04-17 16:05:31 -0500190 }
191
James Smart495a7142008-06-14 22:52:59 -0400192 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
193 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500194 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400195 }
James Smarted957682007-06-17 19:56:37 -0500196
dea31012005-04-17 16:05:31 -0500197 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500198 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500199 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500200 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
201 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
202 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
203 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500204 vp->rev.biuRev = mb->un.varRdRev.biuRev;
205 vp->rev.smRev = mb->un.varRdRev.smRev;
206 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
207 vp->rev.endecRev = mb->un.varRdRev.endecRev;
208 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
209 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
210 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
211 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
212 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
213 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
214
James Smart92d7f7b2007-06-17 19:56:38 -0500215 /* If the sli feature level is less then 9, we must
216 * tear down all RPIs and VPIs on link down if NPIV
217 * is enabled.
218 */
219 if (vp->rev.feaLevelHigh < 9)
220 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
221
dea31012005-04-17 16:05:31 -0500222 if (lpfc_is_LC_HBA(phba->pcidev->device))
223 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
224 sizeof (phba->RandomData));
225
dea31012005-04-17 16:05:31 -0500226 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500227 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
228 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400229 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500230 do {
James Smarta0c87cb2009-07-19 10:01:10 -0400231 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
dea31012005-04-17 16:05:31 -0500232 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
233
234 if (rc != MBX_SUCCESS) {
235 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400236 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500237 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500238 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500239 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500240 }
James Smart04c68492009-05-22 14:52:52 -0400241 /* dump mem may return a zero when finished or we got a
242 * mailbox error, either way we are done.
243 */
244 if (mb->un.varDmp.word_cnt == 0)
245 break;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500246 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
247 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400248 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
249 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500250 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500251 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500252 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
253 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500254
255 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500256out_free_mbox:
257 mempool_free(pmb, phba->mbox_mem_pool);
258 return 0;
259}
260
James Smarte59058c2008-08-24 21:49:00 -0400261/**
James Smart3621a712009-04-06 18:47:14 -0400262 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
James Smarte59058c2008-08-24 21:49:00 -0400263 * @phba: pointer to lpfc hba data structure.
264 * @pmboxq: pointer to the driver internal queue element for mailbox command.
265 *
266 * This is the completion handler for driver's configuring asynchronous event
267 * mailbox command to the device. If the mailbox command returns successfully,
268 * it will set internal async event support flag to 1; otherwise, it will
269 * set internal async event support flag to 0.
270 **/
James Smart57127f12007-10-27 13:37:05 -0400271static void
272lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
273{
James Smart04c68492009-05-22 14:52:52 -0400274 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
James Smart57127f12007-10-27 13:37:05 -0400275 phba->temp_sensor_support = 1;
276 else
277 phba->temp_sensor_support = 0;
278 mempool_free(pmboxq, phba->mbox_mem_pool);
279 return;
280}
281
James Smarte59058c2008-08-24 21:49:00 -0400282/**
James Smart3621a712009-04-06 18:47:14 -0400283 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
James Smart97207482008-12-04 22:39:19 -0500284 * @phba: pointer to lpfc hba data structure.
285 * @pmboxq: pointer to the driver internal queue element for mailbox command.
286 *
287 * This is the completion handler for dump mailbox command for getting
288 * wake up parameters. When this command complete, the response contain
289 * Option rom version of the HBA. This function translate the version number
290 * into a human readable string and store it in OptionROMVersion.
291 **/
292static void
293lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
294{
295 struct prog_id *prg;
296 uint32_t prog_id_word;
297 char dist = ' ';
298 /* character array used for decoding dist type. */
299 char dist_char[] = "nabx";
300
James Smart04c68492009-05-22 14:52:52 -0400301 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
James Smart9f1e1b52008-12-04 22:39:40 -0500302 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500303 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500304 }
James Smart97207482008-12-04 22:39:19 -0500305
306 prg = (struct prog_id *) &prog_id_word;
307
308 /* word 7 contain option rom version */
James Smart04c68492009-05-22 14:52:52 -0400309 prog_id_word = pmboxq->u.mb.un.varWords[7];
James Smart97207482008-12-04 22:39:19 -0500310
311 /* Decode the Option rom version word to a readable string */
312 if (prg->dist < 4)
313 dist = dist_char[prg->dist];
314
315 if ((prg->dist == 3) && (prg->num == 0))
James Smarta2fc4aef2014-09-03 12:57:55 -0400316 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
James Smart97207482008-12-04 22:39:19 -0500317 prg->ver, prg->rev, prg->lev);
318 else
James Smarta2fc4aef2014-09-03 12:57:55 -0400319 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
James Smart97207482008-12-04 22:39:19 -0500320 prg->ver, prg->rev, prg->lev,
321 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500322 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500323 return;
324}
325
326/**
James Smart05580562011-05-24 11:40:48 -0400327 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
328 * cfg_soft_wwnn, cfg_soft_wwpn
329 * @vport: pointer to lpfc vport data structure.
330 *
331 *
332 * Return codes
333 * None.
334 **/
335void
336lpfc_update_vport_wwn(struct lpfc_vport *vport)
337{
James Smartaeb3c812017-04-21 16:05:02 -0700338 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
339 u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0];
340
James Smart05580562011-05-24 11:40:48 -0400341 /* If the soft name exists then update it using the service params */
342 if (vport->phba->cfg_soft_wwnn)
343 u64_to_wwn(vport->phba->cfg_soft_wwnn,
344 vport->fc_sparam.nodeName.u.wwn);
345 if (vport->phba->cfg_soft_wwpn)
346 u64_to_wwn(vport->phba->cfg_soft_wwpn,
347 vport->fc_sparam.portName.u.wwn);
348
349 /*
350 * If the name is empty or there exists a soft name
351 * then copy the service params name, otherwise use the fc name
352 */
353 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
354 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
355 sizeof(struct lpfc_name));
356 else
357 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
358 sizeof(struct lpfc_name));
359
James Smartaeb3c812017-04-21 16:05:02 -0700360 /*
361 * If the port name has changed, then set the Param changes flag
362 * to unreg the login
363 */
364 if (vport->fc_portname.u.wwn[0] != 0 &&
365 memcmp(&vport->fc_portname, &vport->fc_sparam.portName,
366 sizeof(struct lpfc_name)))
367 vport->vport_flag |= FAWWPN_PARAM_CHG;
368
369 if (vport->fc_portname.u.wwn[0] == 0 ||
370 vport->phba->cfg_soft_wwpn ||
371 (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) ||
372 vport->vport_flag & FAWWPN_SET) {
James Smart05580562011-05-24 11:40:48 -0400373 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
374 sizeof(struct lpfc_name));
James Smartaeb3c812017-04-21 16:05:02 -0700375 vport->vport_flag &= ~FAWWPN_SET;
376 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR)
377 vport->vport_flag |= FAWWPN_SET;
378 }
James Smart05580562011-05-24 11:40:48 -0400379 else
380 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
381 sizeof(struct lpfc_name));
382}
383
384/**
James Smart3621a712009-04-06 18:47:14 -0400385 * lpfc_config_port_post - Perform lpfc initialization after config port
James Smarte59058c2008-08-24 21:49:00 -0400386 * @phba: pointer to lpfc hba data structure.
387 *
388 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
389 * command call. It performs all internal resource and state setups on the
390 * port: post IOCB buffers, enable appropriate host interrupt attentions,
391 * ELS ring timers, etc.
392 *
393 * Return codes
394 * 0 - success.
395 * Any other value - error.
396 **/
dea31012005-04-17 16:05:31 -0500397int
James Smart2e0fef82007-06-17 19:56:36 -0500398lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500399{
James Smart2e0fef82007-06-17 19:56:36 -0500400 struct lpfc_vport *vport = phba->pport;
James Smarta257bf92009-04-06 18:48:10 -0400401 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500402 LPFC_MBOXQ_t *pmb;
403 MAILBOX_t *mb;
404 struct lpfc_dmabuf *mp;
405 struct lpfc_sli *psli = &phba->sli;
406 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500407 int i, j;
408 int rc;
dea31012005-04-17 16:05:31 -0500409
James Smart7af67052007-10-27 13:38:11 -0400410 spin_lock_irq(&phba->hbalock);
411 /*
412 * If the Config port completed correctly the HBA is not
413 * over heated any more.
414 */
415 if (phba->over_temp_state == HBA_OVER_TEMP)
416 phba->over_temp_state = HBA_NORMAL_TEMP;
417 spin_unlock_irq(&phba->hbalock);
418
dea31012005-04-17 16:05:31 -0500419 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
420 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500421 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500422 return -ENOMEM;
423 }
James Smart04c68492009-05-22 14:52:52 -0400424 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500425
dea31012005-04-17 16:05:31 -0500426 /* Get login parameters for NID. */
James Smart9f1177a2010-02-26 14:12:57 -0500427 rc = lpfc_read_sparam(phba, pmb, 0);
428 if (rc) {
429 mempool_free(pmb, phba->mbox_mem_pool);
430 return -ENOMEM;
431 }
432
James Smarted957682007-06-17 19:56:37 -0500433 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500434 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500435 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400436 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500437 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500438 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500439 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500440 mp = (struct lpfc_dmabuf *) pmb->context1;
James Smart9f1177a2010-02-26 14:12:57 -0500441 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500442 lpfc_mbuf_free(phba, mp->virt, mp->phys);
443 kfree(mp);
444 return -EIO;
445 }
446
447 mp = (struct lpfc_dmabuf *) pmb->context1;
448
James Smart2e0fef82007-06-17 19:56:36 -0500449 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500450 lpfc_mbuf_free(phba, mp->virt, mp->phys);
451 kfree(mp);
452 pmb->context1 = NULL;
James Smart05580562011-05-24 11:40:48 -0400453 lpfc_update_vport_wwn(vport);
James Smarta257bf92009-04-06 18:48:10 -0400454
455 /* Update the fc_host data structures with new wwn. */
456 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
457 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart21e9a0a2009-05-22 14:53:21 -0400458 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smarta257bf92009-04-06 18:48:10 -0400459
dea31012005-04-17 16:05:31 -0500460 /* If no serial number in VPD data, use low 6 bytes of WWNN */
461 /* This should be consolidated into parse_vpd ? - mr */
462 if (phba->SerialNumber[0] == 0) {
463 uint8_t *outptr;
464
James Smart2e0fef82007-06-17 19:56:36 -0500465 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500466 for (i = 0; i < 12; i++) {
467 status = *outptr++;
468 j = ((status & 0xf0) >> 4);
469 if (j <= 9)
470 phba->SerialNumber[i] =
471 (char)((uint8_t) 0x30 + (uint8_t) j);
472 else
473 phba->SerialNumber[i] =
474 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
475 i++;
476 j = (status & 0xf);
477 if (j <= 9)
478 phba->SerialNumber[i] =
479 (char)((uint8_t) 0x30 + (uint8_t) j);
480 else
481 phba->SerialNumber[i] =
482 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
483 }
484 }
485
dea31012005-04-17 16:05:31 -0500486 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500487 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500488 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500489 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400490 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500491 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500492 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500493 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500494 mempool_free( pmb, phba->mbox_mem_pool);
495 return -EIO;
496 }
497
James Smarta0c87cb2009-07-19 10:01:10 -0400498 /* Check if the port is disabled */
499 lpfc_sli_read_link_ste(phba);
500
dea31012005-04-17 16:05:31 -0500501 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -0400502 i = (mb->un.varRdConfig.max_xri + 1);
503 if (phba->cfg_hba_queue_depth > i) {
504 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
505 "3359 HBA queue depth changed from %d to %d\n",
506 phba->cfg_hba_queue_depth, i);
507 phba->cfg_hba_queue_depth = i;
508 }
509
510 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
511 i = (mb->un.varRdConfig.max_xri >> 3);
512 if (phba->pport->cfg_lun_queue_depth > i) {
513 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
514 "3360 LUN queue depth changed from %d to %d\n",
515 phba->pport->cfg_lun_queue_depth, i);
516 phba->pport->cfg_lun_queue_depth = i;
517 }
dea31012005-04-17 16:05:31 -0500518
519 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500520
521 /* Get the default values for Model Name and Description */
522 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
523
James Smart2e0fef82007-06-17 19:56:36 -0500524 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500525
James Smart0b727fe2007-10-27 13:37:25 -0400526 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smart895427b2017-02-12 13:52:30 -0800527 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
528 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
529 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
530 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500531
532 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500533 if (phba->sli_rev != 3)
534 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500535
James Smart93996272008-08-24 21:50:30 -0400536 /*
537 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
538 */
539 if (phba->intr_type == MSIX) {
540 rc = lpfc_config_msi(phba, pmb);
541 if (rc) {
542 mempool_free(pmb, phba->mbox_mem_pool);
543 return -EIO;
544 }
545 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
546 if (rc != MBX_SUCCESS) {
547 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
548 "0352 Config MSI mailbox command "
549 "failed, mbxCmd x%x, mbxStatus x%x\n",
James Smart04c68492009-05-22 14:52:52 -0400550 pmb->u.mb.mbxCommand,
551 pmb->u.mb.mbxStatus);
James Smart93996272008-08-24 21:50:30 -0400552 mempool_free(pmb, phba->mbox_mem_pool);
553 return -EIO;
554 }
555 }
556
James Smart04c68492009-05-22 14:52:52 -0400557 spin_lock_irq(&phba->hbalock);
James Smart93996272008-08-24 21:50:30 -0400558 /* Initialize ERATT handling flag */
559 phba->hba_flag &= ~HBA_ERATT_HANDLED;
560
dea31012005-04-17 16:05:31 -0500561 /* Enable appropriate host interrupts */
James Smart9940b972011-03-11 16:06:12 -0500562 if (lpfc_readl(phba->HCregaddr, &status)) {
563 spin_unlock_irq(&phba->hbalock);
564 return -EIO;
565 }
dea31012005-04-17 16:05:31 -0500566 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
567 if (psli->num_rings > 0)
568 status |= HC_R0INT_ENA;
569 if (psli->num_rings > 1)
570 status |= HC_R1INT_ENA;
571 if (psli->num_rings > 2)
572 status |= HC_R2INT_ENA;
573 if (psli->num_rings > 3)
574 status |= HC_R3INT_ENA;
575
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500576 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
577 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400578 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500579
dea31012005-04-17 16:05:31 -0500580 writel(status, phba->HCregaddr);
581 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500582 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500583
James Smart93996272008-08-24 21:50:30 -0400584 /* Set up ring-0 (ELS) timer */
585 timeout = phba->fc_ratov * 2;
James Smart256ec0d2013-04-17 20:14:58 -0400586 mod_timer(&vport->els_tmofunc,
587 jiffies + msecs_to_jiffies(1000 * timeout));
James Smart93996272008-08-24 21:50:30 -0400588 /* Set up heart beat (HB) timer */
James Smart256ec0d2013-04-17 20:14:58 -0400589 mod_timer(&phba->hb_tmofunc,
590 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -0500591 phba->hb_outstanding = 0;
592 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400593 /* Set up error attention (ERATT) polling timer */
James Smart256ec0d2013-04-17 20:14:58 -0400594 mod_timer(&phba->eratt_poll,
James Smart65791f12016-07-06 12:35:56 -0700595 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
dea31012005-04-17 16:05:31 -0500596
James Smarta0c87cb2009-07-19 10:01:10 -0400597 if (phba->hba_flag & LINK_DISABLED) {
598 lpfc_printf_log(phba,
599 KERN_ERR, LOG_INIT,
600 "2598 Adapter Link is disabled.\n");
601 lpfc_down_link(phba, pmb);
602 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
603 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
604 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
605 lpfc_printf_log(phba,
606 KERN_ERR, LOG_INIT,
607 "2599 Adapter failed to issue DOWN_LINK"
608 " mbox command rc 0x%x\n", rc);
609
610 mempool_free(pmb, phba->mbox_mem_pool);
611 return -EIO;
612 }
James Smarte40a02c2010-02-26 14:13:54 -0500613 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
James Smart026abb82011-12-13 13:20:45 -0500614 mempool_free(pmb, phba->mbox_mem_pool);
615 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
616 if (rc)
617 return rc;
dea31012005-04-17 16:05:31 -0500618 }
619 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400620 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500621 if (!pmb) {
622 phba->link_state = LPFC_HBA_ERROR;
623 return -ENOMEM;
624 }
625
James Smart57127f12007-10-27 13:37:05 -0400626 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
627 pmb->mbox_cmpl = lpfc_config_async_cmpl;
628 pmb->vport = phba->pport;
629 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500630
James Smart57127f12007-10-27 13:37:05 -0400631 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
632 lpfc_printf_log(phba,
633 KERN_ERR,
634 LOG_INIT,
635 "0456 Adapter failed to issue "
James Smarte4e74272009-07-19 10:01:38 -0400636 "ASYNCEVT_ENABLE mbox status x%x\n",
James Smart57127f12007-10-27 13:37:05 -0400637 rc);
638 mempool_free(pmb, phba->mbox_mem_pool);
639 }
James Smart97207482008-12-04 22:39:19 -0500640
641 /* Get Option rom version */
642 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500643 if (!pmb) {
644 phba->link_state = LPFC_HBA_ERROR;
645 return -ENOMEM;
646 }
647
James Smart97207482008-12-04 22:39:19 -0500648 lpfc_dump_wakeup_param(phba, pmb);
649 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
650 pmb->vport = phba->pport;
651 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
652
653 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
654 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
James Smarte4e74272009-07-19 10:01:38 -0400655 "to get Option ROM version status x%x\n", rc);
James Smart97207482008-12-04 22:39:19 -0500656 mempool_free(pmb, phba->mbox_mem_pool);
657 }
658
James Smartd7c255b2008-08-24 21:50:00 -0400659 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400660}
661
James Smarte59058c2008-08-24 21:49:00 -0400662/**
James Smart84d1b002010-02-12 14:42:33 -0500663 * lpfc_hba_init_link - Initialize the FC link
664 * @phba: pointer to lpfc hba data structure.
James Smart6e7288d2010-06-07 15:23:35 -0400665 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500666 *
667 * This routine will issue the INIT_LINK mailbox command call.
668 * It is available to other drivers through the lpfc_hba data
669 * structure for use as a delayed link up mechanism with the
670 * module parameter lpfc_suppress_link_up.
671 *
672 * Return code
673 * 0 - success
674 * Any other value - error
675 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400676static int
James Smart6e7288d2010-06-07 15:23:35 -0400677lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500678{
James Smart1b511972011-12-13 13:23:09 -0500679 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
680}
681
682/**
683 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
684 * @phba: pointer to lpfc hba data structure.
685 * @fc_topology: desired fc topology.
686 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
687 *
688 * This routine will issue the INIT_LINK mailbox command call.
689 * It is available to other drivers through the lpfc_hba data
690 * structure for use as a delayed link up mechanism with the
691 * module parameter lpfc_suppress_link_up.
692 *
693 * Return code
694 * 0 - success
695 * Any other value - error
696 **/
697int
698lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
699 uint32_t flag)
700{
James Smart84d1b002010-02-12 14:42:33 -0500701 struct lpfc_vport *vport = phba->pport;
702 LPFC_MBOXQ_t *pmb;
703 MAILBOX_t *mb;
704 int rc;
705
706 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
707 if (!pmb) {
708 phba->link_state = LPFC_HBA_ERROR;
709 return -ENOMEM;
710 }
711 mb = &pmb->u.mb;
712 pmb->vport = vport;
713
James Smart026abb82011-12-13 13:20:45 -0500714 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
715 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
716 !(phba->lmt & LMT_1Gb)) ||
717 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
718 !(phba->lmt & LMT_2Gb)) ||
719 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
720 !(phba->lmt & LMT_4Gb)) ||
721 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
722 !(phba->lmt & LMT_8Gb)) ||
723 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
724 !(phba->lmt & LMT_10Gb)) ||
725 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
James Smartd38dd522015-08-31 16:48:17 -0400726 !(phba->lmt & LMT_16Gb)) ||
727 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
728 !(phba->lmt & LMT_32Gb))) {
James Smart026abb82011-12-13 13:20:45 -0500729 /* Reset link speed to auto */
730 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
731 "1302 Invalid speed for this board:%d "
732 "Reset link speed to auto.\n",
733 phba->cfg_link_speed);
734 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
735 }
James Smart1b511972011-12-13 13:23:09 -0500736 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
James Smart84d1b002010-02-12 14:42:33 -0500737 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart1b511972011-12-13 13:23:09 -0500738 if (phba->sli_rev < LPFC_SLI_REV4)
739 lpfc_set_loopback_flag(phba);
James Smart6e7288d2010-06-07 15:23:35 -0400740 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart76a95d72010-11-20 23:11:48 -0500741 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
James Smart84d1b002010-02-12 14:42:33 -0500742 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
743 "0498 Adapter failed to init, mbxCmd x%x "
744 "INIT_LINK, mbxStatus x%x\n",
745 mb->mbxCommand, mb->mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -0500746 if (phba->sli_rev <= LPFC_SLI_REV3) {
747 /* Clear all interrupt enable conditions */
748 writel(0, phba->HCregaddr);
749 readl(phba->HCregaddr); /* flush */
750 /* Clear all pending interrupts */
751 writel(0xffffffff, phba->HAregaddr);
752 readl(phba->HAregaddr); /* flush */
753 }
James Smart84d1b002010-02-12 14:42:33 -0500754 phba->link_state = LPFC_HBA_ERROR;
James Smart6e7288d2010-06-07 15:23:35 -0400755 if (rc != MBX_BUSY || flag == MBX_POLL)
James Smart84d1b002010-02-12 14:42:33 -0500756 mempool_free(pmb, phba->mbox_mem_pool);
757 return -EIO;
758 }
James Smarte40a02c2010-02-26 14:13:54 -0500759 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
James Smart6e7288d2010-06-07 15:23:35 -0400760 if (flag == MBX_POLL)
761 mempool_free(pmb, phba->mbox_mem_pool);
James Smart84d1b002010-02-12 14:42:33 -0500762
763 return 0;
764}
765
766/**
767 * lpfc_hba_down_link - this routine downs the FC link
James Smart6e7288d2010-06-07 15:23:35 -0400768 * @phba: pointer to lpfc hba data structure.
769 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500770 *
771 * This routine will issue the DOWN_LINK mailbox command call.
772 * It is available to other drivers through the lpfc_hba data
773 * structure for use to stop the link.
774 *
775 * Return code
776 * 0 - success
777 * Any other value - error
778 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400779static int
James Smart6e7288d2010-06-07 15:23:35 -0400780lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500781{
782 LPFC_MBOXQ_t *pmb;
783 int rc;
784
785 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
786 if (!pmb) {
787 phba->link_state = LPFC_HBA_ERROR;
788 return -ENOMEM;
789 }
790
791 lpfc_printf_log(phba,
792 KERN_ERR, LOG_INIT,
793 "0491 Adapter Link is disabled.\n");
794 lpfc_down_link(phba, pmb);
795 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart6e7288d2010-06-07 15:23:35 -0400796 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart84d1b002010-02-12 14:42:33 -0500797 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
798 lpfc_printf_log(phba,
799 KERN_ERR, LOG_INIT,
800 "2522 Adapter failed to issue DOWN_LINK"
801 " mbox command rc 0x%x\n", rc);
802
803 mempool_free(pmb, phba->mbox_mem_pool);
804 return -EIO;
805 }
James Smart6e7288d2010-06-07 15:23:35 -0400806 if (flag == MBX_POLL)
807 mempool_free(pmb, phba->mbox_mem_pool);
808
James Smart84d1b002010-02-12 14:42:33 -0500809 return 0;
810}
811
812/**
James Smart3621a712009-04-06 18:47:14 -0400813 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400814 * @phba: pointer to lpfc HBA data structure.
815 *
816 * This routine will do LPFC uninitialization before the HBA is reset when
817 * bringing down the SLI Layer.
818 *
819 * Return codes
820 * 0 - success.
821 * Any other value - error.
822 **/
dea31012005-04-17 16:05:31 -0500823int
James Smart2e0fef82007-06-17 19:56:36 -0500824lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500825{
James Smart1b32f6a2008-02-08 18:49:39 -0500826 struct lpfc_vport **vports;
827 int i;
James Smart3772a992009-05-22 14:50:54 -0400828
829 if (phba->sli_rev <= LPFC_SLI_REV3) {
830 /* Disable interrupts */
831 writel(0, phba->HCregaddr);
832 readl(phba->HCregaddr); /* flush */
833 }
dea31012005-04-17 16:05:31 -0500834
James Smart1b32f6a2008-02-08 18:49:39 -0500835 if (phba->pport->load_flag & FC_UNLOADING)
836 lpfc_cleanup_discovery_resources(phba->pport);
837 else {
838 vports = lpfc_create_vport_work_array(phba);
839 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -0400840 for (i = 0; i <= phba->max_vports &&
841 vports[i] != NULL; i++)
James Smart1b32f6a2008-02-08 18:49:39 -0500842 lpfc_cleanup_discovery_resources(vports[i]);
843 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500844 }
845 return 0;
dea31012005-04-17 16:05:31 -0500846}
847
James Smarte59058c2008-08-24 21:49:00 -0400848/**
James Smart68e814f2014-05-21 08:04:59 -0400849 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
850 * rspiocb which got deferred
851 *
852 * @phba: pointer to lpfc HBA data structure.
853 *
854 * This routine will cleanup completed slow path events after HBA is reset
855 * when bringing down the SLI Layer.
856 *
857 *
858 * Return codes
859 * void.
860 **/
861static void
862lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
863{
864 struct lpfc_iocbq *rspiocbq;
865 struct hbq_dmabuf *dmabuf;
866 struct lpfc_cq_event *cq_event;
867
868 spin_lock_irq(&phba->hbalock);
869 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
870 spin_unlock_irq(&phba->hbalock);
871
872 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
873 /* Get the response iocb from the head of work queue */
874 spin_lock_irq(&phba->hbalock);
875 list_remove_head(&phba->sli4_hba.sp_queue_event,
876 cq_event, struct lpfc_cq_event, list);
877 spin_unlock_irq(&phba->hbalock);
878
879 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
880 case CQE_CODE_COMPL_WQE:
881 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
882 cq_event);
883 lpfc_sli_release_iocbq(phba, rspiocbq);
884 break;
885 case CQE_CODE_RECEIVE:
886 case CQE_CODE_RECEIVE_V1:
887 dmabuf = container_of(cq_event, struct hbq_dmabuf,
888 cq_event);
889 lpfc_in_buf_free(phba, &dmabuf->dbuf);
890 }
891 }
892}
893
894/**
James Smartbcece5f2014-04-04 13:51:34 -0400895 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
896 * @phba: pointer to lpfc HBA data structure.
897 *
898 * This routine will cleanup posted ELS buffers after the HBA is reset
899 * when bringing down the SLI Layer.
900 *
901 *
902 * Return codes
903 * void.
904 **/
905static void
906lpfc_hba_free_post_buf(struct lpfc_hba *phba)
907{
908 struct lpfc_sli *psli = &phba->sli;
909 struct lpfc_sli_ring *pring;
910 struct lpfc_dmabuf *mp, *next_mp;
James Smart07eab622014-04-04 13:51:44 -0400911 LIST_HEAD(buflist);
912 int count;
James Smartbcece5f2014-04-04 13:51:34 -0400913
914 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
915 lpfc_sli_hbqbuf_free_all(phba);
916 else {
917 /* Cleanup preposted buffers on the ELS ring */
James Smart895427b2017-02-12 13:52:30 -0800918 pring = &psli->sli3_ring[LPFC_ELS_RING];
James Smart07eab622014-04-04 13:51:44 -0400919 spin_lock_irq(&phba->hbalock);
920 list_splice_init(&pring->postbufq, &buflist);
921 spin_unlock_irq(&phba->hbalock);
922
923 count = 0;
924 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
James Smartbcece5f2014-04-04 13:51:34 -0400925 list_del(&mp->list);
James Smart07eab622014-04-04 13:51:44 -0400926 count++;
James Smartbcece5f2014-04-04 13:51:34 -0400927 lpfc_mbuf_free(phba, mp->virt, mp->phys);
928 kfree(mp);
929 }
James Smart07eab622014-04-04 13:51:44 -0400930
931 spin_lock_irq(&phba->hbalock);
932 pring->postbufq_cnt -= count;
James Smartbcece5f2014-04-04 13:51:34 -0400933 spin_unlock_irq(&phba->hbalock);
934 }
935}
936
937/**
938 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
939 * @phba: pointer to lpfc HBA data structure.
940 *
941 * This routine will cleanup the txcmplq after the HBA is reset when bringing
942 * down the SLI Layer.
943 *
944 * Return codes
945 * void
946 **/
947static void
948lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
949{
950 struct lpfc_sli *psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -0800951 struct lpfc_queue *qp = NULL;
James Smartbcece5f2014-04-04 13:51:34 -0400952 struct lpfc_sli_ring *pring;
953 LIST_HEAD(completions);
954 int i;
955
James Smart895427b2017-02-12 13:52:30 -0800956 if (phba->sli_rev != LPFC_SLI_REV4) {
957 for (i = 0; i < psli->num_rings; i++) {
958 pring = &psli->sli3_ring[i];
James Smartbcece5f2014-04-04 13:51:34 -0400959 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -0800960 /* At this point in time the HBA is either reset or DOA
961 * Nothing should be on txcmplq as it will
962 * NEVER complete.
963 */
964 list_splice_init(&pring->txcmplq, &completions);
965 pring->txcmplq_cnt = 0;
James Smartbcece5f2014-04-04 13:51:34 -0400966 spin_unlock_irq(&phba->hbalock);
967
James Smart895427b2017-02-12 13:52:30 -0800968 lpfc_sli_abort_iocb_ring(phba, pring);
969 }
James Smartbcece5f2014-04-04 13:51:34 -0400970 /* Cancel all the IOCBs from the completions list */
James Smart895427b2017-02-12 13:52:30 -0800971 lpfc_sli_cancel_iocbs(phba, &completions,
972 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
973 return;
974 }
975 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
976 pring = qp->pring;
977 if (!pring)
978 continue;
979 spin_lock_irq(&pring->ring_lock);
980 list_splice_init(&pring->txcmplq, &completions);
981 pring->txcmplq_cnt = 0;
982 spin_unlock_irq(&pring->ring_lock);
James Smartbcece5f2014-04-04 13:51:34 -0400983 lpfc_sli_abort_iocb_ring(phba, pring);
984 }
James Smart895427b2017-02-12 13:52:30 -0800985 /* Cancel all the IOCBs from the completions list */
986 lpfc_sli_cancel_iocbs(phba, &completions,
987 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smartbcece5f2014-04-04 13:51:34 -0400988}
989
990/**
James Smart3772a992009-05-22 14:50:54 -0400991 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smartbcece5f2014-04-04 13:51:34 -0400992 int i;
James Smarte59058c2008-08-24 21:49:00 -0400993 * @phba: pointer to lpfc HBA data structure.
994 *
995 * This routine will do uninitialization after the HBA is reset when bring
996 * down the SLI Layer.
997 *
998 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200999 * 0 - success.
James Smarte59058c2008-08-24 21:49:00 -04001000 * Any other value - error.
1001 **/
James Smart3772a992009-05-22 14:50:54 -04001002static int
1003lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001004{
James Smartbcece5f2014-04-04 13:51:34 -04001005 lpfc_hba_free_post_buf(phba);
1006 lpfc_hba_clean_txcmplq(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001007 return 0;
1008}
James Smart5af5eee2010-10-22 11:06:38 -04001009
James Smartda0436e2009-05-22 14:51:39 -04001010/**
1011 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
1012 * @phba: pointer to lpfc HBA data structure.
1013 *
1014 * This routine will do uninitialization after the HBA is reset when bring
1015 * down the SLI Layer.
1016 *
1017 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001018 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001019 * Any other value - error.
1020 **/
1021static int
1022lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1023{
1024 struct lpfc_scsi_buf *psb, *psb_next;
1025 LIST_HEAD(aborts);
James Smart895427b2017-02-12 13:52:30 -08001026 LIST_HEAD(nvme_aborts);
James Smartda0436e2009-05-22 14:51:39 -04001027 unsigned long iflag = 0;
James Smart0f65ff62010-02-26 14:14:23 -05001028 struct lpfc_sglq *sglq_entry = NULL;
1029
James Smart895427b2017-02-12 13:52:30 -08001030
1031 lpfc_sli_hbqbuf_free_all(phba);
James Smartbcece5f2014-04-04 13:51:34 -04001032 lpfc_hba_clean_txcmplq(phba);
1033
James Smartda0436e2009-05-22 14:51:39 -04001034 /* At this point in time the HBA is either reset or DOA. Either
1035 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
James Smart895427b2017-02-12 13:52:30 -08001036 * on the lpfc_els_sgl_list so that it can either be freed if the
James Smartda0436e2009-05-22 14:51:39 -04001037 * driver is unloading or reposted if the driver is restarting
1038 * the port.
1039 */
James Smart895427b2017-02-12 13:52:30 -08001040 spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */
James Smartda0436e2009-05-22 14:51:39 -04001041 /* scsl_buf_list */
James Smart895427b2017-02-12 13:52:30 -08001042 /* sgl_list_lock required because worker thread uses this
James Smartda0436e2009-05-22 14:51:39 -04001043 * list.
1044 */
James Smart895427b2017-02-12 13:52:30 -08001045 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05001046 list_for_each_entry(sglq_entry,
1047 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1048 sglq_entry->state = SGL_FREED;
James Smartf358dd02017-02-12 13:52:34 -08001049 list_for_each_entry(sglq_entry,
1050 &phba->sli4_hba.lpfc_abts_nvmet_sgl_list, list)
1051 sglq_entry->state = SGL_FREED;
James Smart0f65ff62010-02-26 14:14:23 -05001052
James Smartda0436e2009-05-22 14:51:39 -04001053 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
James Smart895427b2017-02-12 13:52:30 -08001054 &phba->sli4_hba.lpfc_els_sgl_list);
1055
James Smartf358dd02017-02-12 13:52:34 -08001056 if (phba->sli4_hba.nvme_wq)
1057 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_sgl_list,
1058 &phba->sli4_hba.lpfc_nvmet_sgl_list);
1059
James Smart895427b2017-02-12 13:52:30 -08001060 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04001061 /* abts_scsi_buf_list_lock required because worker thread uses this
1062 * list.
1063 */
James Smart895427b2017-02-12 13:52:30 -08001064 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
1065 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1066 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
1067 &aborts);
1068 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1069 }
1070
1071 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1072 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1073 list_splice_init(&phba->sli4_hba.lpfc_abts_nvme_buf_list,
1074 &nvme_aborts);
1075 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1076 }
1077
James Smartda0436e2009-05-22 14:51:39 -04001078 spin_unlock_irq(&phba->hbalock);
1079
1080 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1081 psb->pCmd = NULL;
1082 psb->status = IOSTAT_SUCCESS;
1083 }
James Smarta40fc5f2013-04-17 20:17:40 -04001084 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1085 list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
1086 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
James Smart68e814f2014-05-21 08:04:59 -04001087
James Smart895427b2017-02-12 13:52:30 -08001088 list_for_each_entry_safe(psb, psb_next, &nvme_aborts, list) {
1089 psb->pCmd = NULL;
1090 psb->status = IOSTAT_SUCCESS;
1091 }
1092 spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag);
1093 list_splice(&nvme_aborts, &phba->lpfc_nvme_buf_list_put);
1094 spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag);
1095
James Smart68e814f2014-05-21 08:04:59 -04001096 lpfc_sli4_free_sp_events(phba);
James Smartda0436e2009-05-22 14:51:39 -04001097 return 0;
1098}
1099
1100/**
1101 * lpfc_hba_down_post - Wrapper func for hba down post routine
1102 * @phba: pointer to lpfc HBA data structure.
1103 *
1104 * This routine wraps the actual SLI3 or SLI4 routine for performing
1105 * uninitialization after the HBA is reset when bring down the SLI Layer.
1106 *
1107 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001108 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001109 * Any other value - error.
1110 **/
1111int
1112lpfc_hba_down_post(struct lpfc_hba *phba)
1113{
1114 return (*phba->lpfc_hba_down_post)(phba);
1115}
Jamie Wellnitz41415862006-02-28 19:25:27 -05001116
James Smarte59058c2008-08-24 21:49:00 -04001117/**
James Smart3621a712009-04-06 18:47:14 -04001118 * lpfc_hb_timeout - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001119 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1120 *
1121 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1122 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1123 * work-port-events bitmap and the worker thread is notified. This timeout
1124 * event will be used by the worker thread to invoke the actual timeout
1125 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1126 * be performed in the timeout handler and the HBA timeout event bit shall
1127 * be cleared by the worker thread after it has taken the event bitmap out.
1128 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001129static void
James Smart858c9f62007-06-17 19:56:39 -05001130lpfc_hb_timeout(unsigned long ptr)
1131{
1132 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001133 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -05001134 unsigned long iflag;
1135
1136 phba = (struct lpfc_hba *)ptr;
James Smart93996272008-08-24 21:50:30 -04001137
1138 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -05001139 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001140 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1141 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -05001142 phba->pport->work_port_events |= WORKER_HB_TMO;
1143 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1144
James Smart93996272008-08-24 21:50:30 -04001145 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -04001146 if (!tmo_posted)
1147 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -05001148 return;
1149}
1150
James Smarte59058c2008-08-24 21:49:00 -04001151/**
James Smart19ca7602010-11-20 23:11:55 -05001152 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1153 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1154 *
1155 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1156 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1157 * work-port-events bitmap and the worker thread is notified. This timeout
1158 * event will be used by the worker thread to invoke the actual timeout
1159 * handler routine, lpfc_rrq_handler. Any periodical operations will
1160 * be performed in the timeout handler and the RRQ timeout event bit shall
1161 * be cleared by the worker thread after it has taken the event bitmap out.
1162 **/
1163static void
1164lpfc_rrq_timeout(unsigned long ptr)
1165{
1166 struct lpfc_hba *phba;
James Smart19ca7602010-11-20 23:11:55 -05001167 unsigned long iflag;
1168
1169 phba = (struct lpfc_hba *)ptr;
1170 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001171 if (!(phba->pport->load_flag & FC_UNLOADING))
1172 phba->hba_flag |= HBA_RRQ_ACTIVE;
1173 else
1174 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
James Smart19ca7602010-11-20 23:11:55 -05001175 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001176
1177 if (!(phba->pport->load_flag & FC_UNLOADING))
1178 lpfc_worker_wake_up(phba);
James Smart19ca7602010-11-20 23:11:55 -05001179}
1180
1181/**
James Smart3621a712009-04-06 18:47:14 -04001182 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -04001183 * @phba: pointer to lpfc hba data structure.
1184 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1185 *
1186 * This is the callback function to the lpfc heart-beat mailbox command.
1187 * If configured, the lpfc driver issues the heart-beat mailbox command to
1188 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1189 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1190 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1191 * heart-beat outstanding state. Once the mailbox command comes back and
1192 * no error conditions detected, the heart-beat mailbox command timer is
1193 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1194 * state is cleared for the next heart-beat. If the timer expired with the
1195 * heart-beat outstanding state set, the driver will put the HBA offline.
1196 **/
James Smart858c9f62007-06-17 19:56:39 -05001197static void
1198lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1199{
1200 unsigned long drvr_flag;
1201
1202 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1203 phba->hb_outstanding = 0;
1204 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1205
James Smart93996272008-08-24 21:50:30 -04001206 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -05001207 mempool_free(pmboxq, phba->mbox_mem_pool);
1208 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1209 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -04001210 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -05001211 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001212 jiffies +
1213 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001214 return;
1215}
1216
James Smarte59058c2008-08-24 21:49:00 -04001217/**
James Smart3621a712009-04-06 18:47:14 -04001218 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001219 * @phba: pointer to lpfc hba data structure.
1220 *
1221 * This is the actual HBA-timer timeout handler to be invoked by the worker
1222 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1223 * handler performs any periodic operations needed for the device. If such
1224 * periodic event has already been attended to either in the interrupt handler
1225 * or by processing slow-ring or fast-ring events within the HBA-timer
1226 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1227 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1228 * is configured and there is no heart-beat mailbox command outstanding, a
1229 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1230 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1231 * to offline.
1232 **/
James Smart858c9f62007-06-17 19:56:39 -05001233void
1234lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1235{
James Smart45ed1192009-10-02 15:17:02 -04001236 struct lpfc_vport **vports;
James Smart858c9f62007-06-17 19:56:39 -05001237 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -05001238 struct lpfc_dmabuf *buf_ptr;
James Smart45ed1192009-10-02 15:17:02 -04001239 int retval, i;
James Smart858c9f62007-06-17 19:56:39 -05001240 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -05001241 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -05001242
James Smart45ed1192009-10-02 15:17:02 -04001243 vports = lpfc_create_vport_work_array(phba);
1244 if (vports != NULL)
James Smart4258e982015-12-16 18:11:58 -05001245 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart45ed1192009-10-02 15:17:02 -04001246 lpfc_rcv_seq_check_edtov(vports[i]);
James Smart4258e982015-12-16 18:11:58 -05001247 lpfc_fdmi_num_disc_check(vports[i]);
1248 }
James Smart45ed1192009-10-02 15:17:02 -04001249 lpfc_destroy_vport_work_array(phba, vports);
1250
James Smart858c9f62007-06-17 19:56:39 -05001251 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -04001252 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -05001253 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1254 return;
1255
1256 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -05001257
James Smart256ec0d2013-04-17 20:14:58 -04001258 if (time_after(phba->last_completion_time +
1259 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1260 jiffies)) {
James Smart858c9f62007-06-17 19:56:39 -05001261 spin_unlock_irq(&phba->pport->work_port_lock);
1262 if (!phba->hb_outstanding)
1263 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001264 jiffies +
1265 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001266 else
1267 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001268 jiffies +
1269 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001270 return;
1271 }
1272 spin_unlock_irq(&phba->pport->work_port_lock);
1273
James Smart0ff10d42008-01-11 01:52:36 -05001274 if (phba->elsbuf_cnt &&
1275 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1276 spin_lock_irq(&phba->hbalock);
1277 list_splice_init(&phba->elsbuf, &completions);
1278 phba->elsbuf_cnt = 0;
1279 phba->elsbuf_prev_cnt = 0;
1280 spin_unlock_irq(&phba->hbalock);
1281
1282 while (!list_empty(&completions)) {
1283 list_remove_head(&completions, buf_ptr,
1284 struct lpfc_dmabuf, list);
1285 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1286 kfree(buf_ptr);
1287 }
1288 }
1289 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1290
James Smart858c9f62007-06-17 19:56:39 -05001291 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -05001292 if (phba->cfg_enable_hba_heartbeat) {
1293 if (!phba->hb_outstanding) {
James Smartbc739052010-08-04 16:11:18 -04001294 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1295 (list_empty(&psli->mboxq))) {
1296 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1297 GFP_KERNEL);
1298 if (!pmboxq) {
1299 mod_timer(&phba->hb_tmofunc,
1300 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001301 msecs_to_jiffies(1000 *
1302 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001303 return;
1304 }
James Smart13815c82008-01-11 01:52:48 -05001305
James Smartbc739052010-08-04 16:11:18 -04001306 lpfc_heart_beat(phba, pmboxq);
1307 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1308 pmboxq->vport = phba->pport;
1309 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1310 MBX_NOWAIT);
James Smart13815c82008-01-11 01:52:48 -05001311
James Smartbc739052010-08-04 16:11:18 -04001312 if (retval != MBX_BUSY &&
1313 retval != MBX_SUCCESS) {
1314 mempool_free(pmboxq,
1315 phba->mbox_mem_pool);
1316 mod_timer(&phba->hb_tmofunc,
1317 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001318 msecs_to_jiffies(1000 *
1319 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001320 return;
1321 }
1322 phba->skipped_hb = 0;
1323 phba->hb_outstanding = 1;
1324 } else if (time_before_eq(phba->last_completion_time,
1325 phba->skipped_hb)) {
1326 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1327 "2857 Last completion time not "
1328 " updated in %d ms\n",
1329 jiffies_to_msecs(jiffies
1330 - phba->last_completion_time));
1331 } else
1332 phba->skipped_hb = jiffies;
1333
James Smart858c9f62007-06-17 19:56:39 -05001334 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001335 jiffies +
1336 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001337 return;
James Smart13815c82008-01-11 01:52:48 -05001338 } else {
1339 /*
1340 * If heart beat timeout called with hb_outstanding set
James Smartdcf2a4e2010-09-29 11:18:53 -04001341 * we need to give the hb mailbox cmd a chance to
1342 * complete or TMO.
James Smart13815c82008-01-11 01:52:48 -05001343 */
James Smartdcf2a4e2010-09-29 11:18:53 -04001344 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1345 "0459 Adapter heartbeat still out"
1346 "standing:last compl time was %d ms.\n",
1347 jiffies_to_msecs(jiffies
1348 - phba->last_completion_time));
1349 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001350 jiffies +
1351 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001352 }
James Smart4258e982015-12-16 18:11:58 -05001353 } else {
1354 mod_timer(&phba->hb_tmofunc,
1355 jiffies +
1356 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001357 }
1358}
1359
James Smarte59058c2008-08-24 21:49:00 -04001360/**
James Smart3621a712009-04-06 18:47:14 -04001361 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -04001362 * @phba: pointer to lpfc hba data structure.
1363 *
1364 * This routine is called to bring the HBA offline when HBA hardware error
1365 * other than Port Error 6 has been detected.
1366 **/
James Smart09372822008-01-11 01:52:54 -05001367static void
1368lpfc_offline_eratt(struct lpfc_hba *phba)
1369{
1370 struct lpfc_sli *psli = &phba->sli;
1371
1372 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001373 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -05001374 spin_unlock_irq(&phba->hbalock);
James Smart618a5232012-06-12 13:54:36 -04001375 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart09372822008-01-11 01:52:54 -05001376
1377 lpfc_offline(phba);
1378 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001379 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001380 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001381 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001382 lpfc_hba_down_post(phba);
1383 lpfc_sli_brdready(phba, HS_MBRDY);
1384 lpfc_unblock_mgmt_io(phba);
1385 phba->link_state = LPFC_HBA_ERROR;
1386 return;
1387}
1388
James Smarte59058c2008-08-24 21:49:00 -04001389/**
James Smartda0436e2009-05-22 14:51:39 -04001390 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1391 * @phba: pointer to lpfc hba data structure.
1392 *
1393 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1394 * other than Port Error 6 has been detected.
1395 **/
James Smarta88dbb62013-04-17 20:18:39 -04001396void
James Smartda0436e2009-05-22 14:51:39 -04001397lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1398{
James Smart946727d2015-04-07 15:07:09 -04001399 spin_lock_irq(&phba->hbalock);
1400 phba->link_state = LPFC_HBA_ERROR;
1401 spin_unlock_irq(&phba->hbalock);
1402
James Smart618a5232012-06-12 13:54:36 -04001403 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smartda0436e2009-05-22 14:51:39 -04001404 lpfc_offline(phba);
James Smartda0436e2009-05-22 14:51:39 -04001405 lpfc_hba_down_post(phba);
James Smartda0436e2009-05-22 14:51:39 -04001406 lpfc_unblock_mgmt_io(phba);
James Smartda0436e2009-05-22 14:51:39 -04001407}
1408
1409/**
James Smarta257bf92009-04-06 18:48:10 -04001410 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1411 * @phba: pointer to lpfc hba data structure.
1412 *
1413 * This routine is invoked to handle the deferred HBA hardware error
1414 * conditions. This type of error is indicated by HBA by setting ER1
1415 * and another ER bit in the host status register. The driver will
1416 * wait until the ER1 bit clears before handling the error condition.
1417 **/
1418static void
1419lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1420{
1421 uint32_t old_host_status = phba->work_hs;
James Smarta257bf92009-04-06 18:48:10 -04001422 struct lpfc_sli *psli = &phba->sli;
1423
James Smartf4b4c682009-05-22 14:53:12 -04001424 /* If the pci channel is offline, ignore possible errors,
1425 * since we cannot communicate with the pci card anyway.
1426 */
1427 if (pci_channel_offline(phba->pcidev)) {
1428 spin_lock_irq(&phba->hbalock);
1429 phba->hba_flag &= ~DEFER_ERATT;
1430 spin_unlock_irq(&phba->hbalock);
1431 return;
1432 }
1433
James Smarta257bf92009-04-06 18:48:10 -04001434 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1435 "0479 Deferred Adapter Hardware Error "
1436 "Data: x%x x%x x%x\n",
1437 phba->work_hs,
1438 phba->work_status[0], phba->work_status[1]);
1439
1440 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001441 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001442 spin_unlock_irq(&phba->hbalock);
1443
1444
1445 /*
1446 * Firmware stops when it triggred erratt. That could cause the I/Os
1447 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1448 * SCSI layer retry it after re-establishing link.
1449 */
James Smartdb55fba2014-04-04 13:52:02 -04001450 lpfc_sli_abort_fcp_rings(phba);
James Smarta257bf92009-04-06 18:48:10 -04001451
1452 /*
1453 * There was a firmware error. Take the hba offline and then
1454 * attempt to restart it.
1455 */
James Smart618a5232012-06-12 13:54:36 -04001456 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smarta257bf92009-04-06 18:48:10 -04001457 lpfc_offline(phba);
1458
1459 /* Wait for the ER1 bit to clear.*/
1460 while (phba->work_hs & HS_FFER1) {
1461 msleep(100);
James Smart9940b972011-03-11 16:06:12 -05001462 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1463 phba->work_hs = UNPLUG_ERR ;
1464 break;
1465 }
James Smarta257bf92009-04-06 18:48:10 -04001466 /* If driver is unloading let the worker thread continue */
1467 if (phba->pport->load_flag & FC_UNLOADING) {
1468 phba->work_hs = 0;
1469 break;
1470 }
1471 }
1472
1473 /*
1474 * This is to ptrotect against a race condition in which
1475 * first write to the host attention register clear the
1476 * host status register.
1477 */
1478 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1479 phba->work_hs = old_host_status & ~HS_FFER1;
1480
James Smart3772a992009-05-22 14:50:54 -04001481 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001482 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001483 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001484 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1485 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1486}
1487
James Smart3772a992009-05-22 14:50:54 -04001488static void
1489lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1490{
1491 struct lpfc_board_event_header board_event;
1492 struct Scsi_Host *shost;
1493
1494 board_event.event_type = FC_REG_BOARD_EVENT;
1495 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1496 shost = lpfc_shost_from_vport(phba->pport);
1497 fc_host_post_vendor_event(shost, fc_get_event_number(),
1498 sizeof(board_event),
1499 (char *) &board_event,
1500 LPFC_NL_VENDOR_ID);
1501}
1502
James Smarta257bf92009-04-06 18:48:10 -04001503/**
James Smart3772a992009-05-22 14:50:54 -04001504 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001505 * @phba: pointer to lpfc hba data structure.
1506 *
1507 * This routine is invoked to handle the following HBA hardware error
1508 * conditions:
1509 * 1 - HBA error attention interrupt
1510 * 2 - DMA ring index out of range
1511 * 3 - Mailbox command came back as unknown
1512 **/
James Smart3772a992009-05-22 14:50:54 -04001513static void
1514lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001515{
James Smart2e0fef82007-06-17 19:56:36 -05001516 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001517 struct lpfc_sli *psli = &phba->sli;
James Smartd2873e42006-08-18 17:46:43 -04001518 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001519 unsigned long temperature;
1520 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001521 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001522
Linas Vepstas8d63f372007-02-14 14:28:36 -06001523 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001524 * since we cannot communicate with the pci card anyway.
1525 */
1526 if (pci_channel_offline(phba->pcidev)) {
1527 spin_lock_irq(&phba->hbalock);
1528 phba->hba_flag &= ~DEFER_ERATT;
1529 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001530 return;
James Smart3772a992009-05-22 14:50:54 -04001531 }
1532
James Smart13815c82008-01-11 01:52:48 -05001533 /* If resets are disabled then leave the HBA alone and return */
1534 if (!phba->cfg_enable_hba_reset)
1535 return;
dea31012005-04-17 16:05:31 -05001536
James Smartea2151b2008-09-07 11:52:10 -04001537 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001538 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001539
James Smarta257bf92009-04-06 18:48:10 -04001540 if (phba->hba_flag & DEFER_ERATT)
1541 lpfc_handle_deferred_eratt(phba);
1542
James Smartdcf2a4e2010-09-29 11:18:53 -04001543 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1544 if (phba->work_hs & HS_FFER6)
1545 /* Re-establishing Link */
1546 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1547 "1301 Re-establishing Link "
1548 "Data: x%x x%x x%x\n",
1549 phba->work_hs, phba->work_status[0],
1550 phba->work_status[1]);
1551 if (phba->work_hs & HS_FFER8)
1552 /* Device Zeroization */
1553 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1554 "2861 Host Authentication device "
1555 "zeroization Data:x%x x%x x%x\n",
1556 phba->work_hs, phba->work_status[0],
1557 phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001558
James Smart92d7f7b2007-06-17 19:56:38 -05001559 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001560 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001561 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001562
1563 /*
1564 * Firmware stops when it triggled erratt with HS_FFER6.
1565 * That could cause the I/Os dropped by the firmware.
1566 * Error iocb (I/O) on txcmplq and let the SCSI layer
1567 * retry it after re-establishing link.
1568 */
James Smartdb55fba2014-04-04 13:52:02 -04001569 lpfc_sli_abort_fcp_rings(phba);
dea31012005-04-17 16:05:31 -05001570
dea31012005-04-17 16:05:31 -05001571 /*
1572 * There was a firmware error. Take the hba offline and then
1573 * attempt to restart it.
1574 */
James Smart618a5232012-06-12 13:54:36 -04001575 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
dea31012005-04-17 16:05:31 -05001576 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001577 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001578 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001579 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001580 return;
1581 }
James Smart46fa3112007-04-25 09:51:45 -04001582 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001583 } else if (phba->work_hs & HS_CRIT_TEMP) {
1584 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1585 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1586 temp_event_data.event_code = LPFC_CRIT_TEMP;
1587 temp_event_data.data = (uint32_t)temperature;
1588
1589 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001590 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001591 "(%ld), taking this port offline "
1592 "Data: x%x x%x x%x\n",
1593 temperature, phba->work_hs,
1594 phba->work_status[0], phba->work_status[1]);
1595
1596 shost = lpfc_shost_from_vport(phba->pport);
1597 fc_host_post_vendor_event(shost, fc_get_event_number(),
1598 sizeof(temp_event_data),
1599 (char *) &temp_event_data,
1600 SCSI_NL_VID_TYPE_PCI
1601 | PCI_VENDOR_ID_EMULEX);
1602
James Smart7af67052007-10-27 13:38:11 -04001603 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001604 phba->over_temp_state = HBA_OVER_TEMP;
1605 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001606 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001607
dea31012005-04-17 16:05:31 -05001608 } else {
1609 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001610 * failure is a value other than FFER6. Do not call the offline
1611 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001612 */
1613 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001614 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001615 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001616 phba->work_hs,
dea31012005-04-17 16:05:31 -05001617 phba->work_status[0], phba->work_status[1]);
1618
James Smartd2873e42006-08-18 17:46:43 -04001619 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001620 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001621 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001622 sizeof(event_data), (char *) &event_data,
1623 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1624
James Smart09372822008-01-11 01:52:54 -05001625 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001626 }
James Smart93996272008-08-24 21:50:30 -04001627 return;
dea31012005-04-17 16:05:31 -05001628}
1629
James Smarte59058c2008-08-24 21:49:00 -04001630/**
James Smart618a5232012-06-12 13:54:36 -04001631 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1632 * @phba: pointer to lpfc hba data structure.
1633 * @mbx_action: flag for mailbox shutdown action.
1634 *
1635 * This routine is invoked to perform an SLI4 port PCI function reset in
1636 * response to port status register polling attention. It waits for port
1637 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1638 * During this process, interrupt vectors are freed and later requested
1639 * for handling possible port resource change.
1640 **/
1641static int
James Smarte10b2022014-02-20 09:57:43 -05001642lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1643 bool en_rn_msg)
James Smart618a5232012-06-12 13:54:36 -04001644{
1645 int rc;
1646 uint32_t intr_mode;
1647
James Smart65791f12016-07-06 12:35:56 -07001648 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1649 LPFC_SLI_INTF_IF_TYPE_2) {
1650 /*
1651 * On error status condition, driver need to wait for port
1652 * ready before performing reset.
1653 */
1654 rc = lpfc_sli4_pdev_status_reg_wait(phba);
James Smart0e916ee2016-07-06 12:36:06 -07001655 if (rc)
James Smart65791f12016-07-06 12:35:56 -07001656 return rc;
James Smart618a5232012-06-12 13:54:36 -04001657 }
James Smart0e916ee2016-07-06 12:36:06 -07001658
James Smart65791f12016-07-06 12:35:56 -07001659 /* need reset: attempt for port recovery */
1660 if (en_rn_msg)
1661 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1662 "2887 Reset Needed: Attempting Port "
1663 "Recovery...\n");
1664 lpfc_offline_prep(phba, mbx_action);
1665 lpfc_offline(phba);
1666 /* release interrupt for possible resource change */
1667 lpfc_sli4_disable_intr(phba);
1668 lpfc_sli_brdrestart(phba);
1669 /* request and enable interrupt */
1670 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1671 if (intr_mode == LPFC_INTR_ERROR) {
1672 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1673 "3175 Failed to enable interrupt\n");
1674 return -EIO;
1675 }
1676 phba->intr_mode = intr_mode;
1677 rc = lpfc_online(phba);
1678 if (rc == 0)
1679 lpfc_unblock_mgmt_io(phba);
1680
James Smart618a5232012-06-12 13:54:36 -04001681 return rc;
1682}
1683
1684/**
James Smartda0436e2009-05-22 14:51:39 -04001685 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1686 * @phba: pointer to lpfc hba data structure.
1687 *
1688 * This routine is invoked to handle the SLI4 HBA hardware error attention
1689 * conditions.
1690 **/
1691static void
1692lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1693{
1694 struct lpfc_vport *vport = phba->pport;
1695 uint32_t event_data;
1696 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001697 uint32_t if_type;
James Smart2e90f4b2011-12-13 13:22:37 -05001698 struct lpfc_register portstat_reg = {0};
1699 uint32_t reg_err1, reg_err2;
1700 uint32_t uerrlo_reg, uemasklo_reg;
James Smart65791f12016-07-06 12:35:56 -07001701 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
James Smarte10b2022014-02-20 09:57:43 -05001702 bool en_rn_msg = true;
James Smart946727d2015-04-07 15:07:09 -04001703 struct temp_event temp_event_data;
James Smart65791f12016-07-06 12:35:56 -07001704 struct lpfc_register portsmphr_reg;
1705 int rc, i;
James Smartda0436e2009-05-22 14:51:39 -04001706
1707 /* If the pci channel is offline, ignore possible errors, since
1708 * we cannot communicate with the pci card anyway.
1709 */
1710 if (pci_channel_offline(phba->pcidev))
1711 return;
James Smartda0436e2009-05-22 14:51:39 -04001712
James Smart65791f12016-07-06 12:35:56 -07001713 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
James Smart2fcee4b2010-12-15 17:57:46 -05001714 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1715 switch (if_type) {
1716 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart2e90f4b2011-12-13 13:22:37 -05001717 pci_rd_rc1 = lpfc_readl(
1718 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1719 &uerrlo_reg);
1720 pci_rd_rc2 = lpfc_readl(
1721 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1722 &uemasklo_reg);
1723 /* consider PCI bus read error as pci_channel_offline */
1724 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1725 return;
James Smart65791f12016-07-06 12:35:56 -07001726 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
1727 lpfc_sli4_offline_eratt(phba);
1728 return;
1729 }
1730 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1731 "7623 Checking UE recoverable");
1732
1733 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
1734 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1735 &portsmphr_reg.word0))
1736 continue;
1737
1738 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
1739 &portsmphr_reg);
1740 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1741 LPFC_PORT_SEM_UE_RECOVERABLE)
1742 break;
1743 /*Sleep for 1Sec, before checking SEMAPHORE */
1744 msleep(1000);
1745 }
1746
1747 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1748 "4827 smphr_port_status x%x : Waited %dSec",
1749 smphr_port_status, i);
1750
1751 /* Recoverable UE, reset the HBA device */
1752 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1753 LPFC_PORT_SEM_UE_RECOVERABLE) {
1754 for (i = 0; i < 20; i++) {
1755 msleep(1000);
1756 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1757 &portsmphr_reg.word0) &&
1758 (LPFC_POST_STAGE_PORT_READY ==
1759 bf_get(lpfc_port_smphr_port_status,
1760 &portsmphr_reg))) {
1761 rc = lpfc_sli4_port_sta_fn_reset(phba,
1762 LPFC_MBX_NO_WAIT, en_rn_msg);
1763 if (rc == 0)
1764 return;
1765 lpfc_printf_log(phba,
1766 KERN_ERR, LOG_INIT,
1767 "4215 Failed to recover UE");
1768 break;
1769 }
1770 }
1771 }
1772 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1773 "7624 Firmware not ready: Failing UE recovery,"
1774 " waited %dSec", i);
James Smart2fcee4b2010-12-15 17:57:46 -05001775 lpfc_sli4_offline_eratt(phba);
1776 break;
James Smart946727d2015-04-07 15:07:09 -04001777
James Smart2fcee4b2010-12-15 17:57:46 -05001778 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2e90f4b2011-12-13 13:22:37 -05001779 pci_rd_rc1 = lpfc_readl(
1780 phba->sli4_hba.u.if_type2.STATUSregaddr,
1781 &portstat_reg.word0);
1782 /* consider PCI bus read error as pci_channel_offline */
James Smart6b5151f2012-01-18 16:24:06 -05001783 if (pci_rd_rc1 == -EIO) {
1784 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1785 "3151 PCI bus read access failure: x%x\n",
1786 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
James Smart2e90f4b2011-12-13 13:22:37 -05001787 return;
James Smart6b5151f2012-01-18 16:24:06 -05001788 }
James Smart2e90f4b2011-12-13 13:22:37 -05001789 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1790 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
James Smart2fcee4b2010-12-15 17:57:46 -05001791 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
James Smart2fcee4b2010-12-15 17:57:46 -05001792 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1793 "2889 Port Overtemperature event, "
James Smart946727d2015-04-07 15:07:09 -04001794 "taking port offline Data: x%x x%x\n",
1795 reg_err1, reg_err2);
1796
James Smart310429e2016-07-06 12:35:54 -07001797 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04001798 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1799 temp_event_data.event_code = LPFC_CRIT_TEMP;
1800 temp_event_data.data = 0xFFFFFFFF;
1801
1802 shost = lpfc_shost_from_vport(phba->pport);
1803 fc_host_post_vendor_event(shost, fc_get_event_number(),
1804 sizeof(temp_event_data),
1805 (char *)&temp_event_data,
1806 SCSI_NL_VID_TYPE_PCI
1807 | PCI_VENDOR_ID_EMULEX);
1808
James Smart2fcee4b2010-12-15 17:57:46 -05001809 spin_lock_irq(&phba->hbalock);
1810 phba->over_temp_state = HBA_OVER_TEMP;
1811 spin_unlock_irq(&phba->hbalock);
1812 lpfc_sli4_offline_eratt(phba);
James Smart946727d2015-04-07 15:07:09 -04001813 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001814 }
James Smart2e90f4b2011-12-13 13:22:37 -05001815 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smarte10b2022014-02-20 09:57:43 -05001816 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
James Smart2e90f4b2011-12-13 13:22:37 -05001817 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte10b2022014-02-20 09:57:43 -05001818 "3143 Port Down: Firmware Update "
1819 "Detected\n");
1820 en_rn_msg = false;
1821 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smart2e90f4b2011-12-13 13:22:37 -05001822 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1823 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1824 "3144 Port Down: Debug Dump\n");
1825 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1826 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1827 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1828 "3145 Port Down: Provisioning\n");
James Smart618a5232012-06-12 13:54:36 -04001829
James Smart946727d2015-04-07 15:07:09 -04001830 /* If resets are disabled then leave the HBA alone and return */
1831 if (!phba->cfg_enable_hba_reset)
1832 return;
1833
James Smart618a5232012-06-12 13:54:36 -04001834 /* Check port status register for function reset */
James Smarte10b2022014-02-20 09:57:43 -05001835 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1836 en_rn_msg);
James Smart618a5232012-06-12 13:54:36 -04001837 if (rc == 0) {
1838 /* don't report event on forced debug dump */
1839 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1840 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1841 return;
1842 else
1843 break;
James Smart2fcee4b2010-12-15 17:57:46 -05001844 }
James Smart618a5232012-06-12 13:54:36 -04001845 /* fall through for not able to recover */
James Smart6b5151f2012-01-18 16:24:06 -05001846 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1847 "3152 Unrecoverable error, bring the port "
1848 "offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05001849 lpfc_sli4_offline_eratt(phba);
1850 break;
1851 case LPFC_SLI_INTF_IF_TYPE_1:
1852 default:
1853 break;
1854 }
James Smart2e90f4b2011-12-13 13:22:37 -05001855 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1856 "3123 Report dump event to upper layer\n");
1857 /* Send an internal error event to mgmt application */
1858 lpfc_board_errevt_to_mgmt(phba);
1859
1860 event_data = FC_REG_DUMP_EVENT;
1861 shost = lpfc_shost_from_vport(vport);
1862 fc_host_post_vendor_event(shost, fc_get_event_number(),
1863 sizeof(event_data), (char *) &event_data,
1864 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
James Smartda0436e2009-05-22 14:51:39 -04001865}
1866
1867/**
1868 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1869 * @phba: pointer to lpfc HBA data structure.
1870 *
1871 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1872 * routine from the API jump table function pointer from the lpfc_hba struct.
1873 *
1874 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001875 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001876 * Any other value - error.
1877 **/
1878void
1879lpfc_handle_eratt(struct lpfc_hba *phba)
1880{
1881 (*phba->lpfc_handle_eratt)(phba);
1882}
1883
1884/**
James Smart3621a712009-04-06 18:47:14 -04001885 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04001886 * @phba: pointer to lpfc hba data structure.
1887 *
1888 * This routine is invoked from the worker thread to handle a HBA host
James Smart895427b2017-02-12 13:52:30 -08001889 * attention link event. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04001890 **/
dea31012005-04-17 16:05:31 -05001891void
James Smart2e0fef82007-06-17 19:56:36 -05001892lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001893{
James Smart2e0fef82007-06-17 19:56:36 -05001894 struct lpfc_vport *vport = phba->pport;
1895 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001896 LPFC_MBOXQ_t *pmb;
1897 volatile uint32_t control;
1898 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05001899 int rc = 0;
dea31012005-04-17 16:05:31 -05001900
1901 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001902 if (!pmb) {
1903 rc = 1;
dea31012005-04-17 16:05:31 -05001904 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05001905 }
dea31012005-04-17 16:05:31 -05001906
1907 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001908 if (!mp) {
1909 rc = 2;
dea31012005-04-17 16:05:31 -05001910 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05001911 }
dea31012005-04-17 16:05:31 -05001912
1913 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05001914 if (!mp->virt) {
1915 rc = 3;
dea31012005-04-17 16:05:31 -05001916 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05001917 }
dea31012005-04-17 16:05:31 -05001918
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001919 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04001920 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05001921
1922 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05001923 lpfc_read_topology(phba, pmb, mp);
1924 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05001925 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04001926 /* Block ELS IOCBs until we have processed this mbox command */
James Smart895427b2017-02-12 13:52:30 -08001927 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04001928 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05001929 if (rc == MBX_NOT_FINISHED) {
1930 rc = 4;
James Smart14691152006-12-02 13:34:28 -05001931 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05001932 }
dea31012005-04-17 16:05:31 -05001933
1934 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05001935 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001936 writel(HA_LATT, phba->HAregaddr);
1937 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001938 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001939
1940 return;
1941
James Smart14691152006-12-02 13:34:28 -05001942lpfc_handle_latt_free_mbuf:
James Smart895427b2017-02-12 13:52:30 -08001943 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05001944 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05001945lpfc_handle_latt_free_mp:
1946 kfree(mp);
1947lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04001948 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001949lpfc_handle_latt_err_exit:
1950 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001951 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001952 psli->sli_flag |= LPFC_PROCESS_LA;
1953 control = readl(phba->HCregaddr);
1954 control |= HC_LAINT_ENA;
1955 writel(control, phba->HCregaddr);
1956 readl(phba->HCregaddr); /* flush */
1957
1958 /* Clear Link Attention in HA REG */
1959 writel(HA_LATT, phba->HAregaddr);
1960 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001961 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001962 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001963 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001964
James Smart09372822008-01-11 01:52:54 -05001965 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1966 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05001967
1968 return;
1969}
1970
James Smarte59058c2008-08-24 21:49:00 -04001971/**
James Smart3621a712009-04-06 18:47:14 -04001972 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04001973 * @phba: pointer to lpfc hba data structure.
1974 * @vpd: pointer to the vital product data.
1975 * @len: length of the vital product data in bytes.
1976 *
1977 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1978 * an array of characters. In this routine, the ModelName, ProgramType, and
1979 * ModelDesc, etc. fields of the phba data structure will be populated.
1980 *
1981 * Return codes
1982 * 0 - pointer to the VPD passed in is NULL
1983 * 1 - success
1984 **/
James Smart3772a992009-05-22 14:50:54 -04001985int
James Smart2e0fef82007-06-17 19:56:36 -05001986lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05001987{
1988 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05001989 int Length;
dea31012005-04-17 16:05:31 -05001990 int i, j;
1991 int finished = 0;
1992 int index = 0;
1993
1994 if (!vpd)
1995 return 0;
1996
1997 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05001998 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001999 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05002000 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
2001 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002002 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05002003 switch (vpd[index]) {
2004 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002005 case 0x91:
dea31012005-04-17 16:05:31 -05002006 index += 1;
2007 lenlo = vpd[index];
2008 index += 1;
2009 lenhi = vpd[index];
2010 index += 1;
2011 i = ((((unsigned short)lenhi) << 8) + lenlo);
2012 index += i;
2013 break;
2014 case 0x90:
2015 index += 1;
2016 lenlo = vpd[index];
2017 index += 1;
2018 lenhi = vpd[index];
2019 index += 1;
2020 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002021 if (Length > len - index)
2022 Length = len - index;
dea31012005-04-17 16:05:31 -05002023 while (Length > 0) {
2024 /* Look for Serial Number */
2025 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
2026 index += 2;
2027 i = vpd[index];
2028 index += 1;
2029 j = 0;
2030 Length -= (3+i);
2031 while(i--) {
2032 phba->SerialNumber[j++] = vpd[index++];
2033 if (j == 31)
2034 break;
2035 }
2036 phba->SerialNumber[j] = 0;
2037 continue;
2038 }
2039 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
2040 phba->vpd_flag |= VPD_MODEL_DESC;
2041 index += 2;
2042 i = vpd[index];
2043 index += 1;
2044 j = 0;
2045 Length -= (3+i);
2046 while(i--) {
2047 phba->ModelDesc[j++] = vpd[index++];
2048 if (j == 255)
2049 break;
2050 }
2051 phba->ModelDesc[j] = 0;
2052 continue;
2053 }
2054 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
2055 phba->vpd_flag |= VPD_MODEL_NAME;
2056 index += 2;
2057 i = vpd[index];
2058 index += 1;
2059 j = 0;
2060 Length -= (3+i);
2061 while(i--) {
2062 phba->ModelName[j++] = vpd[index++];
2063 if (j == 79)
2064 break;
2065 }
2066 phba->ModelName[j] = 0;
2067 continue;
2068 }
2069 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2070 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2071 index += 2;
2072 i = vpd[index];
2073 index += 1;
2074 j = 0;
2075 Length -= (3+i);
2076 while(i--) {
2077 phba->ProgramType[j++] = vpd[index++];
2078 if (j == 255)
2079 break;
2080 }
2081 phba->ProgramType[j] = 0;
2082 continue;
2083 }
2084 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2085 phba->vpd_flag |= VPD_PORT;
2086 index += 2;
2087 i = vpd[index];
2088 index += 1;
2089 j = 0;
2090 Length -= (3+i);
2091 while(i--) {
James Smartcd1c8302011-10-10 21:33:25 -04002092 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2093 (phba->sli4_hba.pport_name_sta ==
2094 LPFC_SLI4_PPNAME_GET)) {
2095 j++;
2096 index++;
2097 } else
2098 phba->Port[j++] = vpd[index++];
2099 if (j == 19)
2100 break;
dea31012005-04-17 16:05:31 -05002101 }
James Smartcd1c8302011-10-10 21:33:25 -04002102 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2103 (phba->sli4_hba.pport_name_sta ==
2104 LPFC_SLI4_PPNAME_NON))
2105 phba->Port[j] = 0;
dea31012005-04-17 16:05:31 -05002106 continue;
2107 }
2108 else {
2109 index += 2;
2110 i = vpd[index];
2111 index += 1;
2112 index += i;
2113 Length -= (3 + i);
2114 }
2115 }
2116 finished = 0;
2117 break;
2118 case 0x78:
2119 finished = 1;
2120 break;
2121 default:
2122 index ++;
2123 break;
2124 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002125 }
dea31012005-04-17 16:05:31 -05002126
2127 return(1);
2128}
2129
James Smarte59058c2008-08-24 21:49:00 -04002130/**
James Smart3621a712009-04-06 18:47:14 -04002131 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04002132 * @phba: pointer to lpfc hba data structure.
2133 * @mdp: pointer to the data structure to hold the derived model name.
2134 * @descp: pointer to the data structure to hold the derived description.
2135 *
2136 * This routine retrieves HBA's description based on its registered PCI device
2137 * ID. The @descp passed into this function points to an array of 256 chars. It
2138 * shall be returned with the model name, maximum speed, and the host bus type.
2139 * The @mdp passed into this function points to an array of 80 chars. When the
2140 * function returns, the @mdp will be filled with the model name.
2141 **/
dea31012005-04-17 16:05:31 -05002142static void
James Smart2e0fef82007-06-17 19:56:36 -05002143lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05002144{
2145 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05002146 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002147 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04002148 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04002149 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002150 struct {
James Smarta747c9c2009-11-18 15:41:10 -05002151 char *name;
2152 char *bus;
2153 char *function;
2154 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002155
2156 if (mdp && mdp[0] != '\0'
2157 && descp && descp[0] != '\0')
2158 return;
2159
James Smartd38dd522015-08-31 16:48:17 -04002160 if (phba->lmt & LMT_32Gb)
2161 max_speed = 32;
2162 else if (phba->lmt & LMT_16Gb)
James Smartc0c11512011-05-24 11:41:34 -04002163 max_speed = 16;
2164 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002165 max_speed = 10;
2166 else if (phba->lmt & LMT_8Gb)
2167 max_speed = 8;
2168 else if (phba->lmt & LMT_4Gb)
2169 max_speed = 4;
2170 else if (phba->lmt & LMT_2Gb)
2171 max_speed = 2;
James Smart4169d862012-09-29 11:32:09 -04002172 else if (phba->lmt & LMT_1Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002173 max_speed = 1;
James Smart4169d862012-09-29 11:32:09 -04002174 else
2175 max_speed = 0;
dea31012005-04-17 16:05:31 -05002176
2177 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05002178
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002179 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002180 case PCI_DEVICE_ID_FIREFLY:
James Smart12222f42014-05-21 08:05:19 -04002181 m = (typeof(m)){"LP6000", "PCI",
2182 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002183 break;
dea31012005-04-17 16:05:31 -05002184 case PCI_DEVICE_ID_SUPERFLY:
2185 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart12222f42014-05-21 08:05:19 -04002186 m = (typeof(m)){"LP7000", "PCI", ""};
dea31012005-04-17 16:05:31 -05002187 else
James Smart12222f42014-05-21 08:05:19 -04002188 m = (typeof(m)){"LP7000E", "PCI", ""};
2189 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002190 break;
2191 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002192 m = (typeof(m)){"LP8000", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002193 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002194 break;
2195 case PCI_DEVICE_ID_CENTAUR:
2196 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart12222f42014-05-21 08:05:19 -04002197 m = (typeof(m)){"LP9002", "PCI", ""};
dea31012005-04-17 16:05:31 -05002198 else
James Smart12222f42014-05-21 08:05:19 -04002199 m = (typeof(m)){"LP9000", "PCI", ""};
2200 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002201 break;
2202 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002203 m = (typeof(m)){"LP952", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002204 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002205 break;
2206 case PCI_DEVICE_ID_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05002207 m = (typeof(m)){"LP9802", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002208 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002209 break;
2210 case PCI_DEVICE_ID_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05002211 m = (typeof(m)){"LP10000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002212 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002213 break;
2214 case PCI_DEVICE_ID_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05002215 m = (typeof(m)){"LPX1000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002216 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002217 break;
2218 case PCI_DEVICE_ID_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002219 m = (typeof(m)){"LP982", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002220 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002221 break;
2222 case PCI_DEVICE_ID_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002223 m = (typeof(m)){"LP1050", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002224 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002225 break;
2226 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05002227 m = (typeof(m)){"LP11000", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002228 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002229 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002230 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002231 m = (typeof(m)){"LP11000-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002232 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002233 break;
2234 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002235 m = (typeof(m)){"LP11002-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002236 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002237 break;
2238 case PCI_DEVICE_ID_NEPTUNE:
James Smart12222f42014-05-21 08:05:19 -04002239 m = (typeof(m)){"LPe1000", "PCIe",
2240 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002241 break;
2242 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart12222f42014-05-21 08:05:19 -04002243 m = (typeof(m)){"LPe1000-SP", "PCIe",
2244 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002245 break;
2246 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart12222f42014-05-21 08:05:19 -04002247 m = (typeof(m)){"LPe1002-SP", "PCIe",
2248 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002249 break;
dea31012005-04-17 16:05:31 -05002250 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05002251 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002252 break;
2253 case PCI_DEVICE_ID_BSMB:
James Smart12222f42014-05-21 08:05:19 -04002254 m = (typeof(m)){"LP111", "PCI-X2",
2255 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002256 break;
2257 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05002258 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002259 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002260 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002261 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002262 break;
2263 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002264 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04002265 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002266 break;
dea31012005-04-17 16:05:31 -05002267 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05002268 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002269 break;
2270 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05002271 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002272 break;
2273 case PCI_DEVICE_ID_LP101:
James Smart12222f42014-05-21 08:05:19 -04002274 m = (typeof(m)){"LP101", "PCI-X",
2275 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002276 break;
2277 case PCI_DEVICE_ID_LP10000S:
James Smart12222f42014-05-21 08:05:19 -04002278 m = (typeof(m)){"LP10000-S", "PCI",
2279 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002280 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002281 case PCI_DEVICE_ID_LP11000S:
James Smart12222f42014-05-21 08:05:19 -04002282 m = (typeof(m)){"LP11000-S", "PCI-X2",
2283 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05002284 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002285 case PCI_DEVICE_ID_LPE11000S:
James Smart12222f42014-05-21 08:05:19 -04002286 m = (typeof(m)){"LPe11000-S", "PCIe",
2287 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002288 break;
James Smartb87eab32007-04-25 09:53:28 -04002289 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05002290 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002291 break;
2292 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05002293 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002294 break;
2295 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05002296 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002297 break;
2298 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002299 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002300 break;
2301 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002302 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002303 break;
2304 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05002305 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002306 break;
James Smart84774a42008-08-24 21:50:06 -04002307 case PCI_DEVICE_ID_HORNET:
James Smart12222f42014-05-21 08:05:19 -04002308 m = (typeof(m)){"LP21000", "PCIe",
2309 "Obsolete, Unsupported FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002310 GE = 1;
2311 break;
2312 case PCI_DEVICE_ID_PROTEUS_VF:
James Smarta747c9c2009-11-18 15:41:10 -05002313 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002314 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002315 break;
2316 case PCI_DEVICE_ID_PROTEUS_PF:
James Smarta747c9c2009-11-18 15:41:10 -05002317 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002318 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002319 break;
2320 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05002321 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002322 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002323 break;
James Smartda0436e2009-05-22 14:51:39 -04002324 case PCI_DEVICE_ID_TIGERSHARK:
2325 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002326 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04002327 break;
James Smarta747c9c2009-11-18 15:41:10 -05002328 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04002329 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002330 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2331 break;
2332 case PCI_DEVICE_ID_FALCON:
2333 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2334 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04002335 break;
James Smart98fc5dd2010-06-07 15:24:29 -04002336 case PCI_DEVICE_ID_BALIUS:
2337 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
James Smart12222f42014-05-21 08:05:19 -04002338 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart98fc5dd2010-06-07 15:24:29 -04002339 break;
James Smart085c6472010-11-20 23:11:37 -05002340 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04002341 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05002342 break;
James Smart12222f42014-05-21 08:05:19 -04002343 case PCI_DEVICE_ID_LANCER_FC_VF:
2344 m = (typeof(m)){"LPe16000", "PCIe",
2345 "Obsolete, Unsupported Fibre Channel Adapter"};
2346 break;
James Smart085c6472010-11-20 23:11:37 -05002347 case PCI_DEVICE_ID_LANCER_FCOE:
2348 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04002349 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05002350 break;
James Smart12222f42014-05-21 08:05:19 -04002351 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2352 oneConnect = 1;
2353 m = (typeof(m)){"OCe15100", "PCIe",
2354 "Obsolete, Unsupported FCoE"};
2355 break;
James Smartd38dd522015-08-31 16:48:17 -04002356 case PCI_DEVICE_ID_LANCER_G6_FC:
2357 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2358 break;
James Smartf8cafd32012-08-03 12:42:51 -04002359 case PCI_DEVICE_ID_SKYHAWK:
2360 case PCI_DEVICE_ID_SKYHAWK_VF:
2361 oneConnect = 1;
2362 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2363 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002364 default:
James Smarta747c9c2009-11-18 15:41:10 -05002365 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002366 break;
dea31012005-04-17 16:05:31 -05002367 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002368
2369 if (mdp && mdp[0] == '\0')
2370 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04002371 /*
2372 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04002373 * and we put the port number on the end
2374 */
2375 if (descp && descp[0] == '\0') {
2376 if (oneConnect)
2377 snprintf(descp, 255,
James Smart4169d862012-09-29 11:32:09 -04002378 "Emulex OneConnect %s, %s Initiator %s",
James Smarta747c9c2009-11-18 15:41:10 -05002379 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04002380 phba->Port);
James Smart4169d862012-09-29 11:32:09 -04002381 else if (max_speed == 0)
2382 snprintf(descp, 255,
Sebastian Herbszt290237d2015-08-31 16:48:08 -04002383 "Emulex %s %s %s",
James Smart4169d862012-09-29 11:32:09 -04002384 m.name, m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002385 else
2386 snprintf(descp, 255,
2387 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05002388 m.name, max_speed, (GE) ? "GE" : "Gb",
2389 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002390 }
dea31012005-04-17 16:05:31 -05002391}
2392
James Smarte59058c2008-08-24 21:49:00 -04002393/**
James Smart3621a712009-04-06 18:47:14 -04002394 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04002395 * @phba: pointer to lpfc hba data structure.
2396 * @pring: pointer to a IOCB ring.
2397 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2398 *
2399 * This routine posts a given number of IOCBs with the associated DMA buffer
2400 * descriptors specified by the cnt argument to the given IOCB ring.
2401 *
2402 * Return codes
2403 * The number of IOCBs NOT able to be posted to the IOCB ring.
2404 **/
dea31012005-04-17 16:05:31 -05002405int
James Smart495a7142008-06-14 22:52:59 -04002406lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002407{
2408 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002409 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002410 struct lpfc_dmabuf *mp1, *mp2;
2411
2412 cnt += pring->missbufcnt;
2413
2414 /* While there are buffers to post */
2415 while (cnt > 0) {
2416 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002417 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002418 if (iocb == NULL) {
2419 pring->missbufcnt = cnt;
2420 return cnt;
2421 }
dea31012005-04-17 16:05:31 -05002422 icmd = &iocb->iocb;
2423
2424 /* 2 buffers can be posted per command */
2425 /* Allocate buffer to post */
2426 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2427 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002428 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2429 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002430 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002431 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002432 pring->missbufcnt = cnt;
2433 return cnt;
2434 }
2435
2436 INIT_LIST_HEAD(&mp1->list);
2437 /* Allocate buffer to post */
2438 if (cnt > 1) {
2439 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2440 if (mp2)
2441 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2442 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002443 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002444 kfree(mp2);
dea31012005-04-17 16:05:31 -05002445 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2446 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002447 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002448 pring->missbufcnt = cnt;
2449 return cnt;
2450 }
2451
2452 INIT_LIST_HEAD(&mp2->list);
2453 } else {
2454 mp2 = NULL;
2455 }
2456
2457 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2458 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2459 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2460 icmd->ulpBdeCount = 1;
2461 cnt--;
2462 if (mp2) {
2463 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2464 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2465 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2466 cnt--;
2467 icmd->ulpBdeCount = 2;
2468 }
2469
2470 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2471 icmd->ulpLe = 1;
2472
James Smart3772a992009-05-22 14:50:54 -04002473 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2474 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002475 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2476 kfree(mp1);
2477 cnt++;
2478 if (mp2) {
2479 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2480 kfree(mp2);
2481 cnt++;
2482 }
James Bottomley604a3e32005-10-29 10:28:33 -05002483 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002484 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002485 return cnt;
2486 }
dea31012005-04-17 16:05:31 -05002487 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002488 if (mp2)
dea31012005-04-17 16:05:31 -05002489 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002490 }
2491 pring->missbufcnt = 0;
2492 return 0;
2493}
2494
James Smarte59058c2008-08-24 21:49:00 -04002495/**
James Smart3621a712009-04-06 18:47:14 -04002496 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002497 * @phba: pointer to lpfc hba data structure.
2498 *
2499 * This routine posts initial receive IOCB buffers to the ELS ring. The
2500 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
James Smart895427b2017-02-12 13:52:30 -08002501 * set to 64 IOCBs. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002502 *
2503 * Return codes
2504 * 0 - success (currently always success)
2505 **/
dea31012005-04-17 16:05:31 -05002506static int
James Smart2e0fef82007-06-17 19:56:36 -05002507lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002508{
2509 struct lpfc_sli *psli = &phba->sli;
2510
2511 /* Ring 0, ELS / CT buffers */
James Smart895427b2017-02-12 13:52:30 -08002512 lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002513 /* Ring 2 - FCP no buffers needed */
2514
2515 return 0;
2516}
2517
2518#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2519
James Smarte59058c2008-08-24 21:49:00 -04002520/**
James Smart3621a712009-04-06 18:47:14 -04002521 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002522 * @HashResultPointer: pointer to an array as hash table.
2523 *
2524 * This routine sets up the initial values to the array of hash table entries
2525 * for the LC HBAs.
2526 **/
dea31012005-04-17 16:05:31 -05002527static void
2528lpfc_sha_init(uint32_t * HashResultPointer)
2529{
2530 HashResultPointer[0] = 0x67452301;
2531 HashResultPointer[1] = 0xEFCDAB89;
2532 HashResultPointer[2] = 0x98BADCFE;
2533 HashResultPointer[3] = 0x10325476;
2534 HashResultPointer[4] = 0xC3D2E1F0;
2535}
2536
James Smarte59058c2008-08-24 21:49:00 -04002537/**
James Smart3621a712009-04-06 18:47:14 -04002538 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002539 * @HashResultPointer: pointer to an initial/result hash table.
2540 * @HashWorkingPointer: pointer to an working hash table.
2541 *
2542 * This routine iterates an initial hash table pointed by @HashResultPointer
2543 * with the values from the working hash table pointeed by @HashWorkingPointer.
2544 * The results are putting back to the initial hash table, returned through
2545 * the @HashResultPointer as the result hash table.
2546 **/
dea31012005-04-17 16:05:31 -05002547static void
2548lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2549{
2550 int t;
2551 uint32_t TEMP;
2552 uint32_t A, B, C, D, E;
2553 t = 16;
2554 do {
2555 HashWorkingPointer[t] =
2556 S(1,
2557 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2558 8] ^
2559 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2560 } while (++t <= 79);
2561 t = 0;
2562 A = HashResultPointer[0];
2563 B = HashResultPointer[1];
2564 C = HashResultPointer[2];
2565 D = HashResultPointer[3];
2566 E = HashResultPointer[4];
2567
2568 do {
2569 if (t < 20) {
2570 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2571 } else if (t < 40) {
2572 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2573 } else if (t < 60) {
2574 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2575 } else {
2576 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2577 }
2578 TEMP += S(5, A) + E + HashWorkingPointer[t];
2579 E = D;
2580 D = C;
2581 C = S(30, B);
2582 B = A;
2583 A = TEMP;
2584 } while (++t <= 79);
2585
2586 HashResultPointer[0] += A;
2587 HashResultPointer[1] += B;
2588 HashResultPointer[2] += C;
2589 HashResultPointer[3] += D;
2590 HashResultPointer[4] += E;
2591
2592}
2593
James Smarte59058c2008-08-24 21:49:00 -04002594/**
James Smart3621a712009-04-06 18:47:14 -04002595 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002596 * @RandomChallenge: pointer to the entry of host challenge random number array.
2597 * @HashWorking: pointer to the entry of the working hash array.
2598 *
2599 * This routine calculates the working hash array referred by @HashWorking
2600 * from the challenge random numbers associated with the host, referred by
2601 * @RandomChallenge. The result is put into the entry of the working hash
2602 * array and returned by reference through @HashWorking.
2603 **/
dea31012005-04-17 16:05:31 -05002604static void
2605lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2606{
2607 *HashWorking = (*RandomChallenge ^ *HashWorking);
2608}
2609
James Smarte59058c2008-08-24 21:49:00 -04002610/**
James Smart3621a712009-04-06 18:47:14 -04002611 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002612 * @phba: pointer to lpfc hba data structure.
2613 * @hbainit: pointer to an array of unsigned 32-bit integers.
2614 *
2615 * This routine performs the special handling for LC HBA initialization.
2616 **/
dea31012005-04-17 16:05:31 -05002617void
2618lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2619{
2620 int t;
2621 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002622 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002623
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002624 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002625 if (!HashWorking)
2626 return;
2627
dea31012005-04-17 16:05:31 -05002628 HashWorking[0] = HashWorking[78] = *pwwnn++;
2629 HashWorking[1] = HashWorking[79] = *pwwnn;
2630
2631 for (t = 0; t < 7; t++)
2632 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2633
2634 lpfc_sha_init(hbainit);
2635 lpfc_sha_iterate(hbainit, HashWorking);
2636 kfree(HashWorking);
2637}
2638
James Smarte59058c2008-08-24 21:49:00 -04002639/**
James Smart3621a712009-04-06 18:47:14 -04002640 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002641 * @vport: pointer to a virtual N_Port data structure.
2642 *
2643 * This routine performs the necessary cleanups before deleting the @vport.
2644 * It invokes the discovery state machine to perform necessary state
2645 * transitions and to release the ndlps associated with the @vport. Note,
2646 * the physical port is treated as @vport 0.
2647 **/
James Smart87af33f2007-10-27 13:37:43 -04002648void
James Smart2e0fef82007-06-17 19:56:36 -05002649lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002650{
James Smart87af33f2007-10-27 13:37:43 -04002651 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002652 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002653 int i = 0;
dea31012005-04-17 16:05:31 -05002654
James Smart87af33f2007-10-27 13:37:43 -04002655 if (phba->link_state > LPFC_LINK_DOWN)
2656 lpfc_port_link_failure(vport);
2657
2658 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002659 if (!NLP_CHK_NODE_ACT(ndlp)) {
2660 ndlp = lpfc_enable_node(vport, ndlp,
2661 NLP_STE_UNUSED_NODE);
2662 if (!ndlp)
2663 continue;
2664 spin_lock_irq(&phba->ndlp_lock);
2665 NLP_SET_FREE_REQ(ndlp);
2666 spin_unlock_irq(&phba->ndlp_lock);
2667 /* Trigger the release of the ndlp memory */
2668 lpfc_nlp_put(ndlp);
2669 continue;
2670 }
2671 spin_lock_irq(&phba->ndlp_lock);
2672 if (NLP_CHK_FREE_REQ(ndlp)) {
2673 /* The ndlp should not be in memory free mode already */
2674 spin_unlock_irq(&phba->ndlp_lock);
2675 continue;
2676 } else
2677 /* Indicate request for freeing ndlp memory */
2678 NLP_SET_FREE_REQ(ndlp);
2679 spin_unlock_irq(&phba->ndlp_lock);
2680
James Smart58da1ff2008-04-07 10:15:56 -04002681 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2682 ndlp->nlp_DID == Fabric_DID) {
2683 /* Just free up ndlp with Fabric_DID for vports */
2684 lpfc_nlp_put(ndlp);
2685 continue;
2686 }
2687
James Smarteff4a012012-01-18 16:25:25 -05002688 /* take care of nodes in unused state before the state
2689 * machine taking action.
2690 */
2691 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2692 lpfc_nlp_put(ndlp);
2693 continue;
2694 }
2695
James Smart87af33f2007-10-27 13:37:43 -04002696 if (ndlp->nlp_type & NLP_FABRIC)
2697 lpfc_disc_state_machine(vport, ndlp, NULL,
2698 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002699
James Smarta0f2d3e2017-02-12 13:52:31 -08002700 if (ndlp->nlp_fc4_type & NLP_FC4_NVME) {
2701 /* Remove the NVME transport reference now and
2702 * continue to remove the node.
2703 */
2704 lpfc_nlp_put(ndlp);
2705 }
2706
James Smart87af33f2007-10-27 13:37:43 -04002707 lpfc_disc_state_machine(vport, ndlp, NULL,
2708 NLP_EVT_DEVICE_RM);
2709 }
2710
James Smarta8adb832007-10-27 13:37:53 -04002711 /* At this point, ALL ndlp's should be gone
2712 * because of the previous NLP_EVT_DEVICE_RM.
2713 * Lets wait for this to happen, if needed.
2714 */
James Smart87af33f2007-10-27 13:37:43 -04002715 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002716 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04002717 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04002718 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002719 list_for_each_entry_safe(ndlp, next_ndlp,
2720 &vport->fc_nodes, nlp_listp) {
2721 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2722 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04002723 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05002724 "usgmap:x%x refcnt:%d\n",
2725 ndlp->nlp_DID, (void *)ndlp,
2726 ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01002727 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05002728 }
James Smarta8adb832007-10-27 13:37:53 -04002729 break;
James Smart87af33f2007-10-27 13:37:43 -04002730 }
James Smarta8adb832007-10-27 13:37:53 -04002731
2732 /* Wait for any activity on ndlps to settle */
2733 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002734 }
James Smart1151e3e2011-02-16 12:39:35 -05002735 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002736}
2737
James Smarte59058c2008-08-24 21:49:00 -04002738/**
James Smart3621a712009-04-06 18:47:14 -04002739 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002740 * @vport: pointer to a virtual N_Port data structure.
2741 *
2742 * This routine stops all the timers associated with a @vport. This function
2743 * is invoked before disabling or deleting a @vport. Note that the physical
2744 * port is treated as @vport 0.
2745 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002746void
2747lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002748{
James Smart92d7f7b2007-06-17 19:56:38 -05002749 del_timer_sync(&vport->els_tmofunc);
James Smart92494142011-02-16 12:39:44 -05002750 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002751 lpfc_can_disctmo(vport);
2752 return;
dea31012005-04-17 16:05:31 -05002753}
2754
James Smarte59058c2008-08-24 21:49:00 -04002755/**
James Smartecfd03c2010-02-12 14:41:27 -05002756 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2757 * @phba: pointer to lpfc hba data structure.
2758 *
2759 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2760 * caller of this routine should already hold the host lock.
2761 **/
2762void
2763__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2764{
James Smart5ac6b302010-10-22 11:05:36 -04002765 /* Clear pending FCF rediscovery wait flag */
2766 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2767
James Smartecfd03c2010-02-12 14:41:27 -05002768 /* Now, try to stop the timer */
2769 del_timer(&phba->fcf.redisc_wait);
2770}
2771
2772/**
2773 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2774 * @phba: pointer to lpfc hba data structure.
2775 *
2776 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2777 * checks whether the FCF rediscovery wait timer is pending with the host
2778 * lock held before proceeding with disabling the timer and clearing the
2779 * wait timer pendig flag.
2780 **/
2781void
2782lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2783{
2784 spin_lock_irq(&phba->hbalock);
2785 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2786 /* FCF rediscovery timer already fired or stopped */
2787 spin_unlock_irq(&phba->hbalock);
2788 return;
2789 }
2790 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002791 /* Clear failover in progress flags */
2792 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002793 spin_unlock_irq(&phba->hbalock);
2794}
2795
2796/**
James Smart3772a992009-05-22 14:50:54 -04002797 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002798 * @phba: pointer to lpfc hba data structure.
2799 *
2800 * This routine stops all the timers associated with a HBA. This function is
2801 * invoked before either putting a HBA offline or unloading the driver.
2802 **/
James Smart3772a992009-05-22 14:50:54 -04002803void
2804lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002805{
James Smart51ef4c22007-08-02 11:10:31 -04002806 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05002807 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002808 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002809 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002810 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002811 if (phba->sli_rev == LPFC_SLI_REV4) {
2812 del_timer_sync(&phba->rrq_tmr);
2813 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2814 }
James Smart3772a992009-05-22 14:50:54 -04002815 phba->hb_outstanding = 0;
2816
2817 switch (phba->pci_dev_grp) {
2818 case LPFC_PCI_DEV_LP:
2819 /* Stop any LightPulse device specific driver timers */
2820 del_timer_sync(&phba->fcp_poll_timer);
2821 break;
2822 case LPFC_PCI_DEV_OC:
2823 /* Stop any OneConnect device sepcific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002824 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002825 break;
2826 default:
2827 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2828 "0297 Invalid device group (x%x)\n",
2829 phba->pci_dev_grp);
2830 break;
2831 }
James Smart2e0fef82007-06-17 19:56:36 -05002832 return;
dea31012005-04-17 16:05:31 -05002833}
2834
James Smarte59058c2008-08-24 21:49:00 -04002835/**
James Smart3621a712009-04-06 18:47:14 -04002836 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002837 * @phba: pointer to lpfc hba data structure.
2838 *
2839 * This routine marks a HBA's management interface as blocked. Once the HBA's
2840 * management interface is marked as blocked, all the user space access to
2841 * the HBA, whether they are from sysfs interface or libdfc interface will
2842 * all be blocked. The HBA is set to block the management interface when the
2843 * driver prepares the HBA interface for online or offline.
2844 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01002845static void
James Smart618a5232012-06-12 13:54:36 -04002846lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
Adrian Bunka6ababd2007-11-05 18:07:33 +01002847{
2848 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04002849 uint8_t actcmd = MBX_HEARTBEAT;
2850 unsigned long timeout;
2851
Adrian Bunka6ababd2007-11-05 18:07:33 +01002852 spin_lock_irqsave(&phba->hbalock, iflag);
2853 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart618a5232012-06-12 13:54:36 -04002854 spin_unlock_irqrestore(&phba->hbalock, iflag);
2855 if (mbx_action == LPFC_MBX_NO_WAIT)
2856 return;
2857 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2858 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002859 if (phba->sli.mbox_active) {
James Smart6e7288d2010-06-07 15:23:35 -04002860 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
James Smarta183a152011-10-10 21:32:43 -04002861 /* Determine how long we might wait for the active mailbox
2862 * command to be gracefully completed by firmware.
2863 */
2864 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
2865 phba->sli.mbox_active) * 1000) + jiffies;
2866 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002867 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002868
James Smart6e7288d2010-06-07 15:23:35 -04002869 /* Wait for the outstnading mailbox command to complete */
2870 while (phba->sli.mbox_active) {
2871 /* Check active mailbox complete status every 2ms */
2872 msleep(2);
2873 if (time_after(jiffies, timeout)) {
2874 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2875 "2813 Mgmt IO is Blocked %x "
2876 "- mbox cmd %x still active\n",
2877 phba->sli.sli_flag, actcmd);
2878 break;
2879 }
2880 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002881}
2882
James Smarte59058c2008-08-24 21:49:00 -04002883/**
James Smart6b5151f2012-01-18 16:24:06 -05002884 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
2885 * @phba: pointer to lpfc hba data structure.
2886 *
2887 * Allocate RPIs for all active remote nodes. This is needed whenever
2888 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
2889 * is to fixup the temporary rpi assignments.
2890 **/
2891void
2892lpfc_sli4_node_prep(struct lpfc_hba *phba)
2893{
2894 struct lpfc_nodelist *ndlp, *next_ndlp;
2895 struct lpfc_vport **vports;
James Smart9d3d3402017-04-21 16:05:00 -07002896 int i, rpi;
2897 unsigned long flags;
James Smart6b5151f2012-01-18 16:24:06 -05002898
2899 if (phba->sli_rev != LPFC_SLI_REV4)
2900 return;
2901
2902 vports = lpfc_create_vport_work_array(phba);
James Smart9d3d3402017-04-21 16:05:00 -07002903 if (vports == NULL)
2904 return;
James Smart6b5151f2012-01-18 16:24:06 -05002905
James Smart9d3d3402017-04-21 16:05:00 -07002906 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2907 if (vports[i]->load_flag & FC_UNLOADING)
2908 continue;
2909
2910 list_for_each_entry_safe(ndlp, next_ndlp,
2911 &vports[i]->fc_nodes,
2912 nlp_listp) {
2913 if (!NLP_CHK_NODE_ACT(ndlp))
2914 continue;
2915 rpi = lpfc_sli4_alloc_rpi(phba);
2916 if (rpi == LPFC_RPI_ALLOC_ERROR) {
2917 spin_lock_irqsave(&phba->ndlp_lock, flags);
2918 NLP_CLR_NODE_ACT(ndlp);
2919 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
2920 continue;
James Smart6b5151f2012-01-18 16:24:06 -05002921 }
James Smart9d3d3402017-04-21 16:05:00 -07002922 ndlp->nlp_rpi = rpi;
2923 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
2924 "0009 rpi:%x DID:%x "
2925 "flg:%x map:%x %p\n", ndlp->nlp_rpi,
2926 ndlp->nlp_DID, ndlp->nlp_flag,
2927 ndlp->nlp_usg_map, ndlp);
James Smart6b5151f2012-01-18 16:24:06 -05002928 }
2929 }
2930 lpfc_destroy_vport_work_array(phba, vports);
2931}
2932
2933/**
James Smart3621a712009-04-06 18:47:14 -04002934 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04002935 * @phba: pointer to lpfc hba data structure.
2936 *
2937 * This routine initializes the HBA and brings a HBA online. During this
2938 * process, the management interface is blocked to prevent user space access
2939 * to the HBA interfering with the driver initialization.
2940 *
2941 * Return codes
2942 * 0 - successful
2943 * 1 - failed
2944 **/
dea31012005-04-17 16:05:31 -05002945int
James Smart2e0fef82007-06-17 19:56:36 -05002946lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002947{
Julia Lawall372bd282008-12-16 16:15:08 +01002948 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04002949 struct lpfc_vport **vports;
2950 int i;
James Smart16a3a202013-04-17 20:14:38 -04002951 bool vpis_cleared = false;
James Smart2e0fef82007-06-17 19:56:36 -05002952
dea31012005-04-17 16:05:31 -05002953 if (!phba)
2954 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01002955 vport = phba->pport;
dea31012005-04-17 16:05:31 -05002956
James Smart2e0fef82007-06-17 19:56:36 -05002957 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05002958 return 0;
2959
James Smarted957682007-06-17 19:56:37 -05002960 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002961 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05002962
James Smart618a5232012-06-12 13:54:36 -04002963 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05002964
James Smartda0436e2009-05-22 14:51:39 -04002965 if (phba->sli_rev == LPFC_SLI_REV4) {
2966 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
2967 lpfc_unblock_mgmt_io(phba);
2968 return 1;
2969 }
James Smart16a3a202013-04-17 20:14:38 -04002970 spin_lock_irq(&phba->hbalock);
2971 if (!phba->sli4_hba.max_cfg_param.vpi_used)
2972 vpis_cleared = true;
2973 spin_unlock_irq(&phba->hbalock);
James Smartda0436e2009-05-22 14:51:39 -04002974 } else {
James Smart895427b2017-02-12 13:52:30 -08002975 lpfc_sli_queue_init(phba);
James Smartda0436e2009-05-22 14:51:39 -04002976 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
2977 lpfc_unblock_mgmt_io(phba);
2978 return 1;
2979 }
James Smart46fa3112007-04-25 09:51:45 -04002980 }
dea31012005-04-17 16:05:31 -05002981
James Smart549e55c2007-08-02 11:09:51 -04002982 vports = lpfc_create_vport_work_array(phba);
Arnd Bergmannaeb66412016-03-14 15:29:44 +01002983 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04002984 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002985 struct Scsi_Host *shost;
2986 shost = lpfc_shost_from_vport(vports[i]);
2987 spin_lock_irq(shost->host_lock);
2988 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
2989 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2990 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart16a3a202013-04-17 20:14:38 -04002991 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart1c6834a2009-07-19 10:01:26 -04002992 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart16a3a202013-04-17 20:14:38 -04002993 if ((vpis_cleared) &&
2994 (vports[i]->port_type !=
2995 LPFC_PHYSICAL_PORT))
2996 vports[i]->vpi = 0;
2997 }
James Smart549e55c2007-08-02 11:09:51 -04002998 spin_unlock_irq(shost->host_lock);
2999 }
Arnd Bergmannaeb66412016-03-14 15:29:44 +01003000 }
3001 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003002
James Smart46fa3112007-04-25 09:51:45 -04003003 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05003004 return 0;
3005}
3006
James Smarte59058c2008-08-24 21:49:00 -04003007/**
James Smart3621a712009-04-06 18:47:14 -04003008 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04003009 * @phba: pointer to lpfc hba data structure.
3010 *
3011 * This routine marks a HBA's management interface as not blocked. Once the
3012 * HBA's management interface is marked as not blocked, all the user space
3013 * access to the HBA, whether they are from sysfs interface or libdfc
3014 * interface will be allowed. The HBA is set to block the management interface
3015 * when the driver prepares the HBA interface for online or offline and then
3016 * set to unblock the management interface afterwards.
3017 **/
James Smart46fa3112007-04-25 09:51:45 -04003018void
James Smart46fa3112007-04-25 09:51:45 -04003019lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
3020{
3021 unsigned long iflag;
3022
James Smart2e0fef82007-06-17 19:56:36 -05003023 spin_lock_irqsave(&phba->hbalock, iflag);
3024 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3025 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04003026}
3027
James Smarte59058c2008-08-24 21:49:00 -04003028/**
James Smart3621a712009-04-06 18:47:14 -04003029 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04003030 * @phba: pointer to lpfc hba data structure.
3031 *
3032 * This routine is invoked to prepare a HBA to be brought offline. It performs
3033 * unregistration login to all the nodes on all vports and flushes the mailbox
3034 * queue to make it ready to be brought offline.
3035 **/
James Smart46fa3112007-04-25 09:51:45 -04003036void
James Smart618a5232012-06-12 13:54:36 -04003037lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04003038{
James Smart2e0fef82007-06-17 19:56:36 -05003039 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04003040 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04003041 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05003042 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04003043 int i;
dea31012005-04-17 16:05:31 -05003044
James Smart2e0fef82007-06-17 19:56:36 -05003045 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003046 return;
dea31012005-04-17 16:05:31 -05003047
James Smart618a5232012-06-12 13:54:36 -04003048 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05003049
3050 lpfc_linkdown(phba);
3051
James Smart87af33f2007-10-27 13:37:43 -04003052 /* Issue an unreg_login to all nodes on all vports */
3053 vports = lpfc_create_vport_work_array(phba);
3054 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003055 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04003056 if (vports[i]->load_flag & FC_UNLOADING)
3057 continue;
James Smart72100cc2010-02-12 14:43:01 -05003058 shost = lpfc_shost_from_vport(vports[i]);
3059 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003060 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003061 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3062 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05003063 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05003064
James Smart87af33f2007-10-27 13:37:43 -04003065 shost = lpfc_shost_from_vport(vports[i]);
3066 list_for_each_entry_safe(ndlp, next_ndlp,
3067 &vports[i]->fc_nodes,
3068 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003069 if (!NLP_CHK_NODE_ACT(ndlp))
3070 continue;
James Smart87af33f2007-10-27 13:37:43 -04003071 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3072 continue;
3073 if (ndlp->nlp_type & NLP_FABRIC) {
3074 lpfc_disc_state_machine(vports[i], ndlp,
3075 NULL, NLP_EVT_DEVICE_RECOVERY);
3076 lpfc_disc_state_machine(vports[i], ndlp,
3077 NULL, NLP_EVT_DEVICE_RM);
3078 }
3079 spin_lock_irq(shost->host_lock);
3080 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart401ee0c2012-03-01 22:35:34 -05003081 spin_unlock_irq(shost->host_lock);
James Smart6b5151f2012-01-18 16:24:06 -05003082 /*
3083 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05003084 * RPI. Get a new RPI when the adapter port
3085 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05003086 */
James Smartbe6bb942015-04-07 15:07:22 -04003087 if (phba->sli_rev == LPFC_SLI_REV4) {
3088 lpfc_printf_vlog(ndlp->vport,
3089 KERN_INFO, LOG_NODE,
3090 "0011 lpfc_offline: "
3091 "ndlp:x%p did %x "
3092 "usgmap:x%x rpi:%x\n",
3093 ndlp, ndlp->nlp_DID,
3094 ndlp->nlp_usg_map,
3095 ndlp->nlp_rpi);
3096
James Smart6b5151f2012-01-18 16:24:06 -05003097 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smartbe6bb942015-04-07 15:07:22 -04003098 }
James Smart87af33f2007-10-27 13:37:43 -04003099 lpfc_unreg_rpi(vports[i], ndlp);
3100 }
3101 }
3102 }
James Smart09372822008-01-11 01:52:54 -05003103 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003104
James Smart618a5232012-06-12 13:54:36 -04003105 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
James Smart46fa3112007-04-25 09:51:45 -04003106}
3107
James Smarte59058c2008-08-24 21:49:00 -04003108/**
James Smart3621a712009-04-06 18:47:14 -04003109 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04003110 * @phba: pointer to lpfc hba data structure.
3111 *
3112 * This routine actually brings a HBA offline. It stops all the timers
3113 * associated with the HBA, brings down the SLI layer, and eventually
3114 * marks the HBA as in offline state for the upper layer protocol.
3115 **/
James Smart46fa3112007-04-25 09:51:45 -04003116void
James Smart2e0fef82007-06-17 19:56:36 -05003117lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04003118{
James Smart549e55c2007-08-02 11:09:51 -04003119 struct Scsi_Host *shost;
3120 struct lpfc_vport **vports;
3121 int i;
James Smart46fa3112007-04-25 09:51:45 -04003122
James Smart549e55c2007-08-02 11:09:51 -04003123 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003124 return;
James Smart688a8862006-07-06 15:49:56 -04003125
James Smartda0436e2009-05-22 14:51:39 -04003126 /* stop port and all timers associated with this hba */
3127 lpfc_stop_port(phba);
James Smart51ef4c22007-08-02 11:10:31 -04003128 vports = lpfc_create_vport_work_array(phba);
3129 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003130 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04003131 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05003132 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05003133 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003134 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05003135 /* Bring down the SLI Layer and cleanup. The HBA is offline
3136 now. */
3137 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003138 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04003139 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003140 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04003141 vports = lpfc_create_vport_work_array(phba);
3142 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003143 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003144 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04003145 spin_lock_irq(shost->host_lock);
3146 vports[i]->work_port_events = 0;
3147 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3148 spin_unlock_irq(shost->host_lock);
3149 }
James Smart09372822008-01-11 01:52:54 -05003150 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003151}
3152
James Smarte59058c2008-08-24 21:49:00 -04003153/**
James Smart3621a712009-04-06 18:47:14 -04003154 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04003155 * @phba: pointer to lpfc hba data structure.
3156 *
3157 * This routine is to free all the SCSI buffers and IOCBs from the driver
3158 * list back to kernel. It is called from lpfc_pci_remove_one to free
3159 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04003160 **/
James Smart8a9d2e82012-05-09 21:16:12 -04003161static void
James Smart2e0fef82007-06-17 19:56:36 -05003162lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003163{
3164 struct lpfc_scsi_buf *sb, *sb_next;
dea31012005-04-17 16:05:31 -05003165
James Smart895427b2017-02-12 13:52:30 -08003166 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3167 return;
3168
James Smart2e0fef82007-06-17 19:56:36 -05003169 spin_lock_irq(&phba->hbalock);
James Smarta40fc5f2013-04-17 20:17:40 -04003170
dea31012005-04-17 16:05:31 -05003171 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smarta40fc5f2013-04-17 20:17:40 -04003172
3173 spin_lock(&phba->scsi_buf_list_put_lock);
3174 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3175 list) {
dea31012005-04-17 16:05:31 -05003176 list_del(&sb->list);
James Smart895427b2017-02-12 13:52:30 -08003177 pci_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05003178 sb->dma_handle);
dea31012005-04-17 16:05:31 -05003179 kfree(sb);
3180 phba->total_scsi_bufs--;
3181 }
James Smarta40fc5f2013-04-17 20:17:40 -04003182 spin_unlock(&phba->scsi_buf_list_put_lock);
3183
3184 spin_lock(&phba->scsi_buf_list_get_lock);
3185 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3186 list) {
3187 list_del(&sb->list);
James Smart895427b2017-02-12 13:52:30 -08003188 pci_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smarta40fc5f2013-04-17 20:17:40 -04003189 sb->dma_handle);
3190 kfree(sb);
3191 phba->total_scsi_bufs--;
3192 }
3193 spin_unlock(&phba->scsi_buf_list_get_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003194 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003195}
James Smart8a9d2e82012-05-09 21:16:12 -04003196/**
James Smart895427b2017-02-12 13:52:30 -08003197 * lpfc_nvme_free - Free all the NVME buffers and IOCBs from driver lists
3198 * @phba: pointer to lpfc hba data structure.
3199 *
3200 * This routine is to free all the NVME buffers and IOCBs from the driver
3201 * list back to kernel. It is called from lpfc_pci_remove_one to free
3202 * the internal resources before the device is removed from the system.
3203 **/
3204static void
3205lpfc_nvme_free(struct lpfc_hba *phba)
3206{
3207 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
James Smart895427b2017-02-12 13:52:30 -08003208
3209 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3210 return;
3211
3212 spin_lock_irq(&phba->hbalock);
3213
3214 /* Release all the lpfc_nvme_bufs maintained by this host. */
3215 spin_lock(&phba->nvme_buf_list_put_lock);
3216 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3217 &phba->lpfc_nvme_buf_list_put, list) {
3218 list_del(&lpfc_ncmd->list);
3219 pci_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
3220 lpfc_ncmd->dma_handle);
3221 kfree(lpfc_ncmd);
3222 phba->total_nvme_bufs--;
3223 }
3224 spin_unlock(&phba->nvme_buf_list_put_lock);
3225
3226 spin_lock(&phba->nvme_buf_list_get_lock);
3227 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3228 &phba->lpfc_nvme_buf_list_get, list) {
3229 list_del(&lpfc_ncmd->list);
3230 pci_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
3231 lpfc_ncmd->dma_handle);
3232 kfree(lpfc_ncmd);
3233 phba->total_nvme_bufs--;
3234 }
3235 spin_unlock(&phba->nvme_buf_list_get_lock);
James Smart895427b2017-02-12 13:52:30 -08003236 spin_unlock_irq(&phba->hbalock);
3237}
3238/**
3239 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
James Smart8a9d2e82012-05-09 21:16:12 -04003240 * @phba: pointer to lpfc hba data structure.
3241 *
3242 * This routine first calculates the sizes of the current els and allocated
3243 * scsi sgl lists, and then goes through all sgls to updates the physical
3244 * XRIs assigned due to port function reset. During port initialization, the
3245 * current els and allocated scsi sgl lists are 0s.
3246 *
3247 * Return codes
3248 * 0 - successful (for now, it always returns 0)
3249 **/
3250int
James Smart895427b2017-02-12 13:52:30 -08003251lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
James Smart8a9d2e82012-05-09 21:16:12 -04003252{
3253 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
James Smart895427b2017-02-12 13:52:30 -08003254 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart8a9d2e82012-05-09 21:16:12 -04003255 LIST_HEAD(els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003256 int rc;
3257
3258 /*
3259 * update on pci function's els xri-sgl list
3260 */
3261 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart895427b2017-02-12 13:52:30 -08003262
James Smart8a9d2e82012-05-09 21:16:12 -04003263 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3264 /* els xri-sgl expanded */
3265 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3266 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3267 "3157 ELS xri-sgl count increased from "
3268 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3269 els_xri_cnt);
3270 /* allocate the additional els sgls */
3271 for (i = 0; i < xri_cnt; i++) {
3272 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3273 GFP_KERNEL);
3274 if (sglq_entry == NULL) {
3275 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3276 "2562 Failure to allocate an "
3277 "ELS sgl entry:%d\n", i);
3278 rc = -ENOMEM;
3279 goto out_free_mem;
3280 }
3281 sglq_entry->buff_type = GEN_BUFF_TYPE;
3282 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3283 &sglq_entry->phys);
3284 if (sglq_entry->virt == NULL) {
3285 kfree(sglq_entry);
3286 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3287 "2563 Failure to allocate an "
3288 "ELS mbuf:%d\n", i);
3289 rc = -ENOMEM;
3290 goto out_free_mem;
3291 }
3292 sglq_entry->sgl = sglq_entry->virt;
3293 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3294 sglq_entry->state = SGL_FREED;
3295 list_add_tail(&sglq_entry->list, &els_sgl_list);
3296 }
James Smart38c20672013-03-01 16:37:44 -05003297 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003298 spin_lock(&phba->sli4_hba.sgl_list_lock);
3299 list_splice_init(&els_sgl_list,
3300 &phba->sli4_hba.lpfc_els_sgl_list);
3301 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart38c20672013-03-01 16:37:44 -05003302 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003303 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3304 /* els xri-sgl shrinked */
3305 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3306 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3307 "3158 ELS xri-sgl count decreased from "
3308 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3309 els_xri_cnt);
3310 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003311 spin_lock(&phba->sli4_hba.sgl_list_lock);
3312 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
3313 &els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003314 /* release extra els sgls from list */
3315 for (i = 0; i < xri_cnt; i++) {
3316 list_remove_head(&els_sgl_list,
3317 sglq_entry, struct lpfc_sglq, list);
3318 if (sglq_entry) {
James Smart895427b2017-02-12 13:52:30 -08003319 __lpfc_mbuf_free(phba, sglq_entry->virt,
3320 sglq_entry->phys);
James Smart8a9d2e82012-05-09 21:16:12 -04003321 kfree(sglq_entry);
3322 }
3323 }
James Smart895427b2017-02-12 13:52:30 -08003324 list_splice_init(&els_sgl_list,
3325 &phba->sli4_hba.lpfc_els_sgl_list);
3326 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003327 spin_unlock_irq(&phba->hbalock);
3328 } else
3329 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3330 "3163 ELS xri-sgl count unchanged: %d\n",
3331 els_xri_cnt);
3332 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3333
3334 /* update xris to els sgls on the list */
3335 sglq_entry = NULL;
3336 sglq_entry_next = NULL;
3337 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
James Smart895427b2017-02-12 13:52:30 -08003338 &phba->sli4_hba.lpfc_els_sgl_list, list) {
James Smart8a9d2e82012-05-09 21:16:12 -04003339 lxri = lpfc_sli4_next_xritag(phba);
3340 if (lxri == NO_XRI) {
3341 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3342 "2400 Failed to allocate xri for "
3343 "ELS sgl\n");
3344 rc = -ENOMEM;
3345 goto out_free_mem;
3346 }
3347 sglq_entry->sli4_lxritag = lxri;
3348 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3349 }
James Smart895427b2017-02-12 13:52:30 -08003350 return 0;
3351
3352out_free_mem:
3353 lpfc_free_els_sgl_list(phba);
3354 return rc;
3355}
3356
3357/**
James Smartf358dd02017-02-12 13:52:34 -08003358 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
3359 * @phba: pointer to lpfc hba data structure.
3360 *
3361 * This routine first calculates the sizes of the current els and allocated
3362 * scsi sgl lists, and then goes through all sgls to updates the physical
3363 * XRIs assigned due to port function reset. During port initialization, the
3364 * current els and allocated scsi sgl lists are 0s.
3365 *
3366 * Return codes
3367 * 0 - successful (for now, it always returns 0)
3368 **/
3369int
3370lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
3371{
3372 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3373 uint16_t i, lxri, xri_cnt, els_xri_cnt;
3374 uint16_t nvmet_xri_cnt, tot_cnt;
3375 LIST_HEAD(nvmet_sgl_list);
3376 int rc;
3377
3378 /*
3379 * update on pci function's nvmet xri-sgl list
3380 */
3381 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart2d7dbc42017-02-12 13:52:35 -08003382 nvmet_xri_cnt = phba->cfg_nvmet_mrq * phba->cfg_nvmet_mrq_post;
James Smartf358dd02017-02-12 13:52:34 -08003383 tot_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
James Smart2d7dbc42017-02-12 13:52:35 -08003384 if (nvmet_xri_cnt > tot_cnt) {
3385 phba->cfg_nvmet_mrq_post = tot_cnt / phba->cfg_nvmet_mrq;
3386 nvmet_xri_cnt = phba->cfg_nvmet_mrq * phba->cfg_nvmet_mrq_post;
3387 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3388 "6301 NVMET post-sgl count changed to %d\n",
3389 phba->cfg_nvmet_mrq_post);
3390 }
James Smartf358dd02017-02-12 13:52:34 -08003391
3392 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
3393 /* els xri-sgl expanded */
3394 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
3395 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3396 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
3397 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
3398 /* allocate the additional nvmet sgls */
3399 for (i = 0; i < xri_cnt; i++) {
3400 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3401 GFP_KERNEL);
3402 if (sglq_entry == NULL) {
3403 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3404 "6303 Failure to allocate an "
3405 "NVMET sgl entry:%d\n", i);
3406 rc = -ENOMEM;
3407 goto out_free_mem;
3408 }
3409 sglq_entry->buff_type = NVMET_BUFF_TYPE;
3410 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
3411 &sglq_entry->phys);
3412 if (sglq_entry->virt == NULL) {
3413 kfree(sglq_entry);
3414 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3415 "6304 Failure to allocate an "
3416 "NVMET buf:%d\n", i);
3417 rc = -ENOMEM;
3418 goto out_free_mem;
3419 }
3420 sglq_entry->sgl = sglq_entry->virt;
3421 memset(sglq_entry->sgl, 0,
3422 phba->cfg_sg_dma_buf_size);
3423 sglq_entry->state = SGL_FREED;
3424 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
3425 }
3426 spin_lock_irq(&phba->hbalock);
3427 spin_lock(&phba->sli4_hba.sgl_list_lock);
3428 list_splice_init(&nvmet_sgl_list,
3429 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3430 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3431 spin_unlock_irq(&phba->hbalock);
3432 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
3433 /* nvmet xri-sgl shrunk */
3434 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
3435 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3436 "6305 NVMET xri-sgl count decreased from "
3437 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
3438 nvmet_xri_cnt);
3439 spin_lock_irq(&phba->hbalock);
3440 spin_lock(&phba->sli4_hba.sgl_list_lock);
3441 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
3442 &nvmet_sgl_list);
3443 /* release extra nvmet sgls from list */
3444 for (i = 0; i < xri_cnt; i++) {
3445 list_remove_head(&nvmet_sgl_list,
3446 sglq_entry, struct lpfc_sglq, list);
3447 if (sglq_entry) {
3448 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
3449 sglq_entry->phys);
3450 kfree(sglq_entry);
3451 }
3452 }
3453 list_splice_init(&nvmet_sgl_list,
3454 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3455 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3456 spin_unlock_irq(&phba->hbalock);
3457 } else
3458 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3459 "6306 NVMET xri-sgl count unchanged: %d\n",
3460 nvmet_xri_cnt);
3461 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
3462
3463 /* update xris to nvmet sgls on the list */
3464 sglq_entry = NULL;
3465 sglq_entry_next = NULL;
3466 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3467 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
3468 lxri = lpfc_sli4_next_xritag(phba);
3469 if (lxri == NO_XRI) {
3470 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3471 "6307 Failed to allocate xri for "
3472 "NVMET sgl\n");
3473 rc = -ENOMEM;
3474 goto out_free_mem;
3475 }
3476 sglq_entry->sli4_lxritag = lxri;
3477 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3478 }
3479 return 0;
3480
3481out_free_mem:
3482 lpfc_free_nvmet_sgl_list(phba);
3483 return rc;
3484}
3485
3486/**
James Smart895427b2017-02-12 13:52:30 -08003487 * lpfc_sli4_scsi_sgl_update - update xri-sgl sizing and mapping
3488 * @phba: pointer to lpfc hba data structure.
3489 *
3490 * This routine first calculates the sizes of the current els and allocated
3491 * scsi sgl lists, and then goes through all sgls to updates the physical
3492 * XRIs assigned due to port function reset. During port initialization, the
3493 * current els and allocated scsi sgl lists are 0s.
3494 *
3495 * Return codes
3496 * 0 - successful (for now, it always returns 0)
3497 **/
3498int
3499lpfc_sli4_scsi_sgl_update(struct lpfc_hba *phba)
3500{
3501 struct lpfc_scsi_buf *psb, *psb_next;
3502 uint16_t i, lxri, els_xri_cnt, scsi_xri_cnt;
3503 LIST_HEAD(scsi_sgl_list);
3504 int rc;
3505
3506 /*
3507 * update on pci function's els xri-sgl list
3508 */
3509 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3510 phba->total_scsi_bufs = 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003511
3512 /*
3513 * update on pci function's allocated scsi xri-sgl list
3514 */
James Smart8a9d2e82012-05-09 21:16:12 -04003515 /* maximum number of xris available for scsi buffers */
3516 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3517 els_xri_cnt;
3518
James Smart895427b2017-02-12 13:52:30 -08003519 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3520 return 0;
3521
3522 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3523 phba->sli4_hba.scsi_xri_max = /* Split them up */
3524 (phba->sli4_hba.scsi_xri_max *
3525 phba->cfg_xri_split) / 100;
James Smart8a9d2e82012-05-09 21:16:12 -04003526
James Smarta40fc5f2013-04-17 20:17:40 -04003527 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003528 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003529 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3530 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
James Smart164cecd2013-09-06 12:22:38 -04003531 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003532 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003533
James Smarte8c0a772017-04-21 16:04:49 -07003534 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3535 "6060 Current allocated SCSI xri-sgl count:%d, "
3536 "maximum SCSI xri count:%d (split:%d)\n",
3537 phba->sli4_hba.scsi_xri_cnt,
3538 phba->sli4_hba.scsi_xri_max, phba->cfg_xri_split);
3539
James Smart8a9d2e82012-05-09 21:16:12 -04003540 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3541 /* max scsi xri shrinked below the allocated scsi buffers */
3542 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3543 phba->sli4_hba.scsi_xri_max;
3544 /* release the extra allocated scsi buffers */
3545 for (i = 0; i < scsi_xri_cnt; i++) {
3546 list_remove_head(&scsi_sgl_list, psb,
3547 struct lpfc_scsi_buf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04003548 if (psb) {
James Smart895427b2017-02-12 13:52:30 -08003549 pci_pool_free(phba->lpfc_sg_dma_buf_pool,
James Smarta2fc4aef2014-09-03 12:57:55 -04003550 psb->data, psb->dma_handle);
3551 kfree(psb);
3552 }
James Smart8a9d2e82012-05-09 21:16:12 -04003553 }
James Smarta40fc5f2013-04-17 20:17:40 -04003554 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003555 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
James Smarta40fc5f2013-04-17 20:17:40 -04003556 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003557 }
3558
3559 /* update xris associated to remaining allocated scsi buffers */
3560 psb = NULL;
3561 psb_next = NULL;
3562 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3563 lxri = lpfc_sli4_next_xritag(phba);
3564 if (lxri == NO_XRI) {
3565 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3566 "2560 Failed to allocate xri for "
3567 "scsi buffer\n");
3568 rc = -ENOMEM;
3569 goto out_free_mem;
3570 }
3571 psb->cur_iocbq.sli4_lxritag = lxri;
3572 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3573 }
James Smarta40fc5f2013-04-17 20:17:40 -04003574 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003575 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003576 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3577 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
James Smart164cecd2013-09-06 12:22:38 -04003578 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003579 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
dea31012005-04-17 16:05:31 -05003580 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003581
3582out_free_mem:
James Smart8a9d2e82012-05-09 21:16:12 -04003583 lpfc_scsi_free(phba);
3584 return rc;
dea31012005-04-17 16:05:31 -05003585}
3586
James Smart96418b52017-03-04 09:30:31 -08003587static uint64_t
3588lpfc_get_wwpn(struct lpfc_hba *phba)
3589{
3590 uint64_t wwn;
3591 int rc;
3592 LPFC_MBOXQ_t *mboxq;
3593 MAILBOX_t *mb;
3594
3595
3596 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
3597 GFP_KERNEL);
3598 if (!mboxq)
3599 return (uint64_t)-1;
3600
3601 /* First get WWN of HBA instance */
3602 lpfc_read_nv(phba, mboxq);
3603 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
3604 if (rc != MBX_SUCCESS) {
3605 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3606 "6019 Mailbox failed , mbxCmd x%x "
3607 "READ_NV, mbxStatus x%x\n",
3608 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
3609 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
3610 mempool_free(mboxq, phba->mbox_mem_pool);
3611 return (uint64_t) -1;
3612 }
3613 mb = &mboxq->u.mb;
3614 memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t));
3615 /* wwn is WWPN of HBA instance */
3616 mempool_free(mboxq, phba->mbox_mem_pool);
3617 if (phba->sli_rev == LPFC_SLI_REV4)
3618 return be64_to_cpu(wwn);
3619 else
3620 return (((wwn & 0xffffffff00000000) >> 32) |
3621 ((wwn & 0x00000000ffffffff) << 32));
3622
3623}
3624
James Smarte59058c2008-08-24 21:49:00 -04003625/**
James Smart895427b2017-02-12 13:52:30 -08003626 * lpfc_sli4_nvme_sgl_update - update xri-sgl sizing and mapping
3627 * @phba: pointer to lpfc hba data structure.
3628 *
3629 * This routine first calculates the sizes of the current els and allocated
3630 * scsi sgl lists, and then goes through all sgls to updates the physical
3631 * XRIs assigned due to port function reset. During port initialization, the
3632 * current els and allocated scsi sgl lists are 0s.
3633 *
3634 * Return codes
3635 * 0 - successful (for now, it always returns 0)
3636 **/
3637int
3638lpfc_sli4_nvme_sgl_update(struct lpfc_hba *phba)
3639{
3640 struct lpfc_nvme_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
3641 uint16_t i, lxri, els_xri_cnt;
3642 uint16_t nvme_xri_cnt, nvme_xri_max;
3643 LIST_HEAD(nvme_sgl_list);
3644 int rc;
3645
3646 phba->total_nvme_bufs = 0;
3647
3648 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3649 return 0;
3650 /*
3651 * update on pci function's allocated nvme xri-sgl list
3652 */
3653
3654 /* maximum number of xris available for nvme buffers */
3655 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3656 nvme_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3657 phba->sli4_hba.nvme_xri_max = nvme_xri_max;
3658 phba->sli4_hba.nvme_xri_max -= phba->sli4_hba.scsi_xri_max;
3659
3660 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3661 "6074 Current allocated NVME xri-sgl count:%d, "
3662 "maximum NVME xri count:%d\n",
3663 phba->sli4_hba.nvme_xri_cnt,
3664 phba->sli4_hba.nvme_xri_max);
3665
3666 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3667 spin_lock(&phba->nvme_buf_list_put_lock);
3668 list_splice_init(&phba->lpfc_nvme_buf_list_get, &nvme_sgl_list);
3669 list_splice(&phba->lpfc_nvme_buf_list_put, &nvme_sgl_list);
3670 spin_unlock(&phba->nvme_buf_list_put_lock);
3671 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3672
3673 if (phba->sli4_hba.nvme_xri_cnt > phba->sli4_hba.nvme_xri_max) {
3674 /* max nvme xri shrunk below the allocated nvme buffers */
3675 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3676 nvme_xri_cnt = phba->sli4_hba.nvme_xri_cnt -
3677 phba->sli4_hba.nvme_xri_max;
3678 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3679 /* release the extra allocated nvme buffers */
3680 for (i = 0; i < nvme_xri_cnt; i++) {
3681 list_remove_head(&nvme_sgl_list, lpfc_ncmd,
3682 struct lpfc_nvme_buf, list);
3683 if (lpfc_ncmd) {
3684 pci_pool_free(phba->lpfc_sg_dma_buf_pool,
3685 lpfc_ncmd->data,
3686 lpfc_ncmd->dma_handle);
3687 kfree(lpfc_ncmd);
3688 }
3689 }
3690 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3691 phba->sli4_hba.nvme_xri_cnt -= nvme_xri_cnt;
3692 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3693 }
3694
3695 /* update xris associated to remaining allocated nvme buffers */
3696 lpfc_ncmd = NULL;
3697 lpfc_ncmd_next = NULL;
3698 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3699 &nvme_sgl_list, list) {
3700 lxri = lpfc_sli4_next_xritag(phba);
3701 if (lxri == NO_XRI) {
3702 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3703 "6075 Failed to allocate xri for "
3704 "nvme buffer\n");
3705 rc = -ENOMEM;
3706 goto out_free_mem;
3707 }
3708 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
3709 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3710 }
3711 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3712 spin_lock(&phba->nvme_buf_list_put_lock);
3713 list_splice_init(&nvme_sgl_list, &phba->lpfc_nvme_buf_list_get);
3714 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
3715 spin_unlock(&phba->nvme_buf_list_put_lock);
3716 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3717 return 0;
3718
3719out_free_mem:
3720 lpfc_nvme_free(phba);
3721 return rc;
3722}
3723
3724/**
James Smart3621a712009-04-06 18:47:14 -04003725 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04003726 * @phba: pointer to lpfc hba data structure.
3727 * @instance: a unique integer ID to this FC port.
3728 * @dev: pointer to the device data structure.
3729 *
3730 * This routine creates a FC port for the upper layer protocol. The FC port
3731 * can be created on top of either a physical port or a virtual port provided
3732 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3733 * and associates the FC port created before adding the shost into the SCSI
3734 * layer.
3735 *
3736 * Return codes
3737 * @vport - pointer to the virtual N_Port data structure.
3738 * NULL - port create failed.
3739 **/
James Smart2e0fef82007-06-17 19:56:36 -05003740struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04003741lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04003742{
James Smart2e0fef82007-06-17 19:56:36 -05003743 struct lpfc_vport *vport;
James Smart895427b2017-02-12 13:52:30 -08003744 struct Scsi_Host *shost = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003745 int error = 0;
James Smart96418b52017-03-04 09:30:31 -08003746 int i;
3747 uint64_t wwn;
3748 bool use_no_reset_hba = false;
3749
3750 wwn = lpfc_get_wwpn(phba);
3751
3752 for (i = 0; i < lpfc_no_hba_reset_cnt; i++) {
3753 if (wwn == lpfc_no_hba_reset[i]) {
3754 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3755 "6020 Setting use_no_reset port=%llx\n",
3756 wwn);
3757 use_no_reset_hba = true;
3758 break;
3759 }
3760 }
James Smart47a86172007-04-25 09:53:22 -04003761
James Smart895427b2017-02-12 13:52:30 -08003762 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
3763 if (dev != &phba->pcidev->dev) {
3764 shost = scsi_host_alloc(&lpfc_vport_template,
3765 sizeof(struct lpfc_vport));
3766 } else {
James Smart96418b52017-03-04 09:30:31 -08003767 if (!use_no_reset_hba)
James Smart895427b2017-02-12 13:52:30 -08003768 shost = scsi_host_alloc(&lpfc_template,
3769 sizeof(struct lpfc_vport));
3770 else
James Smart96418b52017-03-04 09:30:31 -08003771 shost = scsi_host_alloc(&lpfc_template_no_hr,
James Smart895427b2017-02-12 13:52:30 -08003772 sizeof(struct lpfc_vport));
3773 }
3774 } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
3775 shost = scsi_host_alloc(&lpfc_template_nvme,
James Smartea4142f2015-04-07 15:07:13 -04003776 sizeof(struct lpfc_vport));
3777 }
James Smart2e0fef82007-06-17 19:56:36 -05003778 if (!shost)
3779 goto out;
James Smart47a86172007-04-25 09:53:22 -04003780
James Smart2e0fef82007-06-17 19:56:36 -05003781 vport = (struct lpfc_vport *) shost->hostdata;
3782 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05003783 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05003784 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05003785 vport->fc_rscn_flush = 0;
James Smart3de2a652007-08-02 11:09:59 -04003786 lpfc_get_vport_cfgparam(vport);
James Smart895427b2017-02-12 13:52:30 -08003787
James Smart2e0fef82007-06-17 19:56:36 -05003788 shost->unique_id = instance;
3789 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04003790 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05003791 shost->this_id = -1;
3792 shost->max_cmd_len = 16;
James Smart8b0dff12015-05-22 10:42:38 -04003793 shost->nr_hw_queues = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04003794 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05003795 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04003796 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smartda0436e2009-05-22 14:51:39 -04003797 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
3798 }
James Smart81301a92008-12-04 22:39:46 -05003799
James Smart47a86172007-04-25 09:53:22 -04003800 /*
James Smart2e0fef82007-06-17 19:56:36 -05003801 * Set initial can_queue value since 0 is no longer supported and
3802 * scsi_add_host will fail. This will be adjusted later based on the
3803 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04003804 */
James Smart2e0fef82007-06-17 19:56:36 -05003805 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04003806 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05003807 shost->transportt = lpfc_vport_transport_template;
3808 vport->port_type = LPFC_NPIV_PORT;
3809 } else {
3810 shost->transportt = lpfc_transport_template;
3811 vport->port_type = LPFC_PHYSICAL_PORT;
3812 }
James Smart47a86172007-04-25 09:53:22 -04003813
James Smart2e0fef82007-06-17 19:56:36 -05003814 /* Initialize all internally managed lists. */
3815 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04003816 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05003817 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04003818
Tomas Jasek33cc5592017-03-03 13:45:48 +01003819 setup_timer(&vport->fc_disctmo, lpfc_disc_timeout,
3820 (unsigned long)vport);
James Smart47a86172007-04-25 09:53:22 -04003821
Tomas Jasek33cc5592017-03-03 13:45:48 +01003822 setup_timer(&vport->els_tmofunc, lpfc_els_timeout,
3823 (unsigned long)vport);
James Smart92494142011-02-16 12:39:44 -05003824
Tomas Jasek33cc5592017-03-03 13:45:48 +01003825 setup_timer(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo,
3826 (unsigned long)vport);
James Smart92494142011-02-16 12:39:44 -05003827
James Bottomleyd139b9b2009-11-05 13:33:12 -06003828 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05003829 if (error)
3830 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04003831
James Smart549e55c2007-08-02 11:09:51 -04003832 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003833 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04003834 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003835 return vport;
James Smart47a86172007-04-25 09:53:22 -04003836
James Smart2e0fef82007-06-17 19:56:36 -05003837out_put_shost:
3838 scsi_host_put(shost);
3839out:
3840 return NULL;
James Smart47a86172007-04-25 09:53:22 -04003841}
3842
James Smarte59058c2008-08-24 21:49:00 -04003843/**
James Smart3621a712009-04-06 18:47:14 -04003844 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04003845 * @vport: pointer to an lpfc virtual N_Port data structure.
3846 *
3847 * This routine destroys a FC port from the upper layer protocol. All the
3848 * resources associated with the port are released.
3849 **/
James Smart2e0fef82007-06-17 19:56:36 -05003850void
3851destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04003852{
James Smart92d7f7b2007-06-17 19:56:38 -05003853 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3854 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003855
James Smart858c9f62007-06-17 19:56:39 -05003856 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05003857 fc_remove_host(shost);
3858 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04003859
James Smart92d7f7b2007-06-17 19:56:38 -05003860 spin_lock_irq(&phba->hbalock);
3861 list_del_init(&vport->listentry);
3862 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04003863
James Smart92d7f7b2007-06-17 19:56:38 -05003864 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04003865 return;
James Smart47a86172007-04-25 09:53:22 -04003866}
3867
James Smarte59058c2008-08-24 21:49:00 -04003868/**
James Smart3621a712009-04-06 18:47:14 -04003869 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04003870 *
3871 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3872 * uses the kernel idr facility to perform the task.
3873 *
3874 * Return codes:
3875 * instance - a unique integer ID allocated as the new instance.
3876 * -1 - lpfc get instance failed.
3877 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003878int
3879lpfc_get_instance(void)
3880{
Tejun Heoab516032013-02-27 17:04:44 -08003881 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003882
Tejun Heoab516032013-02-27 17:04:44 -08003883 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
3884 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003885}
3886
James Smarte59058c2008-08-24 21:49:00 -04003887/**
James Smart3621a712009-04-06 18:47:14 -04003888 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04003889 * @shost: pointer to SCSI host data structure.
3890 * @time: elapsed time of the scan in jiffies.
3891 *
3892 * This routine is called by the SCSI layer with a SCSI host to determine
3893 * whether the scan host is finished.
3894 *
3895 * Note: there is no scan_start function as adapter initialization will have
3896 * asynchronously kicked off the link initialization.
3897 *
3898 * Return codes
3899 * 0 - SCSI host scan is not over yet.
3900 * 1 - SCSI host scan is over.
3901 **/
James Smart47a86172007-04-25 09:53:22 -04003902int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
3903{
James Smart2e0fef82007-06-17 19:56:36 -05003904 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3905 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05003906 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04003907
James Smart858c9f62007-06-17 19:56:39 -05003908 spin_lock_irq(shost->host_lock);
3909
James Smart51ef4c22007-08-02 11:10:31 -04003910 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05003911 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003912 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05003913 }
James Smart256ec0d2013-04-17 20:14:58 -04003914 if (time >= msecs_to_jiffies(30 * 1000)) {
James Smart2e0fef82007-06-17 19:56:36 -05003915 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003916 "0461 Scanning longer than 30 "
3917 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003918 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003919 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003920 }
James Smart256ec0d2013-04-17 20:14:58 -04003921 if (time >= msecs_to_jiffies(15 * 1000) &&
3922 phba->link_state <= LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05003923 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003924 "0465 Link down longer than 15 "
3925 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003926 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05003927 goto finished;
James Smart47a86172007-04-25 09:53:22 -04003928 }
3929
James Smart2e0fef82007-06-17 19:56:36 -05003930 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05003931 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003932 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05003933 goto finished;
James Smart256ec0d2013-04-17 20:14:58 -04003934 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
James Smart858c9f62007-06-17 19:56:39 -05003935 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003936 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05003937 goto finished;
3938
3939 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003940
3941finished:
James Smart858c9f62007-06-17 19:56:39 -05003942 spin_unlock_irq(shost->host_lock);
3943 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003944}
3945
James Smarte59058c2008-08-24 21:49:00 -04003946/**
James Smart3621a712009-04-06 18:47:14 -04003947 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04003948 * @shost: pointer to SCSI host data structure.
3949 *
3950 * This routine initializes a given SCSI host attributes on a FC port. The
3951 * SCSI host can be either on top of a physical port or a virtual port.
3952 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003953void lpfc_host_attrib_init(struct Scsi_Host *shost)
3954{
3955 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3956 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003957 /*
James Smart2e0fef82007-06-17 19:56:36 -05003958 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04003959 */
3960
James Smart2e0fef82007-06-17 19:56:36 -05003961 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
3962 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04003963 fc_host_supported_classes(shost) = FC_COS_CLASS3;
3964
3965 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003966 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003967 fc_host_supported_fc4s(shost)[2] = 1;
3968 fc_host_supported_fc4s(shost)[7] = 1;
3969
James Smart92d7f7b2007-06-17 19:56:38 -05003970 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
3971 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04003972
3973 fc_host_supported_speeds(shost) = 0;
James Smartd38dd522015-08-31 16:48:17 -04003974 if (phba->lmt & LMT_32Gb)
3975 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
James Smart88a2cfb2011-07-22 18:36:33 -04003976 if (phba->lmt & LMT_16Gb)
3977 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
James Smart47a86172007-04-25 09:53:22 -04003978 if (phba->lmt & LMT_10Gb)
3979 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04003980 if (phba->lmt & LMT_8Gb)
3981 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04003982 if (phba->lmt & LMT_4Gb)
3983 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
3984 if (phba->lmt & LMT_2Gb)
3985 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
3986 if (phba->lmt & LMT_1Gb)
3987 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
3988
3989 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05003990 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
3991 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04003992
Mike Christie0af5d702010-09-15 16:52:31 -05003993 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
3994
James Smart47a86172007-04-25 09:53:22 -04003995 /* This value is also unchanging */
3996 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003997 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003998 fc_host_active_fc4s(shost)[2] = 1;
3999 fc_host_active_fc4s(shost)[7] = 1;
4000
James Smart92d7f7b2007-06-17 19:56:38 -05004001 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04004002 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04004003 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04004004 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04004005}
dea31012005-04-17 16:05:31 -05004006
James Smarte59058c2008-08-24 21:49:00 -04004007/**
James Smartda0436e2009-05-22 14:51:39 -04004008 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04004009 * @phba: pointer to lpfc hba data structure.
4010 *
James Smartda0436e2009-05-22 14:51:39 -04004011 * This routine is invoked to stop an SLI3 device port, it stops the device
4012 * from generating interrupts and stops the device driver's timers for the
4013 * device.
James Smarte59058c2008-08-24 21:49:00 -04004014 **/
James Smartdb2378e2008-02-08 18:49:51 -05004015static void
James Smartda0436e2009-05-22 14:51:39 -04004016lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05004017{
James Smartda0436e2009-05-22 14:51:39 -04004018 /* Clear all interrupt enable conditions */
4019 writel(0, phba->HCregaddr);
4020 readl(phba->HCregaddr); /* flush */
4021 /* Clear all pending interrupts */
4022 writel(0xffffffff, phba->HAregaddr);
4023 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04004024
James Smartda0436e2009-05-22 14:51:39 -04004025 /* Reset some HBA SLI setup states */
4026 lpfc_stop_hba_timers(phba);
4027 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05004028}
4029
James Smarte59058c2008-08-24 21:49:00 -04004030/**
James Smartda0436e2009-05-22 14:51:39 -04004031 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05004032 * @phba: pointer to lpfc hba data structure.
4033 *
James Smartda0436e2009-05-22 14:51:39 -04004034 * This routine is invoked to stop an SLI4 device port, it stops the device
4035 * from generating interrupts and stops the device driver's timers for the
4036 * device.
4037 **/
4038static void
4039lpfc_stop_port_s4(struct lpfc_hba *phba)
4040{
4041 /* Reset some HBA SLI4 setup states */
4042 lpfc_stop_hba_timers(phba);
4043 phba->pport->work_port_events = 0;
4044 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04004045}
4046
4047/**
4048 * lpfc_stop_port - Wrapper function for stopping hba port
4049 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05004050 *
James Smartda0436e2009-05-22 14:51:39 -04004051 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
4052 * the API jump table function pointer from the lpfc_hba struct.
4053 **/
4054void
4055lpfc_stop_port(struct lpfc_hba *phba)
4056{
4057 phba->lpfc_stop_port(phba);
4058}
4059
4060/**
James Smartecfd03c2010-02-12 14:41:27 -05004061 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
4062 * @phba: Pointer to hba for which this call is being executed.
4063 *
4064 * This routine starts the timer waiting for the FCF rediscovery to complete.
4065 **/
4066void
4067lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
4068{
4069 unsigned long fcf_redisc_wait_tmo =
4070 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
4071 /* Start fcf rediscovery wait period timer */
4072 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
4073 spin_lock_irq(&phba->hbalock);
4074 /* Allow action to new fcf asynchronous event */
4075 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
4076 /* Mark the FCF rediscovery pending state */
4077 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
4078 spin_unlock_irq(&phba->hbalock);
4079}
4080
4081/**
4082 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
4083 * @ptr: Map to lpfc_hba data structure pointer.
4084 *
4085 * This routine is invoked when waiting for FCF table rediscover has been
4086 * timed out. If new FCF record(s) has (have) been discovered during the
4087 * wait period, a new FCF event shall be added to the FCOE async event
4088 * list, and then worker thread shall be waked up for processing from the
4089 * worker thread context.
4090 **/
Rashika Kheriae399b222014-09-03 12:55:28 -04004091static void
James Smartecfd03c2010-02-12 14:41:27 -05004092lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
4093{
4094 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
4095
4096 /* Don't send FCF rediscovery event if timer cancelled */
4097 spin_lock_irq(&phba->hbalock);
4098 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
4099 spin_unlock_irq(&phba->hbalock);
4100 return;
4101 }
4102 /* Clear FCF rediscovery timer pending flag */
4103 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
4104 /* FCF rediscovery event to worker thread */
4105 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
4106 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004107 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04004108 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05004109 /* wake up worker thread */
4110 lpfc_worker_wake_up(phba);
4111}
4112
4113/**
James Smartda0436e2009-05-22 14:51:39 -04004114 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
4115 * @phba: pointer to lpfc hba data structure.
4116 * @acqe_link: pointer to the async link completion queue entry.
4117 *
4118 * This routine is to parse the SLI4 link-attention link fault code and
4119 * translate it into the base driver's read link attention mailbox command
4120 * status.
4121 *
4122 * Return: Link-attention status in terms of base driver's coding.
4123 **/
4124static uint16_t
4125lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
4126 struct lpfc_acqe_link *acqe_link)
4127{
4128 uint16_t latt_fault;
4129
4130 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
4131 case LPFC_ASYNC_LINK_FAULT_NONE:
4132 case LPFC_ASYNC_LINK_FAULT_LOCAL:
4133 case LPFC_ASYNC_LINK_FAULT_REMOTE:
4134 latt_fault = 0;
4135 break;
4136 default:
4137 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4138 "0398 Invalid link fault code: x%x\n",
4139 bf_get(lpfc_acqe_link_fault, acqe_link));
4140 latt_fault = MBXERR_ERROR;
4141 break;
4142 }
4143 return latt_fault;
4144}
4145
4146/**
4147 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
4148 * @phba: pointer to lpfc hba data structure.
4149 * @acqe_link: pointer to the async link completion queue entry.
4150 *
4151 * This routine is to parse the SLI4 link attention type and translate it
4152 * into the base driver's link attention type coding.
4153 *
4154 * Return: Link attention type in terms of base driver's coding.
4155 **/
4156static uint8_t
4157lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
4158 struct lpfc_acqe_link *acqe_link)
4159{
4160 uint8_t att_type;
4161
4162 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
4163 case LPFC_ASYNC_LINK_STATUS_DOWN:
4164 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05004165 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04004166 break;
4167 case LPFC_ASYNC_LINK_STATUS_UP:
4168 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05004169 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004170 break;
4171 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05004172 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04004173 break;
4174 default:
4175 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4176 "0399 Invalid link attention type: x%x\n",
4177 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05004178 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004179 break;
4180 }
4181 return att_type;
4182}
4183
4184/**
James Smart8b68cd52012-09-29 11:32:37 -04004185 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
4186 * @phba: pointer to lpfc hba data structure.
4187 *
4188 * This routine is to get an SLI3 FC port's link speed in Mbps.
4189 *
4190 * Return: link speed in terms of Mbps.
4191 **/
4192uint32_t
4193lpfc_sli_port_speed_get(struct lpfc_hba *phba)
4194{
4195 uint32_t link_speed;
4196
4197 if (!lpfc_is_link_up(phba))
4198 return 0;
4199
James Smarta085e872015-12-16 18:12:02 -05004200 if (phba->sli_rev <= LPFC_SLI_REV3) {
4201 switch (phba->fc_linkspeed) {
4202 case LPFC_LINK_SPEED_1GHZ:
4203 link_speed = 1000;
4204 break;
4205 case LPFC_LINK_SPEED_2GHZ:
4206 link_speed = 2000;
4207 break;
4208 case LPFC_LINK_SPEED_4GHZ:
4209 link_speed = 4000;
4210 break;
4211 case LPFC_LINK_SPEED_8GHZ:
4212 link_speed = 8000;
4213 break;
4214 case LPFC_LINK_SPEED_10GHZ:
4215 link_speed = 10000;
4216 break;
4217 case LPFC_LINK_SPEED_16GHZ:
4218 link_speed = 16000;
4219 break;
4220 default:
4221 link_speed = 0;
4222 }
4223 } else {
4224 if (phba->sli4_hba.link_state.logical_speed)
4225 link_speed =
4226 phba->sli4_hba.link_state.logical_speed;
4227 else
4228 link_speed = phba->sli4_hba.link_state.speed;
James Smart8b68cd52012-09-29 11:32:37 -04004229 }
4230 return link_speed;
4231}
4232
4233/**
4234 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
4235 * @phba: pointer to lpfc hba data structure.
4236 * @evt_code: asynchronous event code.
4237 * @speed_code: asynchronous event link speed code.
4238 *
4239 * This routine is to parse the giving SLI4 async event link speed code into
4240 * value of Mbps for the link speed.
4241 *
4242 * Return: link speed in terms of Mbps.
4243 **/
4244static uint32_t
4245lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
4246 uint8_t speed_code)
4247{
4248 uint32_t port_speed;
4249
4250 switch (evt_code) {
4251 case LPFC_TRAILER_CODE_LINK:
4252 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004253 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smart8b68cd52012-09-29 11:32:37 -04004254 port_speed = 0;
4255 break;
James Smart26d830e2015-04-07 15:07:17 -04004256 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004257 port_speed = 10;
4258 break;
James Smart26d830e2015-04-07 15:07:17 -04004259 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004260 port_speed = 100;
4261 break;
James Smart26d830e2015-04-07 15:07:17 -04004262 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004263 port_speed = 1000;
4264 break;
James Smart26d830e2015-04-07 15:07:17 -04004265 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004266 port_speed = 10000;
4267 break;
James Smart26d830e2015-04-07 15:07:17 -04004268 case LPFC_ASYNC_LINK_SPEED_20GBPS:
4269 port_speed = 20000;
4270 break;
4271 case LPFC_ASYNC_LINK_SPEED_25GBPS:
4272 port_speed = 25000;
4273 break;
4274 case LPFC_ASYNC_LINK_SPEED_40GBPS:
4275 port_speed = 40000;
4276 break;
James Smart8b68cd52012-09-29 11:32:37 -04004277 default:
4278 port_speed = 0;
4279 }
4280 break;
4281 case LPFC_TRAILER_CODE_FC:
4282 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004283 case LPFC_FC_LA_SPEED_UNKNOWN:
James Smart8b68cd52012-09-29 11:32:37 -04004284 port_speed = 0;
4285 break;
James Smart26d830e2015-04-07 15:07:17 -04004286 case LPFC_FC_LA_SPEED_1G:
James Smart8b68cd52012-09-29 11:32:37 -04004287 port_speed = 1000;
4288 break;
James Smart26d830e2015-04-07 15:07:17 -04004289 case LPFC_FC_LA_SPEED_2G:
James Smart8b68cd52012-09-29 11:32:37 -04004290 port_speed = 2000;
4291 break;
James Smart26d830e2015-04-07 15:07:17 -04004292 case LPFC_FC_LA_SPEED_4G:
James Smart8b68cd52012-09-29 11:32:37 -04004293 port_speed = 4000;
4294 break;
James Smart26d830e2015-04-07 15:07:17 -04004295 case LPFC_FC_LA_SPEED_8G:
James Smart8b68cd52012-09-29 11:32:37 -04004296 port_speed = 8000;
4297 break;
James Smart26d830e2015-04-07 15:07:17 -04004298 case LPFC_FC_LA_SPEED_10G:
James Smart8b68cd52012-09-29 11:32:37 -04004299 port_speed = 10000;
4300 break;
James Smart26d830e2015-04-07 15:07:17 -04004301 case LPFC_FC_LA_SPEED_16G:
James Smart8b68cd52012-09-29 11:32:37 -04004302 port_speed = 16000;
4303 break;
James Smartd38dd522015-08-31 16:48:17 -04004304 case LPFC_FC_LA_SPEED_32G:
4305 port_speed = 32000;
4306 break;
James Smart8b68cd52012-09-29 11:32:37 -04004307 default:
4308 port_speed = 0;
4309 }
4310 break;
4311 default:
4312 port_speed = 0;
4313 }
4314 return port_speed;
4315}
4316
4317/**
James Smart70f3c072010-12-15 17:57:33 -05004318 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04004319 * @phba: pointer to lpfc hba data structure.
4320 * @acqe_link: pointer to the async link completion queue entry.
4321 *
James Smart70f3c072010-12-15 17:57:33 -05004322 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04004323 **/
4324static void
4325lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
4326 struct lpfc_acqe_link *acqe_link)
4327{
4328 struct lpfc_dmabuf *mp;
4329 LPFC_MBOXQ_t *pmb;
4330 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05004331 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04004332 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05004333 int rc;
James Smartda0436e2009-05-22 14:51:39 -04004334
4335 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05004336 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04004337 return;
James Smart32b97932009-07-19 10:01:21 -04004338 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004339 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4340 if (!pmb) {
4341 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4342 "0395 The mboxq allocation failed\n");
4343 return;
4344 }
4345 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4346 if (!mp) {
4347 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4348 "0396 The lpfc_dmabuf allocation failed\n");
4349 goto out_free_pmb;
4350 }
4351 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4352 if (!mp->virt) {
4353 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4354 "0397 The mbuf allocation failed\n");
4355 goto out_free_dmabuf;
4356 }
4357
4358 /* Cleanup any outstanding ELS commands */
4359 lpfc_els_flush_all_cmd(phba);
4360
4361 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004362 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smartda0436e2009-05-22 14:51:39 -04004363
4364 /* Update link event statistics */
4365 phba->sli.slistat.link_event++;
4366
James Smart76a95d72010-11-20 23:11:48 -05004367 /* Create lpfc_handle_latt mailbox command from link ACQE */
4368 lpfc_read_topology(phba, pmb, mp);
4369 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04004370 pmb->vport = phba->pport;
4371
James Smartda0436e2009-05-22 14:51:39 -04004372 /* Keep the link status for extra SLI4 state machine reference */
4373 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004374 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
4375 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04004376 phba->sli4_hba.link_state.duplex =
4377 bf_get(lpfc_acqe_link_duplex, acqe_link);
4378 phba->sli4_hba.link_state.status =
4379 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05004380 phba->sli4_hba.link_state.type =
4381 bf_get(lpfc_acqe_link_type, acqe_link);
4382 phba->sli4_hba.link_state.number =
4383 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04004384 phba->sli4_hba.link_state.fault =
4385 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05004386 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004387 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
4388
James Smart70f3c072010-12-15 17:57:33 -05004389 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04004390 "2900 Async FC/FCoE Link event - Speed:%dGBit "
4391 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
4392 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05004393 phba->sli4_hba.link_state.speed,
4394 phba->sli4_hba.link_state.topology,
4395 phba->sli4_hba.link_state.status,
4396 phba->sli4_hba.link_state.type,
4397 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004398 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004399 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05004400 /*
4401 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
4402 * topology info. Note: Optional for non FC-AL ports.
4403 */
4404 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
4405 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4406 if (rc == MBX_NOT_FINISHED)
4407 goto out_free_dmabuf;
4408 return;
4409 }
4410 /*
4411 * For FCoE Mode: fill in all the topology information we need and call
4412 * the READ_TOPOLOGY completion routine to continue without actually
4413 * sending the READ_TOPOLOGY mailbox command to the port.
4414 */
4415 /* Parse and translate status field */
4416 mb = &pmb->u.mb;
4417 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
4418
4419 /* Parse and translate link attention fields */
4420 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
4421 la->eventTag = acqe_link->event_tag;
4422 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
4423 bf_set(lpfc_mbx_read_top_link_spd, la,
James Smarta085e872015-12-16 18:12:02 -05004424 (bf_get(lpfc_acqe_link_speed, acqe_link)));
James Smart76a95d72010-11-20 23:11:48 -05004425
4426 /* Fake the the following irrelvant fields */
4427 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
4428 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
4429 bf_set(lpfc_mbx_read_top_il, la, 0);
4430 bf_set(lpfc_mbx_read_top_pb, la, 0);
4431 bf_set(lpfc_mbx_read_top_fa, la, 0);
4432 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04004433
4434 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05004435 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04004436
4437 return;
4438
4439out_free_dmabuf:
4440 kfree(mp);
4441out_free_pmb:
4442 mempool_free(pmb, phba->mbox_mem_pool);
4443}
4444
4445/**
James Smart70f3c072010-12-15 17:57:33 -05004446 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
4447 * @phba: pointer to lpfc hba data structure.
4448 * @acqe_fc: pointer to the async fc completion queue entry.
4449 *
4450 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
4451 * that the event was received and then issue a read_topology mailbox command so
4452 * that the rest of the driver will treat it the same as SLI3.
4453 **/
4454static void
4455lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
4456{
4457 struct lpfc_dmabuf *mp;
4458 LPFC_MBOXQ_t *pmb;
James Smart7bdedb32016-07-06 12:36:00 -07004459 MAILBOX_t *mb;
4460 struct lpfc_mbx_read_top *la;
James Smart70f3c072010-12-15 17:57:33 -05004461 int rc;
4462
4463 if (bf_get(lpfc_trailer_type, acqe_fc) !=
4464 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
4465 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4466 "2895 Non FC link Event detected.(%d)\n",
4467 bf_get(lpfc_trailer_type, acqe_fc));
4468 return;
4469 }
4470 /* Keep the link status for extra SLI4 state machine reference */
4471 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004472 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
4473 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05004474 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
4475 phba->sli4_hba.link_state.topology =
4476 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
4477 phba->sli4_hba.link_state.status =
4478 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
4479 phba->sli4_hba.link_state.type =
4480 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
4481 phba->sli4_hba.link_state.number =
4482 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
4483 phba->sli4_hba.link_state.fault =
4484 bf_get(lpfc_acqe_link_fault, acqe_fc);
4485 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004486 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart70f3c072010-12-15 17:57:33 -05004487 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4488 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4489 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4490 "%dMbps Fault:%d\n",
4491 phba->sli4_hba.link_state.speed,
4492 phba->sli4_hba.link_state.topology,
4493 phba->sli4_hba.link_state.status,
4494 phba->sli4_hba.link_state.type,
4495 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004496 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004497 phba->sli4_hba.link_state.fault);
4498 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4499 if (!pmb) {
4500 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4501 "2897 The mboxq allocation failed\n");
4502 return;
4503 }
4504 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4505 if (!mp) {
4506 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4507 "2898 The lpfc_dmabuf allocation failed\n");
4508 goto out_free_pmb;
4509 }
4510 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4511 if (!mp->virt) {
4512 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4513 "2899 The mbuf allocation failed\n");
4514 goto out_free_dmabuf;
4515 }
4516
4517 /* Cleanup any outstanding ELS commands */
4518 lpfc_els_flush_all_cmd(phba);
4519
4520 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004521 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smart70f3c072010-12-15 17:57:33 -05004522
4523 /* Update link event statistics */
4524 phba->sli.slistat.link_event++;
4525
4526 /* Create lpfc_handle_latt mailbox command from link ACQE */
4527 lpfc_read_topology(phba, pmb, mp);
4528 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4529 pmb->vport = phba->pport;
4530
James Smart7bdedb32016-07-06 12:36:00 -07004531 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
4532 /* Parse and translate status field */
4533 mb = &pmb->u.mb;
4534 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba,
4535 (void *)acqe_fc);
4536
4537 /* Parse and translate link attention fields */
4538 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
4539 la->eventTag = acqe_fc->event_tag;
James Smart7bdedb32016-07-06 12:36:00 -07004540
James Smartaeb3c812017-04-21 16:05:02 -07004541 if (phba->sli4_hba.link_state.status ==
4542 LPFC_FC_LA_TYPE_UNEXP_WWPN) {
4543 bf_set(lpfc_mbx_read_top_att_type, la,
4544 LPFC_FC_LA_TYPE_UNEXP_WWPN);
4545 } else {
4546 bf_set(lpfc_mbx_read_top_att_type, la,
4547 LPFC_FC_LA_TYPE_LINK_DOWN);
4548 }
James Smart7bdedb32016-07-06 12:36:00 -07004549 /* Invoke the mailbox command callback function */
4550 lpfc_mbx_cmpl_read_topology(phba, pmb);
4551
4552 return;
4553 }
4554
James Smart70f3c072010-12-15 17:57:33 -05004555 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4556 if (rc == MBX_NOT_FINISHED)
4557 goto out_free_dmabuf;
4558 return;
4559
4560out_free_dmabuf:
4561 kfree(mp);
4562out_free_pmb:
4563 mempool_free(pmb, phba->mbox_mem_pool);
4564}
4565
4566/**
4567 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4568 * @phba: pointer to lpfc hba data structure.
4569 * @acqe_fc: pointer to the async SLI completion queue entry.
4570 *
4571 * This routine is to handle the SLI4 asynchronous SLI events.
4572 **/
4573static void
4574lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
4575{
James Smart4b8bae02012-06-12 13:55:07 -04004576 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04004577 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04004578 uint8_t status;
James Smart946727d2015-04-07 15:07:09 -04004579 uint8_t evt_type;
James Smart448193b2015-12-16 18:12:05 -05004580 uint8_t operational = 0;
James Smart946727d2015-04-07 15:07:09 -04004581 struct temp_event temp_event_data;
James Smart4b8bae02012-06-12 13:55:07 -04004582 struct lpfc_acqe_misconfigured_event *misconfigured;
James Smart946727d2015-04-07 15:07:09 -04004583 struct Scsi_Host *shost;
James Smart4b8bae02012-06-12 13:55:07 -04004584
James Smart946727d2015-04-07 15:07:09 -04004585 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
4586
James Smart448193b2015-12-16 18:12:05 -05004587 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4588 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4589 "x%08x SLI Event Type:%d\n",
4590 acqe_sli->event_data1, acqe_sli->event_data2,
4591 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004592
4593 port_name = phba->Port[0];
4594 if (port_name == 0x00)
4595 port_name = '?'; /* get port name is empty */
4596
James Smart946727d2015-04-07 15:07:09 -04004597 switch (evt_type) {
4598 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
4599 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4600 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
4601 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4602
4603 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4604 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4605 acqe_sli->event_data1, port_name);
4606
James Smart310429e2016-07-06 12:35:54 -07004607 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04004608 shost = lpfc_shost_from_vport(phba->pport);
4609 fc_host_post_vendor_event(shost, fc_get_event_number(),
4610 sizeof(temp_event_data),
4611 (char *)&temp_event_data,
4612 SCSI_NL_VID_TYPE_PCI
4613 | PCI_VENDOR_ID_EMULEX);
4614 break;
4615 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
4616 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4617 temp_event_data.event_code = LPFC_NORMAL_TEMP;
4618 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4619
4620 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4621 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4622 acqe_sli->event_data1, port_name);
4623
4624 shost = lpfc_shost_from_vport(phba->pport);
4625 fc_host_post_vendor_event(shost, fc_get_event_number(),
4626 sizeof(temp_event_data),
4627 (char *)&temp_event_data,
4628 SCSI_NL_VID_TYPE_PCI
4629 | PCI_VENDOR_ID_EMULEX);
4630 break;
4631 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
4632 misconfigured = (struct lpfc_acqe_misconfigured_event *)
James Smart4b8bae02012-06-12 13:55:07 -04004633 &acqe_sli->event_data1;
4634
James Smart946727d2015-04-07 15:07:09 -04004635 /* fetch the status for this port */
4636 switch (phba->sli4_hba.lnk_info.lnk_no) {
4637 case LPFC_LINK_NUMBER_0:
James Smart448193b2015-12-16 18:12:05 -05004638 status = bf_get(lpfc_sli_misconfigured_port0_state,
4639 &misconfigured->theEvent);
4640 operational = bf_get(lpfc_sli_misconfigured_port0_op,
James Smart4b8bae02012-06-12 13:55:07 -04004641 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004642 break;
4643 case LPFC_LINK_NUMBER_1:
James Smart448193b2015-12-16 18:12:05 -05004644 status = bf_get(lpfc_sli_misconfigured_port1_state,
4645 &misconfigured->theEvent);
4646 operational = bf_get(lpfc_sli_misconfigured_port1_op,
James Smart4b8bae02012-06-12 13:55:07 -04004647 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004648 break;
4649 case LPFC_LINK_NUMBER_2:
James Smart448193b2015-12-16 18:12:05 -05004650 status = bf_get(lpfc_sli_misconfigured_port2_state,
4651 &misconfigured->theEvent);
4652 operational = bf_get(lpfc_sli_misconfigured_port2_op,
James Smart4b8bae02012-06-12 13:55:07 -04004653 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004654 break;
4655 case LPFC_LINK_NUMBER_3:
James Smart448193b2015-12-16 18:12:05 -05004656 status = bf_get(lpfc_sli_misconfigured_port3_state,
4657 &misconfigured->theEvent);
4658 operational = bf_get(lpfc_sli_misconfigured_port3_op,
James Smart4b8bae02012-06-12 13:55:07 -04004659 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004660 break;
4661 default:
James Smart448193b2015-12-16 18:12:05 -05004662 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4663 "3296 "
4664 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
4665 "event: Invalid link %d",
4666 phba->sli4_hba.lnk_info.lnk_no);
4667 return;
James Smart946727d2015-04-07 15:07:09 -04004668 }
James Smart4b8bae02012-06-12 13:55:07 -04004669
James Smart448193b2015-12-16 18:12:05 -05004670 /* Skip if optic state unchanged */
4671 if (phba->sli4_hba.lnk_info.optic_state == status)
4672 return;
4673
James Smart946727d2015-04-07 15:07:09 -04004674 switch (status) {
4675 case LPFC_SLI_EVENT_STATUS_VALID:
James Smart448193b2015-12-16 18:12:05 -05004676 sprintf(message, "Physical Link is functional");
4677 break;
James Smart946727d2015-04-07 15:07:09 -04004678 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
4679 sprintf(message, "Optics faulted/incorrectly "
4680 "installed/not installed - Reseat optics, "
4681 "if issue not resolved, replace.");
4682 break;
4683 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
4684 sprintf(message,
4685 "Optics of two types installed - Remove one "
4686 "optic or install matching pair of optics.");
4687 break;
4688 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
4689 sprintf(message, "Incompatible optics - Replace with "
James Smart292098b2012-09-29 11:31:41 -04004690 "compatible optics for card to function.");
James Smart946727d2015-04-07 15:07:09 -04004691 break;
James Smart448193b2015-12-16 18:12:05 -05004692 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
4693 sprintf(message, "Unqualified optics - Replace with "
4694 "Avago optics for Warranty and Technical "
4695 "Support - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08004696 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05004697 break;
4698 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
4699 sprintf(message, "Uncertified optics - Replace with "
4700 "Avago-certified optics to enable link "
4701 "operation - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08004702 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05004703 break;
James Smart946727d2015-04-07 15:07:09 -04004704 default:
4705 /* firmware is reporting a status we don't know about */
4706 sprintf(message, "Unknown event status x%02x", status);
4707 break;
4708 }
James Smart448193b2015-12-16 18:12:05 -05004709 phba->sli4_hba.lnk_info.optic_state = status;
James Smart946727d2015-04-07 15:07:09 -04004710 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart448193b2015-12-16 18:12:05 -05004711 "3176 Port Name %c %s\n", port_name, message);
James Smart946727d2015-04-07 15:07:09 -04004712 break;
4713 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
4714 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4715 "3192 Remote DPort Test Initiated - "
4716 "Event Data1:x%08x Event Data2: x%08x\n",
4717 acqe_sli->event_data1, acqe_sli->event_data2);
James Smart4b8bae02012-06-12 13:55:07 -04004718 break;
4719 default:
James Smart946727d2015-04-07 15:07:09 -04004720 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4721 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
4722 "x%08x SLI Event Type:%d\n",
4723 acqe_sli->event_data1, acqe_sli->event_data2,
4724 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004725 break;
4726 }
James Smart70f3c072010-12-15 17:57:33 -05004727}
4728
4729/**
James Smartfc2b9892010-02-26 14:15:29 -05004730 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
4731 * @vport: pointer to vport data structure.
4732 *
4733 * This routine is to perform Clear Virtual Link (CVL) on a vport in
4734 * response to a CVL event.
4735 *
4736 * Return the pointer to the ndlp with the vport if successful, otherwise
4737 * return NULL.
4738 **/
4739static struct lpfc_nodelist *
4740lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
4741{
4742 struct lpfc_nodelist *ndlp;
4743 struct Scsi_Host *shost;
4744 struct lpfc_hba *phba;
4745
4746 if (!vport)
4747 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05004748 phba = vport->phba;
4749 if (!phba)
4750 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04004751 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4752 if (!ndlp) {
4753 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07004754 ndlp = lpfc_nlp_init(vport, Fabric_DID);
James Smart78730cf2010-04-06 15:06:30 -04004755 if (!ndlp)
4756 return 0;
James Smart78730cf2010-04-06 15:06:30 -04004757 /* Set the node type */
4758 ndlp->nlp_type |= NLP_FABRIC;
4759 /* Put ndlp onto node list */
4760 lpfc_enqueue_node(vport, ndlp);
4761 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4762 /* re-setup ndlp without removing from node list */
4763 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4764 if (!ndlp)
4765 return 0;
4766 }
James Smart63e801c2010-11-20 23:14:19 -05004767 if ((phba->pport->port_state < LPFC_FLOGI) &&
4768 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004769 return NULL;
4770 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05004771 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
4772 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004773 return NULL;
4774 shost = lpfc_shost_from_vport(vport);
4775 if (!shost)
4776 return NULL;
4777 lpfc_linkdown_port(vport);
4778 lpfc_cleanup_pending_mbox(vport);
4779 spin_lock_irq(shost->host_lock);
4780 vport->fc_flag |= FC_VPORT_CVL_RCVD;
4781 spin_unlock_irq(shost->host_lock);
4782
4783 return ndlp;
4784}
4785
4786/**
4787 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4788 * @vport: pointer to lpfc hba data structure.
4789 *
4790 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4791 * response to a FCF dead event.
4792 **/
4793static void
4794lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
4795{
4796 struct lpfc_vport **vports;
4797 int i;
4798
4799 vports = lpfc_create_vport_work_array(phba);
4800 if (vports)
4801 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4802 lpfc_sli4_perform_vport_cvl(vports[i]);
4803 lpfc_destroy_vport_work_array(phba, vports);
4804}
4805
4806/**
James Smart76a95d72010-11-20 23:11:48 -05004807 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04004808 * @phba: pointer to lpfc hba data structure.
4809 * @acqe_link: pointer to the async fcoe completion queue entry.
4810 *
4811 * This routine is to handle the SLI4 asynchronous fcoe event.
4812 **/
4813static void
James Smart76a95d72010-11-20 23:11:48 -05004814lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05004815 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04004816{
James Smart70f3c072010-12-15 17:57:33 -05004817 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004818 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04004819 struct lpfc_vport *vport;
4820 struct lpfc_nodelist *ndlp;
4821 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05004822 int active_vlink_present;
4823 struct lpfc_vport **vports;
4824 int i;
James Smartda0436e2009-05-22 14:51:39 -04004825
James Smart70f3c072010-12-15 17:57:33 -05004826 phba->fc_eventTag = acqe_fip->event_tag;
4827 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004828 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05004829 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
4830 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
4831 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04004832 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4833 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004834 "2546 New FCF event, evt_tag:x%x, "
4835 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004836 acqe_fip->event_tag,
4837 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04004838 else
4839 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
4840 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004841 "2788 FCF param modified event, "
4842 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004843 acqe_fip->event_tag,
4844 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04004845 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004846 /*
4847 * During period of FCF discovery, read the FCF
4848 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04004849 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05004850 */
4851 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4852 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004853 "2779 Read FCF (x%x) for updating "
4854 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05004855 acqe_fip->index);
4856 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004857 }
James Smart38b92ef2010-08-04 16:11:39 -04004858
4859 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04004860 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04004861 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04004862 spin_unlock_irq(&phba->hbalock);
4863 break;
4864 }
4865 /* If fast FCF failover rescan event is pending, do nothing */
4866 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
4867 spin_unlock_irq(&phba->hbalock);
4868 break;
4869 }
4870
James Smartc2b97122013-05-31 17:05:36 -04004871 /* If the FCF has been in discovered state, do nothing. */
4872 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
James Smart3804dc82010-07-14 15:31:37 -04004873 spin_unlock_irq(&phba->hbalock);
4874 break;
4875 }
4876 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04004877
James Smart0c9ab6f2010-02-26 14:15:57 -05004878 /* Otherwise, scan the entire FCF table and re-discover SAN */
4879 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004880 "2770 Start FCF table scan per async FCF "
4881 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004882 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004883 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
4884 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04004885 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004886 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4887 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04004888 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04004889 break;
4890
James Smart70f3c072010-12-15 17:57:33 -05004891 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04004892 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04004893 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004894 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
4895 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004896 break;
4897
James Smart70f3c072010-12-15 17:57:33 -05004898 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05004899 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004900 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004901 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05004902 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04004903 /*
4904 * If we are in the middle of FCF failover process, clear
4905 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04004906 */
James Smartfc2b9892010-02-26 14:15:29 -05004907 spin_lock_irq(&phba->hbalock);
James Smarta1cadfe2016-07-06 12:36:02 -07004908 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
4909 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
James Smartfc2b9892010-02-26 14:15:29 -05004910 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004911 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05004912 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004913 break;
4914 }
James Smart38b92ef2010-08-04 16:11:39 -04004915 spin_unlock_irq(&phba->hbalock);
4916
4917 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05004918 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04004919 break;
4920
4921 /*
4922 * Otherwise, request the port to rediscover the entire FCF
4923 * table for a fast recovery from case that the current FCF
4924 * is no longer valid as we are not in the middle of FCF
4925 * failover process already.
4926 */
James Smartc2b97122013-05-31 17:05:36 -04004927 spin_lock_irq(&phba->hbalock);
4928 /* Mark the fast failover process in progress */
4929 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
4930 spin_unlock_irq(&phba->hbalock);
4931
4932 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
4933 "2771 Start FCF fast failover process due to "
4934 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
4935 "\n", acqe_fip->event_tag, acqe_fip->index);
4936 rc = lpfc_sli4_redisc_fcf_table(phba);
4937 if (rc) {
4938 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4939 LOG_DISCOVERY,
4940 "2772 Issue FCF rediscover mabilbox "
4941 "command failed, fail through to FCF "
4942 "dead event\n");
4943 spin_lock_irq(&phba->hbalock);
4944 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
4945 spin_unlock_irq(&phba->hbalock);
4946 /*
4947 * Last resort will fail over by treating this
4948 * as a link down to FCF registration.
4949 */
4950 lpfc_sli4_fcf_dead_failthrough(phba);
4951 } else {
4952 /* Reset FCF roundrobin bmask for new discovery */
4953 lpfc_sli4_clear_fcf_rr_bmask(phba);
4954 /*
4955 * Handling fast FCF failover to a DEAD FCF event is
4956 * considered equalivant to receiving CVL to all vports.
4957 */
4958 lpfc_sli4_perform_all_vport_cvl(phba);
4959 }
James Smartda0436e2009-05-22 14:51:39 -04004960 break;
James Smart70f3c072010-12-15 17:57:33 -05004961 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05004962 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004963 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04004964 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05004965 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04004966
James Smart6669f9b2009-10-02 15:16:45 -04004967 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04004968 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004969 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004970 if (!ndlp)
4971 break;
James Smart695a8142010-01-26 23:08:03 -05004972 active_vlink_present = 0;
4973
4974 vports = lpfc_create_vport_work_array(phba);
4975 if (vports) {
4976 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
4977 i++) {
4978 if ((!(vports[i]->fc_flag &
4979 FC_VPORT_CVL_RCVD)) &&
4980 (vports[i]->port_state > LPFC_FDISC)) {
4981 active_vlink_present = 1;
4982 break;
4983 }
4984 }
4985 lpfc_destroy_vport_work_array(phba, vports);
4986 }
4987
James Smartcc823552015-05-21 13:55:26 -04004988 /*
4989 * Don't re-instantiate if vport is marked for deletion.
4990 * If we are here first then vport_delete is going to wait
4991 * for discovery to complete.
4992 */
4993 if (!(vport->load_flag & FC_UNLOADING) &&
4994 active_vlink_present) {
James Smart695a8142010-01-26 23:08:03 -05004995 /*
4996 * If there are other active VLinks present,
4997 * re-instantiate the Vlink using FDISC.
4998 */
James Smart256ec0d2013-04-17 20:14:58 -04004999 mod_timer(&ndlp->nlp_delayfunc,
5000 jiffies + msecs_to_jiffies(1000));
James Smartfc2b9892010-02-26 14:15:29 -05005001 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04005002 spin_lock_irq(shost->host_lock);
5003 ndlp->nlp_flag |= NLP_DELAY_TMO;
5004 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05005005 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
5006 vport->port_state = LPFC_FDISC;
5007 } else {
James Smartecfd03c2010-02-12 14:41:27 -05005008 /*
5009 * Otherwise, we request port to rediscover
5010 * the entire FCF table for a fast recovery
5011 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05005012 * is no longer valid if we are not already
5013 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05005014 */
James Smartfc2b9892010-02-26 14:15:29 -05005015 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005016 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05005017 spin_unlock_irq(&phba->hbalock);
5018 break;
5019 }
5020 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05005021 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05005022 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005023 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
5024 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005025 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05005026 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05005027 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05005028 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05005029 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
5030 LOG_DISCOVERY,
5031 "2774 Issue FCF rediscover "
5032 "mabilbox command failed, "
5033 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05005034 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05005035 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05005036 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05005037 /*
5038 * Last resort will be re-try on the
5039 * the current registered FCF entry.
5040 */
5041 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04005042 } else
5043 /*
5044 * Reset FCF roundrobin bmask for new
5045 * discovery.
5046 */
James Smart7d791df2011-07-22 18:37:52 -04005047 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04005048 }
5049 break;
James Smartda0436e2009-05-22 14:51:39 -04005050 default:
5051 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5052 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05005053 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04005054 break;
5055 }
5056}
5057
5058/**
5059 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
5060 * @phba: pointer to lpfc hba data structure.
5061 * @acqe_link: pointer to the async dcbx completion queue entry.
5062 *
5063 * This routine is to handle the SLI4 asynchronous dcbx event.
5064 **/
5065static void
5066lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
5067 struct lpfc_acqe_dcbx *acqe_dcbx)
5068{
James Smart4d9ab992009-10-02 15:16:39 -04005069 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04005070 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5071 "0290 The SLI4 DCBX asynchronous event is not "
5072 "handled yet\n");
5073}
5074
5075/**
James Smartb19a0612010-04-06 14:48:51 -04005076 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
5077 * @phba: pointer to lpfc hba data structure.
5078 * @acqe_link: pointer to the async grp5 completion queue entry.
5079 *
5080 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
5081 * is an asynchronous notified of a logical link speed change. The Port
5082 * reports the logical link speed in units of 10Mbps.
5083 **/
5084static void
5085lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
5086 struct lpfc_acqe_grp5 *acqe_grp5)
5087{
5088 uint16_t prev_ll_spd;
5089
5090 phba->fc_eventTag = acqe_grp5->event_tag;
5091 phba->fcoe_eventtag = acqe_grp5->event_tag;
5092 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
5093 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04005094 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04005095 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5096 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04005097 "from %dMbps to %dMbps\n", prev_ll_spd,
5098 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04005099}
5100
5101/**
James Smartda0436e2009-05-22 14:51:39 -04005102 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
5103 * @phba: pointer to lpfc hba data structure.
5104 *
5105 * This routine is invoked by the worker thread to process all the pending
5106 * SLI4 asynchronous events.
5107 **/
5108void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
5109{
5110 struct lpfc_cq_event *cq_event;
5111
5112 /* First, declare the async event has been handled */
5113 spin_lock_irq(&phba->hbalock);
5114 phba->hba_flag &= ~ASYNC_EVENT;
5115 spin_unlock_irq(&phba->hbalock);
5116 /* Now, handle all the async events */
5117 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
5118 /* Get the first event from the head of the event queue */
5119 spin_lock_irq(&phba->hbalock);
5120 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
5121 cq_event, struct lpfc_cq_event, list);
5122 spin_unlock_irq(&phba->hbalock);
5123 /* Process the asynchronous event */
5124 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
5125 case LPFC_TRAILER_CODE_LINK:
5126 lpfc_sli4_async_link_evt(phba,
5127 &cq_event->cqe.acqe_link);
5128 break;
5129 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05005130 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04005131 break;
5132 case LPFC_TRAILER_CODE_DCBX:
5133 lpfc_sli4_async_dcbx_evt(phba,
5134 &cq_event->cqe.acqe_dcbx);
5135 break;
James Smartb19a0612010-04-06 14:48:51 -04005136 case LPFC_TRAILER_CODE_GRP5:
5137 lpfc_sli4_async_grp5_evt(phba,
5138 &cq_event->cqe.acqe_grp5);
5139 break;
James Smart70f3c072010-12-15 17:57:33 -05005140 case LPFC_TRAILER_CODE_FC:
5141 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
5142 break;
5143 case LPFC_TRAILER_CODE_SLI:
5144 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
5145 break;
James Smartda0436e2009-05-22 14:51:39 -04005146 default:
5147 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5148 "1804 Invalid asynchrous event code: "
5149 "x%x\n", bf_get(lpfc_trailer_code,
5150 &cq_event->cqe.mcqe_cmpl));
5151 break;
5152 }
5153 /* Free the completion event processed to the free pool */
5154 lpfc_sli4_cq_event_release(phba, cq_event);
5155 }
5156}
5157
5158/**
James Smartecfd03c2010-02-12 14:41:27 -05005159 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
5160 * @phba: pointer to lpfc hba data structure.
5161 *
5162 * This routine is invoked by the worker thread to process FCF table
5163 * rediscovery pending completion event.
5164 **/
5165void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
5166{
5167 int rc;
5168
5169 spin_lock_irq(&phba->hbalock);
5170 /* Clear FCF rediscovery timeout event */
5171 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
5172 /* Clear driver fast failover FCF record flag */
5173 phba->fcf.failover_rec.flag = 0;
5174 /* Set state for FCF fast failover */
5175 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
5176 spin_unlock_irq(&phba->hbalock);
5177
5178 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05005179 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005180 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05005181 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05005182 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05005183 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5184 "2747 Issue FCF scan read FCF mailbox "
5185 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05005186}
5187
5188/**
James Smartda0436e2009-05-22 14:51:39 -04005189 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
5190 * @phba: pointer to lpfc hba data structure.
5191 * @dev_grp: The HBA PCI-Device group number.
5192 *
5193 * This routine is invoked to set up the per HBA PCI-Device group function
5194 * API jump table entries.
5195 *
5196 * Return: 0 if success, otherwise -ENODEV
5197 **/
5198int
5199lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05005200{
5201 int rc;
5202
James Smartda0436e2009-05-22 14:51:39 -04005203 /* Set up lpfc PCI-device group */
5204 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05005205
James Smartda0436e2009-05-22 14:51:39 -04005206 /* The LPFC_PCI_DEV_OC uses SLI4 */
5207 if (dev_grp == LPFC_PCI_DEV_OC)
5208 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05005209
James Smartda0436e2009-05-22 14:51:39 -04005210 /* Set up device INIT API function jump table */
5211 rc = lpfc_init_api_table_setup(phba, dev_grp);
5212 if (rc)
5213 return -ENODEV;
5214 /* Set up SCSI API function jump table */
5215 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
5216 if (rc)
5217 return -ENODEV;
5218 /* Set up SLI API function jump table */
5219 rc = lpfc_sli_api_table_setup(phba, dev_grp);
5220 if (rc)
5221 return -ENODEV;
5222 /* Set up MBOX API function jump table */
5223 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
5224 if (rc)
5225 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05005226
James Smartda0436e2009-05-22 14:51:39 -04005227 return 0;
James Smart5b75da22008-12-04 22:39:35 -05005228}
5229
5230/**
James Smart3621a712009-04-06 18:47:14 -04005231 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05005232 * @phba: pointer to lpfc hba data structure.
5233 * @intr_mode: active interrupt mode adopted.
5234 *
5235 * This routine it invoked to log the currently used active interrupt mode
5236 * to the device.
James Smart3772a992009-05-22 14:50:54 -04005237 **/
5238static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05005239{
5240 switch (intr_mode) {
5241 case 0:
5242 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5243 "0470 Enable INTx interrupt mode.\n");
5244 break;
5245 case 1:
5246 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5247 "0481 Enabled MSI interrupt mode.\n");
5248 break;
5249 case 2:
5250 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5251 "0480 Enabled MSI-X interrupt mode.\n");
5252 break;
5253 default:
5254 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5255 "0482 Illegal interrupt mode.\n");
5256 break;
5257 }
5258 return;
5259}
5260
James Smart5b75da22008-12-04 22:39:35 -05005261/**
James Smart3772a992009-05-22 14:50:54 -04005262 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05005263 * @phba: pointer to lpfc hba data structure.
5264 *
James Smart3772a992009-05-22 14:50:54 -04005265 * This routine is invoked to enable the PCI device that is common to all
5266 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05005267 *
5268 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005269 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005270 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05005271 **/
James Smart3772a992009-05-22 14:50:54 -04005272static int
5273lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05005274{
James Smart3772a992009-05-22 14:50:54 -04005275 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05005276
James Smart3772a992009-05-22 14:50:54 -04005277 /* Obtain PCI device reference */
5278 if (!phba->pcidev)
5279 goto out_error;
5280 else
5281 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04005282 /* Enable PCI device */
5283 if (pci_enable_device_mem(pdev))
5284 goto out_error;
5285 /* Request PCI resource for the device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005286 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
James Smart3772a992009-05-22 14:50:54 -04005287 goto out_disable_device;
5288 /* Set up device as PCI master and save state for EEH */
5289 pci_set_master(pdev);
5290 pci_try_set_mwi(pdev);
5291 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05005292
James Smart05580562011-05-24 11:40:48 -04005293 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
Jon Mason453193e2013-09-11 15:38:13 -07005294 if (pci_is_pcie(pdev))
James Smart05580562011-05-24 11:40:48 -04005295 pdev->needs_freset = 1;
5296
James Smart3772a992009-05-22 14:50:54 -04005297 return 0;
James Smart5b75da22008-12-04 22:39:35 -05005298
James Smart3772a992009-05-22 14:50:54 -04005299out_disable_device:
5300 pci_disable_device(pdev);
5301out_error:
James Smart079b5c92011-08-21 21:48:49 -04005302 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005303 "1401 Failed to enable pci device\n");
James Smart3772a992009-05-22 14:50:54 -04005304 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05005305}
5306
5307/**
James Smart3772a992009-05-22 14:50:54 -04005308 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05005309 * @phba: pointer to lpfc hba data structure.
5310 *
James Smart3772a992009-05-22 14:50:54 -04005311 * This routine is invoked to disable the PCI device that is common to all
5312 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05005313 **/
5314static void
James Smart3772a992009-05-22 14:50:54 -04005315lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05005316{
James Smart3772a992009-05-22 14:50:54 -04005317 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05005318
James Smart3772a992009-05-22 14:50:54 -04005319 /* Obtain PCI device reference */
5320 if (!phba->pcidev)
5321 return;
5322 else
5323 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04005324 /* Release PCI resource and disable PCI device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005325 pci_release_mem_regions(pdev);
James Smart3772a992009-05-22 14:50:54 -04005326 pci_disable_device(pdev);
James Smart5b75da22008-12-04 22:39:35 -05005327
5328 return;
5329}
5330
5331/**
James Smart3772a992009-05-22 14:50:54 -04005332 * lpfc_reset_hba - Reset a hba
5333 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04005334 *
James Smart3772a992009-05-22 14:50:54 -04005335 * This routine is invoked to reset a hba device. It brings the HBA
5336 * offline, performs a board restart, and then brings the board back
5337 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
5338 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04005339 **/
James Smart3772a992009-05-22 14:50:54 -04005340void
5341lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05005342{
James Smart3772a992009-05-22 14:50:54 -04005343 /* If resets are disabled then set error state and return. */
5344 if (!phba->cfg_enable_hba_reset) {
5345 phba->link_state = LPFC_HBA_ERROR;
5346 return;
5347 }
James Smartee620212014-04-04 13:51:53 -04005348 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
5349 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
5350 else
5351 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart3772a992009-05-22 14:50:54 -04005352 lpfc_offline(phba);
5353 lpfc_sli_brdrestart(phba);
5354 lpfc_online(phba);
5355 lpfc_unblock_mgmt_io(phba);
5356}
dea31012005-04-17 16:05:31 -05005357
James Smart3772a992009-05-22 14:50:54 -04005358/**
James Smart0a96e972011-07-22 18:37:28 -04005359 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
5360 * @phba: pointer to lpfc hba data structure.
5361 *
5362 * This function enables the PCI SR-IOV virtual functions to a physical
5363 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5364 * enable the number of virtual functions to the physical function. As
5365 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5366 * API call does not considered as an error condition for most of the device.
5367 **/
5368uint16_t
5369lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
5370{
5371 struct pci_dev *pdev = phba->pcidev;
5372 uint16_t nr_virtfn;
5373 int pos;
5374
James Smart0a96e972011-07-22 18:37:28 -04005375 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
5376 if (pos == 0)
5377 return 0;
5378
5379 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
5380 return nr_virtfn;
5381}
5382
5383/**
James Smart912e3ac2011-05-24 11:42:11 -04005384 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
5385 * @phba: pointer to lpfc hba data structure.
5386 * @nr_vfn: number of virtual functions to be enabled.
5387 *
5388 * This function enables the PCI SR-IOV virtual functions to a physical
5389 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5390 * enable the number of virtual functions to the physical function. As
5391 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5392 * API call does not considered as an error condition for most of the device.
5393 **/
5394int
5395lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
5396{
5397 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04005398 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04005399 int rc;
5400
James Smart0a96e972011-07-22 18:37:28 -04005401 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
5402 if (nr_vfn > max_nr_vfn) {
5403 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5404 "3057 Requested vfs (%d) greater than "
5405 "supported vfs (%d)", nr_vfn, max_nr_vfn);
5406 return -EINVAL;
5407 }
5408
James Smart912e3ac2011-05-24 11:42:11 -04005409 rc = pci_enable_sriov(pdev, nr_vfn);
5410 if (rc) {
5411 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5412 "2806 Failed to enable sriov on this device "
5413 "with vfn number nr_vf:%d, rc:%d\n",
5414 nr_vfn, rc);
5415 } else
5416 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5417 "2807 Successful enable sriov on this device "
5418 "with vfn number nr_vf:%d\n", nr_vfn);
5419 return rc;
5420}
5421
5422/**
James Smart895427b2017-02-12 13:52:30 -08005423 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
James Smart3772a992009-05-22 14:50:54 -04005424 * @phba: pointer to lpfc hba data structure.
5425 *
James Smart895427b2017-02-12 13:52:30 -08005426 * This routine is invoked to set up the driver internal resources before the
5427 * device specific resource setup to support the HBA device it attached to.
James Smart3772a992009-05-22 14:50:54 -04005428 *
5429 * Return codes
James Smart895427b2017-02-12 13:52:30 -08005430 * 0 - successful
5431 * other values - error
James Smart3772a992009-05-22 14:50:54 -04005432 **/
5433static int
James Smart895427b2017-02-12 13:52:30 -08005434lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
James Smart3772a992009-05-22 14:50:54 -04005435{
James Smart895427b2017-02-12 13:52:30 -08005436 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05005437
James Smart3772a992009-05-22 14:50:54 -04005438 /*
James Smart895427b2017-02-12 13:52:30 -08005439 * Driver resources common to all SLI revisions
James Smart3772a992009-05-22 14:50:54 -04005440 */
James Smart895427b2017-02-12 13:52:30 -08005441 atomic_set(&phba->fast_event_count, 0);
5442 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005443
James Smart895427b2017-02-12 13:52:30 -08005444 /* Initialize ndlp management spinlock */
5445 spin_lock_init(&phba->ndlp_lock);
James Smart3772a992009-05-22 14:50:54 -04005446
James Smart895427b2017-02-12 13:52:30 -08005447 INIT_LIST_HEAD(&phba->port_list);
5448 INIT_LIST_HEAD(&phba->work_list);
5449 init_waitqueue_head(&phba->wait_4_mlo_m_q);
5450
5451 /* Initialize the wait queue head for the kernel thread */
5452 init_waitqueue_head(&phba->work_waitq);
5453
5454 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartf358dd02017-02-12 13:52:34 -08005455 "1403 Protocols supported %s %s %s\n",
James Smart895427b2017-02-12 13:52:30 -08005456 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
5457 "SCSI" : " "),
5458 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
James Smartf358dd02017-02-12 13:52:34 -08005459 "NVME" : " "),
5460 (phba->nvmet_support ? "NVMET" : " "));
James Smart895427b2017-02-12 13:52:30 -08005461
5462 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5463 /* Initialize the scsi buffer list used by driver for scsi IO */
5464 spin_lock_init(&phba->scsi_buf_list_get_lock);
5465 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5466 spin_lock_init(&phba->scsi_buf_list_put_lock);
5467 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
5468 }
5469
5470 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
5471 (phba->nvmet_support == 0)) {
5472 /* Initialize the NVME buffer list used by driver for NVME IO */
5473 spin_lock_init(&phba->nvme_buf_list_get_lock);
5474 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_get);
5475 spin_lock_init(&phba->nvme_buf_list_put_lock);
5476 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
5477 }
5478
5479 /* Initialize the fabric iocb list */
5480 INIT_LIST_HEAD(&phba->fabric_iocb_list);
5481
5482 /* Initialize list to save ELS buffers */
5483 INIT_LIST_HEAD(&phba->elsbuf);
5484
5485 /* Initialize FCF connection rec list */
5486 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
5487
5488 /* Initialize OAS configuration list */
5489 spin_lock_init(&phba->devicelock);
5490 INIT_LIST_HEAD(&phba->luns);
5491
James Smart3772a992009-05-22 14:50:54 -04005492 /* MBOX heartbeat timer */
Tomas Jasek33cc5592017-03-03 13:45:48 +01005493 setup_timer(&psli->mbox_tmo, lpfc_mbox_timeout, (unsigned long)phba);
James Smart3772a992009-05-22 14:50:54 -04005494 /* Fabric block timer */
Tomas Jasek33cc5592017-03-03 13:45:48 +01005495 setup_timer(&phba->fabric_block_timer, lpfc_fabric_block_timeout,
5496 (unsigned long)phba);
James Smart3772a992009-05-22 14:50:54 -04005497 /* EA polling mode timer */
Tomas Jasek33cc5592017-03-03 13:45:48 +01005498 setup_timer(&phba->eratt_poll, lpfc_poll_eratt,
5499 (unsigned long)phba);
James Smart895427b2017-02-12 13:52:30 -08005500 /* Heartbeat timer */
Tomas Jasek33cc5592017-03-03 13:45:48 +01005501 setup_timer(&phba->hb_tmofunc, lpfc_hb_timeout, (unsigned long)phba);
James Smart895427b2017-02-12 13:52:30 -08005502
5503 return 0;
5504}
5505
5506/**
5507 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
5508 * @phba: pointer to lpfc hba data structure.
5509 *
5510 * This routine is invoked to set up the driver internal resources specific to
5511 * support the SLI-3 HBA device it attached to.
5512 *
5513 * Return codes
5514 * 0 - successful
5515 * other values - error
5516 **/
5517static int
5518lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
5519{
5520 int rc;
5521
5522 /*
5523 * Initialize timers used by driver
5524 */
5525
5526 /* FCP polling mode timer */
Tomas Jasek33cc5592017-03-03 13:45:48 +01005527 setup_timer(&phba->fcp_poll_timer, lpfc_poll_timeout,
5528 (unsigned long)phba);
James Smart3772a992009-05-22 14:50:54 -04005529
5530 /* Host attention work mask setup */
5531 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
5532 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
5533
5534 /* Get all the module params for configuring this host */
5535 lpfc_get_cfgparam(phba);
James Smart895427b2017-02-12 13:52:30 -08005536 /* Set up phase-1 common device driver resources */
5537
5538 rc = lpfc_setup_driver_resource_phase1(phba);
5539 if (rc)
5540 return -ENODEV;
5541
James Smart49198b32010-04-06 15:04:33 -04005542 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
5543 phba->menlo_flag |= HBA_MENLO_SUPPORT;
5544 /* check for menlo minimum sg count */
5545 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
5546 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
5547 }
5548
James Smart895427b2017-02-12 13:52:30 -08005549 if (!phba->sli.sli3_ring)
5550 phba->sli.sli3_ring = kzalloc(LPFC_SLI3_MAX_RING *
James Smart2a76a282012-08-03 12:35:54 -04005551 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
James Smart895427b2017-02-12 13:52:30 -08005552 if (!phba->sli.sli3_ring)
James Smart2a76a282012-08-03 12:35:54 -04005553 return -ENOMEM;
5554
James Smart3772a992009-05-22 14:50:54 -04005555 /*
James Smart96f70772013-04-17 20:16:15 -04005556 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smart3772a992009-05-22 14:50:54 -04005557 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart3772a992009-05-22 14:50:54 -04005558 */
James Smart3772a992009-05-22 14:50:54 -04005559
James Smart96f70772013-04-17 20:16:15 -04005560 /* Initialize the host templates the configured values. */
James Smart3772a992009-05-22 14:50:54 -04005561 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart96418b52017-03-04 09:30:31 -08005562 lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt;
5563 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart3772a992009-05-22 14:50:54 -04005564
James Smart96f70772013-04-17 20:16:15 -04005565 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
5566 if (phba->cfg_enable_bg) {
5567 /*
5568 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5569 * the FCP rsp, and a BDE for each. Sice we have no control
5570 * over how many protection data segments the SCSI Layer
5571 * will hand us (ie: there could be one for every block
5572 * in the IO), we just allocate enough BDEs to accomidate
5573 * our max amount and we need to limit lpfc_sg_seg_cnt to
5574 * minimize the risk of running out.
5575 */
5576 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5577 sizeof(struct fcp_rsp) +
5578 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
5579
5580 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
5581 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
5582
5583 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
5584 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
5585 } else {
5586 /*
5587 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5588 * the FCP rsp, a BDE for each, and a BDE for up to
5589 * cfg_sg_seg_cnt data segments.
5590 */
5591 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5592 sizeof(struct fcp_rsp) +
5593 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
5594
5595 /* Total BDEs in BPL for scsi_sg_list */
5596 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5597 }
5598
5599 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5600 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
5601 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5602 phba->cfg_total_seg_cnt);
5603
James Smart3772a992009-05-22 14:50:54 -04005604 phba->max_vpi = LPFC_MAX_VPI;
5605 /* This will be set to correct value after config_port mbox */
5606 phba->max_vports = 0;
5607
5608 /*
5609 * Initialize the SLI Layer to run with lpfc HBAs.
5610 */
5611 lpfc_sli_setup(phba);
James Smart895427b2017-02-12 13:52:30 -08005612 lpfc_sli_queue_init(phba);
James Smart3772a992009-05-22 14:50:54 -04005613
5614 /* Allocate device driver memory */
5615 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
5616 return -ENOMEM;
5617
James Smart912e3ac2011-05-24 11:42:11 -04005618 /*
5619 * Enable sr-iov virtual functions if supported and configured
5620 * through the module parameter.
5621 */
5622 if (phba->cfg_sriov_nr_virtfn > 0) {
5623 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5624 phba->cfg_sriov_nr_virtfn);
5625 if (rc) {
5626 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5627 "2808 Requested number of SR-IOV "
5628 "virtual functions (%d) is not "
5629 "supported\n",
5630 phba->cfg_sriov_nr_virtfn);
5631 phba->cfg_sriov_nr_virtfn = 0;
5632 }
5633 }
5634
James Smart3772a992009-05-22 14:50:54 -04005635 return 0;
5636}
5637
5638/**
5639 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
5640 * @phba: pointer to lpfc hba data structure.
5641 *
5642 * This routine is invoked to unset the driver internal resources set up
5643 * specific for supporting the SLI-3 HBA device it attached to.
5644 **/
5645static void
5646lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
5647{
5648 /* Free device driver memory allocated */
5649 lpfc_mem_free_all(phba);
5650
5651 return;
5652}
5653
5654/**
James Smartda0436e2009-05-22 14:51:39 -04005655 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
5656 * @phba: pointer to lpfc hba data structure.
5657 *
5658 * This routine is invoked to set up the driver internal resources specific to
5659 * support the SLI-4 HBA device it attached to.
5660 *
5661 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005662 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04005663 * other values - error
5664 **/
5665static int
5666lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5667{
James Smart28baac72010-02-12 14:42:03 -05005668 LPFC_MBOXQ_t *mboxq;
James Smartf358dd02017-02-12 13:52:34 -08005669 MAILBOX_t *mb;
James Smart895427b2017-02-12 13:52:30 -08005670 int rc, i, max_buf_size;
James Smart28baac72010-02-12 14:42:03 -05005671 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
5672 struct lpfc_mqe *mqe;
James Smart09294d42013-04-17 20:16:05 -04005673 int longs;
James Smart1ba981f2014-02-20 09:56:45 -05005674 int fof_vectors = 0;
James Smartf358dd02017-02-12 13:52:34 -08005675 uint64_t wwn;
James Smartda0436e2009-05-22 14:51:39 -04005676
James Smart895427b2017-02-12 13:52:30 -08005677 phba->sli4_hba.num_online_cpu = num_online_cpus();
5678 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
5679 phba->sli4_hba.curr_disp_cpu = 0;
5680
James Smart716d3bc2013-09-06 12:18:28 -04005681 /* Get all the module params for configuring this host */
5682 lpfc_get_cfgparam(phba);
5683
James Smart895427b2017-02-12 13:52:30 -08005684 /* Set up phase-1 common device driver resources */
5685 rc = lpfc_setup_driver_resource_phase1(phba);
5686 if (rc)
5687 return -ENODEV;
5688
James Smartda0436e2009-05-22 14:51:39 -04005689 /* Before proceed, wait for POST done and device ready */
5690 rc = lpfc_sli4_post_status_check(phba);
5691 if (rc)
5692 return -ENODEV;
5693
5694 /*
5695 * Initialize timers used by driver
5696 */
5697
Tomas Jasek33cc5592017-03-03 13:45:48 +01005698 setup_timer(&phba->rrq_tmr, lpfc_rrq_timeout, (unsigned long)phba);
James Smartda0436e2009-05-22 14:51:39 -04005699
James Smartecfd03c2010-02-12 14:41:27 -05005700 /* FCF rediscover timer */
Tomas Jasek33cc5592017-03-03 13:45:48 +01005701 setup_timer(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo,
5702 (unsigned long)phba);
James Smartecfd03c2010-02-12 14:41:27 -05005703
James Smartda0436e2009-05-22 14:51:39 -04005704 /*
James Smart7ad20aa2011-05-24 11:44:28 -04005705 * Control structure for handling external multi-buffer mailbox
5706 * command pass-through.
5707 */
5708 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
5709 sizeof(struct lpfc_mbox_ext_buf_ctx));
5710 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
5711
James Smartda0436e2009-05-22 14:51:39 -04005712 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04005713
James Smartda0436e2009-05-22 14:51:39 -04005714 /* This will be set to correct value after the read_config mbox */
5715 phba->max_vports = 0;
5716
5717 /* Program the default value of vlan_id and fc_map */
5718 phba->valid_vlan = 0;
5719 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5720 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5721 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5722
5723 /*
James Smart2a76a282012-08-03 12:35:54 -04005724 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
James Smart895427b2017-02-12 13:52:30 -08005725 * we will associate a new ring, for each EQ/CQ/WQ tuple.
5726 * The WQ create will allocate the ring.
James Smart2a76a282012-08-03 12:35:54 -04005727 */
James Smart085c6472010-11-20 23:11:37 -05005728
James Smart09294d42013-04-17 20:16:05 -04005729 /*
5730 * It doesn't matter what family our adapter is in, we are
5731 * limited to 2 Pages, 512 SGEs, for our SGL.
5732 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
5733 */
5734 max_buf_size = (2 * SLI4_PAGE_SIZE);
5735 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2)
5736 phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2;
James Smart09294d42013-04-17 20:16:05 -04005737
James Smartda0436e2009-05-22 14:51:39 -04005738 /*
James Smart895427b2017-02-12 13:52:30 -08005739 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
5740 * used to create the sg_dma_buf_pool must be calculated.
James Smart28baac72010-02-12 14:42:03 -05005741 */
James Smart96f70772013-04-17 20:16:15 -04005742 if (phba->cfg_enable_bg) {
5743 /*
James Smart895427b2017-02-12 13:52:30 -08005744 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
5745 * the FCP rsp, and a SGE. Sice we have no control
5746 * over how many protection segments the SCSI Layer
James Smart96f70772013-04-17 20:16:15 -04005747 * will hand us (ie: there could be one for every block
James Smart895427b2017-02-12 13:52:30 -08005748 * in the IO), just allocate enough SGEs to accomidate
5749 * our max amount and we need to limit lpfc_sg_seg_cnt
5750 * to minimize the risk of running out.
James Smart96f70772013-04-17 20:16:15 -04005751 */
5752 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08005753 sizeof(struct fcp_rsp) + max_buf_size;
James Smart96f70772013-04-17 20:16:15 -04005754
5755 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
5756 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
5757
5758 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
James Smart895427b2017-02-12 13:52:30 -08005759 phba->cfg_sg_seg_cnt =
5760 LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
James Smart96f70772013-04-17 20:16:15 -04005761 } else {
5762 /*
James Smart895427b2017-02-12 13:52:30 -08005763 * The scsi_buf for a regular I/O holds the FCP cmnd,
James Smart96f70772013-04-17 20:16:15 -04005764 * the FCP rsp, a SGE for each, and a SGE for up to
5765 * cfg_sg_seg_cnt data segments.
5766 */
5767 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08005768 sizeof(struct fcp_rsp) +
5769 ((phba->cfg_sg_seg_cnt + 2) *
5770 sizeof(struct sli4_sge));
James Smart96f70772013-04-17 20:16:15 -04005771
5772 /* Total SGEs for scsi_sg_list */
5773 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
James Smart895427b2017-02-12 13:52:30 -08005774
James Smart96f70772013-04-17 20:16:15 -04005775 /*
James Smart895427b2017-02-12 13:52:30 -08005776 * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only
5777 * need to post 1 page for the SGL.
James Smart96f70772013-04-17 20:16:15 -04005778 */
James Smart085c6472010-11-20 23:11:37 -05005779 }
James Smartacd68592012-01-18 16:25:09 -05005780
James Smart96f70772013-04-17 20:16:15 -04005781 /* Initialize the host templates with the updated values. */
5782 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5783 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart96418b52017-03-04 09:30:31 -08005784 lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart96f70772013-04-17 20:16:15 -04005785
5786 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
5787 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
5788 else
5789 phba->cfg_sg_dma_buf_size =
5790 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
5791
5792 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5793 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
5794 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5795 phba->cfg_total_seg_cnt);
James Smartda0436e2009-05-22 14:51:39 -04005796
5797 /* Initialize buffer queue management fields */
James Smart895427b2017-02-12 13:52:30 -08005798 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
James Smartda0436e2009-05-22 14:51:39 -04005799 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
5800 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
5801
5802 /*
5803 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
5804 */
James Smart895427b2017-02-12 13:52:30 -08005805 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5806 /* Initialize the Abort scsi buffer list used by driver */
5807 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
5808 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
5809 }
5810
5811 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
5812 /* Initialize the Abort nvme buffer list used by driver */
5813 spin_lock_init(&phba->sli4_hba.abts_nvme_buf_list_lock);
5814 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
James Smart318083a2017-03-04 09:30:30 -08005815 /* Fast-path XRI aborted CQ Event work queue list */
5816 INIT_LIST_HEAD(&phba->sli4_hba.sp_nvme_xri_aborted_work_queue);
James Smart895427b2017-02-12 13:52:30 -08005817 }
5818
James Smartda0436e2009-05-22 14:51:39 -04005819 /* This abort list used by worker thread */
James Smart895427b2017-02-12 13:52:30 -08005820 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
James Smartf358dd02017-02-12 13:52:34 -08005821 spin_lock_init(&phba->sli4_hba.nvmet_io_lock);
James Smartda0436e2009-05-22 14:51:39 -04005822
5823 /*
James Smart6d368e52011-05-24 11:44:12 -04005824 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04005825 */
5826
5827 /* Driver internel slow-path CQ Event pool */
5828 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
5829 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04005830 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04005831 /* Asynchronous event CQ Event work queue list */
5832 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
5833 /* Fast-path XRI aborted CQ Event work queue list */
5834 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
5835 /* Slow-path XRI aborted CQ Event work queue list */
5836 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
5837 /* Receive queue CQ Event work queue list */
5838 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
5839
James Smart6d368e52011-05-24 11:44:12 -04005840 /* Initialize extent block lists. */
5841 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
5842 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
5843 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
5844 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
5845
James Smartd1f525a2017-04-21 16:04:55 -07005846 /* Initialize mboxq lists. If the early init routines fail
5847 * these lists need to be correctly initialized.
5848 */
5849 INIT_LIST_HEAD(&phba->sli.mboxq);
5850 INIT_LIST_HEAD(&phba->sli.mboxq_cmpl);
5851
James Smart448193b2015-12-16 18:12:05 -05005852 /* initialize optic_state to 0xFF */
5853 phba->sli4_hba.lnk_info.optic_state = 0xff;
5854
James Smartda0436e2009-05-22 14:51:39 -04005855 /* Allocate device driver memory */
5856 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
5857 if (rc)
5858 return -ENOMEM;
5859
James Smart2fcee4b2010-12-15 17:57:46 -05005860 /* IF Type 2 ports get initialized now. */
5861 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5862 LPFC_SLI_INTF_IF_TYPE_2) {
5863 rc = lpfc_pci_function_reset(phba);
James Smart895427b2017-02-12 13:52:30 -08005864 if (unlikely(rc)) {
5865 rc = -ENODEV;
5866 goto out_free_mem;
5867 }
James Smart946727d2015-04-07 15:07:09 -04005868 phba->temp_sensor_support = 1;
James Smart2fcee4b2010-12-15 17:57:46 -05005869 }
5870
James Smartda0436e2009-05-22 14:51:39 -04005871 /* Create the bootstrap mailbox command */
5872 rc = lpfc_create_bootstrap_mbox(phba);
5873 if (unlikely(rc))
5874 goto out_free_mem;
5875
5876 /* Set up the host's endian order with the device. */
5877 rc = lpfc_setup_endian_order(phba);
5878 if (unlikely(rc))
5879 goto out_free_bsmbx;
5880
5881 /* Set up the hba's configuration parameters. */
5882 rc = lpfc_sli4_read_config(phba);
5883 if (unlikely(rc))
5884 goto out_free_bsmbx;
James Smartcff261f2013-12-17 20:29:47 -05005885 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
5886 if (unlikely(rc))
5887 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005888
James Smart2fcee4b2010-12-15 17:57:46 -05005889 /* IF Type 0 ports get initialized now. */
5890 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5891 LPFC_SLI_INTF_IF_TYPE_0) {
5892 rc = lpfc_pci_function_reset(phba);
5893 if (unlikely(rc))
5894 goto out_free_bsmbx;
5895 }
James Smartda0436e2009-05-22 14:51:39 -04005896
James Smartcb5172e2010-03-15 11:25:07 -04005897 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
5898 GFP_KERNEL);
5899 if (!mboxq) {
5900 rc = -ENOMEM;
5901 goto out_free_bsmbx;
5902 }
5903
James Smartf358dd02017-02-12 13:52:34 -08005904 /* Check for NVMET being configured */
James Smart895427b2017-02-12 13:52:30 -08005905 phba->nvmet_support = 0;
James Smartf358dd02017-02-12 13:52:34 -08005906 if (lpfc_enable_nvmet_cnt) {
5907
5908 /* First get WWN of HBA instance */
5909 lpfc_read_nv(phba, mboxq);
5910 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5911 if (rc != MBX_SUCCESS) {
5912 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5913 "6016 Mailbox failed , mbxCmd x%x "
5914 "READ_NV, mbxStatus x%x\n",
5915 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
5916 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
James Smartd1f525a2017-04-21 16:04:55 -07005917 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartf358dd02017-02-12 13:52:34 -08005918 rc = -EIO;
5919 goto out_free_bsmbx;
5920 }
5921 mb = &mboxq->u.mb;
5922 memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
5923 sizeof(uint64_t));
5924 wwn = cpu_to_be64(wwn);
5925 phba->sli4_hba.wwnn.u.name = wwn;
5926 memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
5927 sizeof(uint64_t));
5928 /* wwn is WWPN of HBA instance */
5929 wwn = cpu_to_be64(wwn);
5930 phba->sli4_hba.wwpn.u.name = wwn;
5931
5932 /* Check to see if it matches any module parameter */
5933 for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
5934 if (wwn == lpfc_enable_nvmet[i]) {
James Smart7d708032017-03-08 14:36:01 -08005935#if (IS_ENABLED(CONFIG_NVME_TARGET_FC))
James Smartf358dd02017-02-12 13:52:34 -08005936 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5937 "6017 NVME Target %016llx\n",
5938 wwn);
5939 phba->nvmet_support = 1; /* a match */
James Smart7d708032017-03-08 14:36:01 -08005940#else
5941 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5942 "6021 Can't enable NVME Target."
5943 " NVME_TARGET_FC infrastructure"
5944 " is not in kernel\n");
5945#endif
James Smartf358dd02017-02-12 13:52:34 -08005946 }
5947 }
5948 }
James Smart895427b2017-02-12 13:52:30 -08005949
5950 lpfc_nvme_mod_param_dep(phba);
5951
James Smartfedd3b72011-02-16 12:39:24 -05005952 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04005953 lpfc_supported_pages(mboxq);
5954 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05005955 if (!rc) {
5956 mqe = &mboxq->u.mqe;
5957 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
5958 LPFC_MAX_SUPPORTED_PAGES);
5959 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
5960 switch (pn_page[i]) {
5961 case LPFC_SLI4_PARAMETERS:
5962 phba->sli4_hba.pc_sli4_params.supported = 1;
5963 break;
5964 default:
5965 break;
5966 }
5967 }
5968 /* Read the port's SLI4 Parameters capabilities if supported. */
5969 if (phba->sli4_hba.pc_sli4_params.supported)
5970 rc = lpfc_pc_sli4_params_get(phba, mboxq);
5971 if (rc) {
5972 mempool_free(mboxq, phba->mbox_mem_pool);
5973 rc = -EIO;
5974 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04005975 }
5976 }
James Smart65791f12016-07-06 12:35:56 -07005977
James Smartfedd3b72011-02-16 12:39:24 -05005978 /*
5979 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04005980 * If this call fails, it isn't critical unless the SLI4 parameters come
5981 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05005982 */
James Smart6d368e52011-05-24 11:44:12 -04005983 rc = lpfc_get_sli4_parameters(phba, mboxq);
5984 if (rc) {
5985 if (phba->sli4_hba.extents_in_use &&
5986 phba->sli4_hba.rpi_hdrs_in_use) {
5987 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5988 "2999 Unsupported SLI4 Parameters "
5989 "Extents and RPI headers enabled.\n");
James Smart6d368e52011-05-24 11:44:12 -04005990 }
James Smart895427b2017-02-12 13:52:30 -08005991 mempool_free(mboxq, phba->mbox_mem_pool);
5992 goto out_free_bsmbx;
James Smart6d368e52011-05-24 11:44:12 -04005993 }
James Smart895427b2017-02-12 13:52:30 -08005994
James Smartcb5172e2010-03-15 11:25:07 -04005995 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -05005996
5997 /* Verify OAS is supported */
5998 lpfc_sli4_oas_verify(phba);
5999 if (phba->cfg_fof)
6000 fof_vectors = 1;
6001
James Smart5350d872011-10-10 21:33:49 -04006002 /* Verify all the SLI4 queues */
6003 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04006004 if (rc)
6005 goto out_free_bsmbx;
6006
6007 /* Create driver internal CQE event pool */
6008 rc = lpfc_sli4_cq_event_pool_create(phba);
6009 if (rc)
James Smart5350d872011-10-10 21:33:49 -04006010 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04006011
James Smart8a9d2e82012-05-09 21:16:12 -04006012 /* Initialize sgl lists per host */
6013 lpfc_init_sgl_list(phba);
6014
6015 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04006016 rc = lpfc_init_active_sgl_array(phba);
6017 if (rc) {
6018 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6019 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04006020 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04006021 }
James Smartda0436e2009-05-22 14:51:39 -04006022 rc = lpfc_sli4_init_rpi_hdrs(phba);
6023 if (rc) {
6024 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6025 "1432 Failed to initialize rpi headers.\n");
6026 goto out_free_active_sgl;
6027 }
6028
James Smarta93ff372010-10-22 11:06:08 -04006029 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05006030 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
6031 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
6032 GFP_KERNEL);
6033 if (!phba->fcf.fcf_rr_bmask) {
6034 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6035 "2759 Failed allocate memory for FCF round "
6036 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04006037 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05006038 goto out_remove_rpi_hdrs;
6039 }
6040
James Smart895427b2017-02-12 13:52:30 -08006041 phba->sli4_hba.hba_eq_hdl = kcalloc(fof_vectors + phba->io_channel_irqs,
6042 sizeof(struct lpfc_hba_eq_hdl),
6043 GFP_KERNEL);
6044 if (!phba->sli4_hba.hba_eq_hdl) {
James Smart67d12732012-08-03 12:36:13 -04006045 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6046 "2572 Failed allocate memory for "
6047 "fast-path per-EQ handle array\n");
6048 rc = -ENOMEM;
6049 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04006050 }
6051
James Smart895427b2017-02-12 13:52:30 -08006052 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_present_cpu,
6053 sizeof(struct lpfc_vector_map_info),
6054 GFP_KERNEL);
James Smart7bb03bb2013-04-17 20:19:16 -04006055 if (!phba->sli4_hba.cpu_map) {
6056 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6057 "3327 Failed allocate memory for msi-x "
6058 "interrupt vector mapping\n");
6059 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08006060 goto out_free_hba_eq_hdl;
James Smart7bb03bb2013-04-17 20:19:16 -04006061 }
James Smartb246de12013-05-31 17:03:07 -04006062 if (lpfc_used_cpu == NULL) {
James Smart895427b2017-02-12 13:52:30 -08006063 lpfc_used_cpu = kcalloc(lpfc_present_cpu, sizeof(uint16_t),
6064 GFP_KERNEL);
James Smartb246de12013-05-31 17:03:07 -04006065 if (!lpfc_used_cpu) {
6066 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6067 "3335 Failed allocate memory for msi-x "
6068 "interrupt vector mapping\n");
6069 kfree(phba->sli4_hba.cpu_map);
6070 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08006071 goto out_free_hba_eq_hdl;
James Smartb246de12013-05-31 17:03:07 -04006072 }
6073 for (i = 0; i < lpfc_present_cpu; i++)
6074 lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
6075 }
6076
James Smart912e3ac2011-05-24 11:42:11 -04006077 /*
6078 * Enable sr-iov virtual functions if supported and configured
6079 * through the module parameter.
6080 */
6081 if (phba->cfg_sriov_nr_virtfn > 0) {
6082 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
6083 phba->cfg_sriov_nr_virtfn);
6084 if (rc) {
6085 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6086 "3020 Requested number of SR-IOV "
6087 "virtual functions (%d) is not "
6088 "supported\n",
6089 phba->cfg_sriov_nr_virtfn);
6090 phba->cfg_sriov_nr_virtfn = 0;
6091 }
6092 }
6093
James Smart5248a742011-07-22 18:37:06 -04006094 return 0;
James Smartda0436e2009-05-22 14:51:39 -04006095
James Smart895427b2017-02-12 13:52:30 -08006096out_free_hba_eq_hdl:
6097 kfree(phba->sli4_hba.hba_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05006098out_free_fcf_rr_bmask:
6099 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04006100out_remove_rpi_hdrs:
6101 lpfc_sli4_remove_rpi_hdrs(phba);
6102out_free_active_sgl:
6103 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04006104out_destroy_cq_event_pool:
6105 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04006106out_free_bsmbx:
6107 lpfc_destroy_bootstrap_mbox(phba);
6108out_free_mem:
6109 lpfc_mem_free(phba);
6110 return rc;
6111}
6112
6113/**
6114 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
6115 * @phba: pointer to lpfc hba data structure.
6116 *
6117 * This routine is invoked to unset the driver internal resources set up
6118 * specific for supporting the SLI-4 HBA device it attached to.
6119 **/
6120static void
6121lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
6122{
6123 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6124
James Smart7bb03bb2013-04-17 20:19:16 -04006125 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
6126 kfree(phba->sli4_hba.cpu_map);
6127 phba->sli4_hba.num_present_cpu = 0;
6128 phba->sli4_hba.num_online_cpu = 0;
James Smart76fd07a2014-02-20 09:57:18 -05006129 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04006130
James Smartda0436e2009-05-22 14:51:39 -04006131 /* Free memory allocated for fast-path work queue handles */
James Smart895427b2017-02-12 13:52:30 -08006132 kfree(phba->sli4_hba.hba_eq_hdl);
James Smartda0436e2009-05-22 14:51:39 -04006133
6134 /* Free the allocated rpi headers. */
6135 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04006136 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04006137
James Smart0c9ab6f2010-02-26 14:15:57 -05006138 /* Free eligible FCF index bmask */
6139 kfree(phba->fcf.fcf_rr_bmask);
6140
James Smartda0436e2009-05-22 14:51:39 -04006141 /* Free the ELS sgl list */
6142 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04006143 lpfc_free_els_sgl_list(phba);
James Smartf358dd02017-02-12 13:52:34 -08006144 lpfc_free_nvmet_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04006145
James Smartda0436e2009-05-22 14:51:39 -04006146 /* Free the completion queue EQ event pool */
6147 lpfc_sli4_cq_event_release_all(phba);
6148 lpfc_sli4_cq_event_pool_destroy(phba);
6149
James Smart6d368e52011-05-24 11:44:12 -04006150 /* Release resource identifiers. */
6151 lpfc_sli4_dealloc_resource_identifiers(phba);
6152
James Smartda0436e2009-05-22 14:51:39 -04006153 /* Free the bsmbx region. */
6154 lpfc_destroy_bootstrap_mbox(phba);
6155
6156 /* Free the SLI Layer memory with SLI4 HBAs */
6157 lpfc_mem_free_all(phba);
6158
6159 /* Free the current connect table */
6160 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04006161 &phba->fcf_conn_rec_list, list) {
6162 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04006163 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04006164 }
James Smartda0436e2009-05-22 14:51:39 -04006165
6166 return;
6167}
6168
6169/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006170 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04006171 * @phba: The hba struct for which this call is being executed.
6172 * @dev_grp: The HBA PCI-Device group number.
6173 *
6174 * This routine sets up the device INIT interface API function jump table
6175 * in @phba struct.
6176 *
6177 * Returns: 0 - success, -ENODEV - failure.
6178 **/
6179int
6180lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
6181{
James Smart84d1b002010-02-12 14:42:33 -05006182 phba->lpfc_hba_init_link = lpfc_hba_init_link;
6183 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05006184 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04006185 switch (dev_grp) {
6186 case LPFC_PCI_DEV_LP:
6187 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
6188 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
6189 phba->lpfc_stop_port = lpfc_stop_port_s3;
6190 break;
James Smartda0436e2009-05-22 14:51:39 -04006191 case LPFC_PCI_DEV_OC:
6192 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
6193 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
6194 phba->lpfc_stop_port = lpfc_stop_port_s4;
6195 break;
James Smart3772a992009-05-22 14:50:54 -04006196 default:
6197 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6198 "1431 Invalid HBA PCI-device group: 0x%x\n",
6199 dev_grp);
6200 return -ENODEV;
6201 break;
6202 }
6203 return 0;
6204}
6205
6206/**
James Smart3772a992009-05-22 14:50:54 -04006207 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
6208 * @phba: pointer to lpfc hba data structure.
6209 *
6210 * This routine is invoked to set up the driver internal resources after the
6211 * device specific resource setup to support the HBA device it attached to.
6212 *
6213 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006214 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006215 * other values - error
6216 **/
6217static int
6218lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
6219{
6220 int error;
6221
6222 /* Startup the kernel thread for this host adapter. */
6223 phba->worker_thread = kthread_run(lpfc_do_work, phba,
6224 "lpfc_worker_%d", phba->brd_no);
6225 if (IS_ERR(phba->worker_thread)) {
6226 error = PTR_ERR(phba->worker_thread);
6227 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006228 }
6229
James Smart3772a992009-05-22 14:50:54 -04006230 return 0;
6231}
6232
6233/**
6234 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
6235 * @phba: pointer to lpfc hba data structure.
6236 *
6237 * This routine is invoked to unset the driver internal resources set up after
6238 * the device specific resource setup for supporting the HBA device it
6239 * attached to.
6240 **/
6241static void
6242lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
6243{
6244 /* Stop kernel worker thread */
6245 kthread_stop(phba->worker_thread);
6246}
6247
6248/**
6249 * lpfc_free_iocb_list - Free iocb list.
6250 * @phba: pointer to lpfc hba data structure.
6251 *
6252 * This routine is invoked to free the driver's IOCB list and memory.
6253 **/
6254static void
6255lpfc_free_iocb_list(struct lpfc_hba *phba)
6256{
6257 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
6258
6259 spin_lock_irq(&phba->hbalock);
6260 list_for_each_entry_safe(iocbq_entry, iocbq_next,
6261 &phba->lpfc_iocb_list, list) {
6262 list_del(&iocbq_entry->list);
6263 kfree(iocbq_entry);
6264 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006265 }
James Smart3772a992009-05-22 14:50:54 -04006266 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006267
James Smart3772a992009-05-22 14:50:54 -04006268 return;
6269}
dea31012005-04-17 16:05:31 -05006270
James Smart3772a992009-05-22 14:50:54 -04006271/**
6272 * lpfc_init_iocb_list - Allocate and initialize iocb list.
6273 * @phba: pointer to lpfc hba data structure.
6274 *
6275 * This routine is invoked to allocate and initizlize the driver's IOCB
6276 * list and set up the IOCB tag array accordingly.
6277 *
6278 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006279 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006280 * other values - error
6281 **/
6282static int
6283lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
6284{
6285 struct lpfc_iocbq *iocbq_entry = NULL;
6286 uint16_t iotag;
6287 int i;
dea31012005-04-17 16:05:31 -05006288
6289 /* Initialize and populate the iocb list per host. */
6290 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04006291 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07006292 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05006293 if (iocbq_entry == NULL) {
6294 printk(KERN_ERR "%s: only allocated %d iocbs of "
6295 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07006296 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05006297 goto out_free_iocbq;
6298 }
6299
James Bottomley604a3e32005-10-29 10:28:33 -05006300 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
6301 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04006302 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05006303 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04006304 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05006305 goto out_free_iocbq;
6306 }
James Smart6d368e52011-05-24 11:44:12 -04006307 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04006308 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05006309
6310 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006311 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
6312 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05006313 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006314 }
6315
James Smart3772a992009-05-22 14:50:54 -04006316 return 0;
6317
6318out_free_iocbq:
6319 lpfc_free_iocb_list(phba);
6320
6321 return -ENOMEM;
6322}
6323
6324/**
James Smart8a9d2e82012-05-09 21:16:12 -04006325 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04006326 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04006327 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04006328 *
James Smart8a9d2e82012-05-09 21:16:12 -04006329 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04006330 **/
James Smart8a9d2e82012-05-09 21:16:12 -04006331void
6332lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04006333{
6334 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04006335
6336 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
6337 list_del(&sglq_entry->list);
6338 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
6339 kfree(sglq_entry);
6340 }
6341}
6342
6343/**
6344 * lpfc_free_els_sgl_list - Free els sgl list.
6345 * @phba: pointer to lpfc hba data structure.
6346 *
6347 * This routine is invoked to free the driver's els sgl list and memory.
6348 **/
6349static void
6350lpfc_free_els_sgl_list(struct lpfc_hba *phba)
6351{
James Smartda0436e2009-05-22 14:51:39 -04006352 LIST_HEAD(sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04006353
James Smart8a9d2e82012-05-09 21:16:12 -04006354 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04006355 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08006356 spin_lock(&phba->sli4_hba.sgl_list_lock);
6357 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
6358 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04006359 spin_unlock_irq(&phba->hbalock);
6360
James Smart8a9d2e82012-05-09 21:16:12 -04006361 /* Now free the sgl list */
6362 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04006363}
6364
6365/**
James Smartf358dd02017-02-12 13:52:34 -08006366 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
6367 * @phba: pointer to lpfc hba data structure.
6368 *
6369 * This routine is invoked to free the driver's nvmet sgl list and memory.
6370 **/
6371static void
6372lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
6373{
6374 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6375 LIST_HEAD(sglq_list);
6376
6377 /* Retrieve all nvmet sgls from driver list */
6378 spin_lock_irq(&phba->hbalock);
6379 spin_lock(&phba->sli4_hba.sgl_list_lock);
6380 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
6381 spin_unlock(&phba->sli4_hba.sgl_list_lock);
6382 spin_unlock_irq(&phba->hbalock);
6383
6384 /* Now free the sgl list */
6385 list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
6386 list_del(&sglq_entry->list);
6387 lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
6388 kfree(sglq_entry);
6389 }
6390}
6391
6392/**
James Smartda0436e2009-05-22 14:51:39 -04006393 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
6394 * @phba: pointer to lpfc hba data structure.
6395 *
6396 * This routine is invoked to allocate the driver's active sgl memory.
6397 * This array will hold the sglq_entry's for active IOs.
6398 **/
6399static int
6400lpfc_init_active_sgl_array(struct lpfc_hba *phba)
6401{
6402 int size;
6403 size = sizeof(struct lpfc_sglq *);
6404 size *= phba->sli4_hba.max_cfg_param.max_xri;
6405
6406 phba->sli4_hba.lpfc_sglq_active_list =
6407 kzalloc(size, GFP_KERNEL);
6408 if (!phba->sli4_hba.lpfc_sglq_active_list)
6409 return -ENOMEM;
6410 return 0;
6411}
6412
6413/**
6414 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
6415 * @phba: pointer to lpfc hba data structure.
6416 *
6417 * This routine is invoked to walk through the array of active sglq entries
6418 * and free all of the resources.
6419 * This is just a place holder for now.
6420 **/
6421static void
6422lpfc_free_active_sgl(struct lpfc_hba *phba)
6423{
6424 kfree(phba->sli4_hba.lpfc_sglq_active_list);
6425}
6426
6427/**
6428 * lpfc_init_sgl_list - Allocate and initialize sgl list.
6429 * @phba: pointer to lpfc hba data structure.
6430 *
6431 * This routine is invoked to allocate and initizlize the driver's sgl
6432 * list and set up the sgl xritag tag array accordingly.
6433 *
James Smartda0436e2009-05-22 14:51:39 -04006434 **/
James Smart8a9d2e82012-05-09 21:16:12 -04006435static void
James Smartda0436e2009-05-22 14:51:39 -04006436lpfc_init_sgl_list(struct lpfc_hba *phba)
6437{
James Smartda0436e2009-05-22 14:51:39 -04006438 /* Initialize and populate the sglq list per host/VF. */
James Smart895427b2017-02-12 13:52:30 -08006439 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
James Smartda0436e2009-05-22 14:51:39 -04006440 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -08006441 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
6442 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_sgl_list);
James Smartda0436e2009-05-22 14:51:39 -04006443
James Smart8a9d2e82012-05-09 21:16:12 -04006444 /* els xri-sgl book keeping */
6445 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04006446
James Smart8a9d2e82012-05-09 21:16:12 -04006447 /* scsi xri-buffer book keeping */
James Smartda0436e2009-05-22 14:51:39 -04006448 phba->sli4_hba.scsi_xri_cnt = 0;
James Smart895427b2017-02-12 13:52:30 -08006449
6450 /* nvme xri-buffer book keeping */
6451 phba->sli4_hba.nvme_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04006452}
6453
6454/**
6455 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
6456 * @phba: pointer to lpfc hba data structure.
6457 *
6458 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04006459 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04006460 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04006461 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
6462 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04006463 *
6464 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006465 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04006466 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04006467 **/
6468int
6469lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
6470{
6471 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04006472 struct lpfc_rpi_hdr *rpi_hdr;
6473
6474 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05006475 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04006476 return rc;
James Smart6d368e52011-05-24 11:44:12 -04006477 if (phba->sli4_hba.extents_in_use)
6478 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04006479
6480 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
6481 if (!rpi_hdr) {
6482 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6483 "0391 Error during rpi post operation\n");
6484 lpfc_sli4_remove_rpis(phba);
6485 rc = -ENODEV;
6486 }
6487
6488 return rc;
6489}
6490
6491/**
6492 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
6493 * @phba: pointer to lpfc hba data structure.
6494 *
6495 * This routine is invoked to allocate a single 4KB memory region to
6496 * support rpis and stores them in the phba. This single region
6497 * provides support for up to 64 rpis. The region is used globally
6498 * by the device.
6499 *
6500 * Returns:
6501 * A valid rpi hdr on success.
6502 * A NULL pointer on any failure.
6503 **/
6504struct lpfc_rpi_hdr *
6505lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
6506{
6507 uint16_t rpi_limit, curr_rpi_range;
6508 struct lpfc_dmabuf *dmabuf;
6509 struct lpfc_rpi_hdr *rpi_hdr;
James Smart9589b0622011-04-16 11:03:17 -04006510 uint32_t rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04006511
James Smart6d368e52011-05-24 11:44:12 -04006512 /*
6513 * If the SLI4 port supports extents, posting the rpi header isn't
6514 * required. Set the expected maximum count and let the actual value
6515 * get set when extents are fully allocated.
6516 */
6517 if (!phba->sli4_hba.rpi_hdrs_in_use)
6518 return NULL;
6519 if (phba->sli4_hba.extents_in_use)
6520 return NULL;
6521
6522 /* The limit on the logical index is just the max_rpi count. */
James Smartda0436e2009-05-22 14:51:39 -04006523 rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
James Smart6d368e52011-05-24 11:44:12 -04006524 phba->sli4_hba.max_cfg_param.max_rpi - 1;
James Smartda0436e2009-05-22 14:51:39 -04006525
6526 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006527 /*
6528 * Establish the starting RPI in this header block. The starting
6529 * rpi is normalized to a zero base because the physical rpi is
6530 * port based.
6531 */
James Smart97f2ecf2012-03-01 22:35:23 -05006532 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04006533 spin_unlock_irq(&phba->hbalock);
6534
6535 /*
6536 * The port has a limited number of rpis. The increment here
6537 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
6538 * and to allow the full max_rpi range per port.
6539 */
6540 if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
James Smart9589b0622011-04-16 11:03:17 -04006541 rpi_count = rpi_limit - curr_rpi_range;
6542 else
6543 rpi_count = LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04006544
James Smart6d368e52011-05-24 11:44:12 -04006545 if (!rpi_count)
6546 return NULL;
James Smartda0436e2009-05-22 14:51:39 -04006547 /*
6548 * First allocate the protocol header region for the port. The
6549 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
6550 */
6551 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6552 if (!dmabuf)
6553 return NULL;
6554
Joe Perches1aee3832014-09-03 12:56:12 -04006555 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
6556 LPFC_HDR_TEMPLATE_SIZE,
6557 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04006558 if (!dmabuf->virt) {
6559 rpi_hdr = NULL;
6560 goto err_free_dmabuf;
6561 }
6562
James Smartda0436e2009-05-22 14:51:39 -04006563 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
6564 rpi_hdr = NULL;
6565 goto err_free_coherent;
6566 }
6567
6568 /* Save the rpi header data for cleanup later. */
6569 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
6570 if (!rpi_hdr)
6571 goto err_free_coherent;
6572
6573 rpi_hdr->dmabuf = dmabuf;
6574 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
6575 rpi_hdr->page_count = 1;
6576 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006577
6578 /* The rpi_hdr stores the logical index only. */
6579 rpi_hdr->start_rpi = curr_rpi_range;
James Smartda0436e2009-05-22 14:51:39 -04006580 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
6581
6582 /*
James Smart6d368e52011-05-24 11:44:12 -04006583 * The next_rpi stores the next logical module-64 rpi value used
6584 * to post physical rpis in subsequent rpi postings.
James Smartda0436e2009-05-22 14:51:39 -04006585 */
James Smart9589b0622011-04-16 11:03:17 -04006586 phba->sli4_hba.next_rpi += rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04006587 spin_unlock_irq(&phba->hbalock);
6588 return rpi_hdr;
6589
6590 err_free_coherent:
6591 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
6592 dmabuf->virt, dmabuf->phys);
6593 err_free_dmabuf:
6594 kfree(dmabuf);
6595 return NULL;
6596}
6597
6598/**
6599 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
6600 * @phba: pointer to lpfc hba data structure.
6601 *
6602 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04006603 * to support rpis for SLI4 ports not supporting extents. This routine
6604 * presumes the caller has released all rpis consumed by fabric or port
6605 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04006606 **/
6607void
6608lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
6609{
6610 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
6611
James Smart6d368e52011-05-24 11:44:12 -04006612 if (!phba->sli4_hba.rpi_hdrs_in_use)
6613 goto exit;
6614
James Smartda0436e2009-05-22 14:51:39 -04006615 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
6616 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
6617 list_del(&rpi_hdr->list);
6618 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
6619 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
6620 kfree(rpi_hdr->dmabuf);
6621 kfree(rpi_hdr);
6622 }
James Smart6d368e52011-05-24 11:44:12 -04006623 exit:
6624 /* There are no rpis available to the port now. */
6625 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04006626}
6627
6628/**
James Smart3772a992009-05-22 14:50:54 -04006629 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
6630 * @pdev: pointer to pci device data structure.
6631 *
6632 * This routine is invoked to allocate the driver hba data structure for an
6633 * HBA device. If the allocation is successful, the phba reference to the
6634 * PCI device data structure is set.
6635 *
6636 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006637 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04006638 * NULL - error
6639 **/
6640static struct lpfc_hba *
6641lpfc_hba_alloc(struct pci_dev *pdev)
6642{
6643 struct lpfc_hba *phba;
6644
6645 /* Allocate memory for HBA structure */
6646 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
6647 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02006648 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04006649 return NULL;
6650 }
6651
6652 /* Set reference to PCI device in HBA structure */
6653 phba->pcidev = pdev;
6654
6655 /* Assign an unused board number */
6656 phba->brd_no = lpfc_get_instance();
6657 if (phba->brd_no < 0) {
6658 kfree(phba);
6659 return NULL;
6660 }
James Smart65791f12016-07-06 12:35:56 -07006661 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
James Smart3772a992009-05-22 14:50:54 -04006662
James Smart4fede782010-01-26 23:08:55 -05006663 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04006664 INIT_LIST_HEAD(&phba->ct_ev_waiters);
6665
James Smart3772a992009-05-22 14:50:54 -04006666 return phba;
6667}
6668
6669/**
6670 * lpfc_hba_free - Free driver hba data structure with a device.
6671 * @phba: pointer to lpfc hba data structure.
6672 *
6673 * This routine is invoked to free the driver hba data structure with an
6674 * HBA device.
6675 **/
6676static void
6677lpfc_hba_free(struct lpfc_hba *phba)
6678{
6679 /* Release the driver assigned board number */
6680 idr_remove(&lpfc_hba_index, phba->brd_no);
6681
James Smart895427b2017-02-12 13:52:30 -08006682 /* Free memory allocated with sli3 rings */
6683 kfree(phba->sli.sli3_ring);
6684 phba->sli.sli3_ring = NULL;
James Smart2a76a282012-08-03 12:35:54 -04006685
James Smart3772a992009-05-22 14:50:54 -04006686 kfree(phba);
6687 return;
6688}
6689
6690/**
6691 * lpfc_create_shost - Create hba physical port with associated scsi host.
6692 * @phba: pointer to lpfc hba data structure.
6693 *
6694 * This routine is invoked to create HBA physical port and associate a SCSI
6695 * host with it.
6696 *
6697 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006698 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006699 * other values - error
6700 **/
6701static int
6702lpfc_create_shost(struct lpfc_hba *phba)
6703{
6704 struct lpfc_vport *vport;
6705 struct Scsi_Host *shost;
6706
6707 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05006708 phba->fc_edtov = FF_DEF_EDTOV;
6709 phba->fc_ratov = FF_DEF_RATOV;
6710 phba->fc_altov = FF_DEF_ALTOV;
6711 phba->fc_arbtov = FF_DEF_ARBTOV;
6712
James Smartd7c47992010-06-08 18:31:54 -04006713 atomic_set(&phba->sdev_cnt, 0);
James Smart3de2a652007-08-02 11:09:59 -04006714 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05006715 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04006716 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05006717
6718 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05006719 phba->pport = vport;
James Smart2ea259e2017-02-12 13:52:27 -08006720
James Smartf358dd02017-02-12 13:52:34 -08006721 if (phba->nvmet_support) {
6722 /* Only 1 vport (pport) will support NVME target */
6723 if (phba->txrdy_payload_pool == NULL) {
6724 phba->txrdy_payload_pool = pci_pool_create(
6725 "txrdy_pool", phba->pcidev,
6726 TXRDY_PAYLOAD_LEN, 16, 0);
6727 if (phba->txrdy_payload_pool) {
6728 phba->targetport = NULL;
6729 phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
6730 lpfc_printf_log(phba, KERN_INFO,
6731 LOG_INIT | LOG_NVME_DISC,
6732 "6076 NVME Target Found\n");
6733 }
6734 }
6735 }
6736
James Smart858c9f62007-06-17 19:56:39 -05006737 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04006738 /* Put reference to SCSI host to driver's device private data */
6739 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05006740
James Smart4258e982015-12-16 18:11:58 -05006741 /*
6742 * At this point we are fully registered with PSA. In addition,
6743 * any initial discovery should be completed.
6744 */
6745 vport->load_flag |= FC_ALLOW_FDMI;
James Smart8663cbb2016-03-31 14:12:33 -07006746 if (phba->cfg_enable_SmartSAN ||
6747 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -05006748
6749 /* Setup appropriate attribute masks */
6750 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -07006751 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -05006752 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
6753 else
6754 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
6755 }
James Smart3772a992009-05-22 14:50:54 -04006756 return 0;
6757}
dea31012005-04-17 16:05:31 -05006758
James Smart3772a992009-05-22 14:50:54 -04006759/**
6760 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
6761 * @phba: pointer to lpfc hba data structure.
6762 *
6763 * This routine is invoked to destroy HBA physical port and the associated
6764 * SCSI host.
6765 **/
6766static void
6767lpfc_destroy_shost(struct lpfc_hba *phba)
6768{
6769 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04006770
James Smart3772a992009-05-22 14:50:54 -04006771 /* Destroy physical port that associated with the SCSI host */
6772 destroy_port(vport);
6773
6774 return;
6775}
6776
6777/**
6778 * lpfc_setup_bg - Setup Block guard structures and debug areas.
6779 * @phba: pointer to lpfc hba data structure.
6780 * @shost: the shost to be used to detect Block guard settings.
6781 *
6782 * This routine sets up the local Block guard protocol settings for @shost.
6783 * This routine also allocates memory for debugging bg buffers.
6784 **/
6785static void
6786lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
6787{
James Smartbbeb79b2012-06-12 13:54:27 -04006788 uint32_t old_mask;
6789 uint32_t old_guard;
6790
James Smart3772a992009-05-22 14:50:54 -04006791 int pagecnt = 10;
James Smartb3b98b72016-10-13 15:06:06 -07006792 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
James Smart3772a992009-05-22 14:50:54 -04006793 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6794 "1478 Registering BlockGuard with the "
6795 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04006796
James Smartb3b98b72016-10-13 15:06:06 -07006797 old_mask = phba->cfg_prot_mask;
6798 old_guard = phba->cfg_prot_guard;
James Smartbbeb79b2012-06-12 13:54:27 -04006799
6800 /* Only allow supported values */
James Smartb3b98b72016-10-13 15:06:06 -07006801 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
James Smartbbeb79b2012-06-12 13:54:27 -04006802 SHOST_DIX_TYPE0_PROTECTION |
6803 SHOST_DIX_TYPE1_PROTECTION);
James Smartb3b98b72016-10-13 15:06:06 -07006804 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
6805 SHOST_DIX_GUARD_CRC);
James Smartbbeb79b2012-06-12 13:54:27 -04006806
6807 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
James Smartb3b98b72016-10-13 15:06:06 -07006808 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
6809 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
James Smartbbeb79b2012-06-12 13:54:27 -04006810
James Smartb3b98b72016-10-13 15:06:06 -07006811 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
6812 if ((old_mask != phba->cfg_prot_mask) ||
6813 (old_guard != phba->cfg_prot_guard))
James Smartbbeb79b2012-06-12 13:54:27 -04006814 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6815 "1475 Registering BlockGuard with the "
6816 "SCSI layer: mask %d guard %d\n",
James Smartb3b98b72016-10-13 15:06:06 -07006817 phba->cfg_prot_mask,
6818 phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04006819
James Smartb3b98b72016-10-13 15:06:06 -07006820 scsi_host_set_prot(shost, phba->cfg_prot_mask);
6821 scsi_host_set_guard(shost, phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04006822 } else
6823 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6824 "1479 Not Registering BlockGuard with the SCSI "
6825 "layer, Bad protection parameters: %d %d\n",
6826 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04006827 }
James Smartbbeb79b2012-06-12 13:54:27 -04006828
James Smart81301a92008-12-04 22:39:46 -05006829 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05006830 while (pagecnt) {
6831 spin_lock_init(&_dump_buf_lock);
6832 _dump_buf_data =
6833 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6834 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04006835 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6836 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04006837 "_dump_buf_data at 0x%p\n",
6838 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05006839 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04006840 memset(_dump_buf_data, 0,
6841 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05006842 break;
James Smart3772a992009-05-22 14:50:54 -04006843 } else
James Smart81301a92008-12-04 22:39:46 -05006844 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05006845 }
James Smart81301a92008-12-04 22:39:46 -05006846 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04006847 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6848 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04006849 "memory for hexdump\n");
6850 } else
James Smart6a9c52c2009-10-02 15:16:51 -04006851 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6852 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05006853 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05006854 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05006855 while (pagecnt) {
6856 _dump_buf_dif =
6857 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6858 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04006859 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6860 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04006861 "_dump_buf_dif at 0x%p\n",
6862 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05006863 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04006864 memset(_dump_buf_dif, 0,
6865 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05006866 break;
James Smart3772a992009-05-22 14:50:54 -04006867 } else
James Smart81301a92008-12-04 22:39:46 -05006868 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05006869 }
James Smart81301a92008-12-04 22:39:46 -05006870 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04006871 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6872 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04006873 "memory for hexdump\n");
6874 } else
James Smart6a9c52c2009-10-02 15:16:51 -04006875 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6876 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04006877 _dump_buf_dif);
6878}
6879
6880/**
6881 * lpfc_post_init_setup - Perform necessary device post initialization setup.
6882 * @phba: pointer to lpfc hba data structure.
6883 *
6884 * This routine is invoked to perform all the necessary post initialization
6885 * setup for the device.
6886 **/
6887static void
6888lpfc_post_init_setup(struct lpfc_hba *phba)
6889{
6890 struct Scsi_Host *shost;
6891 struct lpfc_adapter_event_header adapter_event;
6892
6893 /* Get the default values for Model Name and Description */
6894 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
6895
6896 /*
6897 * hba setup may have changed the hba_queue_depth so we need to
6898 * adjust the value of can_queue.
6899 */
6900 shost = pci_get_drvdata(phba->pcidev);
6901 shost->can_queue = phba->cfg_hba_queue_depth - 10;
6902 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
6903 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05006904
6905 lpfc_host_attrib_init(shost);
6906
James Smart2e0fef82007-06-17 19:56:36 -05006907 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
6908 spin_lock_irq(shost->host_lock);
6909 lpfc_poll_start_timer(phba);
6910 spin_unlock_irq(shost->host_lock);
6911 }
James Smart8f6d98d2006-08-01 07:34:00 -04006912
James Smart93996272008-08-24 21:50:30 -04006913 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6914 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04006915 /* Send board arrival event to upper layer */
6916 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
6917 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
6918 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04006919 sizeof(adapter_event),
6920 (char *) &adapter_event,
6921 LPFC_NL_VENDOR_ID);
6922 return;
6923}
6924
6925/**
6926 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
6927 * @phba: pointer to lpfc hba data structure.
6928 *
6929 * This routine is invoked to set up the PCI device memory space for device
6930 * with SLI-3 interface spec.
6931 *
6932 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006933 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006934 * other values - error
6935 **/
6936static int
6937lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
6938{
6939 struct pci_dev *pdev;
6940 unsigned long bar0map_len, bar2map_len;
6941 int i, hbq_count;
6942 void *ptr;
6943 int error = -ENODEV;
6944
6945 /* Obtain PCI device reference */
6946 if (!phba->pcidev)
6947 return error;
6948 else
6949 pdev = phba->pcidev;
6950
6951 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05006952 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
6953 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
6954 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
6955 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smart3772a992009-05-22 14:50:54 -04006956 return error;
Michael Reed8e685972009-09-18 12:02:05 -05006957 }
6958 }
James Smart3772a992009-05-22 14:50:54 -04006959
6960 /* Get the bus address of Bar0 and Bar2 and the number of bytes
6961 * required by each mapping.
6962 */
6963 phba->pci_bar0_map = pci_resource_start(pdev, 0);
6964 bar0map_len = pci_resource_len(pdev, 0);
6965
6966 phba->pci_bar2_map = pci_resource_start(pdev, 2);
6967 bar2map_len = pci_resource_len(pdev, 2);
6968
6969 /* Map HBA SLIM to a kernel virtual address. */
6970 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
6971 if (!phba->slim_memmap_p) {
6972 dev_printk(KERN_ERR, &pdev->dev,
6973 "ioremap failed for SLIM memory.\n");
6974 goto out;
6975 }
6976
6977 /* Map HBA Control Registers to a kernel virtual address. */
6978 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
6979 if (!phba->ctrl_regs_memmap_p) {
6980 dev_printk(KERN_ERR, &pdev->dev,
6981 "ioremap failed for HBA control registers.\n");
6982 goto out_iounmap_slim;
6983 }
6984
6985 /* Allocate memory for SLI-2 structures */
Joe Perches1aee3832014-09-03 12:56:12 -04006986 phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6987 &phba->slim2p.phys, GFP_KERNEL);
James Smart3772a992009-05-22 14:50:54 -04006988 if (!phba->slim2p.virt)
6989 goto out_iounmap;
6990
James Smart3772a992009-05-22 14:50:54 -04006991 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04006992 phba->mbox_ext = (phba->slim2p.virt +
6993 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04006994 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
6995 phba->IOCBs = (phba->slim2p.virt +
6996 offsetof(struct lpfc_sli2_slim, IOCBs));
6997
6998 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
6999 lpfc_sli_hbq_size(),
7000 &phba->hbqslimp.phys,
7001 GFP_KERNEL);
7002 if (!phba->hbqslimp.virt)
7003 goto out_free_slim;
7004
7005 hbq_count = lpfc_sli_hbq_count();
7006 ptr = phba->hbqslimp.virt;
7007 for (i = 0; i < hbq_count; ++i) {
7008 phba->hbqs[i].hbq_virt = ptr;
7009 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
7010 ptr += (lpfc_hbq_defs[i]->entry_count *
7011 sizeof(struct lpfc_hbq_entry));
7012 }
7013 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
7014 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
7015
7016 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
7017
James Smart3772a992009-05-22 14:50:54 -04007018 phba->MBslimaddr = phba->slim_memmap_p;
7019 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
7020 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
7021 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
7022 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04007023
dea31012005-04-17 16:05:31 -05007024 return 0;
7025
dea31012005-04-17 16:05:31 -05007026out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04007027 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7028 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05007029out_iounmap:
7030 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05007031out_iounmap_slim:
dea31012005-04-17 16:05:31 -05007032 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05007033out:
7034 return error;
7035}
7036
James Smarte59058c2008-08-24 21:49:00 -04007037/**
James Smart3772a992009-05-22 14:50:54 -04007038 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
7039 * @phba: pointer to lpfc hba data structure.
7040 *
7041 * This routine is invoked to unset the PCI device memory space for device
7042 * with SLI-3 interface spec.
7043 **/
7044static void
7045lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
7046{
7047 struct pci_dev *pdev;
7048
7049 /* Obtain PCI device reference */
7050 if (!phba->pcidev)
7051 return;
7052 else
7053 pdev = phba->pcidev;
7054
7055 /* Free coherent DMA memory allocated */
7056 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
7057 phba->hbqslimp.virt, phba->hbqslimp.phys);
7058 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
7059 phba->slim2p.virt, phba->slim2p.phys);
7060
7061 /* I/O memory unmap */
7062 iounmap(phba->ctrl_regs_memmap_p);
7063 iounmap(phba->slim_memmap_p);
7064
7065 return;
7066}
7067
7068/**
James Smartda0436e2009-05-22 14:51:39 -04007069 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
7070 * @phba: pointer to lpfc hba data structure.
7071 *
7072 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
7073 * done and check status.
7074 *
7075 * Return 0 if successful, otherwise -ENODEV.
7076 **/
7077int
7078lpfc_sli4_post_status_check(struct lpfc_hba *phba)
7079{
James Smart2fcee4b2010-12-15 17:57:46 -05007080 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
7081 struct lpfc_register reg_data;
7082 int i, port_error = 0;
7083 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04007084
James Smart9940b972011-03-11 16:06:12 -05007085 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
7086 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05007087 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04007088 return -ENODEV;
7089
James Smartda0436e2009-05-22 14:51:39 -04007090 /* Wait up to 30 seconds for the SLI Port POST done and ready */
7091 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05007092 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
7093 &portsmphr_reg.word0) ||
7094 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007095 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04007096 port_error = -ENODEV;
7097 break;
7098 }
James Smart2fcee4b2010-12-15 17:57:46 -05007099 if (LPFC_POST_STAGE_PORT_READY ==
7100 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04007101 break;
James Smartda0436e2009-05-22 14:51:39 -04007102 msleep(10);
7103 }
7104
James Smart2fcee4b2010-12-15 17:57:46 -05007105 /*
7106 * If there was a port error during POST, then don't proceed with
7107 * other register reads as the data may not be valid. Just exit.
7108 */
7109 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04007110 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05007111 "1408 Port Failed POST - portsmphr=0x%x, "
7112 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
7113 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
7114 portsmphr_reg.word0,
7115 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
7116 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
7117 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
7118 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
7119 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
7120 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
7121 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
7122 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
7123 } else {
James Smart28baac72010-02-12 14:42:03 -05007124 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05007125 "2534 Device Info: SLIFamily=0x%x, "
7126 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
7127 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05007128 bf_get(lpfc_sli_intf_sli_family,
7129 &phba->sli4_hba.sli_intf),
7130 bf_get(lpfc_sli_intf_slirev,
7131 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05007132 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05007133 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05007134 bf_get(lpfc_sli_intf_sli_hint1,
7135 &phba->sli4_hba.sli_intf),
7136 bf_get(lpfc_sli_intf_sli_hint2,
7137 &phba->sli4_hba.sli_intf),
7138 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05007139 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05007140 /*
7141 * Check for other Port errors during the initialization
7142 * process. Fail the load if the port did not come up
7143 * correctly.
7144 */
7145 if_type = bf_get(lpfc_sli_intf_if_type,
7146 &phba->sli4_hba.sli_intf);
7147 switch (if_type) {
7148 case LPFC_SLI_INTF_IF_TYPE_0:
7149 phba->sli4_hba.ue_mask_lo =
7150 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
7151 phba->sli4_hba.ue_mask_hi =
7152 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
7153 uerrlo_reg.word0 =
7154 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
7155 uerrhi_reg.word0 =
7156 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
7157 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
7158 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
7159 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7160 "1422 Unrecoverable Error "
7161 "Detected during POST "
7162 "uerr_lo_reg=0x%x, "
7163 "uerr_hi_reg=0x%x, "
7164 "ue_mask_lo_reg=0x%x, "
7165 "ue_mask_hi_reg=0x%x\n",
7166 uerrlo_reg.word0,
7167 uerrhi_reg.word0,
7168 phba->sli4_hba.ue_mask_lo,
7169 phba->sli4_hba.ue_mask_hi);
7170 port_error = -ENODEV;
7171 }
7172 break;
7173 case LPFC_SLI_INTF_IF_TYPE_2:
7174 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05007175 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
7176 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04007177 (bf_get(lpfc_sliport_status_err, &reg_data) &&
7178 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007179 phba->work_status[0] =
7180 readl(phba->sli4_hba.u.if_type2.
7181 ERR1regaddr);
7182 phba->work_status[1] =
7183 readl(phba->sli4_hba.u.if_type2.
7184 ERR2regaddr);
7185 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05007186 "2888 Unrecoverable port error "
7187 "following POST: port status reg "
7188 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05007189 "error 1=0x%x, error 2=0x%x\n",
7190 reg_data.word0,
7191 portsmphr_reg.word0,
7192 phba->work_status[0],
7193 phba->work_status[1]);
7194 port_error = -ENODEV;
7195 }
7196 break;
7197 case LPFC_SLI_INTF_IF_TYPE_1:
7198 default:
7199 break;
7200 }
James Smart28baac72010-02-12 14:42:03 -05007201 }
James Smartda0436e2009-05-22 14:51:39 -04007202 return port_error;
7203}
7204
7205/**
7206 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
7207 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05007208 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04007209 *
7210 * This routine is invoked to set up SLI4 BAR0 PCI config space register
7211 * memory map.
7212 **/
7213static void
James Smart2fcee4b2010-12-15 17:57:46 -05007214lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04007215{
James Smart2fcee4b2010-12-15 17:57:46 -05007216 switch (if_type) {
7217 case LPFC_SLI_INTF_IF_TYPE_0:
7218 phba->sli4_hba.u.if_type0.UERRLOregaddr =
7219 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
7220 phba->sli4_hba.u.if_type0.UERRHIregaddr =
7221 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
7222 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
7223 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
7224 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
7225 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
7226 phba->sli4_hba.SLIINTFregaddr =
7227 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7228 break;
7229 case LPFC_SLI_INTF_IF_TYPE_2:
7230 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007231 phba->sli4_hba.conf_regs_memmap_p +
7232 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007233 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007234 phba->sli4_hba.conf_regs_memmap_p +
7235 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007236 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007237 phba->sli4_hba.conf_regs_memmap_p +
7238 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007239 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007240 phba->sli4_hba.conf_regs_memmap_p +
7241 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007242 phba->sli4_hba.SLIINTFregaddr =
7243 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7244 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007245 phba->sli4_hba.conf_regs_memmap_p +
7246 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007247 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05007248 phba->sli4_hba.conf_regs_memmap_p +
7249 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05007250 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05007251 phba->sli4_hba.conf_regs_memmap_p +
7252 LPFC_ULP0_WQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05007253 phba->sli4_hba.EQCQDBregaddr =
7254 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
7255 phba->sli4_hba.MQDBregaddr =
7256 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
7257 phba->sli4_hba.BMBXregaddr =
7258 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
7259 break;
7260 case LPFC_SLI_INTF_IF_TYPE_1:
7261 default:
7262 dev_printk(KERN_ERR, &phba->pcidev->dev,
7263 "FATAL - unsupported SLI4 interface type - %d\n",
7264 if_type);
7265 break;
7266 }
James Smartda0436e2009-05-22 14:51:39 -04007267}
7268
7269/**
7270 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
7271 * @phba: pointer to lpfc hba data structure.
7272 *
7273 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
7274 * memory map.
7275 **/
7276static void
7277lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
7278{
James Smart2fcee4b2010-12-15 17:57:46 -05007279 phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7280 LPFC_SLIPORT_IF0_SMPHR;
James Smartda0436e2009-05-22 14:51:39 -04007281 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05007282 LPFC_HST_ISR0;
James Smartda0436e2009-05-22 14:51:39 -04007283 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05007284 LPFC_HST_IMR0;
James Smartda0436e2009-05-22 14:51:39 -04007285 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05007286 LPFC_HST_ISCR0;
James Smartda0436e2009-05-22 14:51:39 -04007287}
7288
7289/**
7290 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
7291 * @phba: pointer to lpfc hba data structure.
7292 * @vf: virtual function number
7293 *
7294 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
7295 * based on the given viftual function number, @vf.
7296 *
7297 * Return 0 if successful, otherwise -ENODEV.
7298 **/
7299static int
7300lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
7301{
7302 if (vf > LPFC_VIR_FUNC_MAX)
7303 return -ENODEV;
7304
7305 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05007306 vf * LPFC_VFR_PAGE_SIZE +
7307 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04007308 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05007309 vf * LPFC_VFR_PAGE_SIZE +
7310 LPFC_ULP0_WQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04007311 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7312 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
7313 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7314 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
7315 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7316 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
7317 return 0;
7318}
7319
7320/**
7321 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
7322 * @phba: pointer to lpfc hba data structure.
7323 *
7324 * This routine is invoked to create the bootstrap mailbox
7325 * region consistent with the SLI-4 interface spec. This
7326 * routine allocates all memory necessary to communicate
7327 * mailbox commands to the port and sets up all alignment
7328 * needs. No locks are expected to be held when calling
7329 * this routine.
7330 *
7331 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007332 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04007333 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04007334 **/
7335static int
7336lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
7337{
7338 uint32_t bmbx_size;
7339 struct lpfc_dmabuf *dmabuf;
7340 struct dma_address *dma_address;
7341 uint32_t pa_addr;
7342 uint64_t phys_addr;
7343
7344 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
7345 if (!dmabuf)
7346 return -ENOMEM;
7347
7348 /*
7349 * The bootstrap mailbox region is comprised of 2 parts
7350 * plus an alignment restriction of 16 bytes.
7351 */
7352 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
Joe Perches1aee3832014-09-03 12:56:12 -04007353 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
7354 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04007355 if (!dmabuf->virt) {
7356 kfree(dmabuf);
7357 return -ENOMEM;
7358 }
James Smartda0436e2009-05-22 14:51:39 -04007359
7360 /*
7361 * Initialize the bootstrap mailbox pointers now so that the register
7362 * operations are simple later. The mailbox dma address is required
7363 * to be 16-byte aligned. Also align the virtual memory as each
7364 * maibox is copied into the bmbx mailbox region before issuing the
7365 * command to the port.
7366 */
7367 phba->sli4_hba.bmbx.dmabuf = dmabuf;
7368 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
7369
7370 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
7371 LPFC_ALIGN_16_BYTE);
7372 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
7373 LPFC_ALIGN_16_BYTE);
7374
7375 /*
7376 * Set the high and low physical addresses now. The SLI4 alignment
7377 * requirement is 16 bytes and the mailbox is posted to the port
7378 * as two 30-bit addresses. The other data is a bit marking whether
7379 * the 30-bit address is the high or low address.
7380 * Upcast bmbx aphys to 64bits so shift instruction compiles
7381 * clean on 32 bit machines.
7382 */
7383 dma_address = &phba->sli4_hba.bmbx.dma_address;
7384 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
7385 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
7386 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
7387 LPFC_BMBX_BIT1_ADDR_HI);
7388
7389 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
7390 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
7391 LPFC_BMBX_BIT1_ADDR_LO);
7392 return 0;
7393}
7394
7395/**
7396 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
7397 * @phba: pointer to lpfc hba data structure.
7398 *
7399 * This routine is invoked to teardown the bootstrap mailbox
7400 * region and release all host resources. This routine requires
7401 * the caller to ensure all mailbox commands recovered, no
7402 * additional mailbox comands are sent, and interrupts are disabled
7403 * before calling this routine.
7404 *
7405 **/
7406static void
7407lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
7408{
7409 dma_free_coherent(&phba->pcidev->dev,
7410 phba->sli4_hba.bmbx.bmbx_size,
7411 phba->sli4_hba.bmbx.dmabuf->virt,
7412 phba->sli4_hba.bmbx.dmabuf->phys);
7413
7414 kfree(phba->sli4_hba.bmbx.dmabuf);
7415 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
7416}
7417
7418/**
7419 * lpfc_sli4_read_config - Get the config parameters.
7420 * @phba: pointer to lpfc hba data structure.
7421 *
7422 * This routine is invoked to read the configuration parameters from the HBA.
7423 * The configuration parameters are used to set the base and maximum values
7424 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
7425 * allocation for the port.
7426 *
7427 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007428 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007429 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007430 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007431 **/
James Smartff78d8f2011-12-13 13:21:35 -05007432int
James Smartda0436e2009-05-22 14:51:39 -04007433lpfc_sli4_read_config(struct lpfc_hba *phba)
7434{
7435 LPFC_MBOXQ_t *pmb;
7436 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04007437 union lpfc_sli4_cfg_shdr *shdr;
7438 uint32_t shdr_status, shdr_add_status;
7439 struct lpfc_mbx_get_func_cfg *get_func_cfg;
7440 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04007441 char *pdesc_0;
James Smartc6918162016-10-13 15:06:16 -07007442 uint16_t forced_link_speed;
7443 uint32_t if_type;
James Smart8aa134a2012-08-14 14:25:29 -04007444 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04007445
7446 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7447 if (!pmb) {
7448 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7449 "2011 Unable to allocate memory for issuing "
7450 "SLI_CONFIG_SPECIAL mailbox command\n");
7451 return -ENOMEM;
7452 }
7453
7454 lpfc_read_config(phba, pmb);
7455
7456 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
7457 if (rc != MBX_SUCCESS) {
7458 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7459 "2012 Mailbox failed , mbxCmd x%x "
7460 "READ_CONFIG, mbxStatus x%x\n",
7461 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7462 bf_get(lpfc_mqe_status, &pmb->u.mqe));
7463 rc = -EIO;
7464 } else {
7465 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05007466 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
7467 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
7468 phba->sli4_hba.lnk_info.lnk_tp =
7469 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
7470 phba->sli4_hba.lnk_info.lnk_no =
7471 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
7472 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7473 "3081 lnk_type:%d, lnk_numb:%d\n",
7474 phba->sli4_hba.lnk_info.lnk_tp,
7475 phba->sli4_hba.lnk_info.lnk_no);
7476 } else
7477 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
7478 "3082 Mailbox (x%x) returned ldv:x0\n",
7479 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart6d368e52011-05-24 11:44:12 -04007480 phba->sli4_hba.extents_in_use =
7481 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04007482 phba->sli4_hba.max_cfg_param.max_xri =
7483 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
7484 phba->sli4_hba.max_cfg_param.xri_base =
7485 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
7486 phba->sli4_hba.max_cfg_param.max_vpi =
7487 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
7488 phba->sli4_hba.max_cfg_param.vpi_base =
7489 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
7490 phba->sli4_hba.max_cfg_param.max_rpi =
7491 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
7492 phba->sli4_hba.max_cfg_param.rpi_base =
7493 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
7494 phba->sli4_hba.max_cfg_param.max_vfi =
7495 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
7496 phba->sli4_hba.max_cfg_param.vfi_base =
7497 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
7498 phba->sli4_hba.max_cfg_param.max_fcfi =
7499 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04007500 phba->sli4_hba.max_cfg_param.max_eq =
7501 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
7502 phba->sli4_hba.max_cfg_param.max_rq =
7503 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
7504 phba->sli4_hba.max_cfg_param.max_wq =
7505 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
7506 phba->sli4_hba.max_cfg_param.max_cq =
7507 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
7508 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
7509 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
7510 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
7511 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05007512 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
7513 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04007514 phba->max_vports = phba->max_vpi;
7515 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04007516 "2003 cfg params Extents? %d "
7517 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04007518 "VPI(B:%d M:%d) "
7519 "VFI(B:%d M:%d) "
7520 "RPI(B:%d M:%d) "
James Smart2ea259e2017-02-12 13:52:27 -08007521 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n",
James Smart6d368e52011-05-24 11:44:12 -04007522 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04007523 phba->sli4_hba.max_cfg_param.xri_base,
7524 phba->sli4_hba.max_cfg_param.max_xri,
7525 phba->sli4_hba.max_cfg_param.vpi_base,
7526 phba->sli4_hba.max_cfg_param.max_vpi,
7527 phba->sli4_hba.max_cfg_param.vfi_base,
7528 phba->sli4_hba.max_cfg_param.max_vfi,
7529 phba->sli4_hba.max_cfg_param.rpi_base,
7530 phba->sli4_hba.max_cfg_param.max_rpi,
James Smart2ea259e2017-02-12 13:52:27 -08007531 phba->sli4_hba.max_cfg_param.max_fcfi,
7532 phba->sli4_hba.max_cfg_param.max_eq,
7533 phba->sli4_hba.max_cfg_param.max_cq,
7534 phba->sli4_hba.max_cfg_param.max_wq,
7535 phba->sli4_hba.max_cfg_param.max_rq);
7536
James Smartda0436e2009-05-22 14:51:39 -04007537 }
James Smart912e3ac2011-05-24 11:42:11 -04007538
7539 if (rc)
7540 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04007541
James Smartc6918162016-10-13 15:06:16 -07007542 /* Update link speed if forced link speed is supported */
7543 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7544 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
7545 forced_link_speed =
7546 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
7547 if (forced_link_speed) {
7548 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
7549
7550 switch (forced_link_speed) {
7551 case LINK_SPEED_1G:
7552 phba->cfg_link_speed =
7553 LPFC_USER_LINK_SPEED_1G;
7554 break;
7555 case LINK_SPEED_2G:
7556 phba->cfg_link_speed =
7557 LPFC_USER_LINK_SPEED_2G;
7558 break;
7559 case LINK_SPEED_4G:
7560 phba->cfg_link_speed =
7561 LPFC_USER_LINK_SPEED_4G;
7562 break;
7563 case LINK_SPEED_8G:
7564 phba->cfg_link_speed =
7565 LPFC_USER_LINK_SPEED_8G;
7566 break;
7567 case LINK_SPEED_10G:
7568 phba->cfg_link_speed =
7569 LPFC_USER_LINK_SPEED_10G;
7570 break;
7571 case LINK_SPEED_16G:
7572 phba->cfg_link_speed =
7573 LPFC_USER_LINK_SPEED_16G;
7574 break;
7575 case LINK_SPEED_32G:
7576 phba->cfg_link_speed =
7577 LPFC_USER_LINK_SPEED_32G;
7578 break;
7579 case 0xffff:
7580 phba->cfg_link_speed =
7581 LPFC_USER_LINK_SPEED_AUTO;
7582 break;
7583 default:
7584 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7585 "0047 Unrecognized link "
7586 "speed : %d\n",
7587 forced_link_speed);
7588 phba->cfg_link_speed =
7589 LPFC_USER_LINK_SPEED_AUTO;
7590 }
7591 }
7592 }
7593
James Smartda0436e2009-05-22 14:51:39 -04007594 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -04007595 length = phba->sli4_hba.max_cfg_param.max_xri -
7596 lpfc_sli4_get_els_iocb_cnt(phba);
7597 if (phba->cfg_hba_queue_depth > length) {
7598 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7599 "3361 HBA queue depth changed from %d to %d\n",
7600 phba->cfg_hba_queue_depth, length);
7601 phba->cfg_hba_queue_depth = length;
7602 }
James Smart912e3ac2011-05-24 11:42:11 -04007603
7604 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
7605 LPFC_SLI_INTF_IF_TYPE_2)
7606 goto read_cfg_out;
7607
7608 /* get the pf# and vf# for SLI4 if_type 2 port */
7609 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
7610 sizeof(struct lpfc_sli4_cfg_mhdr));
7611 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
7612 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
7613 length, LPFC_SLI4_MBX_EMBED);
7614
James Smart8aa134a2012-08-14 14:25:29 -04007615 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04007616 shdr = (union lpfc_sli4_cfg_shdr *)
7617 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
7618 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7619 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04007620 if (rc2 || shdr_status || shdr_add_status) {
James Smart912e3ac2011-05-24 11:42:11 -04007621 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7622 "3026 Mailbox failed , mbxCmd x%x "
7623 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
7624 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7625 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04007626 goto read_cfg_out;
7627 }
7628
7629 /* search for fc_fcoe resrouce descriptor */
7630 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
James Smart912e3ac2011-05-24 11:42:11 -04007631
James Smart8aa134a2012-08-14 14:25:29 -04007632 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
7633 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
7634 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
7635 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
7636 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
7637 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
7638 goto read_cfg_out;
7639
James Smart912e3ac2011-05-24 11:42:11 -04007640 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04007641 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04007642 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04007643 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04007644 phba->sli4_hba.iov.pf_number =
7645 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
7646 phba->sli4_hba.iov.vf_number =
7647 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
7648 break;
7649 }
7650 }
7651
7652 if (i < LPFC_RSRC_DESC_MAX_NUM)
7653 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7654 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
7655 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
7656 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04007657 else
James Smart912e3ac2011-05-24 11:42:11 -04007658 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7659 "3028 GET_FUNCTION_CONFIG: failed to find "
7660 "Resrouce Descriptor:x%x\n",
7661 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04007662
7663read_cfg_out:
7664 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04007665 return rc;
7666}
7667
7668/**
James Smart2fcee4b2010-12-15 17:57:46 -05007669 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04007670 * @phba: pointer to lpfc hba data structure.
7671 *
James Smart2fcee4b2010-12-15 17:57:46 -05007672 * This routine is invoked to setup the port-side endian order when
7673 * the port if_type is 0. This routine has no function for other
7674 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04007675 *
7676 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007677 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007678 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007679 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007680 **/
7681static int
7682lpfc_setup_endian_order(struct lpfc_hba *phba)
7683{
7684 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05007685 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04007686 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
7687 HOST_ENDIAN_HIGH_WORD1};
7688
James Smart2fcee4b2010-12-15 17:57:46 -05007689 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7690 switch (if_type) {
7691 case LPFC_SLI_INTF_IF_TYPE_0:
7692 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7693 GFP_KERNEL);
7694 if (!mboxq) {
7695 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7696 "0492 Unable to allocate memory for "
7697 "issuing SLI_CONFIG_SPECIAL mailbox "
7698 "command\n");
7699 return -ENOMEM;
7700 }
James Smartda0436e2009-05-22 14:51:39 -04007701
James Smart2fcee4b2010-12-15 17:57:46 -05007702 /*
7703 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
7704 * two words to contain special data values and no other data.
7705 */
7706 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
7707 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
7708 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7709 if (rc != MBX_SUCCESS) {
7710 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7711 "0493 SLI_CONFIG_SPECIAL mailbox "
7712 "failed with status x%x\n",
7713 rc);
7714 rc = -EIO;
7715 }
7716 mempool_free(mboxq, phba->mbox_mem_pool);
7717 break;
7718 case LPFC_SLI_INTF_IF_TYPE_2:
7719 case LPFC_SLI_INTF_IF_TYPE_1:
7720 default:
7721 break;
James Smartda0436e2009-05-22 14:51:39 -04007722 }
James Smartda0436e2009-05-22 14:51:39 -04007723 return rc;
7724}
7725
7726/**
James Smart895427b2017-02-12 13:52:30 -08007727 * lpfc_sli4_queue_verify - Verify and update EQ counts
James Smartda0436e2009-05-22 14:51:39 -04007728 * @phba: pointer to lpfc hba data structure.
7729 *
James Smart895427b2017-02-12 13:52:30 -08007730 * This routine is invoked to check the user settable queue counts for EQs.
7731 * After this routine is called the counts will be set to valid values that
James Smart5350d872011-10-10 21:33:49 -04007732 * adhere to the constraints of the system's interrupt vectors and the port's
7733 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04007734 *
7735 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007736 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007737 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007738 **/
7739static int
James Smart5350d872011-10-10 21:33:49 -04007740lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04007741{
James Smart895427b2017-02-12 13:52:30 -08007742 int io_channel;
James Smart1ba981f2014-02-20 09:56:45 -05007743 int fof_vectors = phba->cfg_fof ? 1 : 0;
James Smartda0436e2009-05-22 14:51:39 -04007744
7745 /*
James Smart67d12732012-08-03 12:36:13 -04007746 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04007747 * device parameters
7748 */
7749
James Smart67d12732012-08-03 12:36:13 -04007750 /* Sanity check on HBA EQ parameters */
James Smart895427b2017-02-12 13:52:30 -08007751 io_channel = phba->io_channel_irqs;
James Smartda0436e2009-05-22 14:51:39 -04007752
James Smart895427b2017-02-12 13:52:30 -08007753 if (phba->sli4_hba.num_online_cpu < io_channel) {
James Smart82c3e9b2012-09-29 11:29:50 -04007754 lpfc_printf_log(phba,
7755 KERN_ERR, LOG_INIT,
James Smart90695ee2012-08-14 14:25:36 -04007756 "3188 Reducing IO channels to match number of "
James Smart7bb03bb2013-04-17 20:19:16 -04007757 "online CPUs: from %d to %d\n",
James Smart895427b2017-02-12 13:52:30 -08007758 io_channel, phba->sli4_hba.num_online_cpu);
7759 io_channel = phba->sli4_hba.num_online_cpu;
James Smart90695ee2012-08-14 14:25:36 -04007760 }
7761
James Smart895427b2017-02-12 13:52:30 -08007762 if (io_channel + fof_vectors > phba->sli4_hba.max_cfg_param.max_eq) {
James Smart82c3e9b2012-09-29 11:29:50 -04007763 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7764 "2575 Reducing IO channels to match number of "
7765 "available EQs: from %d to %d\n",
James Smart895427b2017-02-12 13:52:30 -08007766 io_channel,
James Smart82c3e9b2012-09-29 11:29:50 -04007767 phba->sli4_hba.max_cfg_param.max_eq);
James Smart895427b2017-02-12 13:52:30 -08007768 io_channel = phba->sli4_hba.max_cfg_param.max_eq - fof_vectors;
James Smartda0436e2009-05-22 14:51:39 -04007769 }
James Smart67d12732012-08-03 12:36:13 -04007770
James Smart895427b2017-02-12 13:52:30 -08007771 /* The actual number of FCP / NVME event queues adopted */
7772 if (io_channel != phba->io_channel_irqs)
7773 phba->io_channel_irqs = io_channel;
7774 if (phba->cfg_fcp_io_channel > io_channel)
7775 phba->cfg_fcp_io_channel = io_channel;
7776 if (phba->cfg_nvme_io_channel > io_channel)
7777 phba->cfg_nvme_io_channel = io_channel;
James Smart2d7dbc42017-02-12 13:52:35 -08007778 if (phba->cfg_nvme_io_channel < phba->cfg_nvmet_mrq)
7779 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
James Smart895427b2017-02-12 13:52:30 -08007780
7781 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2d7dbc42017-02-12 13:52:35 -08007782 "2574 IO channels: irqs %d fcp %d nvme %d MRQ: %d\n",
James Smart895427b2017-02-12 13:52:30 -08007783 phba->io_channel_irqs, phba->cfg_fcp_io_channel,
James Smart2d7dbc42017-02-12 13:52:35 -08007784 phba->cfg_nvme_io_channel, phba->cfg_nvmet_mrq);
James Smartda0436e2009-05-22 14:51:39 -04007785
James Smartda0436e2009-05-22 14:51:39 -04007786 /* Get EQ depth from module parameter, fake the default for now */
7787 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
7788 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
7789
James Smart5350d872011-10-10 21:33:49 -04007790 /* Get CQ depth from module parameter, fake the default for now */
7791 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
7792 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart5350d872011-10-10 21:33:49 -04007793 return 0;
James Smart895427b2017-02-12 13:52:30 -08007794}
7795
7796static int
7797lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx)
7798{
7799 struct lpfc_queue *qdesc;
7800 int cnt;
7801
7802 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7803 phba->sli4_hba.cq_ecount);
7804 if (!qdesc) {
7805 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7806 "0508 Failed allocate fast-path NVME CQ (%d)\n",
7807 wqidx);
7808 return 1;
7809 }
7810 phba->sli4_hba.nvme_cq[wqidx] = qdesc;
7811
7812 cnt = LPFC_NVME_WQSIZE;
7813 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_WQE128_SIZE, cnt);
7814 if (!qdesc) {
7815 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7816 "0509 Failed allocate fast-path NVME WQ (%d)\n",
7817 wqidx);
7818 return 1;
7819 }
7820 phba->sli4_hba.nvme_wq[wqidx] = qdesc;
7821 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
7822 return 0;
7823}
7824
7825static int
7826lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx)
7827{
7828 struct lpfc_queue *qdesc;
7829 uint32_t wqesize;
7830
7831 /* Create Fast Path FCP CQs */
7832 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7833 phba->sli4_hba.cq_ecount);
7834 if (!qdesc) {
7835 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7836 "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx);
7837 return 1;
7838 }
7839 phba->sli4_hba.fcp_cq[wqidx] = qdesc;
7840
7841 /* Create Fast Path FCP WQs */
7842 wqesize = (phba->fcp_embed_io) ?
James Smartd1f525a2017-04-21 16:04:55 -07007843 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
James Smart895427b2017-02-12 13:52:30 -08007844 qdesc = lpfc_sli4_queue_alloc(phba, wqesize, phba->sli4_hba.wq_ecount);
7845 if (!qdesc) {
7846 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7847 "0503 Failed allocate fast-path FCP WQ (%d)\n",
7848 wqidx);
7849 return 1;
7850 }
7851 phba->sli4_hba.fcp_wq[wqidx] = qdesc;
7852 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
7853 return 0;
James Smart5350d872011-10-10 21:33:49 -04007854}
7855
7856/**
7857 * lpfc_sli4_queue_create - Create all the SLI4 queues
7858 * @phba: pointer to lpfc hba data structure.
7859 *
7860 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
7861 * operation. For each SLI4 queue type, the parameters such as queue entry
7862 * count (queue depth) shall be taken from the module parameter. For now,
7863 * we just use some constant number as place holder.
7864 *
7865 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07007866 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04007867 * -ENOMEM - No availble memory
7868 * -EIO - The mailbox failed to complete successfully.
7869 **/
7870int
7871lpfc_sli4_queue_create(struct lpfc_hba *phba)
7872{
7873 struct lpfc_queue *qdesc;
James Smartd1f525a2017-04-21 16:04:55 -07007874 int idx, io_channel;
James Smart5350d872011-10-10 21:33:49 -04007875
7876 /*
James Smart67d12732012-08-03 12:36:13 -04007877 * Create HBA Record arrays.
James Smart895427b2017-02-12 13:52:30 -08007878 * Both NVME and FCP will share that same vectors / EQs
James Smart5350d872011-10-10 21:33:49 -04007879 */
James Smart895427b2017-02-12 13:52:30 -08007880 io_channel = phba->io_channel_irqs;
7881 if (!io_channel)
James Smart67d12732012-08-03 12:36:13 -04007882 return -ERANGE;
James Smart5350d872011-10-10 21:33:49 -04007883
James Smart67d12732012-08-03 12:36:13 -04007884 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
7885 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
7886 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
7887 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
7888 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
7889 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
James Smart895427b2017-02-12 13:52:30 -08007890 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
7891 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
7892 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
7893 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart67d12732012-08-03 12:36:13 -04007894
James Smart895427b2017-02-12 13:52:30 -08007895 phba->sli4_hba.hba_eq = kcalloc(io_channel,
7896 sizeof(struct lpfc_queue *),
7897 GFP_KERNEL);
James Smart67d12732012-08-03 12:36:13 -04007898 if (!phba->sli4_hba.hba_eq) {
James Smartda0436e2009-05-22 14:51:39 -04007899 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007900 "2576 Failed allocate memory for "
7901 "fast-path EQ record array\n");
James Smartda0436e2009-05-22 14:51:39 -04007902 goto out_error;
7903 }
James Smart67d12732012-08-03 12:36:13 -04007904
James Smart895427b2017-02-12 13:52:30 -08007905 if (phba->cfg_fcp_io_channel) {
7906 phba->sli4_hba.fcp_cq = kcalloc(phba->cfg_fcp_io_channel,
7907 sizeof(struct lpfc_queue *),
7908 GFP_KERNEL);
7909 if (!phba->sli4_hba.fcp_cq) {
7910 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7911 "2577 Failed allocate memory for "
7912 "fast-path CQ record array\n");
7913 goto out_error;
7914 }
7915 phba->sli4_hba.fcp_wq = kcalloc(phba->cfg_fcp_io_channel,
7916 sizeof(struct lpfc_queue *),
7917 GFP_KERNEL);
7918 if (!phba->sli4_hba.fcp_wq) {
7919 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7920 "2578 Failed allocate memory for "
7921 "fast-path FCP WQ record array\n");
7922 goto out_error;
7923 }
7924 /*
7925 * Since the first EQ can have multiple CQs associated with it,
7926 * this array is used to quickly see if we have a FCP fast-path
7927 * CQ match.
7928 */
7929 phba->sli4_hba.fcp_cq_map = kcalloc(phba->cfg_fcp_io_channel,
7930 sizeof(uint16_t),
7931 GFP_KERNEL);
7932 if (!phba->sli4_hba.fcp_cq_map) {
7933 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7934 "2545 Failed allocate memory for "
7935 "fast-path CQ map\n");
7936 goto out_error;
7937 }
James Smart67d12732012-08-03 12:36:13 -04007938 }
7939
James Smart895427b2017-02-12 13:52:30 -08007940 if (phba->cfg_nvme_io_channel) {
7941 phba->sli4_hba.nvme_cq = kcalloc(phba->cfg_nvme_io_channel,
7942 sizeof(struct lpfc_queue *),
7943 GFP_KERNEL);
7944 if (!phba->sli4_hba.nvme_cq) {
7945 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7946 "6077 Failed allocate memory for "
7947 "fast-path CQ record array\n");
7948 goto out_error;
7949 }
7950
James Smart895427b2017-02-12 13:52:30 -08007951 phba->sli4_hba.nvme_wq = kcalloc(phba->cfg_nvme_io_channel,
7952 sizeof(struct lpfc_queue *),
7953 GFP_KERNEL);
7954 if (!phba->sli4_hba.nvme_wq) {
7955 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7956 "2581 Failed allocate memory for "
7957 "fast-path NVME WQ record array\n");
7958 goto out_error;
7959 }
7960
7961 /*
7962 * Since the first EQ can have multiple CQs associated with it,
7963 * this array is used to quickly see if we have a NVME fast-path
7964 * CQ match.
7965 */
7966 phba->sli4_hba.nvme_cq_map = kcalloc(phba->cfg_nvme_io_channel,
7967 sizeof(uint16_t),
7968 GFP_KERNEL);
7969 if (!phba->sli4_hba.nvme_cq_map) {
7970 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7971 "6078 Failed allocate memory for "
7972 "fast-path CQ map\n");
7973 goto out_error;
7974 }
James Smart2d7dbc42017-02-12 13:52:35 -08007975
7976 if (phba->nvmet_support) {
7977 phba->sli4_hba.nvmet_cqset = kcalloc(
7978 phba->cfg_nvmet_mrq,
7979 sizeof(struct lpfc_queue *),
7980 GFP_KERNEL);
7981 if (!phba->sli4_hba.nvmet_cqset) {
7982 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7983 "3121 Fail allocate memory for "
7984 "fast-path CQ set array\n");
7985 goto out_error;
7986 }
7987 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
7988 phba->cfg_nvmet_mrq,
7989 sizeof(struct lpfc_queue *),
7990 GFP_KERNEL);
7991 if (!phba->sli4_hba.nvmet_mrq_hdr) {
7992 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7993 "3122 Fail allocate memory for "
7994 "fast-path RQ set hdr array\n");
7995 goto out_error;
7996 }
7997 phba->sli4_hba.nvmet_mrq_data = kcalloc(
7998 phba->cfg_nvmet_mrq,
7999 sizeof(struct lpfc_queue *),
8000 GFP_KERNEL);
8001 if (!phba->sli4_hba.nvmet_mrq_data) {
8002 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8003 "3124 Fail allocate memory for "
8004 "fast-path RQ set data array\n");
8005 goto out_error;
8006 }
8007 }
James Smart67d12732012-08-03 12:36:13 -04008008 }
James Smartda0436e2009-05-22 14:51:39 -04008009
James Smart895427b2017-02-12 13:52:30 -08008010 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
James Smart67d12732012-08-03 12:36:13 -04008011
James Smart895427b2017-02-12 13:52:30 -08008012 /* Create HBA Event Queues (EQs) */
8013 for (idx = 0; idx < io_channel; idx++) {
James Smart67d12732012-08-03 12:36:13 -04008014 /* Create EQs */
James Smartda0436e2009-05-22 14:51:39 -04008015 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
8016 phba->sli4_hba.eq_ecount);
8017 if (!qdesc) {
8018 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04008019 "0497 Failed allocate EQ (%d)\n", idx);
8020 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008021 }
James Smart67d12732012-08-03 12:36:13 -04008022 phba->sli4_hba.hba_eq[idx] = qdesc;
James Smartda0436e2009-05-22 14:51:39 -04008023 }
8024
James Smart895427b2017-02-12 13:52:30 -08008025 /* FCP and NVME io channels are not required to be balanced */
8026
8027 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
8028 if (lpfc_alloc_fcp_wq_cq(phba, idx))
8029 goto out_error;
8030
8031 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
8032 if (lpfc_alloc_nvme_wq_cq(phba, idx))
8033 goto out_error;
James Smart67d12732012-08-03 12:36:13 -04008034
James Smart2d7dbc42017-02-12 13:52:35 -08008035 if (phba->nvmet_support) {
8036 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8037 qdesc = lpfc_sli4_queue_alloc(phba,
8038 phba->sli4_hba.cq_esize,
8039 phba->sli4_hba.cq_ecount);
8040 if (!qdesc) {
8041 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8042 "3142 Failed allocate NVME "
8043 "CQ Set (%d)\n", idx);
8044 goto out_error;
8045 }
8046 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
8047 }
8048 }
8049
James Smartda0436e2009-05-22 14:51:39 -04008050 /*
James Smart67d12732012-08-03 12:36:13 -04008051 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04008052 */
8053
James Smartda0436e2009-05-22 14:51:39 -04008054 /* Create slow-path Mailbox Command Complete Queue */
8055 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
8056 phba->sli4_hba.cq_ecount);
8057 if (!qdesc) {
8058 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8059 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04008060 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008061 }
8062 phba->sli4_hba.mbx_cq = qdesc;
8063
8064 /* Create slow-path ELS Complete Queue */
8065 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
8066 phba->sli4_hba.cq_ecount);
8067 if (!qdesc) {
8068 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8069 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -04008070 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008071 }
8072 phba->sli4_hba.els_cq = qdesc;
8073
James Smartda0436e2009-05-22 14:51:39 -04008074
James Smart5350d872011-10-10 21:33:49 -04008075 /*
James Smart67d12732012-08-03 12:36:13 -04008076 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04008077 */
James Smartda0436e2009-05-22 14:51:39 -04008078
8079 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04008080
8081 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
8082 phba->sli4_hba.mq_ecount);
8083 if (!qdesc) {
8084 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8085 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04008086 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008087 }
8088 phba->sli4_hba.mbx_wq = qdesc;
8089
8090 /*
James Smart67d12732012-08-03 12:36:13 -04008091 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04008092 */
James Smartda0436e2009-05-22 14:51:39 -04008093
8094 /* Create slow-path ELS Work Queue */
8095 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
8096 phba->sli4_hba.wq_ecount);
8097 if (!qdesc) {
8098 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8099 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04008100 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008101 }
8102 phba->sli4_hba.els_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08008103 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8104
8105 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8106 /* Create NVME LS Complete Queue */
8107 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
8108 phba->sli4_hba.cq_ecount);
8109 if (!qdesc) {
8110 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8111 "6079 Failed allocate NVME LS CQ\n");
8112 goto out_error;
8113 }
8114 phba->sli4_hba.nvmels_cq = qdesc;
8115
8116 /* Create NVME LS Work Queue */
8117 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
8118 phba->sli4_hba.wq_ecount);
8119 if (!qdesc) {
8120 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8121 "6080 Failed allocate NVME LS WQ\n");
8122 goto out_error;
8123 }
8124 phba->sli4_hba.nvmels_wq = qdesc;
8125 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8126 }
James Smartda0436e2009-05-22 14:51:39 -04008127
James Smartda0436e2009-05-22 14:51:39 -04008128 /*
8129 * Create Receive Queue (RQ)
8130 */
James Smartda0436e2009-05-22 14:51:39 -04008131
8132 /* Create Receive Queue for header */
8133 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
8134 phba->sli4_hba.rq_ecount);
8135 if (!qdesc) {
8136 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8137 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04008138 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008139 }
8140 phba->sli4_hba.hdr_rq = qdesc;
8141
8142 /* Create Receive Queue for data */
8143 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
8144 phba->sli4_hba.rq_ecount);
8145 if (!qdesc) {
8146 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8147 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04008148 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008149 }
8150 phba->sli4_hba.dat_rq = qdesc;
8151
James Smart2d7dbc42017-02-12 13:52:35 -08008152 if (phba->nvmet_support) {
8153 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8154 /* Create NVMET Receive Queue for header */
8155 qdesc = lpfc_sli4_queue_alloc(phba,
8156 phba->sli4_hba.rq_esize,
8157 phba->sli4_hba.rq_ecount);
8158 if (!qdesc) {
8159 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8160 "3146 Failed allocate "
8161 "receive HRQ\n");
8162 goto out_error;
8163 }
8164 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
8165
8166 /* Only needed for header of RQ pair */
8167 qdesc->rqbp = kzalloc(sizeof(struct lpfc_rqb),
8168 GFP_KERNEL);
8169 if (qdesc->rqbp == NULL) {
8170 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8171 "6131 Failed allocate "
8172 "Header RQBP\n");
8173 goto out_error;
8174 }
8175
8176 /* Create NVMET Receive Queue for data */
8177 qdesc = lpfc_sli4_queue_alloc(phba,
8178 phba->sli4_hba.rq_esize,
8179 phba->sli4_hba.rq_ecount);
8180 if (!qdesc) {
8181 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8182 "3156 Failed allocate "
8183 "receive DRQ\n");
8184 goto out_error;
8185 }
8186 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
8187 }
8188 }
8189
James Smart1ba981f2014-02-20 09:56:45 -05008190 /* Create the Queues needed for Flash Optimized Fabric operations */
8191 if (phba->cfg_fof)
8192 lpfc_fof_queue_create(phba);
James Smartda0436e2009-05-22 14:51:39 -04008193 return 0;
8194
James Smartda0436e2009-05-22 14:51:39 -04008195out_error:
James Smart67d12732012-08-03 12:36:13 -04008196 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04008197 return -ENOMEM;
8198}
8199
James Smart895427b2017-02-12 13:52:30 -08008200static inline void
8201__lpfc_sli4_release_queue(struct lpfc_queue **qp)
8202{
8203 if (*qp != NULL) {
8204 lpfc_sli4_queue_free(*qp);
8205 *qp = NULL;
8206 }
8207}
8208
8209static inline void
8210lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
8211{
8212 int idx;
8213
8214 if (*qs == NULL)
8215 return;
8216
8217 for (idx = 0; idx < max; idx++)
8218 __lpfc_sli4_release_queue(&(*qs)[idx]);
8219
8220 kfree(*qs);
8221 *qs = NULL;
8222}
8223
8224static inline void
8225lpfc_sli4_release_queue_map(uint16_t **qmap)
8226{
8227 if (*qmap != NULL) {
8228 kfree(*qmap);
8229 *qmap = NULL;
8230 }
8231}
8232
James Smartda0436e2009-05-22 14:51:39 -04008233/**
8234 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
8235 * @phba: pointer to lpfc hba data structure.
8236 *
8237 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
8238 * operation.
8239 *
8240 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008241 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008242 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008243 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008244 **/
James Smart5350d872011-10-10 21:33:49 -04008245void
James Smartda0436e2009-05-22 14:51:39 -04008246lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
8247{
James Smart1ba981f2014-02-20 09:56:45 -05008248 if (phba->cfg_fof)
8249 lpfc_fof_queue_destroy(phba);
8250
James Smart895427b2017-02-12 13:52:30 -08008251 /* Release HBA eqs */
8252 lpfc_sli4_release_queues(&phba->sli4_hba.hba_eq, phba->io_channel_irqs);
James Smart67d12732012-08-03 12:36:13 -04008253
James Smart895427b2017-02-12 13:52:30 -08008254 /* Release FCP cqs */
8255 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_cq,
James Smartd1f525a2017-04-21 16:04:55 -07008256 phba->cfg_fcp_io_channel);
James Smart67d12732012-08-03 12:36:13 -04008257
James Smart895427b2017-02-12 13:52:30 -08008258 /* Release FCP wqs */
8259 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_wq,
James Smartd1f525a2017-04-21 16:04:55 -07008260 phba->cfg_fcp_io_channel);
James Smart67d12732012-08-03 12:36:13 -04008261
8262 /* Release FCP CQ mapping array */
James Smart895427b2017-02-12 13:52:30 -08008263 lpfc_sli4_release_queue_map(&phba->sli4_hba.fcp_cq_map);
8264
8265 /* Release NVME cqs */
8266 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_cq,
8267 phba->cfg_nvme_io_channel);
8268
8269 /* Release NVME wqs */
8270 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_wq,
8271 phba->cfg_nvme_io_channel);
8272
8273 /* Release NVME CQ mapping array */
8274 lpfc_sli4_release_queue_map(&phba->sli4_hba.nvme_cq_map);
James Smartda0436e2009-05-22 14:51:39 -04008275
James Smart2d7dbc42017-02-12 13:52:35 -08008276 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
8277 phba->cfg_nvmet_mrq);
8278
8279 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
8280 phba->cfg_nvmet_mrq);
8281 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
8282 phba->cfg_nvmet_mrq);
8283
James Smartda0436e2009-05-22 14:51:39 -04008284 /* Release mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08008285 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
James Smartda0436e2009-05-22 14:51:39 -04008286
8287 /* Release ELS work queue */
James Smart895427b2017-02-12 13:52:30 -08008288 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
8289
8290 /* Release ELS work queue */
8291 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
James Smartda0436e2009-05-22 14:51:39 -04008292
8293 /* Release unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08008294 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
8295 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
James Smartda0436e2009-05-22 14:51:39 -04008296
James Smartda0436e2009-05-22 14:51:39 -04008297 /* Release ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08008298 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
8299
8300 /* Release NVME LS complete queue */
8301 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
James Smartda0436e2009-05-22 14:51:39 -04008302
8303 /* Release mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08008304 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
8305
8306 /* Everything on this list has been freed */
8307 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
8308}
8309
8310int
8311lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq,
8312 struct lpfc_queue *drq, int count)
8313{
8314 int rc, i;
8315 struct lpfc_rqe hrqe;
8316 struct lpfc_rqe drqe;
8317 struct lpfc_rqb *rqbp;
8318 struct rqb_dmabuf *rqb_buffer;
8319 LIST_HEAD(rqb_buf_list);
8320
8321 rqbp = hrq->rqbp;
8322 for (i = 0; i < count; i++) {
8323 rqb_buffer = (rqbp->rqb_alloc_buffer)(phba);
8324 if (!rqb_buffer)
8325 break;
8326 rqb_buffer->hrq = hrq;
8327 rqb_buffer->drq = drq;
8328 list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list);
8329 }
8330 while (!list_empty(&rqb_buf_list)) {
8331 list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf,
8332 hbuf.list);
8333
8334 hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys);
8335 hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys);
8336 drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys);
8337 drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys);
8338 rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe);
8339 if (rc < 0) {
8340 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
8341 } else {
8342 list_add_tail(&rqb_buffer->hbuf.list,
8343 &rqbp->rqb_buffer_list);
8344 rqbp->buffer_count++;
8345 }
8346 }
8347 return 1;
8348}
8349
8350int
8351lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
8352{
8353 struct lpfc_rqb *rqbp;
8354 struct lpfc_dmabuf *h_buf;
8355 struct rqb_dmabuf *rqb_buffer;
8356
8357 rqbp = rq->rqbp;
8358 while (!list_empty(&rqbp->rqb_buffer_list)) {
8359 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
8360 struct lpfc_dmabuf, list);
8361
8362 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
8363 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
8364 rqbp->buffer_count--;
8365 }
8366 return 1;
8367}
8368
8369static int
8370lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
8371 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
8372 int qidx, uint32_t qtype)
8373{
8374 struct lpfc_sli_ring *pring;
8375 int rc;
8376
8377 if (!eq || !cq || !wq) {
8378 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8379 "6085 Fast-path %s (%d) not allocated\n",
8380 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
8381 return -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04008382 }
James Smartda0436e2009-05-22 14:51:39 -04008383
James Smart895427b2017-02-12 13:52:30 -08008384 /* create the Cq first */
8385 rc = lpfc_cq_create(phba, cq, eq,
8386 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
8387 if (rc) {
8388 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8389 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
8390 qidx, (uint32_t)rc);
8391 return rc;
8392 }
8393
8394 if (qtype != LPFC_MBOX) {
8395 /* Setup nvme_cq_map for fast lookup */
8396 if (cq_map)
8397 *cq_map = cq->queue_id;
8398
8399 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8400 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
8401 qidx, cq->queue_id, qidx, eq->queue_id);
8402
8403 /* create the wq */
8404 rc = lpfc_wq_create(phba, wq, cq, qtype);
8405 if (rc) {
8406 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8407 "6123 Fail setup fastpath WQ (%d), rc = 0x%x\n",
8408 qidx, (uint32_t)rc);
8409 /* no need to tear down cq - caller will do so */
8410 return rc;
8411 }
8412
8413 /* Bind this CQ/WQ to the NVME ring */
8414 pring = wq->pring;
8415 pring->sli.sli4.wqp = (void *)wq;
8416 cq->pring = pring;
8417
8418 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8419 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
8420 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
8421 } else {
8422 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
8423 if (rc) {
8424 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8425 "0539 Failed setup of slow-path MQ: "
8426 "rc = 0x%x\n", rc);
8427 /* no need to tear down cq - caller will do so */
8428 return rc;
8429 }
8430
8431 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8432 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
8433 phba->sli4_hba.mbx_wq->queue_id,
8434 phba->sli4_hba.mbx_cq->queue_id);
8435 }
8436
8437 return 0;
James Smartda0436e2009-05-22 14:51:39 -04008438}
8439
8440/**
8441 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
8442 * @phba: pointer to lpfc hba data structure.
8443 *
8444 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
8445 * operation.
8446 *
8447 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008448 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008449 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008450 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008451 **/
8452int
8453lpfc_sli4_queue_setup(struct lpfc_hba *phba)
8454{
James Smart962bc512013-01-03 15:44:00 -05008455 uint32_t shdr_status, shdr_add_status;
8456 union lpfc_sli4_cfg_shdr *shdr;
8457 LPFC_MBOXQ_t *mboxq;
James Smart895427b2017-02-12 13:52:30 -08008458 int qidx;
8459 uint32_t length, io_channel;
8460 int rc = -ENOMEM;
James Smart962bc512013-01-03 15:44:00 -05008461
8462 /* Check for dual-ULP support */
8463 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8464 if (!mboxq) {
8465 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8466 "3249 Unable to allocate memory for "
8467 "QUERY_FW_CFG mailbox command\n");
8468 return -ENOMEM;
8469 }
8470 length = (sizeof(struct lpfc_mbx_query_fw_config) -
8471 sizeof(struct lpfc_sli4_cfg_mhdr));
8472 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8473 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
8474 length, LPFC_SLI4_MBX_EMBED);
8475
8476 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8477
8478 shdr = (union lpfc_sli4_cfg_shdr *)
8479 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
8480 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8481 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
8482 if (shdr_status || shdr_add_status || rc) {
8483 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8484 "3250 QUERY_FW_CFG mailbox failed with status "
8485 "x%x add_status x%x, mbx status x%x\n",
8486 shdr_status, shdr_add_status, rc);
8487 if (rc != MBX_TIMEOUT)
8488 mempool_free(mboxq, phba->mbox_mem_pool);
8489 rc = -ENXIO;
8490 goto out_error;
8491 }
8492
8493 phba->sli4_hba.fw_func_mode =
8494 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
8495 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
8496 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
James Smart8b017a32015-05-21 13:55:18 -04008497 phba->sli4_hba.physical_port =
8498 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
James Smart962bc512013-01-03 15:44:00 -05008499 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8500 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
8501 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
8502 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
8503
8504 if (rc != MBX_TIMEOUT)
8505 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04008506
8507 /*
James Smart67d12732012-08-03 12:36:13 -04008508 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04008509 */
James Smart895427b2017-02-12 13:52:30 -08008510 io_channel = phba->io_channel_irqs;
James Smartda0436e2009-05-22 14:51:39 -04008511
James Smart67d12732012-08-03 12:36:13 -04008512 /* Set up HBA event queue */
James Smart895427b2017-02-12 13:52:30 -08008513 if (io_channel && !phba->sli4_hba.hba_eq) {
James Smart2e90f4b2011-12-13 13:22:37 -05008514 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8515 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05008516 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04008517 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05008518 }
James Smart895427b2017-02-12 13:52:30 -08008519 for (qidx = 0; qidx < io_channel; qidx++) {
8520 if (!phba->sli4_hba.hba_eq[qidx]) {
James Smartda0436e2009-05-22 14:51:39 -04008521 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8522 "0522 Fast-path EQ (%d) not "
James Smart895427b2017-02-12 13:52:30 -08008523 "allocated\n", qidx);
James Smart1b511972011-12-13 13:23:09 -05008524 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008525 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008526 }
James Smart895427b2017-02-12 13:52:30 -08008527 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[qidx],
8528 phba->cfg_fcp_imax);
James Smartda0436e2009-05-22 14:51:39 -04008529 if (rc) {
8530 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8531 "0523 Failed setup of fast-path EQ "
James Smart895427b2017-02-12 13:52:30 -08008532 "(%d), rc = 0x%x\n", qidx,
James Smarta2fc4aef2014-09-03 12:57:55 -04008533 (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08008534 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008535 }
8536 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008537 "2584 HBA EQ setup: queue[%d]-id=%d\n",
8538 qidx, phba->sli4_hba.hba_eq[qidx]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04008539 }
8540
James Smart895427b2017-02-12 13:52:30 -08008541 if (phba->cfg_nvme_io_channel) {
8542 if (!phba->sli4_hba.nvme_cq || !phba->sli4_hba.nvme_wq) {
James Smart67d12732012-08-03 12:36:13 -04008543 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008544 "6084 Fast-path NVME %s array not allocated\n",
8545 (phba->sli4_hba.nvme_cq) ? "CQ" : "WQ");
James Smart67d12732012-08-03 12:36:13 -04008546 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008547 goto out_destroy;
James Smart67d12732012-08-03 12:36:13 -04008548 }
8549
James Smart895427b2017-02-12 13:52:30 -08008550 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
8551 rc = lpfc_create_wq_cq(phba,
8552 phba->sli4_hba.hba_eq[
8553 qidx % io_channel],
8554 phba->sli4_hba.nvme_cq[qidx],
8555 phba->sli4_hba.nvme_wq[qidx],
8556 &phba->sli4_hba.nvme_cq_map[qidx],
8557 qidx, LPFC_NVME);
8558 if (rc) {
8559 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8560 "6123 Failed to setup fastpath "
8561 "NVME WQ/CQ (%d), rc = 0x%x\n",
8562 qidx, (uint32_t)rc);
8563 goto out_destroy;
8564 }
8565 }
James Smart67d12732012-08-03 12:36:13 -04008566 }
8567
James Smart895427b2017-02-12 13:52:30 -08008568 if (phba->cfg_fcp_io_channel) {
8569 /* Set up fast-path FCP Response Complete Queue */
8570 if (!phba->sli4_hba.fcp_cq || !phba->sli4_hba.fcp_wq) {
James Smart67d12732012-08-03 12:36:13 -04008571 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008572 "3148 Fast-path FCP %s array not allocated\n",
8573 phba->sli4_hba.fcp_cq ? "WQ" : "CQ");
James Smart67d12732012-08-03 12:36:13 -04008574 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008575 goto out_destroy;
James Smart67d12732012-08-03 12:36:13 -04008576 }
8577
James Smart895427b2017-02-12 13:52:30 -08008578 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
8579 rc = lpfc_create_wq_cq(phba,
8580 phba->sli4_hba.hba_eq[
8581 qidx % io_channel],
8582 phba->sli4_hba.fcp_cq[qidx],
8583 phba->sli4_hba.fcp_wq[qidx],
8584 &phba->sli4_hba.fcp_cq_map[qidx],
8585 qidx, LPFC_FCP);
8586 if (rc) {
8587 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8588 "0535 Failed to setup fastpath "
8589 "FCP WQ/CQ (%d), rc = 0x%x\n",
8590 qidx, (uint32_t)rc);
8591 goto out_destroy;
8592 }
8593 }
James Smart67d12732012-08-03 12:36:13 -04008594 }
James Smartda0436e2009-05-22 14:51:39 -04008595
8596 /*
James Smart895427b2017-02-12 13:52:30 -08008597 * Set up Slow Path Complete Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04008598 */
8599
James Smart895427b2017-02-12 13:52:30 -08008600 /* Set up slow-path MBOX CQ/MQ */
8601
8602 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
James Smartda0436e2009-05-22 14:51:39 -04008603 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008604 "0528 %s not allocated\n",
8605 phba->sli4_hba.mbx_cq ?
James Smartd1f525a2017-04-21 16:04:55 -07008606 "Mailbox WQ" : "Mailbox CQ");
James Smart1b511972011-12-13 13:23:09 -05008607 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008608 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008609 }
James Smart895427b2017-02-12 13:52:30 -08008610
8611 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
James Smartd1f525a2017-04-21 16:04:55 -07008612 phba->sli4_hba.mbx_cq,
8613 phba->sli4_hba.mbx_wq,
8614 NULL, 0, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04008615 if (rc) {
8616 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008617 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
8618 (uint32_t)rc);
8619 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008620 }
James Smart2d7dbc42017-02-12 13:52:35 -08008621 if (phba->nvmet_support) {
8622 if (!phba->sli4_hba.nvmet_cqset) {
8623 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8624 "3165 Fast-path NVME CQ Set "
8625 "array not allocated\n");
8626 rc = -ENOMEM;
8627 goto out_destroy;
8628 }
8629 if (phba->cfg_nvmet_mrq > 1) {
8630 rc = lpfc_cq_create_set(phba,
8631 phba->sli4_hba.nvmet_cqset,
8632 phba->sli4_hba.hba_eq,
8633 LPFC_WCQ, LPFC_NVMET);
8634 if (rc) {
8635 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8636 "3164 Failed setup of NVME CQ "
8637 "Set, rc = 0x%x\n",
8638 (uint32_t)rc);
8639 goto out_destroy;
8640 }
8641 } else {
8642 /* Set up NVMET Receive Complete Queue */
8643 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
8644 phba->sli4_hba.hba_eq[0],
8645 LPFC_WCQ, LPFC_NVMET);
8646 if (rc) {
8647 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8648 "6089 Failed setup NVMET CQ: "
8649 "rc = 0x%x\n", (uint32_t)rc);
8650 goto out_destroy;
8651 }
8652 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8653 "6090 NVMET CQ setup: cq-id=%d, "
8654 "parent eq-id=%d\n",
8655 phba->sli4_hba.nvmet_cqset[0]->queue_id,
8656 phba->sli4_hba.hba_eq[0]->queue_id);
8657 }
8658 }
James Smartda0436e2009-05-22 14:51:39 -04008659
James Smart895427b2017-02-12 13:52:30 -08008660 /* Set up slow-path ELS WQ/CQ */
8661 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
James Smartda0436e2009-05-22 14:51:39 -04008662 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008663 "0530 ELS %s not allocated\n",
8664 phba->sli4_hba.els_cq ? "WQ" : "CQ");
James Smart1b511972011-12-13 13:23:09 -05008665 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008666 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008667 }
James Smart895427b2017-02-12 13:52:30 -08008668 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8669 phba->sli4_hba.els_cq,
8670 phba->sli4_hba.els_wq,
8671 NULL, 0, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04008672 if (rc) {
8673 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008674 "0529 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
8675 (uint32_t)rc);
8676 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008677 }
8678 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8679 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
8680 phba->sli4_hba.els_wq->queue_id,
8681 phba->sli4_hba.els_cq->queue_id);
8682
James Smart895427b2017-02-12 13:52:30 -08008683 if (phba->cfg_nvme_io_channel) {
8684 /* Set up NVME LS Complete Queue */
8685 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
8686 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8687 "6091 LS %s not allocated\n",
8688 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
8689 rc = -ENOMEM;
8690 goto out_destroy;
8691 }
8692 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8693 phba->sli4_hba.nvmels_cq,
8694 phba->sli4_hba.nvmels_wq,
8695 NULL, 0, LPFC_NVME_LS);
8696 if (rc) {
8697 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8698 "0529 Failed setup of NVVME LS WQ/CQ: "
8699 "rc = 0x%x\n", (uint32_t)rc);
8700 goto out_destroy;
8701 }
8702
8703 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8704 "6096 ELS WQ setup: wq-id=%d, "
8705 "parent cq-id=%d\n",
8706 phba->sli4_hba.nvmels_wq->queue_id,
8707 phba->sli4_hba.nvmels_cq->queue_id);
8708 }
8709
James Smart2d7dbc42017-02-12 13:52:35 -08008710 /*
8711 * Create NVMET Receive Queue (RQ)
8712 */
8713 if (phba->nvmet_support) {
8714 if ((!phba->sli4_hba.nvmet_cqset) ||
8715 (!phba->sli4_hba.nvmet_mrq_hdr) ||
8716 (!phba->sli4_hba.nvmet_mrq_data)) {
8717 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8718 "6130 MRQ CQ Queues not "
8719 "allocated\n");
8720 rc = -ENOMEM;
8721 goto out_destroy;
8722 }
8723 if (phba->cfg_nvmet_mrq > 1) {
8724 rc = lpfc_mrq_create(phba,
8725 phba->sli4_hba.nvmet_mrq_hdr,
8726 phba->sli4_hba.nvmet_mrq_data,
8727 phba->sli4_hba.nvmet_cqset,
8728 LPFC_NVMET);
8729 if (rc) {
8730 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8731 "6098 Failed setup of NVMET "
8732 "MRQ: rc = 0x%x\n",
8733 (uint32_t)rc);
8734 goto out_destroy;
8735 }
8736
8737 } else {
8738 rc = lpfc_rq_create(phba,
8739 phba->sli4_hba.nvmet_mrq_hdr[0],
8740 phba->sli4_hba.nvmet_mrq_data[0],
8741 phba->sli4_hba.nvmet_cqset[0],
8742 LPFC_NVMET);
8743 if (rc) {
8744 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8745 "6057 Failed setup of NVMET "
8746 "Receive Queue: rc = 0x%x\n",
8747 (uint32_t)rc);
8748 goto out_destroy;
8749 }
8750
8751 lpfc_printf_log(
8752 phba, KERN_INFO, LOG_INIT,
8753 "6099 NVMET RQ setup: hdr-rq-id=%d, "
8754 "dat-rq-id=%d parent cq-id=%d\n",
8755 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
8756 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
8757 phba->sli4_hba.nvmet_cqset[0]->queue_id);
8758
8759 }
8760 }
8761
James Smartda0436e2009-05-22 14:51:39 -04008762 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
8763 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8764 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05008765 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008766 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008767 }
James Smart73d91e52011-10-10 21:32:10 -04008768
8769 lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
8770 lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
8771
James Smartda0436e2009-05-22 14:51:39 -04008772 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04008773 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04008774 if (rc) {
8775 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8776 "0541 Failed setup of Receive Queue: "
James Smarta2fc4aef2014-09-03 12:57:55 -04008777 "rc = 0x%x\n", (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08008778 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008779 }
James Smart73d91e52011-10-10 21:32:10 -04008780
James Smartda0436e2009-05-22 14:51:39 -04008781 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8782 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
8783 "parent cq-id=%d\n",
8784 phba->sli4_hba.hdr_rq->queue_id,
8785 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04008786 phba->sli4_hba.els_cq->queue_id);
James Smart1ba981f2014-02-20 09:56:45 -05008787
8788 if (phba->cfg_fof) {
8789 rc = lpfc_fof_queue_setup(phba);
8790 if (rc) {
8791 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8792 "0549 Failed setup of FOF Queues: "
8793 "rc = 0x%x\n", rc);
James Smart895427b2017-02-12 13:52:30 -08008794 goto out_destroy;
James Smart1ba981f2014-02-20 09:56:45 -05008795 }
8796 }
James Smart2c9c5a02015-04-07 15:07:15 -04008797
James Smart43140ca2017-03-04 09:30:34 -08008798 for (qidx = 0; qidx < io_channel; qidx += LPFC_MAX_EQ_DELAY_EQID_CNT)
James Smart895427b2017-02-12 13:52:30 -08008799 lpfc_modify_hba_eq_delay(phba, qidx);
James Smart43140ca2017-03-04 09:30:34 -08008800
James Smartda0436e2009-05-22 14:51:39 -04008801 return 0;
8802
James Smart895427b2017-02-12 13:52:30 -08008803out_destroy:
8804 lpfc_sli4_queue_unset(phba);
James Smartda0436e2009-05-22 14:51:39 -04008805out_error:
8806 return rc;
8807}
8808
8809/**
8810 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
8811 * @phba: pointer to lpfc hba data structure.
8812 *
8813 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
8814 * operation.
8815 *
8816 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008817 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008818 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008819 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008820 **/
8821void
8822lpfc_sli4_queue_unset(struct lpfc_hba *phba)
8823{
James Smart895427b2017-02-12 13:52:30 -08008824 int qidx;
James Smartda0436e2009-05-22 14:51:39 -04008825
James Smart1ba981f2014-02-20 09:56:45 -05008826 /* Unset the queues created for Flash Optimized Fabric operations */
8827 if (phba->cfg_fof)
8828 lpfc_fof_queue_destroy(phba);
James Smart895427b2017-02-12 13:52:30 -08008829
James Smartda0436e2009-05-22 14:51:39 -04008830 /* Unset mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08008831 if (phba->sli4_hba.mbx_wq)
8832 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
8833
8834 /* Unset NVME LS work queue */
8835 if (phba->sli4_hba.nvmels_wq)
8836 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
8837
James Smartda0436e2009-05-22 14:51:39 -04008838 /* Unset ELS work queue */
James Smart895427b2017-02-12 13:52:30 -08008839 if (phba->sli4_hba.els_cq)
8840 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
8841
James Smartda0436e2009-05-22 14:51:39 -04008842 /* Unset unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08008843 if (phba->sli4_hba.hdr_rq)
8844 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
8845 phba->sli4_hba.dat_rq);
8846
James Smartda0436e2009-05-22 14:51:39 -04008847 /* Unset FCP work queue */
James Smart895427b2017-02-12 13:52:30 -08008848 if (phba->sli4_hba.fcp_wq)
8849 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
8850 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[qidx]);
8851
8852 /* Unset NVME work queue */
8853 if (phba->sli4_hba.nvme_wq) {
8854 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
8855 lpfc_wq_destroy(phba, phba->sli4_hba.nvme_wq[qidx]);
James Smart67d12732012-08-03 12:36:13 -04008856 }
James Smart895427b2017-02-12 13:52:30 -08008857
James Smartda0436e2009-05-22 14:51:39 -04008858 /* Unset mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08008859 if (phba->sli4_hba.mbx_cq)
8860 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
8861
James Smartda0436e2009-05-22 14:51:39 -04008862 /* Unset ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08008863 if (phba->sli4_hba.els_cq)
8864 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
8865
8866 /* Unset NVME LS complete queue */
8867 if (phba->sli4_hba.nvmels_cq)
8868 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
8869
8870 /* Unset NVME response complete queue */
8871 if (phba->sli4_hba.nvme_cq)
8872 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
8873 lpfc_cq_destroy(phba, phba->sli4_hba.nvme_cq[qidx]);
8874
James Smart2d7dbc42017-02-12 13:52:35 -08008875 /* Unset NVMET MRQ queue */
8876 if (phba->sli4_hba.nvmet_mrq_hdr) {
8877 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
8878 lpfc_rq_destroy(phba,
8879 phba->sli4_hba.nvmet_mrq_hdr[qidx],
8880 phba->sli4_hba.nvmet_mrq_data[qidx]);
8881 }
8882
8883 /* Unset NVMET CQ Set complete queue */
8884 if (phba->sli4_hba.nvmet_cqset) {
8885 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
8886 lpfc_cq_destroy(phba,
8887 phba->sli4_hba.nvmet_cqset[qidx]);
8888 }
8889
James Smartda0436e2009-05-22 14:51:39 -04008890 /* Unset FCP response complete queue */
James Smart895427b2017-02-12 13:52:30 -08008891 if (phba->sli4_hba.fcp_cq)
8892 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
8893 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[qidx]);
8894
James Smartda0436e2009-05-22 14:51:39 -04008895 /* Unset fast-path event queue */
James Smart895427b2017-02-12 13:52:30 -08008896 if (phba->sli4_hba.hba_eq)
8897 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++)
8898 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[qidx]);
James Smartda0436e2009-05-22 14:51:39 -04008899}
8900
8901/**
8902 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
8903 * @phba: pointer to lpfc hba data structure.
8904 *
8905 * This routine is invoked to allocate and set up a pool of completion queue
8906 * events. The body of the completion queue event is a completion queue entry
8907 * CQE. For now, this pool is used for the interrupt service routine to queue
8908 * the following HBA completion queue events for the worker thread to process:
8909 * - Mailbox asynchronous events
8910 * - Receive queue completion unsolicited events
8911 * Later, this can be used for all the slow-path events.
8912 *
8913 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008914 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008915 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04008916 **/
8917static int
8918lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
8919{
8920 struct lpfc_cq_event *cq_event;
8921 int i;
8922
8923 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
8924 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
8925 if (!cq_event)
8926 goto out_pool_create_fail;
8927 list_add_tail(&cq_event->list,
8928 &phba->sli4_hba.sp_cqe_event_pool);
8929 }
8930 return 0;
8931
8932out_pool_create_fail:
8933 lpfc_sli4_cq_event_pool_destroy(phba);
8934 return -ENOMEM;
8935}
8936
8937/**
8938 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
8939 * @phba: pointer to lpfc hba data structure.
8940 *
8941 * This routine is invoked to free the pool of completion queue events at
8942 * driver unload time. Note that, it is the responsibility of the driver
8943 * cleanup routine to free all the outstanding completion-queue events
8944 * allocated from this pool back into the pool before invoking this routine
8945 * to destroy the pool.
8946 **/
8947static void
8948lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
8949{
8950 struct lpfc_cq_event *cq_event, *next_cq_event;
8951
8952 list_for_each_entry_safe(cq_event, next_cq_event,
8953 &phba->sli4_hba.sp_cqe_event_pool, list) {
8954 list_del(&cq_event->list);
8955 kfree(cq_event);
8956 }
8957}
8958
8959/**
8960 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
8961 * @phba: pointer to lpfc hba data structure.
8962 *
8963 * This routine is the lock free version of the API invoked to allocate a
8964 * completion-queue event from the free pool.
8965 *
8966 * Return: Pointer to the newly allocated completion-queue event if successful
8967 * NULL otherwise.
8968 **/
8969struct lpfc_cq_event *
8970__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
8971{
8972 struct lpfc_cq_event *cq_event = NULL;
8973
8974 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
8975 struct lpfc_cq_event, list);
8976 return cq_event;
8977}
8978
8979/**
8980 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
8981 * @phba: pointer to lpfc hba data structure.
8982 *
8983 * This routine is the lock version of the API invoked to allocate a
8984 * completion-queue event from the free pool.
8985 *
8986 * Return: Pointer to the newly allocated completion-queue event if successful
8987 * NULL otherwise.
8988 **/
8989struct lpfc_cq_event *
8990lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
8991{
8992 struct lpfc_cq_event *cq_event;
8993 unsigned long iflags;
8994
8995 spin_lock_irqsave(&phba->hbalock, iflags);
8996 cq_event = __lpfc_sli4_cq_event_alloc(phba);
8997 spin_unlock_irqrestore(&phba->hbalock, iflags);
8998 return cq_event;
8999}
9000
9001/**
9002 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9003 * @phba: pointer to lpfc hba data structure.
9004 * @cq_event: pointer to the completion queue event to be freed.
9005 *
9006 * This routine is the lock free version of the API invoked to release a
9007 * completion-queue event back into the free pool.
9008 **/
9009void
9010__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9011 struct lpfc_cq_event *cq_event)
9012{
9013 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
9014}
9015
9016/**
9017 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
9018 * @phba: pointer to lpfc hba data structure.
9019 * @cq_event: pointer to the completion queue event to be freed.
9020 *
9021 * This routine is the lock version of the API invoked to release a
9022 * completion-queue event back into the free pool.
9023 **/
9024void
9025lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
9026 struct lpfc_cq_event *cq_event)
9027{
9028 unsigned long iflags;
9029 spin_lock_irqsave(&phba->hbalock, iflags);
9030 __lpfc_sli4_cq_event_release(phba, cq_event);
9031 spin_unlock_irqrestore(&phba->hbalock, iflags);
9032}
9033
9034/**
9035 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
9036 * @phba: pointer to lpfc hba data structure.
9037 *
9038 * This routine is to free all the pending completion-queue events to the
9039 * back into the free pool for device reset.
9040 **/
9041static void
9042lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
9043{
9044 LIST_HEAD(cqelist);
9045 struct lpfc_cq_event *cqe;
9046 unsigned long iflags;
9047
9048 /* Retrieve all the pending WCQEs from pending WCQE lists */
9049 spin_lock_irqsave(&phba->hbalock, iflags);
9050 /* Pending FCP XRI abort events */
9051 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
9052 &cqelist);
9053 /* Pending ELS XRI abort events */
9054 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
9055 &cqelist);
James Smart318083a2017-03-04 09:30:30 -08009056 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
9057 /* Pending NVME XRI abort events */
9058 list_splice_init(&phba->sli4_hba.sp_nvme_xri_aborted_work_queue,
9059 &cqelist);
9060 }
James Smartda0436e2009-05-22 14:51:39 -04009061 /* Pending asynnc events */
9062 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
9063 &cqelist);
9064 spin_unlock_irqrestore(&phba->hbalock, iflags);
9065
9066 while (!list_empty(&cqelist)) {
9067 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
9068 lpfc_sli4_cq_event_release(phba, cqe);
9069 }
9070}
9071
9072/**
9073 * lpfc_pci_function_reset - Reset pci function.
9074 * @phba: pointer to lpfc hba data structure.
9075 *
9076 * This routine is invoked to request a PCI function reset. It will destroys
9077 * all resources assigned to the PCI function which originates this request.
9078 *
9079 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009080 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009081 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04009082 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04009083 **/
9084int
9085lpfc_pci_function_reset(struct lpfc_hba *phba)
9086{
9087 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05009088 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04009089 uint32_t shdr_status, shdr_add_status;
James Smart2f6fa2c2014-09-03 12:57:08 -04009090 uint32_t rdy_chk;
9091 uint32_t port_reset = 0;
James Smartda0436e2009-05-22 14:51:39 -04009092 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05009093 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -05009094 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -04009095
James Smart2fcee4b2010-12-15 17:57:46 -05009096 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9097 switch (if_type) {
9098 case LPFC_SLI_INTF_IF_TYPE_0:
9099 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
9100 GFP_KERNEL);
9101 if (!mboxq) {
9102 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9103 "0494 Unable to allocate memory for "
9104 "issuing SLI_FUNCTION_RESET mailbox "
9105 "command\n");
9106 return -ENOMEM;
9107 }
9108
9109 /* Setup PCI function reset mailbox-ioctl command */
9110 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9111 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
9112 LPFC_SLI4_MBX_EMBED);
9113 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9114 shdr = (union lpfc_sli4_cfg_shdr *)
9115 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
9116 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9117 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
9118 &shdr->response);
9119 if (rc != MBX_TIMEOUT)
9120 mempool_free(mboxq, phba->mbox_mem_pool);
9121 if (shdr_status || shdr_add_status || rc) {
9122 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9123 "0495 SLI_FUNCTION_RESET mailbox "
9124 "failed with status x%x add_status x%x,"
9125 " mbx status x%x\n",
9126 shdr_status, shdr_add_status, rc);
9127 rc = -ENXIO;
9128 }
9129 break;
9130 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2f6fa2c2014-09-03 12:57:08 -04009131wait:
9132 /*
9133 * Poll the Port Status Register and wait for RDY for
9134 * up to 30 seconds. If the port doesn't respond, treat
9135 * it as an error.
9136 */
James Smart77d093f2015-04-07 15:07:08 -04009137 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
James Smart2f6fa2c2014-09-03 12:57:08 -04009138 if (lpfc_readl(phba->sli4_hba.u.if_type2.
9139 STATUSregaddr, &reg_data.word0)) {
9140 rc = -ENODEV;
9141 goto out;
9142 }
9143 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
9144 break;
9145 msleep(20);
9146 }
9147
9148 if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
9149 phba->work_status[0] = readl(
9150 phba->sli4_hba.u.if_type2.ERR1regaddr);
9151 phba->work_status[1] = readl(
9152 phba->sli4_hba.u.if_type2.ERR2regaddr);
9153 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9154 "2890 Port not ready, port status reg "
9155 "0x%x error 1=0x%x, error 2=0x%x\n",
9156 reg_data.word0,
9157 phba->work_status[0],
9158 phba->work_status[1]);
9159 rc = -ENODEV;
9160 goto out;
9161 }
9162
9163 if (!port_reset) {
9164 /*
9165 * Reset the port now
9166 */
James Smart2fcee4b2010-12-15 17:57:46 -05009167 reg_data.word0 = 0;
9168 bf_set(lpfc_sliport_ctrl_end, &reg_data,
9169 LPFC_SLIPORT_LITTLE_ENDIAN);
9170 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
9171 LPFC_SLIPORT_INIT_PORT);
9172 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
9173 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -05009174 /* flush */
James Smart2b81f942012-03-01 22:37:18 -05009175 pci_read_config_word(phba->pcidev,
9176 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -05009177
James Smart2f6fa2c2014-09-03 12:57:08 -04009178 port_reset = 1;
9179 msleep(20);
9180 goto wait;
9181 } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
9182 rc = -ENODEV;
9183 goto out;
James Smart2fcee4b2010-12-15 17:57:46 -05009184 }
9185 break;
James Smart2f6fa2c2014-09-03 12:57:08 -04009186
James Smart2fcee4b2010-12-15 17:57:46 -05009187 case LPFC_SLI_INTF_IF_TYPE_1:
9188 default:
9189 break;
James Smartda0436e2009-05-22 14:51:39 -04009190 }
9191
James Smart73d91e52011-10-10 21:32:10 -04009192out:
James Smart2fcee4b2010-12-15 17:57:46 -05009193 /* Catch the not-ready port failure after a port reset. */
James Smart2f6fa2c2014-09-03 12:57:08 -04009194 if (rc) {
James Smart229adb02013-04-17 20:16:51 -04009195 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9196 "3317 HBA not functional: IP Reset Failed "
James Smart2f6fa2c2014-09-03 12:57:08 -04009197 "try: echo fw_reset > board_mode\n");
James Smart2fcee4b2010-12-15 17:57:46 -05009198 rc = -ENODEV;
James Smart229adb02013-04-17 20:16:51 -04009199 }
James Smart2fcee4b2010-12-15 17:57:46 -05009200
James Smartda0436e2009-05-22 14:51:39 -04009201 return rc;
9202}
9203
9204/**
James Smartda0436e2009-05-22 14:51:39 -04009205 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
9206 * @phba: pointer to lpfc hba data structure.
9207 *
9208 * This routine is invoked to set up the PCI device memory space for device
9209 * with SLI-4 interface spec.
9210 *
9211 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009212 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009213 * other values - error
9214 **/
9215static int
9216lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
9217{
9218 struct pci_dev *pdev;
9219 unsigned long bar0map_len, bar1map_len, bar2map_len;
9220 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05009221 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04009222
9223 /* Obtain PCI device reference */
9224 if (!phba->pcidev)
9225 return error;
9226 else
9227 pdev = phba->pcidev;
9228
9229 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05009230 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
9231 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
9232 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
9233 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smartda0436e2009-05-22 14:51:39 -04009234 return error;
Michael Reed8e685972009-09-18 12:02:05 -05009235 }
9236 }
James Smartda0436e2009-05-22 14:51:39 -04009237
James Smart2fcee4b2010-12-15 17:57:46 -05009238 /*
9239 * The BARs and register set definitions and offset locations are
9240 * dependent on the if_type.
9241 */
9242 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
9243 &phba->sli4_hba.sli_intf.word0)) {
9244 return error;
9245 }
9246
9247 /* There is no SLI3 failback for SLI4 devices. */
9248 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
9249 LPFC_SLI_INTF_VALID) {
9250 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9251 "2894 SLI_INTF reg contents invalid "
9252 "sli_intf reg 0x%x\n",
9253 phba->sli4_hba.sli_intf.word0);
9254 return error;
9255 }
9256
9257 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9258 /*
9259 * Get the bus address of SLI4 device Bar regions and the
9260 * number of bytes required by each mapping. The mapping of the
9261 * particular PCI BARs regions is dependent on the type of
9262 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04009263 */
James Smartf5ca6f22013-09-06 12:21:09 -04009264 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
9265 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
9266 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
James Smart2fcee4b2010-12-15 17:57:46 -05009267
9268 /*
9269 * Map SLI4 PCI Config Space Register base to a kernel virtual
9270 * addr
9271 */
9272 phba->sli4_hba.conf_regs_memmap_p =
9273 ioremap(phba->pci_bar0_map, bar0map_len);
9274 if (!phba->sli4_hba.conf_regs_memmap_p) {
9275 dev_printk(KERN_ERR, &pdev->dev,
9276 "ioremap failed for SLI4 PCI config "
9277 "registers.\n");
9278 goto out;
9279 }
James Smartf5ca6f22013-09-06 12:21:09 -04009280 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05009281 /* Set up BAR0 PCI config space register memory map */
9282 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05009283 } else {
9284 phba->pci_bar0_map = pci_resource_start(pdev, 1);
9285 bar0map_len = pci_resource_len(pdev, 1);
James Smart2fcee4b2010-12-15 17:57:46 -05009286 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
9287 dev_printk(KERN_ERR, &pdev->dev,
9288 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
9289 goto out;
9290 }
9291 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04009292 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05009293 if (!phba->sli4_hba.conf_regs_memmap_p) {
9294 dev_printk(KERN_ERR, &pdev->dev,
9295 "ioremap failed for SLI4 PCI config "
9296 "registers.\n");
9297 goto out;
9298 }
9299 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04009300 }
9301
James Smartc31098c2011-04-16 11:03:33 -04009302 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04009303 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
James Smart2fcee4b2010-12-15 17:57:46 -05009304 /*
9305 * Map SLI4 if type 0 HBA Control Register base to a kernel
9306 * virtual address and setup the registers.
9307 */
James Smartf5ca6f22013-09-06 12:21:09 -04009308 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
9309 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
James Smart2fcee4b2010-12-15 17:57:46 -05009310 phba->sli4_hba.ctrl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04009311 ioremap(phba->pci_bar1_map, bar1map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05009312 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
9313 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04009314 "ioremap failed for SLI4 HBA control registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05009315 goto out_iounmap_conf;
9316 }
James Smartf5ca6f22013-09-06 12:21:09 -04009317 phba->pci_bar2_memmap_p = phba->sli4_hba.ctrl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05009318 lpfc_sli4_bar1_register_memmap(phba);
James Smartda0436e2009-05-22 14:51:39 -04009319 }
9320
James Smartc31098c2011-04-16 11:03:33 -04009321 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04009322 (pci_resource_start(pdev, PCI_64BIT_BAR4))) {
James Smart2fcee4b2010-12-15 17:57:46 -05009323 /*
9324 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
9325 * virtual address and setup the registers.
9326 */
James Smartf5ca6f22013-09-06 12:21:09 -04009327 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
9328 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
James Smart2fcee4b2010-12-15 17:57:46 -05009329 phba->sli4_hba.drbl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04009330 ioremap(phba->pci_bar2_map, bar2map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05009331 if (!phba->sli4_hba.drbl_regs_memmap_p) {
9332 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04009333 "ioremap failed for SLI4 HBA doorbell registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05009334 goto out_iounmap_ctrl;
9335 }
James Smartf5ca6f22013-09-06 12:21:09 -04009336 phba->pci_bar4_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05009337 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
9338 if (error)
9339 goto out_iounmap_all;
James Smartda0436e2009-05-22 14:51:39 -04009340 }
9341
James Smartda0436e2009-05-22 14:51:39 -04009342 return 0;
9343
9344out_iounmap_all:
9345 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9346out_iounmap_ctrl:
9347 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9348out_iounmap_conf:
9349 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9350out:
9351 return error;
9352}
9353
9354/**
9355 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
9356 * @phba: pointer to lpfc hba data structure.
9357 *
9358 * This routine is invoked to unset the PCI device memory space for device
9359 * with SLI-4 interface spec.
9360 **/
9361static void
9362lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
9363{
James Smart2e90f4b2011-12-13 13:22:37 -05009364 uint32_t if_type;
9365 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -04009366
James Smart2e90f4b2011-12-13 13:22:37 -05009367 switch (if_type) {
9368 case LPFC_SLI_INTF_IF_TYPE_0:
9369 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9370 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9371 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9372 break;
9373 case LPFC_SLI_INTF_IF_TYPE_2:
9374 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9375 break;
9376 case LPFC_SLI_INTF_IF_TYPE_1:
9377 default:
9378 dev_printk(KERN_ERR, &phba->pcidev->dev,
9379 "FATAL - unsupported SLI4 interface type - %d\n",
9380 if_type);
9381 break;
9382 }
James Smartda0436e2009-05-22 14:51:39 -04009383}
9384
9385/**
James Smart3772a992009-05-22 14:50:54 -04009386 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
9387 * @phba: pointer to lpfc hba data structure.
9388 *
9389 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009390 * with SLI-3 interface specs.
James Smart3772a992009-05-22 14:50:54 -04009391 *
9392 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009393 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009394 * other values - error
9395 **/
9396static int
9397lpfc_sli_enable_msix(struct lpfc_hba *phba)
9398{
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009399 int rc;
James Smart3772a992009-05-22 14:50:54 -04009400 LPFC_MBOXQ_t *pmb;
9401
9402 /* Set up MSI-X multi-message vectors */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009403 rc = pci_alloc_irq_vectors(phba->pcidev,
9404 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
9405 if (rc < 0) {
James Smart3772a992009-05-22 14:50:54 -04009406 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9407 "0420 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009408 goto vec_fail_out;
James Smart3772a992009-05-22 14:50:54 -04009409 }
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009410
James Smart3772a992009-05-22 14:50:54 -04009411 /*
9412 * Assign MSI-X vectors to interrupt handlers
9413 */
9414
9415 /* vector-0 is associated to slow-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009416 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
James Smarted243d32015-05-21 13:55:25 -04009417 &lpfc_sli_sp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04009418 LPFC_SP_DRIVER_HANDLER_NAME, phba);
9419 if (rc) {
9420 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9421 "0421 MSI-X slow-path request_irq failed "
9422 "(%d)\n", rc);
9423 goto msi_fail_out;
9424 }
9425
9426 /* vector-1 is associated to fast-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009427 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
James Smarted243d32015-05-21 13:55:25 -04009428 &lpfc_sli_fp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04009429 LPFC_FP_DRIVER_HANDLER_NAME, phba);
9430
9431 if (rc) {
9432 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9433 "0429 MSI-X fast-path request_irq failed "
9434 "(%d)\n", rc);
9435 goto irq_fail_out;
9436 }
9437
9438 /*
9439 * Configure HBA MSI-X attention conditions to messages
9440 */
9441 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9442
9443 if (!pmb) {
9444 rc = -ENOMEM;
9445 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9446 "0474 Unable to allocate memory for issuing "
9447 "MBOX_CONFIG_MSI command\n");
9448 goto mem_fail_out;
9449 }
9450 rc = lpfc_config_msi(phba, pmb);
9451 if (rc)
9452 goto mbx_fail_out;
9453 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
9454 if (rc != MBX_SUCCESS) {
9455 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
9456 "0351 Config MSI mailbox command failed, "
9457 "mbxCmd x%x, mbxStatus x%x\n",
9458 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
9459 goto mbx_fail_out;
9460 }
9461
9462 /* Free memory allocated for mailbox command */
9463 mempool_free(pmb, phba->mbox_mem_pool);
9464 return rc;
9465
9466mbx_fail_out:
9467 /* Free memory allocated for mailbox command */
9468 mempool_free(pmb, phba->mbox_mem_pool);
9469
9470mem_fail_out:
9471 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009472 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
James Smart3772a992009-05-22 14:50:54 -04009473
9474irq_fail_out:
9475 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009476 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
James Smart3772a992009-05-22 14:50:54 -04009477
9478msi_fail_out:
9479 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009480 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009481
9482vec_fail_out:
James Smart3772a992009-05-22 14:50:54 -04009483 return rc;
9484}
9485
9486/**
James Smart3772a992009-05-22 14:50:54 -04009487 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
9488 * @phba: pointer to lpfc hba data structure.
9489 *
9490 * This routine is invoked to enable the MSI interrupt mode to device with
9491 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
9492 * enable the MSI vector. The device driver is responsible for calling the
9493 * request_irq() to register MSI vector with a interrupt the handler, which
9494 * is done in this function.
9495 *
9496 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009497 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009498 * other values - error
9499 */
9500static int
9501lpfc_sli_enable_msi(struct lpfc_hba *phba)
9502{
9503 int rc;
9504
9505 rc = pci_enable_msi(phba->pcidev);
9506 if (!rc)
9507 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9508 "0462 PCI enable MSI mode success.\n");
9509 else {
9510 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9511 "0471 PCI enable MSI mode failed (%d)\n", rc);
9512 return rc;
9513 }
9514
9515 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04009516 0, LPFC_DRIVER_NAME, phba);
James Smart3772a992009-05-22 14:50:54 -04009517 if (rc) {
9518 pci_disable_msi(phba->pcidev);
9519 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9520 "0478 MSI request_irq failed (%d)\n", rc);
9521 }
9522 return rc;
9523}
9524
9525/**
James Smart3772a992009-05-22 14:50:54 -04009526 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
9527 * @phba: pointer to lpfc hba data structure.
9528 *
9529 * This routine is invoked to enable device interrupt and associate driver's
9530 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
9531 * spec. Depends on the interrupt mode configured to the driver, the driver
9532 * will try to fallback from the configured interrupt mode to an interrupt
9533 * mode which is supported by the platform, kernel, and device in the order
9534 * of:
9535 * MSI-X -> MSI -> IRQ.
9536 *
9537 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009538 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009539 * other values - error
9540 **/
9541static uint32_t
9542lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9543{
9544 uint32_t intr_mode = LPFC_INTR_ERROR;
9545 int retval;
9546
9547 if (cfg_mode == 2) {
9548 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
9549 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
9550 if (!retval) {
9551 /* Now, try to enable MSI-X interrupt mode */
9552 retval = lpfc_sli_enable_msix(phba);
9553 if (!retval) {
9554 /* Indicate initialization to MSI-X mode */
9555 phba->intr_type = MSIX;
9556 intr_mode = 2;
9557 }
9558 }
9559 }
9560
9561 /* Fallback to MSI if MSI-X initialization failed */
9562 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9563 retval = lpfc_sli_enable_msi(phba);
9564 if (!retval) {
9565 /* Indicate initialization to MSI mode */
9566 phba->intr_type = MSI;
9567 intr_mode = 1;
9568 }
9569 }
9570
9571 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9572 if (phba->intr_type == NONE) {
9573 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
9574 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9575 if (!retval) {
9576 /* Indicate initialization to INTx mode */
9577 phba->intr_type = INTx;
9578 intr_mode = 0;
9579 }
9580 }
9581 return intr_mode;
9582}
9583
9584/**
9585 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
9586 * @phba: pointer to lpfc hba data structure.
9587 *
9588 * This routine is invoked to disable device interrupt and disassociate the
9589 * driver's interrupt handler(s) from interrupt vector(s) to device with
9590 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
9591 * release the interrupt vector(s) for the message signaled interrupt.
9592 **/
9593static void
9594lpfc_sli_disable_intr(struct lpfc_hba *phba)
9595{
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009596 int nr_irqs, i;
9597
James Smart3772a992009-05-22 14:50:54 -04009598 if (phba->intr_type == MSIX)
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009599 nr_irqs = LPFC_MSIX_VECTORS;
9600 else
9601 nr_irqs = 1;
9602
9603 for (i = 0; i < nr_irqs; i++)
9604 free_irq(pci_irq_vector(phba->pcidev, i), phba);
9605 pci_free_irq_vectors(phba->pcidev);
James Smart3772a992009-05-22 14:50:54 -04009606
9607 /* Reset interrupt management states */
9608 phba->intr_type = NONE;
9609 phba->sli.slistat.sli_intr = 0;
James Smart3772a992009-05-22 14:50:54 -04009610}
9611
9612/**
James Smart895427b2017-02-12 13:52:30 -08009613 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
James Smart7bb03bb2013-04-17 20:19:16 -04009614 * @phba: pointer to lpfc hba data structure.
James Smart895427b2017-02-12 13:52:30 -08009615 * @vectors: number of msix vectors allocated.
James Smart7bb03bb2013-04-17 20:19:16 -04009616 *
James Smart895427b2017-02-12 13:52:30 -08009617 * The routine will figure out the CPU affinity assignment for every
9618 * MSI-X vector allocated for the HBA. The hba_eq_hdl will be updated
9619 * with a pointer to the CPU mask that defines ALL the CPUs this vector
9620 * can be associated with. If the vector can be unquely associated with
9621 * a single CPU, that CPU will be recorded in hba_eq_hdl[index].cpu.
9622 * In addition, the CPU to IO channel mapping will be calculated
9623 * and the phba->sli4_hba.cpu_map array will reflect this.
James Smart7bb03bb2013-04-17 20:19:16 -04009624 */
James Smart895427b2017-02-12 13:52:30 -08009625static void
9626lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
James Smart7bb03bb2013-04-17 20:19:16 -04009627{
9628 struct lpfc_vector_map_info *cpup;
James Smart895427b2017-02-12 13:52:30 -08009629 int index = 0;
9630 int vec = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04009631 int cpu;
James Smart7bb03bb2013-04-17 20:19:16 -04009632#ifdef CONFIG_X86
9633 struct cpuinfo_x86 *cpuinfo;
9634#endif
James Smart7bb03bb2013-04-17 20:19:16 -04009635
9636 /* Init cpu_map array */
9637 memset(phba->sli4_hba.cpu_map, 0xff,
9638 (sizeof(struct lpfc_vector_map_info) *
James Smart895427b2017-02-12 13:52:30 -08009639 phba->sli4_hba.num_present_cpu));
James Smart7bb03bb2013-04-17 20:19:16 -04009640
9641 /* Update CPU map with physical id and core id of each CPU */
9642 cpup = phba->sli4_hba.cpu_map;
9643 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
9644#ifdef CONFIG_X86
9645 cpuinfo = &cpu_data(cpu);
9646 cpup->phys_id = cpuinfo->phys_proc_id;
9647 cpup->core_id = cpuinfo->cpu_core_id;
9648#else
9649 /* No distinction between CPUs for other platforms */
9650 cpup->phys_id = 0;
9651 cpup->core_id = 0;
9652#endif
James Smart895427b2017-02-12 13:52:30 -08009653 cpup->channel_id = index; /* For now round robin */
9654 cpup->irq = pci_irq_vector(phba->pcidev, vec);
9655 vec++;
9656 if (vec >= vectors)
9657 vec = 0;
9658 index++;
9659 if (index >= phba->cfg_fcp_io_channel)
9660 index = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04009661 cpup++;
9662 }
James Smart7bb03bb2013-04-17 20:19:16 -04009663}
9664
9665
9666/**
James Smartda0436e2009-05-22 14:51:39 -04009667 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
9668 * @phba: pointer to lpfc hba data structure.
9669 *
9670 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009671 * with SLI-4 interface spec.
James Smartda0436e2009-05-22 14:51:39 -04009672 *
9673 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009674 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009675 * other values - error
9676 **/
9677static int
9678lpfc_sli4_enable_msix(struct lpfc_hba *phba)
9679{
James Smart75baf692010-06-08 18:31:21 -04009680 int vectors, rc, index;
James Smartda0436e2009-05-22 14:51:39 -04009681
9682 /* Set up MSI-X multi-message vectors */
James Smart895427b2017-02-12 13:52:30 -08009683 vectors = phba->io_channel_irqs;
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009684 if (phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05009685 vectors++;
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009686
James Smartf358dd02017-02-12 13:52:34 -08009687 rc = pci_alloc_irq_vectors(phba->pcidev,
9688 (phba->nvmet_support) ? 1 : 2,
9689 vectors, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY);
Alexander Gordeev4f871e12014-09-03 12:56:29 -04009690 if (rc < 0) {
James Smartda0436e2009-05-22 14:51:39 -04009691 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9692 "0484 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009693 goto vec_fail_out;
James Smartda0436e2009-05-22 14:51:39 -04009694 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -04009695 vectors = rc;
James Smart75baf692010-06-08 18:31:21 -04009696
James Smart7bb03bb2013-04-17 20:19:16 -04009697 /* Assign MSI-X vectors to interrupt handlers */
James Smart67d12732012-08-03 12:36:13 -04009698 for (index = 0; index < vectors; index++) {
James Smart4305f182012-08-03 12:36:33 -04009699 memset(&phba->sli4_hba.handler_name[index], 0, 16);
James Smarta2fc4aef2014-09-03 12:57:55 -04009700 snprintf((char *)&phba->sli4_hba.handler_name[index],
9701 LPFC_SLI4_HANDLER_NAME_SZ,
James Smart4305f182012-08-03 12:36:33 -04009702 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -04009703
James Smart895427b2017-02-12 13:52:30 -08009704 phba->sli4_hba.hba_eq_hdl[index].idx = index;
9705 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
9706 atomic_set(&phba->sli4_hba.hba_eq_hdl[index].hba_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -05009707 if (phba->cfg_fof && (index == (vectors - 1)))
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009708 rc = request_irq(pci_irq_vector(phba->pcidev, index),
James Smarted243d32015-05-21 13:55:25 -04009709 &lpfc_sli4_fof_intr_handler, 0,
James Smart1ba981f2014-02-20 09:56:45 -05009710 (char *)&phba->sli4_hba.handler_name[index],
James Smart895427b2017-02-12 13:52:30 -08009711 &phba->sli4_hba.hba_eq_hdl[index]);
James Smart1ba981f2014-02-20 09:56:45 -05009712 else
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009713 rc = request_irq(pci_irq_vector(phba->pcidev, index),
James Smarted243d32015-05-21 13:55:25 -04009714 &lpfc_sli4_hba_intr_handler, 0,
James Smart4305f182012-08-03 12:36:33 -04009715 (char *)&phba->sli4_hba.handler_name[index],
James Smart895427b2017-02-12 13:52:30 -08009716 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -04009717 if (rc) {
9718 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9719 "0486 MSI-X fast-path (%d) "
9720 "request_irq failed (%d)\n", index, rc);
9721 goto cfg_fail_out;
9722 }
9723 }
9724
James Smart1ba981f2014-02-20 09:56:45 -05009725 if (phba->cfg_fof)
9726 vectors--;
9727
James Smart895427b2017-02-12 13:52:30 -08009728 if (vectors != phba->io_channel_irqs) {
James Smart82c3e9b2012-09-29 11:29:50 -04009729 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9730 "3238 Reducing IO channels to match number of "
9731 "MSI-X vectors, requested %d got %d\n",
James Smart895427b2017-02-12 13:52:30 -08009732 phba->io_channel_irqs, vectors);
9733 if (phba->cfg_fcp_io_channel > vectors)
9734 phba->cfg_fcp_io_channel = vectors;
9735 if (phba->cfg_nvme_io_channel > vectors)
9736 phba->cfg_nvme_io_channel = vectors;
9737 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
9738 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
9739 else
9740 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
James Smart82c3e9b2012-09-29 11:29:50 -04009741 }
James Smart895427b2017-02-12 13:52:30 -08009742 lpfc_cpu_affinity_check(phba, vectors);
James Smart7bb03bb2013-04-17 20:19:16 -04009743
James Smartda0436e2009-05-22 14:51:39 -04009744 return rc;
9745
9746cfg_fail_out:
9747 /* free the irq already requested */
James Smart895427b2017-02-12 13:52:30 -08009748 for (--index; index >= 0; index--)
9749 free_irq(pci_irq_vector(phba->pcidev, index),
9750 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -04009751
James Smartda0436e2009-05-22 14:51:39 -04009752 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009753 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009754
9755vec_fail_out:
James Smartda0436e2009-05-22 14:51:39 -04009756 return rc;
9757}
9758
9759/**
James Smartda0436e2009-05-22 14:51:39 -04009760 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
9761 * @phba: pointer to lpfc hba data structure.
9762 *
9763 * This routine is invoked to enable the MSI interrupt mode to device with
9764 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
9765 * to enable the MSI vector. The device driver is responsible for calling
9766 * the request_irq() to register MSI vector with a interrupt the handler,
9767 * which is done in this function.
9768 *
9769 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009770 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009771 * other values - error
9772 **/
9773static int
9774lpfc_sli4_enable_msi(struct lpfc_hba *phba)
9775{
9776 int rc, index;
9777
9778 rc = pci_enable_msi(phba->pcidev);
9779 if (!rc)
9780 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9781 "0487 PCI enable MSI mode success.\n");
9782 else {
9783 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9784 "0488 PCI enable MSI mode failed (%d)\n", rc);
9785 return rc;
9786 }
9787
9788 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04009789 0, LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -04009790 if (rc) {
9791 pci_disable_msi(phba->pcidev);
9792 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9793 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -04009794 return rc;
James Smartda0436e2009-05-22 14:51:39 -04009795 }
9796
James Smart895427b2017-02-12 13:52:30 -08009797 for (index = 0; index < phba->io_channel_irqs; index++) {
9798 phba->sli4_hba.hba_eq_hdl[index].idx = index;
9799 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smartda0436e2009-05-22 14:51:39 -04009800 }
9801
James Smart1ba981f2014-02-20 09:56:45 -05009802 if (phba->cfg_fof) {
James Smart895427b2017-02-12 13:52:30 -08009803 phba->sli4_hba.hba_eq_hdl[index].idx = index;
9804 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smart1ba981f2014-02-20 09:56:45 -05009805 }
James Smart75baf692010-06-08 18:31:21 -04009806 return 0;
James Smartda0436e2009-05-22 14:51:39 -04009807}
9808
9809/**
James Smartda0436e2009-05-22 14:51:39 -04009810 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
9811 * @phba: pointer to lpfc hba data structure.
9812 *
9813 * This routine is invoked to enable device interrupt and associate driver's
9814 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
9815 * interface spec. Depends on the interrupt mode configured to the driver,
9816 * the driver will try to fallback from the configured interrupt mode to an
9817 * interrupt mode which is supported by the platform, kernel, and device in
9818 * the order of:
9819 * MSI-X -> MSI -> IRQ.
9820 *
9821 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009822 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009823 * other values - error
9824 **/
9825static uint32_t
9826lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9827{
9828 uint32_t intr_mode = LPFC_INTR_ERROR;
James Smart895427b2017-02-12 13:52:30 -08009829 int retval, idx;
James Smartda0436e2009-05-22 14:51:39 -04009830
9831 if (cfg_mode == 2) {
9832 /* Preparation before conf_msi mbox cmd */
9833 retval = 0;
9834 if (!retval) {
9835 /* Now, try to enable MSI-X interrupt mode */
9836 retval = lpfc_sli4_enable_msix(phba);
9837 if (!retval) {
9838 /* Indicate initialization to MSI-X mode */
9839 phba->intr_type = MSIX;
9840 intr_mode = 2;
9841 }
9842 }
9843 }
9844
9845 /* Fallback to MSI if MSI-X initialization failed */
9846 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9847 retval = lpfc_sli4_enable_msi(phba);
9848 if (!retval) {
9849 /* Indicate initialization to MSI mode */
9850 phba->intr_type = MSI;
9851 intr_mode = 1;
9852 }
9853 }
9854
9855 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9856 if (phba->intr_type == NONE) {
9857 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
9858 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9859 if (!retval) {
James Smart895427b2017-02-12 13:52:30 -08009860 struct lpfc_hba_eq_hdl *eqhdl;
9861
James Smartda0436e2009-05-22 14:51:39 -04009862 /* Indicate initialization to INTx mode */
9863 phba->intr_type = INTx;
9864 intr_mode = 0;
James Smart895427b2017-02-12 13:52:30 -08009865
9866 for (idx = 0; idx < phba->io_channel_irqs; idx++) {
9867 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
9868 eqhdl->idx = idx;
9869 eqhdl->phba = phba;
9870 atomic_set(&eqhdl->hba_eq_in_use, 1);
James Smartda0436e2009-05-22 14:51:39 -04009871 }
James Smart1ba981f2014-02-20 09:56:45 -05009872 if (phba->cfg_fof) {
James Smart895427b2017-02-12 13:52:30 -08009873 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
9874 eqhdl->idx = idx;
9875 eqhdl->phba = phba;
9876 atomic_set(&eqhdl->hba_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -05009877 }
James Smartda0436e2009-05-22 14:51:39 -04009878 }
9879 }
9880 return intr_mode;
9881}
9882
9883/**
9884 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
9885 * @phba: pointer to lpfc hba data structure.
9886 *
9887 * This routine is invoked to disable device interrupt and disassociate
9888 * the driver's interrupt handler(s) from interrupt vector(s) to device
9889 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
9890 * will release the interrupt vector(s) for the message signaled interrupt.
9891 **/
9892static void
9893lpfc_sli4_disable_intr(struct lpfc_hba *phba)
9894{
9895 /* Disable the currently initialized interrupt mode */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009896 if (phba->intr_type == MSIX) {
9897 int index;
9898
9899 /* Free up MSI-X multi-message vectors */
James Smart895427b2017-02-12 13:52:30 -08009900 for (index = 0; index < phba->io_channel_irqs; index++)
9901 free_irq(pci_irq_vector(phba->pcidev, index),
9902 &phba->sli4_hba.hba_eq_hdl[index]);
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009903
9904 if (phba->cfg_fof)
James Smart895427b2017-02-12 13:52:30 -08009905 free_irq(pci_irq_vector(phba->pcidev, index),
9906 &phba->sli4_hba.hba_eq_hdl[index]);
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009907 } else {
James Smartda0436e2009-05-22 14:51:39 -04009908 free_irq(phba->pcidev->irq, phba);
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009909 }
9910
9911 pci_free_irq_vectors(phba->pcidev);
James Smartda0436e2009-05-22 14:51:39 -04009912
9913 /* Reset interrupt management states */
9914 phba->intr_type = NONE;
9915 phba->sli.slistat.sli_intr = 0;
James Smartda0436e2009-05-22 14:51:39 -04009916}
9917
9918/**
James Smart3772a992009-05-22 14:50:54 -04009919 * lpfc_unset_hba - Unset SLI3 hba device initialization
9920 * @phba: pointer to lpfc hba data structure.
9921 *
9922 * This routine is invoked to unset the HBA device initialization steps to
9923 * a device with SLI-3 interface spec.
9924 **/
9925static void
9926lpfc_unset_hba(struct lpfc_hba *phba)
9927{
9928 struct lpfc_vport *vport = phba->pport;
9929 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9930
9931 spin_lock_irq(shost->host_lock);
9932 vport->load_flag |= FC_UNLOADING;
9933 spin_unlock_irq(shost->host_lock);
9934
James Smart72859902012-01-18 16:25:38 -05009935 kfree(phba->vpi_bmask);
9936 kfree(phba->vpi_ids);
9937
James Smart3772a992009-05-22 14:50:54 -04009938 lpfc_stop_hba_timers(phba);
9939
9940 phba->pport->work_port_events = 0;
9941
9942 lpfc_sli_hba_down(phba);
9943
9944 lpfc_sli_brdrestart(phba);
9945
9946 lpfc_sli_disable_intr(phba);
9947
9948 return;
9949}
9950
9951/**
James Smart5af5eee2010-10-22 11:06:38 -04009952 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
9953 * @phba: Pointer to HBA context object.
9954 *
9955 * This function is called in the SLI4 code path to wait for completion
9956 * of device's XRIs exchange busy. It will check the XRI exchange busy
9957 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
9958 * that, it will check the XRI exchange busy on outstanding FCP and ELS
9959 * I/Os every 30 seconds, log error message, and wait forever. Only when
9960 * all XRI exchange busy complete, the driver unload shall proceed with
9961 * invoking the function reset ioctl mailbox command to the CNA and the
9962 * the rest of the driver unload resource release.
9963 **/
9964static void
9965lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
9966{
9967 int wait_time = 0;
James Smart895427b2017-02-12 13:52:30 -08009968 int nvme_xri_cmpl = 1;
9969 int fcp_xri_cmpl = 1;
James Smart5af5eee2010-10-22 11:06:38 -04009970 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -08009971 int nvmet_xri_cmpl =
9972 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_sgl_list);
James Smart5af5eee2010-10-22 11:06:38 -04009973
James Smart895427b2017-02-12 13:52:30 -08009974 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
9975 fcp_xri_cmpl =
9976 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
9977 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
9978 nvme_xri_cmpl =
9979 list_empty(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
9980
James Smartf358dd02017-02-12 13:52:34 -08009981 while (!fcp_xri_cmpl || !els_xri_cmpl || !nvme_xri_cmpl ||
9982 !nvmet_xri_cmpl) {
James Smart5af5eee2010-10-22 11:06:38 -04009983 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
James Smart895427b2017-02-12 13:52:30 -08009984 if (!nvme_xri_cmpl)
9985 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9986 "6100 NVME XRI exchange busy "
9987 "wait time: %d seconds.\n",
9988 wait_time/1000);
James Smart5af5eee2010-10-22 11:06:38 -04009989 if (!fcp_xri_cmpl)
9990 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9991 "2877 FCP XRI exchange busy "
9992 "wait time: %d seconds.\n",
9993 wait_time/1000);
9994 if (!els_xri_cmpl)
9995 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9996 "2878 ELS XRI exchange busy "
9997 "wait time: %d seconds.\n",
9998 wait_time/1000);
9999 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
10000 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
10001 } else {
10002 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
10003 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
10004 }
James Smart895427b2017-02-12 13:52:30 -080010005 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
10006 nvme_xri_cmpl = list_empty(
10007 &phba->sli4_hba.lpfc_abts_nvme_buf_list);
10008
10009 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
10010 fcp_xri_cmpl = list_empty(
10011 &phba->sli4_hba.lpfc_abts_scsi_buf_list);
10012
James Smart5af5eee2010-10-22 11:06:38 -040010013 els_xri_cmpl =
10014 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -080010015
10016 nvmet_xri_cmpl =
10017 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_sgl_list);
James Smart5af5eee2010-10-22 11:06:38 -040010018 }
10019}
10020
10021/**
James Smartda0436e2009-05-22 14:51:39 -040010022 * lpfc_sli4_hba_unset - Unset the fcoe hba
10023 * @phba: Pointer to HBA context object.
10024 *
10025 * This function is called in the SLI4 code path to reset the HBA's FCoE
10026 * function. The caller is not required to hold any lock. This routine
10027 * issues PCI function reset mailbox command to reset the FCoE function.
10028 * At the end of the function, it calls lpfc_hba_down_post function to
10029 * free any pending commands.
10030 **/
10031static void
10032lpfc_sli4_hba_unset(struct lpfc_hba *phba)
10033{
10034 int wait_cnt = 0;
10035 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -040010036 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -040010037
10038 lpfc_stop_hba_timers(phba);
10039 phba->sli4_hba.intr_enable = 0;
10040
10041 /*
10042 * Gracefully wait out the potential current outstanding asynchronous
10043 * mailbox command.
10044 */
10045
10046 /* First, block any pending async mailbox command from posted */
10047 spin_lock_irq(&phba->hbalock);
10048 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
10049 spin_unlock_irq(&phba->hbalock);
10050 /* Now, trying to wait it out if we can */
10051 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
10052 msleep(10);
10053 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
10054 break;
10055 }
10056 /* Forcefully release the outstanding mailbox command if timed out */
10057 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
10058 spin_lock_irq(&phba->hbalock);
10059 mboxq = phba->sli.mbox_active;
10060 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
10061 __lpfc_mbox_cmpl_put(phba, mboxq);
10062 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
10063 phba->sli.mbox_active = NULL;
10064 spin_unlock_irq(&phba->hbalock);
10065 }
10066
James Smart5af5eee2010-10-22 11:06:38 -040010067 /* Abort all iocbs associated with the hba */
10068 lpfc_sli_hba_iocb_abort(phba);
10069
10070 /* Wait for completion of device XRI exchange busy */
10071 lpfc_sli4_xri_exchange_busy_wait(phba);
10072
James Smartda0436e2009-05-22 14:51:39 -040010073 /* Disable PCI subsystem interrupt */
10074 lpfc_sli4_disable_intr(phba);
10075
James Smart912e3ac2011-05-24 11:42:11 -040010076 /* Disable SR-IOV if enabled */
10077 if (phba->cfg_sriov_nr_virtfn)
10078 pci_disable_sriov(pdev);
10079
James Smartda0436e2009-05-22 14:51:39 -040010080 /* Stop kthread signal shall trigger work_done one more time */
10081 kthread_stop(phba->worker_thread);
10082
James Smartd1f525a2017-04-21 16:04:55 -070010083 /* Unset the queues shared with the hardware then release all
10084 * allocated resources.
10085 */
10086 lpfc_sli4_queue_unset(phba);
10087 lpfc_sli4_queue_destroy(phba);
10088
James Smart3677a3a2010-09-29 11:19:14 -040010089 /* Reset SLI4 HBA FCoE function */
10090 lpfc_pci_function_reset(phba);
10091
James Smartda0436e2009-05-22 14:51:39 -040010092 /* Stop the SLI4 device port */
10093 phba->pport->work_port_events = 0;
10094}
10095
James Smart28baac72010-02-12 14:42:03 -050010096 /**
10097 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
10098 * @phba: Pointer to HBA context object.
10099 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10100 *
10101 * This function is called in the SLI4 code path to read the port's
10102 * sli4 capabilities.
10103 *
10104 * This function may be be called from any context that can block-wait
10105 * for the completion. The expectation is that this routine is called
10106 * typically from probe_one or from the online routine.
10107 **/
10108int
10109lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10110{
10111 int rc;
10112 struct lpfc_mqe *mqe;
10113 struct lpfc_pc_sli4_params *sli4_params;
10114 uint32_t mbox_tmo;
10115
10116 rc = 0;
10117 mqe = &mboxq->u.mqe;
10118
10119 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -050010120 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -050010121 if (!phba->sli4_hba.intr_enable)
10122 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10123 else {
James Smarta183a152011-10-10 21:32:43 -040010124 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -050010125 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10126 }
10127
10128 if (unlikely(rc))
10129 return 1;
10130
10131 sli4_params = &phba->sli4_hba.pc_sli4_params;
10132 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
10133 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
10134 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
10135 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
10136 &mqe->un.sli4_params);
10137 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
10138 &mqe->un.sli4_params);
10139 sli4_params->proto_types = mqe->un.sli4_params.word3;
10140 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
10141 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
10142 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
10143 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
10144 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
10145 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
10146 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
10147 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
10148 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
10149 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
10150 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
10151 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
10152 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
10153 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
10154 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
10155 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
10156 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
10157 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
10158 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
10159 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -040010160
10161 /* Make sure that sge_supp_len can be handled by the driver */
10162 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10163 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10164
James Smart28baac72010-02-12 14:42:03 -050010165 return rc;
10166}
10167
James Smartda0436e2009-05-22 14:51:39 -040010168/**
James Smartfedd3b72011-02-16 12:39:24 -050010169 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
10170 * @phba: Pointer to HBA context object.
10171 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10172 *
10173 * This function is called in the SLI4 code path to read the port's
10174 * sli4 capabilities.
10175 *
10176 * This function may be be called from any context that can block-wait
10177 * for the completion. The expectation is that this routine is called
10178 * typically from probe_one or from the online routine.
10179 **/
10180int
10181lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10182{
10183 int rc;
10184 struct lpfc_mqe *mqe = &mboxq->u.mqe;
10185 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -040010186 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -050010187 int length;
10188 struct lpfc_sli4_parameters *mbx_sli4_parameters;
10189
James Smart6d368e52011-05-24 11:44:12 -040010190 /*
10191 * By default, the driver assumes the SLI4 port requires RPI
10192 * header postings. The SLI4_PARAM response will correct this
10193 * assumption.
10194 */
10195 phba->sli4_hba.rpi_hdrs_in_use = 1;
10196
James Smartfedd3b72011-02-16 12:39:24 -050010197 /* Read the port's SLI4 Config Parameters */
10198 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
10199 sizeof(struct lpfc_sli4_cfg_mhdr));
10200 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
10201 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
10202 length, LPFC_SLI4_MBX_EMBED);
10203 if (!phba->sli4_hba.intr_enable)
10204 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -040010205 else {
10206 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
10207 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10208 }
James Smartfedd3b72011-02-16 12:39:24 -050010209 if (unlikely(rc))
10210 return rc;
10211 sli4_params = &phba->sli4_hba.pc_sli4_params;
10212 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
10213 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
10214 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
10215 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
10216 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
10217 mbx_sli4_parameters);
10218 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
10219 mbx_sli4_parameters);
10220 if (bf_get(cfg_phwq, mbx_sli4_parameters))
10221 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
10222 else
10223 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
10224 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
10225 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
James Smart1ba981f2014-02-20 09:56:45 -050010226 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010227 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
10228 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
10229 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
10230 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
James Smart0c651872013-07-15 18:33:23 -040010231 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010232 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
10233 mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080010234 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010235 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
10236 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -040010237 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
10238 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080010239 phba->nvme_support = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
10240 bf_get(cfg_xib, mbx_sli4_parameters));
10241
10242 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) ||
10243 !phba->nvme_support) {
10244 phba->nvme_support = 0;
10245 phba->nvmet_support = 0;
James Smart2d7dbc42017-02-12 13:52:35 -080010246 phba->cfg_nvmet_mrq = 0;
James Smart895427b2017-02-12 13:52:30 -080010247 phba->cfg_nvme_io_channel = 0;
10248 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
10249 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
10250 "6101 Disabling NVME support: "
10251 "Not supported by firmware: %d %d\n",
10252 bf_get(cfg_nvme, mbx_sli4_parameters),
10253 bf_get(cfg_xib, mbx_sli4_parameters));
10254
10255 /* If firmware doesn't support NVME, just use SCSI support */
10256 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
10257 return -ENODEV;
10258 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
10259 }
James Smart05580562011-05-24 11:40:48 -040010260
James Smartf358dd02017-02-12 13:52:34 -080010261 if (bf_get(cfg_xib, mbx_sli4_parameters) && phba->cfg_suppress_rsp)
10262 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
10263
James Smart05580562011-05-24 11:40:48 -040010264 /* Make sure that sge_supp_len can be handled by the driver */
10265 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10266 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10267
James Smartb5c53952016-03-31 14:12:30 -070010268 /*
10269 * Issue IOs with CDB embedded in WQE to minimized the number
10270 * of DMAs the firmware has to do. Setting this to 1 also forces
10271 * the driver to use 128 bytes WQEs for FCP IOs.
10272 */
10273 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
10274 phba->fcp_embed_io = 1;
10275 else
10276 phba->fcp_embed_io = 0;
James Smart7bdedb32016-07-06 12:36:00 -070010277
10278 /*
10279 * Check if the SLI port supports MDS Diagnostics
10280 */
10281 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
10282 phba->mds_diags_support = 1;
10283 else
10284 phba->mds_diags_support = 0;
James Smartfedd3b72011-02-16 12:39:24 -050010285 return 0;
10286}
10287
10288/**
James Smart3772a992009-05-22 14:50:54 -040010289 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
10290 * @pdev: pointer to PCI device
10291 * @pid: pointer to PCI device identifier
10292 *
10293 * This routine is to be called to attach a device with SLI-3 interface spec
10294 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10295 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10296 * information of the device and driver to see if the driver state that it can
10297 * support this kind of device. If the match is successful, the driver core
10298 * invokes this routine. If this routine determines it can claim the HBA, it
10299 * does all the initialization that it needs to do to handle the HBA properly.
10300 *
10301 * Return code
10302 * 0 - driver can claim the device
10303 * negative value - driver can not claim the device
10304 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010305static int
James Smart3772a992009-05-22 14:50:54 -040010306lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
10307{
10308 struct lpfc_hba *phba;
10309 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040010310 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -040010311 int error;
10312 uint32_t cfg_mode, intr_mode;
10313
10314 /* Allocate memory for HBA structure */
10315 phba = lpfc_hba_alloc(pdev);
10316 if (!phba)
10317 return -ENOMEM;
10318
10319 /* Perform generic PCI device enabling operation */
10320 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040010321 if (error)
James Smart3772a992009-05-22 14:50:54 -040010322 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -040010323
10324 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
10325 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
10326 if (error)
10327 goto out_disable_pci_dev;
10328
10329 /* Set up SLI-3 specific device PCI memory space */
10330 error = lpfc_sli_pci_mem_setup(phba);
10331 if (error) {
10332 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10333 "1402 Failed to set up pci memory space.\n");
10334 goto out_disable_pci_dev;
10335 }
10336
James Smart3772a992009-05-22 14:50:54 -040010337 /* Set up SLI-3 specific device driver resources */
10338 error = lpfc_sli_driver_resource_setup(phba);
10339 if (error) {
10340 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10341 "1404 Failed to set up driver resource.\n");
10342 goto out_unset_pci_mem_s3;
10343 }
10344
10345 /* Initialize and populate the iocb list per host */
James Smartd1f525a2017-04-21 16:04:55 -070010346
James Smart3772a992009-05-22 14:50:54 -040010347 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
10348 if (error) {
10349 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10350 "1405 Failed to initialize iocb list.\n");
10351 goto out_unset_driver_resource_s3;
10352 }
10353
10354 /* Set up common device driver resources */
10355 error = lpfc_setup_driver_resource_phase2(phba);
10356 if (error) {
10357 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10358 "1406 Failed to set up driver resource.\n");
10359 goto out_free_iocb_list;
10360 }
10361
James Smart079b5c92011-08-21 21:48:49 -040010362 /* Get the default values for Model Name and Description */
10363 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
10364
James Smart3772a992009-05-22 14:50:54 -040010365 /* Create SCSI host to the physical port */
10366 error = lpfc_create_shost(phba);
10367 if (error) {
10368 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10369 "1407 Failed to create scsi host.\n");
10370 goto out_unset_driver_resource;
10371 }
10372
10373 /* Configure sysfs attributes */
10374 vport = phba->pport;
10375 error = lpfc_alloc_sysfs_attr(vport);
10376 if (error) {
10377 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10378 "1476 Failed to allocate sysfs attr\n");
10379 goto out_destroy_shost;
10380 }
10381
James Smart6669f9b2009-10-02 15:16:45 -040010382 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -040010383 /* Now, trying to enable interrupt and bring up the device */
10384 cfg_mode = phba->cfg_use_msi;
10385 while (true) {
10386 /* Put device to a known state before enabling interrupt */
10387 lpfc_stop_port(phba);
10388 /* Configure and enable interrupt */
10389 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
10390 if (intr_mode == LPFC_INTR_ERROR) {
10391 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10392 "0431 Failed to enable interrupt.\n");
10393 error = -ENODEV;
10394 goto out_free_sysfs_attr;
10395 }
10396 /* SLI-3 HBA setup */
10397 if (lpfc_sli_hba_setup(phba)) {
10398 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10399 "1477 Failed to set up hba\n");
10400 error = -ENODEV;
10401 goto out_remove_device;
10402 }
10403
10404 /* Wait 50ms for the interrupts of previous mailbox commands */
10405 msleep(50);
10406 /* Check active interrupts on message signaled interrupts */
10407 if (intr_mode == 0 ||
10408 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
10409 /* Log the current active interrupt mode */
10410 phba->intr_mode = intr_mode;
10411 lpfc_log_intr_mode(phba, intr_mode);
10412 break;
10413 } else {
10414 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10415 "0447 Configure interrupt mode (%d) "
10416 "failed active interrupt test.\n",
10417 intr_mode);
10418 /* Disable the current interrupt mode */
10419 lpfc_sli_disable_intr(phba);
10420 /* Try next level of interrupt mode */
10421 cfg_mode = --intr_mode;
10422 }
10423 }
10424
10425 /* Perform post initialization setup */
10426 lpfc_post_init_setup(phba);
10427
10428 /* Check if there are static vports to be created. */
10429 lpfc_create_static_vport(phba);
10430
10431 return 0;
10432
10433out_remove_device:
10434 lpfc_unset_hba(phba);
10435out_free_sysfs_attr:
10436 lpfc_free_sysfs_attr(vport);
10437out_destroy_shost:
10438 lpfc_destroy_shost(phba);
10439out_unset_driver_resource:
10440 lpfc_unset_driver_resource_phase2(phba);
10441out_free_iocb_list:
10442 lpfc_free_iocb_list(phba);
10443out_unset_driver_resource_s3:
10444 lpfc_sli_driver_resource_unset(phba);
10445out_unset_pci_mem_s3:
10446 lpfc_sli_pci_mem_unset(phba);
10447out_disable_pci_dev:
10448 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040010449 if (shost)
10450 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -040010451out_free_phba:
10452 lpfc_hba_free(phba);
10453 return error;
10454}
10455
10456/**
10457 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -040010458 * @pdev: pointer to PCI device
10459 *
James Smart3772a992009-05-22 14:50:54 -040010460 * This routine is to be called to disattach a device with SLI-3 interface
10461 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10462 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10463 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -040010464 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010465static void
James Smart3772a992009-05-22 14:50:54 -040010466lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -050010467{
James Smart2e0fef82007-06-17 19:56:36 -050010468 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10469 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -050010470 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -050010471 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -050010472 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -050010473
James Smart549e55c2007-08-02 11:09:51 -040010474 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -040010475 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -040010476 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -050010477
James Smart858c9f62007-06-17 19:56:39 -050010478 lpfc_free_sysfs_attr(vport);
10479
James Smarteada2722008-12-04 22:39:13 -050010480 /* Release all the vports against this physical port */
10481 vports = lpfc_create_vport_work_array(phba);
10482 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040010483 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10484 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
10485 continue;
James Smarteada2722008-12-04 22:39:13 -050010486 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040010487 }
James Smarteada2722008-12-04 22:39:13 -050010488 lpfc_destroy_vport_work_array(phba, vports);
10489
10490 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -050010491 fc_remove_host(shost);
10492 scsi_remove_host(shost);
James Smartd613b6a2017-02-12 13:52:37 -080010493
James Smart87af33f2007-10-27 13:37:43 -040010494 lpfc_cleanup(vport);
10495
James Smart2e0fef82007-06-17 19:56:36 -050010496 /*
10497 * Bring down the SLI Layer. This step disable all interrupts,
10498 * clears the rings, discards all mailbox commands, and resets
10499 * the HBA.
10500 */
James Smarta257bf92009-04-06 18:48:10 -040010501
Justin P. Mattock48e34d02010-12-30 15:07:58 -080010502 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -050010503 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -040010504 /* Stop kthread signal shall trigger work_done one more time */
10505 kthread_stop(phba->worker_thread);
10506 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -050010507 lpfc_sli_brdrestart(phba);
10508
James Smart72859902012-01-18 16:25:38 -050010509 kfree(phba->vpi_bmask);
10510 kfree(phba->vpi_ids);
10511
James Smart3772a992009-05-22 14:50:54 -040010512 lpfc_stop_hba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -050010513 spin_lock_irq(&phba->hbalock);
10514 list_del_init(&vport->listentry);
10515 spin_unlock_irq(&phba->hbalock);
10516
James Smart858c9f62007-06-17 19:56:39 -050010517 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -050010518
James Smart912e3ac2011-05-24 11:42:11 -040010519 /* Disable SR-IOV if enabled */
10520 if (phba->cfg_sriov_nr_virtfn)
10521 pci_disable_sriov(pdev);
10522
James Smart5b75da22008-12-04 22:39:35 -050010523 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -040010524 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -050010525
James Smart858c9f62007-06-17 19:56:39 -050010526 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -050010527
10528 /*
10529 * Call scsi_free before mem_free since scsi bufs are released to their
10530 * corresponding pools here.
10531 */
10532 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -040010533 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -050010534
James Smart34b02dc2008-08-24 21:49:55 -040010535 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
10536 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -050010537
James Smart2e0fef82007-06-17 19:56:36 -050010538 /* Free resources associated with SLI2 interface */
10539 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -040010540 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -050010541
10542 /* unmap adapter SLIM and Control Registers */
10543 iounmap(phba->ctrl_regs_memmap_p);
10544 iounmap(phba->slim_memmap_p);
10545
James Smart3772a992009-05-22 14:50:54 -040010546 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -050010547
Johannes Thumshirne0c04832016-06-07 09:44:03 +020010548 pci_release_mem_regions(pdev);
James Smart2e0fef82007-06-17 19:56:36 -050010549 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -050010550}
10551
Linas Vepstas8d63f372007-02-14 14:28:36 -060010552/**
James Smart3772a992009-05-22 14:50:54 -040010553 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050010554 * @pdev: pointer to PCI device
10555 * @msg: power management message
10556 *
James Smart3772a992009-05-22 14:50:54 -040010557 * This routine is to be called from the kernel's PCI subsystem to support
10558 * system Power Management (PM) to device with SLI-3 interface spec. When
10559 * PM invokes this method, it quiesces the device by stopping the driver's
10560 * worker thread for the device, turning off device's interrupt and DMA,
10561 * and bring the device offline. Note that as the driver implements the
10562 * minimum PM requirements to a power-aware driver's PM support for the
10563 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10564 * to the suspend() method call will be treated as SUSPEND and the driver will
10565 * fully reinitialize its device during resume() method call, the driver will
10566 * set device to PCI_D3hot state in PCI config space instead of setting it
10567 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -050010568 *
10569 * Return code
James Smart3772a992009-05-22 14:50:54 -040010570 * 0 - driver suspended the device
10571 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050010572 **/
10573static int
James Smart3772a992009-05-22 14:50:54 -040010574lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -050010575{
10576 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10577 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10578
10579 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10580 "0473 PCI device Power Management suspend.\n");
10581
10582 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040010583 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -050010584 lpfc_offline(phba);
10585 kthread_stop(phba->worker_thread);
10586
10587 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -040010588 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -050010589
10590 /* Save device state to PCI config space */
10591 pci_save_state(pdev);
10592 pci_set_power_state(pdev, PCI_D3hot);
10593
10594 return 0;
10595}
10596
10597/**
James Smart3772a992009-05-22 14:50:54 -040010598 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050010599 * @pdev: pointer to PCI device
10600 *
James Smart3772a992009-05-22 14:50:54 -040010601 * This routine is to be called from the kernel's PCI subsystem to support
10602 * system Power Management (PM) to device with SLI-3 interface spec. When PM
10603 * invokes this method, it restores the device's PCI config space state and
10604 * fully reinitializes the device and brings it online. Note that as the
10605 * driver implements the minimum PM requirements to a power-aware driver's
10606 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
10607 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
10608 * driver will fully reinitialize its device during resume() method call,
10609 * the device will be set to PCI_D0 directly in PCI config space before
10610 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -050010611 *
10612 * Return code
James Smart3772a992009-05-22 14:50:54 -040010613 * 0 - driver suspended the device
10614 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050010615 **/
10616static int
James Smart3772a992009-05-22 14:50:54 -040010617lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -050010618{
10619 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10620 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -050010621 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050010622 int error;
10623
10624 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10625 "0452 PCI device Power Management resume.\n");
10626
10627 /* Restore device state from PCI config space */
10628 pci_set_power_state(pdev, PCI_D0);
10629 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -040010630
James Smart1dfb5a42010-02-12 14:40:50 -050010631 /*
10632 * As the new kernel behavior of pci_restore_state() API call clears
10633 * device saved_state flag, need to save the restored state again.
10634 */
10635 pci_save_state(pdev);
10636
James Smart3a55b532008-12-04 22:38:54 -050010637 if (pdev->is_busmaster)
10638 pci_set_master(pdev);
10639
10640 /* Startup the kernel thread for this host adapter. */
10641 phba->worker_thread = kthread_run(lpfc_do_work, phba,
10642 "lpfc_worker_%d", phba->brd_no);
10643 if (IS_ERR(phba->worker_thread)) {
10644 error = PTR_ERR(phba->worker_thread);
10645 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10646 "0434 PM resume failed to start worker "
10647 "thread: error=x%x.\n", error);
10648 return error;
10649 }
10650
James Smart5b75da22008-12-04 22:39:35 -050010651 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040010652 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050010653 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -050010654 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -050010655 "0430 PM resume Failed to enable interrupt\n");
10656 return -EIO;
10657 } else
10658 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050010659
10660 /* Restart HBA and bring it online */
10661 lpfc_sli_brdrestart(phba);
10662 lpfc_online(phba);
10663
James Smart5b75da22008-12-04 22:39:35 -050010664 /* Log the current active interrupt mode */
10665 lpfc_log_intr_mode(phba, phba->intr_mode);
10666
James Smart3a55b532008-12-04 22:38:54 -050010667 return 0;
10668}
10669
10670/**
James Smart891478a2009-11-18 15:40:23 -050010671 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
10672 * @phba: pointer to lpfc hba data structure.
10673 *
10674 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -040010675 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -050010676 **/
10677static void
10678lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
10679{
10680 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10681 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -040010682
10683 /*
10684 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10685 * and let the SCSI mid-layer to retry them to recover.
10686 */
James Smartdb55fba2014-04-04 13:52:02 -040010687 lpfc_sli_abort_fcp_rings(phba);
James Smart891478a2009-11-18 15:40:23 -050010688}
10689
10690/**
James Smart0d878412009-10-02 15:16:56 -040010691 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
10692 * @phba: pointer to lpfc hba data structure.
10693 *
10694 * This routine is called to prepare the SLI3 device for PCI slot reset. It
10695 * disables the device interrupt and pci device, and aborts the internal FCP
10696 * pending I/Os.
10697 **/
10698static void
10699lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
10700{
James Smart0d878412009-10-02 15:16:56 -040010701 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050010702 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -040010703
James Smart75baf692010-06-08 18:31:21 -040010704 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040010705 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010706
James Smarte2af0d22010-03-15 11:25:32 -040010707 /* Block all SCSI devices' I/Os on the host */
10708 lpfc_scsi_dev_block(phba);
10709
James Smartea714f32013-04-17 20:18:47 -040010710 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10711 lpfc_sli_flush_fcp_rings(phba);
10712
James Smarte2af0d22010-03-15 11:25:32 -040010713 /* stop all timers */
10714 lpfc_stop_hba_timers(phba);
10715
James Smart0d878412009-10-02 15:16:56 -040010716 /* Disable interrupt and pci device */
10717 lpfc_sli_disable_intr(phba);
10718 pci_disable_device(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -040010719}
10720
10721/**
10722 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
10723 * @phba: pointer to lpfc hba data structure.
10724 *
10725 * This routine is called to prepare the SLI3 device for PCI slot permanently
10726 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10727 * pending I/Os.
10728 **/
10729static void
James Smart75baf692010-06-08 18:31:21 -040010730lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -040010731{
10732 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050010733 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -040010734 /* Block all SCSI devices' I/Os on the host */
10735 lpfc_scsi_dev_block(phba);
10736
10737 /* stop all timers */
10738 lpfc_stop_hba_timers(phba);
10739
James Smart0d878412009-10-02 15:16:56 -040010740 /* Clean up all driver's outstanding SCSI I/Os */
10741 lpfc_sli_flush_fcp_rings(phba);
10742}
10743
10744/**
James Smart3772a992009-05-22 14:50:54 -040010745 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -040010746 * @pdev: pointer to PCI device.
10747 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010748 *
James Smart3772a992009-05-22 14:50:54 -040010749 * This routine is called from the PCI subsystem for I/O error handling to
10750 * device with SLI-3 interface spec. This function is called by the PCI
10751 * subsystem after a PCI bus error affecting this device has been detected.
10752 * When this function is invoked, it will need to stop all the I/Os and
10753 * interrupt(s) to the device. Once that is done, it will return
10754 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
10755 * as desired.
James Smarte59058c2008-08-24 21:49:00 -040010756 *
10757 * Return codes
James Smart0d878412009-10-02 15:16:56 -040010758 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -040010759 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10760 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -040010761 **/
James Smart3772a992009-05-22 14:50:54 -040010762static pci_ers_result_t
10763lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010764{
James Smart51ef4c22007-08-02 11:10:31 -040010765 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10766 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010767
James Smart0d878412009-10-02 15:16:56 -040010768 switch (state) {
10769 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -050010770 /* Non-fatal error, prepare for recovery */
10771 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -040010772 return PCI_ERS_RESULT_CAN_RECOVER;
10773 case pci_channel_io_frozen:
10774 /* Fatal error, prepare for slot reset */
10775 lpfc_sli_prep_dev_for_reset(phba);
10776 return PCI_ERS_RESULT_NEED_RESET;
10777 case pci_channel_io_perm_failure:
10778 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -040010779 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010780 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -040010781 default:
10782 /* Unknown state, prepare and request slot reset */
10783 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10784 "0472 Unknown PCI error state: x%x\n", state);
10785 lpfc_sli_prep_dev_for_reset(phba);
10786 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -040010787 }
Linas Vepstas8d63f372007-02-14 14:28:36 -060010788}
10789
10790/**
James Smart3772a992009-05-22 14:50:54 -040010791 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -040010792 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010793 *
James Smart3772a992009-05-22 14:50:54 -040010794 * This routine is called from the PCI subsystem for error handling to
10795 * device with SLI-3 interface spec. This is called after PCI bus has been
10796 * reset to restart the PCI card from scratch, as if from a cold-boot.
10797 * During the PCI subsystem error recovery, after driver returns
10798 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10799 * recovery and then call this routine before calling the .resume method
10800 * to recover the device. This function will initialize the HBA device,
10801 * enable the interrupt, but it will just put the HBA to offline state
10802 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -040010803 *
10804 * Return codes
James Smart3772a992009-05-22 14:50:54 -040010805 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10806 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -060010807 */
James Smart3772a992009-05-22 14:50:54 -040010808static pci_ers_result_t
10809lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010810{
James Smart51ef4c22007-08-02 11:10:31 -040010811 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10812 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010813 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -050010814 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010815
10816 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +110010817 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -060010818 printk(KERN_ERR "lpfc: Cannot re-enable "
10819 "PCI device after reset.\n");
10820 return PCI_ERS_RESULT_DISCONNECT;
10821 }
10822
James Smart97207482008-12-04 22:39:19 -050010823 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050010824
10825 /*
10826 * As the new kernel behavior of pci_restore_state() API call clears
10827 * device saved_state flag, need to save the restored state again.
10828 */
10829 pci_save_state(pdev);
10830
James Smart97207482008-12-04 22:39:19 -050010831 if (pdev->is_busmaster)
10832 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010833
James Smart92d7f7b2007-06-17 19:56:38 -050010834 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040010835 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -050010836 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010837
James Smart5b75da22008-12-04 22:39:35 -050010838 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040010839 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050010840 if (intr_mode == LPFC_INTR_ERROR) {
10841 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10842 "0427 Cannot re-enable interrupt after "
10843 "slot reset.\n");
10844 return PCI_ERS_RESULT_DISCONNECT;
10845 } else
10846 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010847
James Smart75baf692010-06-08 18:31:21 -040010848 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -040010849 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010850 lpfc_offline(phba);
10851 lpfc_sli_brdrestart(phba);
10852
James Smart5b75da22008-12-04 22:39:35 -050010853 /* Log the current active interrupt mode */
10854 lpfc_log_intr_mode(phba, phba->intr_mode);
10855
Linas Vepstas8d63f372007-02-14 14:28:36 -060010856 return PCI_ERS_RESULT_RECOVERED;
10857}
10858
10859/**
James Smart3772a992009-05-22 14:50:54 -040010860 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -040010861 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -060010862 *
James Smart3772a992009-05-22 14:50:54 -040010863 * This routine is called from the PCI subsystem for error handling to device
10864 * with SLI-3 interface spec. It is called when kernel error recovery tells
10865 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10866 * error recovery. After this call, traffic can start to flow from this device
10867 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010868 */
James Smart3772a992009-05-22 14:50:54 -040010869static void
10870lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010871{
James Smart51ef4c22007-08-02 11:10:31 -040010872 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10873 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010874
James Smarte2af0d22010-03-15 11:25:32 -040010875 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -040010876 lpfc_online(phba);
James Smart0d878412009-10-02 15:16:56 -040010877
10878 /* Clean up Advanced Error Reporting (AER) if needed */
10879 if (phba->hba_flag & HBA_AER_ENABLED)
10880 pci_cleanup_aer_uncorrect_error_status(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010881}
10882
James Smart3772a992009-05-22 14:50:54 -040010883/**
James Smartda0436e2009-05-22 14:51:39 -040010884 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
10885 * @phba: pointer to lpfc hba data structure.
10886 *
10887 * returns the number of ELS/CT IOCBs to reserve
10888 **/
10889int
10890lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
10891{
10892 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
10893
James Smartf1126682009-06-10 17:22:44 -040010894 if (phba->sli_rev == LPFC_SLI_REV4) {
10895 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -040010896 return 10;
James Smartf1126682009-06-10 17:22:44 -040010897 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -040010898 return 25;
James Smartf1126682009-06-10 17:22:44 -040010899 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -040010900 return 50;
James Smartf1126682009-06-10 17:22:44 -040010901 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -040010902 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -040010903 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -040010904 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -040010905 else if (max_xri <= 2048)
10906 return 200;
10907 else
10908 return 250;
James Smartf1126682009-06-10 17:22:44 -040010909 } else
10910 return 0;
James Smartda0436e2009-05-22 14:51:39 -040010911}
10912
10913/**
James Smart895427b2017-02-12 13:52:30 -080010914 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
10915 * @phba: pointer to lpfc hba data structure.
10916 *
James Smartf358dd02017-02-12 13:52:34 -080010917 * returns the number of ELS/CT + NVMET IOCBs to reserve
James Smart895427b2017-02-12 13:52:30 -080010918 **/
10919int
10920lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
10921{
10922 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
10923
James Smartf358dd02017-02-12 13:52:34 -080010924 if (phba->nvmet_support)
10925 max_xri += LPFC_NVMET_BUF_POST;
James Smart895427b2017-02-12 13:52:30 -080010926 return max_xri;
10927}
10928
10929
10930/**
James Smart52d52442011-05-24 11:42:45 -040010931 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -040010932 * @fw: pointer to firmware image returned from request_firmware.
James Smartce396282012-09-29 11:30:56 -040010933 * @phba: pointer to lpfc hba data structure.
James Smart52d52442011-05-24 11:42:45 -040010934 *
James Smart52d52442011-05-24 11:42:45 -040010935 **/
James Smartce396282012-09-29 11:30:56 -040010936static void
10937lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -040010938{
James Smartce396282012-09-29 11:30:56 -040010939 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -050010940 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -040010941 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -040010942 struct list_head dma_buffer_list;
10943 int i, rc = 0;
10944 struct lpfc_dmabuf *dmabuf, *next;
10945 uint32_t offset = 0, temp_offset = 0;
James Smart6b6ef5d2016-10-13 15:06:17 -070010946 uint32_t magic_number, ftype, fid, fsize;
James Smart52d52442011-05-24 11:42:45 -040010947
James Smartc71ab862012-10-31 14:44:33 -040010948 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -040010949 if (!fw) {
10950 rc = -ENXIO;
10951 goto out;
10952 }
10953 image = (struct lpfc_grp_hdr *)fw->data;
10954
James Smart6b6ef5d2016-10-13 15:06:17 -070010955 magic_number = be32_to_cpu(image->magic_number);
10956 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
10957 fid = bf_get_be32(lpfc_grp_hdr_id, image),
10958 fsize = be32_to_cpu(image->size);
10959
James Smart52d52442011-05-24 11:42:45 -040010960 INIT_LIST_HEAD(&dma_buffer_list);
James Smart6b6ef5d2016-10-13 15:06:17 -070010961 if ((magic_number != LPFC_GROUP_OJECT_MAGIC_G5 &&
10962 magic_number != LPFC_GROUP_OJECT_MAGIC_G6) ||
10963 ftype != LPFC_FILE_TYPE_GROUP || fsize != fw->size) {
James Smart52d52442011-05-24 11:42:45 -040010964 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10965 "3022 Invalid FW image found. "
Arnd Bergmannefe583c2016-10-17 14:35:46 +020010966 "Magic:%x Type:%x ID:%x Size %d %zd\n",
James Smart6b6ef5d2016-10-13 15:06:17 -070010967 magic_number, ftype, fid, fsize, fw->size);
James Smartce396282012-09-29 11:30:56 -040010968 rc = -EINVAL;
10969 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010970 }
10971 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -040010972 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -040010973 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartce396282012-09-29 11:30:56 -040010974 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -040010975 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -040010976 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -040010977 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
10978 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
10979 GFP_KERNEL);
10980 if (!dmabuf) {
10981 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040010982 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010983 }
10984 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
10985 SLI4_PAGE_SIZE,
10986 &dmabuf->phys,
10987 GFP_KERNEL);
10988 if (!dmabuf->virt) {
10989 kfree(dmabuf);
10990 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040010991 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010992 }
10993 list_add_tail(&dmabuf->list, &dma_buffer_list);
10994 }
10995 while (offset < fw->size) {
10996 temp_offset = offset;
10997 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -040010998 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -040010999 memcpy(dmabuf->virt,
11000 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -040011001 fw->size - temp_offset);
11002 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -040011003 break;
11004 }
James Smart52d52442011-05-24 11:42:45 -040011005 memcpy(dmabuf->virt, fw->data + temp_offset,
11006 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -040011007 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -040011008 }
11009 rc = lpfc_wr_object(phba, &dma_buffer_list,
11010 (fw->size - offset), &offset);
James Smartce396282012-09-29 11:30:56 -040011011 if (rc)
11012 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040011013 }
11014 rc = offset;
11015 }
James Smartce396282012-09-29 11:30:56 -040011016
11017release_out:
James Smart52d52442011-05-24 11:42:45 -040011018 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
11019 list_del(&dmabuf->list);
11020 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
11021 dmabuf->virt, dmabuf->phys);
11022 kfree(dmabuf);
11023 }
James Smartce396282012-09-29 11:30:56 -040011024 release_firmware(fw);
11025out:
11026 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc71ab862012-10-31 14:44:33 -040011027 "3024 Firmware update done: %d.\n", rc);
James Smartce396282012-09-29 11:30:56 -040011028 return;
James Smart52d52442011-05-24 11:42:45 -040011029}
11030
11031/**
James Smartc71ab862012-10-31 14:44:33 -040011032 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
11033 * @phba: pointer to lpfc hba data structure.
11034 *
11035 * This routine is called to perform Linux generic firmware upgrade on device
11036 * that supports such feature.
11037 **/
11038int
11039lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
11040{
11041 uint8_t file_name[ELX_MODEL_NAME_SIZE];
11042 int ret;
11043 const struct firmware *fw;
11044
11045 /* Only supported on SLI4 interface type 2 for now */
11046 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
11047 LPFC_SLI_INTF_IF_TYPE_2)
11048 return -EPERM;
11049
11050 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
11051
11052 if (fw_upgrade == INT_FW_UPGRADE) {
11053 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
11054 file_name, &phba->pcidev->dev,
11055 GFP_KERNEL, (void *)phba,
11056 lpfc_write_firmware);
11057 } else if (fw_upgrade == RUN_FW_UPGRADE) {
11058 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
11059 if (!ret)
11060 lpfc_write_firmware(fw, (void *)phba);
11061 } else {
11062 ret = -EINVAL;
11063 }
11064
11065 return ret;
11066}
11067
11068/**
James Smartda0436e2009-05-22 14:51:39 -040011069 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
11070 * @pdev: pointer to PCI device
11071 * @pid: pointer to PCI device identifier
11072 *
11073 * This routine is called from the kernel's PCI subsystem to device with
11074 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11075 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
11076 * information of the device and driver to see if the driver state that it
11077 * can support this kind of device. If the match is successful, the driver
11078 * core invokes this routine. If this routine determines it can claim the HBA,
11079 * it does all the initialization that it needs to do to handle the HBA
11080 * properly.
11081 *
11082 * Return code
11083 * 0 - driver can claim the device
11084 * negative value - driver can not claim the device
11085 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011086static int
James Smartda0436e2009-05-22 14:51:39 -040011087lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
11088{
11089 struct lpfc_hba *phba;
11090 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040011091 struct Scsi_Host *shost = NULL;
James Smart2b7824d2017-04-21 16:04:59 -070011092 int error, cnt;
James Smartda0436e2009-05-22 14:51:39 -040011093 uint32_t cfg_mode, intr_mode;
James Smartda0436e2009-05-22 14:51:39 -040011094
11095 /* Allocate memory for HBA structure */
11096 phba = lpfc_hba_alloc(pdev);
11097 if (!phba)
11098 return -ENOMEM;
11099
11100 /* Perform generic PCI device enabling operation */
11101 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040011102 if (error)
James Smartda0436e2009-05-22 14:51:39 -040011103 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -040011104
11105 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
11106 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
11107 if (error)
11108 goto out_disable_pci_dev;
11109
11110 /* Set up SLI-4 specific device PCI memory space */
11111 error = lpfc_sli4_pci_mem_setup(phba);
11112 if (error) {
11113 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11114 "1410 Failed to set up pci memory space.\n");
11115 goto out_disable_pci_dev;
11116 }
11117
James Smartda0436e2009-05-22 14:51:39 -040011118 /* Set up SLI-4 Specific device driver resources */
11119 error = lpfc_sli4_driver_resource_setup(phba);
11120 if (error) {
11121 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11122 "1412 Failed to set up driver resource.\n");
11123 goto out_unset_pci_mem_s4;
11124 }
11125
James Smart2b7824d2017-04-21 16:04:59 -070011126 cnt = phba->cfg_iocb_cnt * 1024;
11127 if (phba->nvmet_support)
11128 cnt += phba->cfg_nvmet_mrq_post * phba->cfg_nvmet_mrq;
11129
James Smartda0436e2009-05-22 14:51:39 -040011130 /* Initialize and populate the iocb list per host */
James Smart2a9bf3d2010-06-07 15:24:45 -040011131 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2b7824d2017-04-21 16:04:59 -070011132 "2821 initialize iocb list %d total %d\n",
11133 phba->cfg_iocb_cnt, cnt);
11134 error = lpfc_init_iocb_list(phba, cnt);
James Smart2a9bf3d2010-06-07 15:24:45 -040011135
James Smartda0436e2009-05-22 14:51:39 -040011136 if (error) {
11137 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11138 "1413 Failed to initialize iocb list.\n");
11139 goto out_unset_driver_resource_s4;
11140 }
11141
James Smart19ca7602010-11-20 23:11:55 -050011142 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -040011143 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -050011144
James Smartda0436e2009-05-22 14:51:39 -040011145 /* Set up common device driver resources */
11146 error = lpfc_setup_driver_resource_phase2(phba);
11147 if (error) {
11148 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11149 "1414 Failed to set up driver resource.\n");
11150 goto out_free_iocb_list;
11151 }
11152
James Smart079b5c92011-08-21 21:48:49 -040011153 /* Get the default values for Model Name and Description */
11154 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
11155
James Smartda0436e2009-05-22 14:51:39 -040011156 /* Create SCSI host to the physical port */
11157 error = lpfc_create_shost(phba);
11158 if (error) {
11159 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11160 "1415 Failed to create scsi host.\n");
11161 goto out_unset_driver_resource;
11162 }
11163
11164 /* Configure sysfs attributes */
11165 vport = phba->pport;
11166 error = lpfc_alloc_sysfs_attr(vport);
11167 if (error) {
11168 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11169 "1416 Failed to allocate sysfs attr\n");
11170 goto out_destroy_shost;
11171 }
11172
James Smart6669f9b2009-10-02 15:16:45 -040011173 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -040011174 /* Now, trying to enable interrupt and bring up the device */
11175 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -040011176
James Smart7b15db32013-01-03 15:43:29 -050011177 /* Put device to a known state before enabling interrupt */
11178 lpfc_stop_port(phba);
James Smart895427b2017-02-12 13:52:30 -080011179
James Smart7b15db32013-01-03 15:43:29 -050011180 /* Configure and enable interrupt */
11181 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
11182 if (intr_mode == LPFC_INTR_ERROR) {
11183 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11184 "0426 Failed to enable interrupt.\n");
11185 error = -ENODEV;
11186 goto out_free_sysfs_attr;
James Smartda0436e2009-05-22 14:51:39 -040011187 }
James Smart7b15db32013-01-03 15:43:29 -050011188 /* Default to single EQ for non-MSI-X */
James Smart895427b2017-02-12 13:52:30 -080011189 if (phba->intr_type != MSIX) {
11190 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
11191 phba->cfg_fcp_io_channel = 1;
James Smart2d7dbc42017-02-12 13:52:35 -080011192 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -080011193 phba->cfg_nvme_io_channel = 1;
James Smart2d7dbc42017-02-12 13:52:35 -080011194 if (phba->nvmet_support)
11195 phba->cfg_nvmet_mrq = 1;
11196 }
James Smart895427b2017-02-12 13:52:30 -080011197 phba->io_channel_irqs = 1;
11198 }
11199
James Smart7b15db32013-01-03 15:43:29 -050011200 /* Set up SLI-4 HBA */
11201 if (lpfc_sli4_hba_setup(phba)) {
11202 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11203 "1421 Failed to set up hba\n");
11204 error = -ENODEV;
11205 goto out_disable_intr;
11206 }
11207
11208 /* Log the current active interrupt mode */
11209 phba->intr_mode = intr_mode;
11210 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -040011211
11212 /* Perform post initialization setup */
11213 lpfc_post_init_setup(phba);
11214
James Smart01649562017-02-12 13:52:32 -080011215 /* NVME support in FW earlier in the driver load corrects the
11216 * FC4 type making a check for nvme_support unnecessary.
11217 */
11218 if ((phba->nvmet_support == 0) &&
11219 (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
11220 /* Create NVME binding with nvme_fc_transport. This
James Smartd1f525a2017-04-21 16:04:55 -070011221 * ensures the vport is initialized. If the localport
11222 * create fails, it should not unload the driver to
11223 * support field issues.
James Smart01649562017-02-12 13:52:32 -080011224 */
11225 error = lpfc_nvme_create_localport(vport);
11226 if (error) {
11227 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11228 "6004 NVME registration failed, "
11229 "error x%x\n",
11230 error);
James Smart01649562017-02-12 13:52:32 -080011231 }
11232 }
James Smart895427b2017-02-12 13:52:30 -080011233
James Smartc71ab862012-10-31 14:44:33 -040011234 /* check for firmware upgrade or downgrade */
11235 if (phba->cfg_request_firmware_upgrade)
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040011236 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -040011237
James Smart1c6834a2009-07-19 10:01:26 -040011238 /* Check if there are static vports to be created. */
11239 lpfc_create_static_vport(phba);
James Smartda0436e2009-05-22 14:51:39 -040011240 return 0;
11241
11242out_disable_intr:
11243 lpfc_sli4_disable_intr(phba);
11244out_free_sysfs_attr:
11245 lpfc_free_sysfs_attr(vport);
11246out_destroy_shost:
11247 lpfc_destroy_shost(phba);
11248out_unset_driver_resource:
11249 lpfc_unset_driver_resource_phase2(phba);
11250out_free_iocb_list:
11251 lpfc_free_iocb_list(phba);
11252out_unset_driver_resource_s4:
11253 lpfc_sli4_driver_resource_unset(phba);
11254out_unset_pci_mem_s4:
11255 lpfc_sli4_pci_mem_unset(phba);
11256out_disable_pci_dev:
11257 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040011258 if (shost)
11259 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -040011260out_free_phba:
11261 lpfc_hba_free(phba);
11262 return error;
11263}
11264
11265/**
11266 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
11267 * @pdev: pointer to PCI device
11268 *
11269 * This routine is called from the kernel's PCI subsystem to device with
11270 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11271 * removed from PCI bus, it performs all the necessary cleanup for the HBA
11272 * device to be removed from the PCI subsystem properly.
11273 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011274static void
James Smartda0436e2009-05-22 14:51:39 -040011275lpfc_pci_remove_one_s4(struct pci_dev *pdev)
11276{
11277 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11278 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
11279 struct lpfc_vport **vports;
11280 struct lpfc_hba *phba = vport->phba;
11281 int i;
11282
11283 /* Mark the device unloading flag */
11284 spin_lock_irq(&phba->hbalock);
11285 vport->load_flag |= FC_UNLOADING;
11286 spin_unlock_irq(&phba->hbalock);
11287
11288 /* Free the HBA sysfs attributes */
11289 lpfc_free_sysfs_attr(vport);
11290
11291 /* Release all the vports against this physical port */
11292 vports = lpfc_create_vport_work_array(phba);
11293 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040011294 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
11295 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
11296 continue;
James Smartda0436e2009-05-22 14:51:39 -040011297 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040011298 }
James Smartda0436e2009-05-22 14:51:39 -040011299 lpfc_destroy_vport_work_array(phba, vports);
11300
11301 /* Remove FC host and then SCSI host with the physical port */
11302 fc_remove_host(shost);
11303 scsi_remove_host(shost);
11304
James Smartd613b6a2017-02-12 13:52:37 -080011305 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
11306 * localports are destroyed after to cleanup all transport memory.
James Smart895427b2017-02-12 13:52:30 -080011307 */
James Smartda0436e2009-05-22 14:51:39 -040011308 lpfc_cleanup(vport);
James Smartd613b6a2017-02-12 13:52:37 -080011309 lpfc_nvmet_destroy_targetport(phba);
11310 lpfc_nvme_destroy_localport(vport);
James Smartda0436e2009-05-22 14:51:39 -040011311
11312 /*
11313 * Bring down the SLI Layer. This step disables all interrupts,
11314 * clears the rings, discards all mailbox commands, and resets
11315 * the HBA FCoE function.
11316 */
11317 lpfc_debugfs_terminate(vport);
11318 lpfc_sli4_hba_unset(phba);
11319
11320 spin_lock_irq(&phba->hbalock);
11321 list_del_init(&vport->listentry);
11322 spin_unlock_irq(&phba->hbalock);
11323
James Smart3677a3a2010-09-29 11:19:14 -040011324 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -040011325 * buffers are released to their corresponding pools here.
11326 */
11327 lpfc_scsi_free(phba);
James Smart895427b2017-02-12 13:52:30 -080011328 lpfc_nvme_free(phba);
James Smart01649562017-02-12 13:52:32 -080011329 lpfc_free_iocb_list(phba);
James Smart67d12732012-08-03 12:36:13 -040011330
James Smartda0436e2009-05-22 14:51:39 -040011331 lpfc_sli4_driver_resource_unset(phba);
11332
11333 /* Unmap adapter Control and Doorbell registers */
11334 lpfc_sli4_pci_mem_unset(phba);
11335
11336 /* Release PCI resources and disable device's PCI function */
11337 scsi_host_put(shost);
11338 lpfc_disable_pci_dev(phba);
11339
11340 /* Finally, free the driver's device data structure */
11341 lpfc_hba_free(phba);
11342
11343 return;
11344}
11345
11346/**
11347 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
11348 * @pdev: pointer to PCI device
11349 * @msg: power management message
11350 *
11351 * This routine is called from the kernel's PCI subsystem to support system
11352 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
11353 * this method, it quiesces the device by stopping the driver's worker
11354 * thread for the device, turning off device's interrupt and DMA, and bring
11355 * the device offline. Note that as the driver implements the minimum PM
11356 * requirements to a power-aware driver's PM support for suspend/resume -- all
11357 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
11358 * method call will be treated as SUSPEND and the driver will fully
11359 * reinitialize its device during resume() method call, the driver will set
11360 * device to PCI_D3hot state in PCI config space instead of setting it
11361 * according to the @msg provided by the PM.
11362 *
11363 * Return code
11364 * 0 - driver suspended the device
11365 * Error otherwise
11366 **/
11367static int
11368lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
11369{
11370 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11371 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11372
11373 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -040011374 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -040011375
11376 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040011377 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -040011378 lpfc_offline(phba);
11379 kthread_stop(phba->worker_thread);
11380
11381 /* Disable interrupt from device */
11382 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040011383 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040011384
11385 /* Save device state to PCI config space */
11386 pci_save_state(pdev);
11387 pci_set_power_state(pdev, PCI_D3hot);
11388
11389 return 0;
11390}
11391
11392/**
11393 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
11394 * @pdev: pointer to PCI device
11395 *
11396 * This routine is called from the kernel's PCI subsystem to support system
11397 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
11398 * this method, it restores the device's PCI config space state and fully
11399 * reinitializes the device and brings it online. Note that as the driver
11400 * implements the minimum PM requirements to a power-aware driver's PM for
11401 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
11402 * to the suspend() method call will be treated as SUSPEND and the driver
11403 * will fully reinitialize its device during resume() method call, the device
11404 * will be set to PCI_D0 directly in PCI config space before restoring the
11405 * state.
11406 *
11407 * Return code
11408 * 0 - driver suspended the device
11409 * Error otherwise
11410 **/
11411static int
11412lpfc_pci_resume_one_s4(struct pci_dev *pdev)
11413{
11414 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11415 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11416 uint32_t intr_mode;
11417 int error;
11418
11419 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11420 "0292 PCI device Power Management resume.\n");
11421
11422 /* Restore device state from PCI config space */
11423 pci_set_power_state(pdev, PCI_D0);
11424 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050011425
11426 /*
11427 * As the new kernel behavior of pci_restore_state() API call clears
11428 * device saved_state flag, need to save the restored state again.
11429 */
11430 pci_save_state(pdev);
11431
James Smartda0436e2009-05-22 14:51:39 -040011432 if (pdev->is_busmaster)
11433 pci_set_master(pdev);
11434
11435 /* Startup the kernel thread for this host adapter. */
11436 phba->worker_thread = kthread_run(lpfc_do_work, phba,
11437 "lpfc_worker_%d", phba->brd_no);
11438 if (IS_ERR(phba->worker_thread)) {
11439 error = PTR_ERR(phba->worker_thread);
11440 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11441 "0293 PM resume failed to start worker "
11442 "thread: error=x%x.\n", error);
11443 return error;
11444 }
11445
11446 /* Configure and enable interrupt */
11447 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
11448 if (intr_mode == LPFC_INTR_ERROR) {
11449 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11450 "0294 PM resume Failed to enable interrupt\n");
11451 return -EIO;
11452 } else
11453 phba->intr_mode = intr_mode;
11454
11455 /* Restart HBA and bring it online */
11456 lpfc_sli_brdrestart(phba);
11457 lpfc_online(phba);
11458
11459 /* Log the current active interrupt mode */
11460 lpfc_log_intr_mode(phba, phba->intr_mode);
11461
11462 return 0;
11463}
11464
11465/**
James Smart75baf692010-06-08 18:31:21 -040011466 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
11467 * @phba: pointer to lpfc hba data structure.
11468 *
11469 * This routine is called to prepare the SLI4 device for PCI slot recover. It
11470 * aborts all the outstanding SCSI I/Os to the pci device.
11471 **/
11472static void
11473lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
11474{
James Smart75baf692010-06-08 18:31:21 -040011475 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11476 "2828 PCI channel I/O abort preparing for recovery\n");
11477 /*
11478 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
11479 * and let the SCSI mid-layer to retry them to recover.
11480 */
James Smartdb55fba2014-04-04 13:52:02 -040011481 lpfc_sli_abort_fcp_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040011482}
11483
11484/**
11485 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
11486 * @phba: pointer to lpfc hba data structure.
11487 *
11488 * This routine is called to prepare the SLI4 device for PCI slot reset. It
11489 * disables the device interrupt and pci device, and aborts the internal FCP
11490 * pending I/Os.
11491 **/
11492static void
11493lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
11494{
11495 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11496 "2826 PCI channel disable preparing for reset\n");
11497
11498 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040011499 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -040011500
11501 /* Block all SCSI devices' I/Os on the host */
11502 lpfc_scsi_dev_block(phba);
11503
James Smartea714f32013-04-17 20:18:47 -040011504 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
11505 lpfc_sli_flush_fcp_rings(phba);
11506
James Smart75baf692010-06-08 18:31:21 -040011507 /* stop all timers */
11508 lpfc_stop_hba_timers(phba);
11509
11510 /* Disable interrupt and pci device */
11511 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040011512 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -040011513 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -040011514}
11515
11516/**
11517 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
11518 * @phba: pointer to lpfc hba data structure.
11519 *
11520 * This routine is called to prepare the SLI4 device for PCI slot permanently
11521 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
11522 * pending I/Os.
11523 **/
11524static void
11525lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
11526{
11527 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11528 "2827 PCI channel permanent disable for failure\n");
11529
11530 /* Block all SCSI devices' I/Os on the host */
11531 lpfc_scsi_dev_block(phba);
11532
11533 /* stop all timers */
11534 lpfc_stop_hba_timers(phba);
11535
11536 /* Clean up all driver's outstanding SCSI I/Os */
11537 lpfc_sli_flush_fcp_rings(phba);
11538}
11539
11540/**
James Smartda0436e2009-05-22 14:51:39 -040011541 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
11542 * @pdev: pointer to PCI device.
11543 * @state: the current PCI connection state.
11544 *
11545 * This routine is called from the PCI subsystem for error handling to device
11546 * with SLI-4 interface spec. This function is called by the PCI subsystem
11547 * after a PCI bus error affecting this device has been detected. When this
11548 * function is invoked, it will need to stop all the I/Os and interrupt(s)
11549 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
11550 * for the PCI subsystem to perform proper recovery as desired.
11551 *
11552 * Return codes
11553 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11554 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11555 **/
11556static pci_ers_result_t
11557lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
11558{
James Smart75baf692010-06-08 18:31:21 -040011559 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11560 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11561
11562 switch (state) {
11563 case pci_channel_io_normal:
11564 /* Non-fatal error, prepare for recovery */
11565 lpfc_sli4_prep_dev_for_recover(phba);
11566 return PCI_ERS_RESULT_CAN_RECOVER;
11567 case pci_channel_io_frozen:
11568 /* Fatal error, prepare for slot reset */
11569 lpfc_sli4_prep_dev_for_reset(phba);
11570 return PCI_ERS_RESULT_NEED_RESET;
11571 case pci_channel_io_perm_failure:
11572 /* Permanent failure, prepare for device down */
11573 lpfc_sli4_prep_dev_for_perm_failure(phba);
11574 return PCI_ERS_RESULT_DISCONNECT;
11575 default:
11576 /* Unknown state, prepare and request slot reset */
11577 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11578 "2825 Unknown PCI error state: x%x\n", state);
11579 lpfc_sli4_prep_dev_for_reset(phba);
11580 return PCI_ERS_RESULT_NEED_RESET;
11581 }
James Smartda0436e2009-05-22 14:51:39 -040011582}
11583
11584/**
11585 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
11586 * @pdev: pointer to PCI device.
11587 *
11588 * This routine is called from the PCI subsystem for error handling to device
11589 * with SLI-4 interface spec. It is called after PCI bus has been reset to
11590 * restart the PCI card from scratch, as if from a cold-boot. During the
11591 * PCI subsystem error recovery, after the driver returns
11592 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
11593 * recovery and then call this routine before calling the .resume method to
11594 * recover the device. This function will initialize the HBA device, enable
11595 * the interrupt, but it will just put the HBA to offline state without
11596 * passing any I/O traffic.
11597 *
11598 * Return codes
11599 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11600 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11601 */
11602static pci_ers_result_t
11603lpfc_io_slot_reset_s4(struct pci_dev *pdev)
11604{
James Smart75baf692010-06-08 18:31:21 -040011605 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11606 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11607 struct lpfc_sli *psli = &phba->sli;
11608 uint32_t intr_mode;
11609
11610 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
11611 if (pci_enable_device_mem(pdev)) {
11612 printk(KERN_ERR "lpfc: Cannot re-enable "
11613 "PCI device after reset.\n");
11614 return PCI_ERS_RESULT_DISCONNECT;
11615 }
11616
11617 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040011618
11619 /*
11620 * As the new kernel behavior of pci_restore_state() API call clears
11621 * device saved_state flag, need to save the restored state again.
11622 */
11623 pci_save_state(pdev);
11624
James Smart75baf692010-06-08 18:31:21 -040011625 if (pdev->is_busmaster)
11626 pci_set_master(pdev);
11627
11628 spin_lock_irq(&phba->hbalock);
11629 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
11630 spin_unlock_irq(&phba->hbalock);
11631
11632 /* Configure and enable interrupt */
11633 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
11634 if (intr_mode == LPFC_INTR_ERROR) {
11635 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11636 "2824 Cannot re-enable interrupt after "
11637 "slot reset.\n");
11638 return PCI_ERS_RESULT_DISCONNECT;
11639 } else
11640 phba->intr_mode = intr_mode;
11641
11642 /* Log the current active interrupt mode */
11643 lpfc_log_intr_mode(phba, phba->intr_mode);
11644
James Smartda0436e2009-05-22 14:51:39 -040011645 return PCI_ERS_RESULT_RECOVERED;
11646}
11647
11648/**
11649 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
11650 * @pdev: pointer to PCI device
11651 *
11652 * This routine is called from the PCI subsystem for error handling to device
11653 * with SLI-4 interface spec. It is called when kernel error recovery tells
11654 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
11655 * error recovery. After this call, traffic can start to flow from this device
11656 * again.
11657 **/
11658static void
11659lpfc_io_resume_s4(struct pci_dev *pdev)
11660{
James Smart75baf692010-06-08 18:31:21 -040011661 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11662 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11663
11664 /*
11665 * In case of slot reset, as function reset is performed through
11666 * mailbox command which needs DMA to be enabled, this operation
11667 * has to be moved to the io resume phase. Taking device offline
11668 * will perform the necessary cleanup.
11669 */
11670 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
11671 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040011672 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040011673 lpfc_offline(phba);
11674 lpfc_sli_brdrestart(phba);
11675 /* Bring the device back online */
11676 lpfc_online(phba);
11677 }
11678
11679 /* Clean up Advanced Error Reporting (AER) if needed */
11680 if (phba->hba_flag & HBA_AER_ENABLED)
11681 pci_cleanup_aer_uncorrect_error_status(pdev);
James Smartda0436e2009-05-22 14:51:39 -040011682}
11683
11684/**
James Smart3772a992009-05-22 14:50:54 -040011685 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
11686 * @pdev: pointer to PCI device
11687 * @pid: pointer to PCI device identifier
11688 *
11689 * This routine is to be registered to the kernel's PCI subsystem. When an
11690 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
11691 * at PCI device-specific information of the device and driver to see if the
11692 * driver state that it can support this kind of device. If the match is
11693 * successful, the driver core invokes this routine. This routine dispatches
11694 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
11695 * do all the initialization that it needs to do to handle the HBA device
11696 * properly.
11697 *
11698 * Return code
11699 * 0 - driver can claim the device
11700 * negative value - driver can not claim the device
11701 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011702static int
James Smart3772a992009-05-22 14:50:54 -040011703lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
11704{
11705 int rc;
James Smart8fa38512009-07-19 10:01:03 -040011706 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040011707
James Smart28baac72010-02-12 14:42:03 -050011708 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040011709 return -ENODEV;
11710
James Smart8fa38512009-07-19 10:01:03 -040011711 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050011712 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040011713 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040011714 else
James Smart3772a992009-05-22 14:50:54 -040011715 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040011716
James Smart3772a992009-05-22 14:50:54 -040011717 return rc;
11718}
11719
11720/**
11721 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
11722 * @pdev: pointer to PCI device
11723 *
11724 * This routine is to be registered to the kernel's PCI subsystem. When an
11725 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
11726 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
11727 * remove routine, which will perform all the necessary cleanup for the
11728 * device to be removed from the PCI subsystem properly.
11729 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011730static void
James Smart3772a992009-05-22 14:50:54 -040011731lpfc_pci_remove_one(struct pci_dev *pdev)
11732{
11733 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11734 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11735
11736 switch (phba->pci_dev_grp) {
11737 case LPFC_PCI_DEV_LP:
11738 lpfc_pci_remove_one_s3(pdev);
11739 break;
James Smartda0436e2009-05-22 14:51:39 -040011740 case LPFC_PCI_DEV_OC:
11741 lpfc_pci_remove_one_s4(pdev);
11742 break;
James Smart3772a992009-05-22 14:50:54 -040011743 default:
11744 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11745 "1424 Invalid PCI device group: 0x%x\n",
11746 phba->pci_dev_grp);
11747 break;
11748 }
11749 return;
11750}
11751
11752/**
11753 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
11754 * @pdev: pointer to PCI device
11755 * @msg: power management message
11756 *
11757 * This routine is to be registered to the kernel's PCI subsystem to support
11758 * system Power Management (PM). When PM invokes this method, it dispatches
11759 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
11760 * suspend the device.
11761 *
11762 * Return code
11763 * 0 - driver suspended the device
11764 * Error otherwise
11765 **/
11766static int
11767lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
11768{
11769 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11770 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11771 int rc = -ENODEV;
11772
11773 switch (phba->pci_dev_grp) {
11774 case LPFC_PCI_DEV_LP:
11775 rc = lpfc_pci_suspend_one_s3(pdev, msg);
11776 break;
James Smartda0436e2009-05-22 14:51:39 -040011777 case LPFC_PCI_DEV_OC:
11778 rc = lpfc_pci_suspend_one_s4(pdev, msg);
11779 break;
James Smart3772a992009-05-22 14:50:54 -040011780 default:
11781 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11782 "1425 Invalid PCI device group: 0x%x\n",
11783 phba->pci_dev_grp);
11784 break;
11785 }
11786 return rc;
11787}
11788
11789/**
11790 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
11791 * @pdev: pointer to PCI device
11792 *
11793 * This routine is to be registered to the kernel's PCI subsystem to support
11794 * system Power Management (PM). When PM invokes this method, it dispatches
11795 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
11796 * resume the device.
11797 *
11798 * Return code
11799 * 0 - driver suspended the device
11800 * Error otherwise
11801 **/
11802static int
11803lpfc_pci_resume_one(struct pci_dev *pdev)
11804{
11805 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11806 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11807 int rc = -ENODEV;
11808
11809 switch (phba->pci_dev_grp) {
11810 case LPFC_PCI_DEV_LP:
11811 rc = lpfc_pci_resume_one_s3(pdev);
11812 break;
James Smartda0436e2009-05-22 14:51:39 -040011813 case LPFC_PCI_DEV_OC:
11814 rc = lpfc_pci_resume_one_s4(pdev);
11815 break;
James Smart3772a992009-05-22 14:50:54 -040011816 default:
11817 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11818 "1426 Invalid PCI device group: 0x%x\n",
11819 phba->pci_dev_grp);
11820 break;
11821 }
11822 return rc;
11823}
11824
11825/**
11826 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
11827 * @pdev: pointer to PCI device.
11828 * @state: the current PCI connection state.
11829 *
11830 * This routine is registered to the PCI subsystem for error handling. This
11831 * function is called by the PCI subsystem after a PCI bus error affecting
11832 * this device has been detected. When this routine is invoked, it dispatches
11833 * the action to the proper SLI-3 or SLI-4 device error detected handling
11834 * routine, which will perform the proper error detected operation.
11835 *
11836 * Return codes
11837 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11838 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11839 **/
11840static pci_ers_result_t
11841lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
11842{
11843 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11844 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11845 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11846
11847 switch (phba->pci_dev_grp) {
11848 case LPFC_PCI_DEV_LP:
11849 rc = lpfc_io_error_detected_s3(pdev, state);
11850 break;
James Smartda0436e2009-05-22 14:51:39 -040011851 case LPFC_PCI_DEV_OC:
11852 rc = lpfc_io_error_detected_s4(pdev, state);
11853 break;
James Smart3772a992009-05-22 14:50:54 -040011854 default:
11855 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11856 "1427 Invalid PCI device group: 0x%x\n",
11857 phba->pci_dev_grp);
11858 break;
11859 }
11860 return rc;
11861}
11862
11863/**
11864 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
11865 * @pdev: pointer to PCI device.
11866 *
11867 * This routine is registered to the PCI subsystem for error handling. This
11868 * function is called after PCI bus has been reset to restart the PCI card
11869 * from scratch, as if from a cold-boot. When this routine is invoked, it
11870 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
11871 * routine, which will perform the proper device reset.
11872 *
11873 * Return codes
11874 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11875 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11876 **/
11877static pci_ers_result_t
11878lpfc_io_slot_reset(struct pci_dev *pdev)
11879{
11880 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11881 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11882 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11883
11884 switch (phba->pci_dev_grp) {
11885 case LPFC_PCI_DEV_LP:
11886 rc = lpfc_io_slot_reset_s3(pdev);
11887 break;
James Smartda0436e2009-05-22 14:51:39 -040011888 case LPFC_PCI_DEV_OC:
11889 rc = lpfc_io_slot_reset_s4(pdev);
11890 break;
James Smart3772a992009-05-22 14:50:54 -040011891 default:
11892 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11893 "1428 Invalid PCI device group: 0x%x\n",
11894 phba->pci_dev_grp);
11895 break;
11896 }
11897 return rc;
11898}
11899
11900/**
11901 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
11902 * @pdev: pointer to PCI device
11903 *
11904 * This routine is registered to the PCI subsystem for error handling. It
11905 * is called when kernel error recovery tells the lpfc driver that it is
11906 * OK to resume normal PCI operation after PCI bus error recovery. When
11907 * this routine is invoked, it dispatches the action to the proper SLI-3
11908 * or SLI-4 device io_resume routine, which will resume the device operation.
11909 **/
11910static void
11911lpfc_io_resume(struct pci_dev *pdev)
11912{
11913 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11914 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11915
11916 switch (phba->pci_dev_grp) {
11917 case LPFC_PCI_DEV_LP:
11918 lpfc_io_resume_s3(pdev);
11919 break;
James Smartda0436e2009-05-22 14:51:39 -040011920 case LPFC_PCI_DEV_OC:
11921 lpfc_io_resume_s4(pdev);
11922 break;
James Smart3772a992009-05-22 14:50:54 -040011923 default:
11924 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11925 "1429 Invalid PCI device group: 0x%x\n",
11926 phba->pci_dev_grp);
11927 break;
11928 }
11929 return;
11930}
11931
James Smart1ba981f2014-02-20 09:56:45 -050011932/**
11933 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
11934 * @phba: pointer to lpfc hba data structure.
11935 *
11936 * This routine checks to see if OAS is supported for this adapter. If
11937 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
11938 * the enable oas flag is cleared and the pool created for OAS device data
11939 * is destroyed.
11940 *
11941 **/
11942void
11943lpfc_sli4_oas_verify(struct lpfc_hba *phba)
11944{
11945
11946 if (!phba->cfg_EnableXLane)
11947 return;
11948
11949 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
11950 phba->cfg_fof = 1;
11951 } else {
James Smartf38fa0b2014-04-04 13:52:21 -040011952 phba->cfg_fof = 0;
James Smart1ba981f2014-02-20 09:56:45 -050011953 if (phba->device_data_mem_pool)
11954 mempool_destroy(phba->device_data_mem_pool);
11955 phba->device_data_mem_pool = NULL;
11956 }
11957
11958 return;
11959}
11960
11961/**
11962 * lpfc_fof_queue_setup - Set up all the fof queues
11963 * @phba: pointer to lpfc hba data structure.
11964 *
11965 * This routine is invoked to set up all the fof queues for the FC HBA
11966 * operation.
11967 *
11968 * Return codes
11969 * 0 - successful
11970 * -ENOMEM - No available memory
11971 **/
11972int
11973lpfc_fof_queue_setup(struct lpfc_hba *phba)
11974{
James Smart895427b2017-02-12 13:52:30 -080011975 struct lpfc_sli_ring *pring;
James Smart1ba981f2014-02-20 09:56:45 -050011976 int rc;
11977
11978 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
11979 if (rc)
11980 return -ENOMEM;
11981
James Smartf38fa0b2014-04-04 13:52:21 -040011982 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050011983
11984 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
11985 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
11986 if (rc)
11987 goto out_oas_cq;
11988
11989 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
11990 phba->sli4_hba.oas_cq, LPFC_FCP);
11991 if (rc)
11992 goto out_oas_wq;
11993
James Smart895427b2017-02-12 13:52:30 -080011994 /* Bind this CQ/WQ to the NVME ring */
11995 pring = phba->sli4_hba.oas_wq->pring;
11996 pring->sli.sli4.wqp =
11997 (void *)phba->sli4_hba.oas_wq;
11998 phba->sli4_hba.oas_cq->pring = pring;
James Smart1ba981f2014-02-20 09:56:45 -050011999 }
12000
12001 return 0;
12002
12003out_oas_wq:
James Smartf38fa0b2014-04-04 13:52:21 -040012004 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
James Smart1ba981f2014-02-20 09:56:45 -050012005out_oas_cq:
12006 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
12007 return rc;
12008
12009}
12010
12011/**
12012 * lpfc_fof_queue_create - Create all the fof queues
12013 * @phba: pointer to lpfc hba data structure.
12014 *
12015 * This routine is invoked to allocate all the fof queues for the FC HBA
12016 * operation. For each SLI4 queue type, the parameters such as queue entry
12017 * count (queue depth) shall be taken from the module parameter. For now,
12018 * we just use some constant number as place holder.
12019 *
12020 * Return codes
12021 * 0 - successful
12022 * -ENOMEM - No availble memory
12023 * -EIO - The mailbox failed to complete successfully.
12024 **/
12025int
12026lpfc_fof_queue_create(struct lpfc_hba *phba)
12027{
12028 struct lpfc_queue *qdesc;
12029
12030 /* Create FOF EQ */
12031 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
12032 phba->sli4_hba.eq_ecount);
12033 if (!qdesc)
12034 goto out_error;
12035
12036 phba->sli4_hba.fof_eq = qdesc;
12037
James Smartf38fa0b2014-04-04 13:52:21 -040012038 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050012039
12040 /* Create OAS CQ */
12041 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
12042 phba->sli4_hba.cq_ecount);
12043 if (!qdesc)
12044 goto out_error;
12045
12046 phba->sli4_hba.oas_cq = qdesc;
12047
12048 /* Create OAS WQ */
12049 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
12050 phba->sli4_hba.wq_ecount);
12051 if (!qdesc)
12052 goto out_error;
12053
12054 phba->sli4_hba.oas_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -080012055 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
James Smart1ba981f2014-02-20 09:56:45 -050012056
12057 }
12058 return 0;
12059
12060out_error:
12061 lpfc_fof_queue_destroy(phba);
12062 return -ENOMEM;
12063}
12064
12065/**
12066 * lpfc_fof_queue_destroy - Destroy all the fof queues
12067 * @phba: pointer to lpfc hba data structure.
12068 *
12069 * This routine is invoked to release all the SLI4 queues with the FC HBA
12070 * operation.
12071 *
12072 * Return codes
12073 * 0 - successful
12074 **/
12075int
12076lpfc_fof_queue_destroy(struct lpfc_hba *phba)
12077{
12078 /* Release FOF Event queue */
12079 if (phba->sli4_hba.fof_eq != NULL) {
12080 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
12081 phba->sli4_hba.fof_eq = NULL;
12082 }
12083
12084 /* Release OAS Completion queue */
12085 if (phba->sli4_hba.oas_cq != NULL) {
12086 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
12087 phba->sli4_hba.oas_cq = NULL;
12088 }
12089
12090 /* Release OAS Work queue */
12091 if (phba->sli4_hba.oas_wq != NULL) {
12092 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
12093 phba->sli4_hba.oas_wq = NULL;
12094 }
12095 return 0;
12096}
12097
dea31012005-04-17 16:05:31 -050012098MODULE_DEVICE_TABLE(pci, lpfc_id_table);
12099
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070012100static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060012101 .error_detected = lpfc_io_error_detected,
12102 .slot_reset = lpfc_io_slot_reset,
12103 .resume = lpfc_io_resume,
12104};
12105
dea31012005-04-17 16:05:31 -050012106static struct pci_driver lpfc_driver = {
12107 .name = LPFC_DRIVER_NAME,
12108 .id_table = lpfc_id_table,
12109 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012110 .remove = lpfc_pci_remove_one,
Anton Blanchard85e8a232017-02-13 08:49:20 +110012111 .shutdown = lpfc_pci_remove_one,
James Smart3a55b532008-12-04 22:38:54 -050012112 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040012113 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050012114 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050012115};
12116
James Smart3ef6d242012-01-18 16:23:48 -050012117static const struct file_operations lpfc_mgmt_fop = {
Al Viro858feac2013-04-14 22:39:37 -040012118 .owner = THIS_MODULE,
James Smart3ef6d242012-01-18 16:23:48 -050012119};
12120
12121static struct miscdevice lpfc_mgmt_dev = {
12122 .minor = MISC_DYNAMIC_MINOR,
12123 .name = "lpfcmgmt",
12124 .fops = &lpfc_mgmt_fop,
12125};
12126
James Smarte59058c2008-08-24 21:49:00 -040012127/**
James Smart3621a712009-04-06 18:47:14 -040012128 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040012129 *
12130 * This routine is to be invoked when the lpfc module is loaded into the
12131 * kernel. The special kernel macro module_init() is used to indicate the
12132 * role of this routine to the kernel as lpfc module entry point.
12133 *
12134 * Return codes
12135 * 0 - successful
12136 * -ENOMEM - FC attach transport failed
12137 * all others - failed
12138 */
dea31012005-04-17 16:05:31 -050012139static int __init
12140lpfc_init(void)
12141{
12142 int error = 0;
12143
12144 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012145 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050012146
James Smart3ef6d242012-01-18 16:23:48 -050012147 error = misc_register(&lpfc_mgmt_dev);
12148 if (error)
12149 printk(KERN_ERR "Could not register lpfcmgmt device, "
12150 "misc_register returned with status %d", error);
12151
James Smart458c0832016-07-06 12:36:07 -070012152 lpfc_transport_functions.vport_create = lpfc_vport_create;
12153 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
dea31012005-04-17 16:05:31 -050012154 lpfc_transport_template =
12155 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040012156 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050012157 return -ENOMEM;
James Smart458c0832016-07-06 12:36:07 -070012158 lpfc_vport_transport_template =
12159 fc_attach_transport(&lpfc_vport_transport_functions);
12160 if (lpfc_vport_transport_template == NULL) {
12161 fc_release_transport(lpfc_transport_template);
12162 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040012163 }
James Smart7bb03bb2013-04-17 20:19:16 -040012164
12165 /* Initialize in case vector mapping is needed */
James Smartb246de12013-05-31 17:03:07 -040012166 lpfc_used_cpu = NULL;
James Smart2ea259e2017-02-12 13:52:27 -080012167 lpfc_present_cpu = num_present_cpus();
James Smart7bb03bb2013-04-17 20:19:16 -040012168
dea31012005-04-17 16:05:31 -050012169 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050012170 if (error) {
dea31012005-04-17 16:05:31 -050012171 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070012172 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050012173 }
dea31012005-04-17 16:05:31 -050012174
12175 return error;
12176}
12177
James Smarte59058c2008-08-24 21:49:00 -040012178/**
James Smart3621a712009-04-06 18:47:14 -040012179 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040012180 *
12181 * This routine is invoked when the lpfc module is removed from the kernel.
12182 * The special kernel macro module_exit() is used to indicate the role of
12183 * this routine to the kernel as lpfc module exit point.
12184 */
dea31012005-04-17 16:05:31 -050012185static void __exit
12186lpfc_exit(void)
12187{
James Smart3ef6d242012-01-18 16:23:48 -050012188 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050012189 pci_unregister_driver(&lpfc_driver);
12190 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070012191 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050012192 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040012193 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
12194 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050012195 (1L << _dump_buf_data_order), _dump_buf_data);
12196 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
12197 }
12198
12199 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040012200 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
12201 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050012202 (1L << _dump_buf_dif_order), _dump_buf_dif);
12203 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
12204 }
James Smartb246de12013-05-31 17:03:07 -040012205 kfree(lpfc_used_cpu);
Johannes Thumshirn79739672015-08-31 16:48:11 -040012206 idr_destroy(&lpfc_hba_index);
dea31012005-04-17 16:05:31 -050012207}
12208
12209module_init(lpfc_init);
12210module_exit(lpfc_exit);
12211MODULE_LICENSE("GPL");
12212MODULE_DESCRIPTION(LPFC_MODULE_DESC);
James Smartd080abe2017-02-12 13:52:39 -080012213MODULE_AUTHOR("Broadcom");
dea31012005-04-17 16:05:31 -050012214MODULE_VERSION("0:" LPFC_DRIVER_VERSION);