blob: 5eafd0db758dd541c54d3548895c6d616e79a8f4 [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 Smart50611572016-03-31 14:12:34 -07004 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/delay.h>
24#include <linux/dma-mapping.h>
25#include <linux/idr.h>
26#include <linux/interrupt.h>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040027#include <linux/module.h>
dea31012005-04-17 16:05:31 -050028#include <linux/kthread.h>
29#include <linux/pci.h>
30#include <linux/spinlock.h>
James Smart92d7f7b2007-06-17 19:56:38 -050031#include <linux/ctype.h>
James Smart0d878412009-10-02 15:16:56 -040032#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
James Smart52d52442011-05-24 11:42:45 -040034#include <linux/firmware.h>
James Smart3ef6d242012-01-18 16:23:48 -050035#include <linux/miscdevice.h>
James Smart7bb03bb2013-04-17 20:19:16 -040036#include <linux/percpu.h>
James Smart895427b2017-02-12 13:52:30 -080037#include <linux/msi.h>
dea31012005-04-17 16:05:31 -050038
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040039#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050040#include <scsi/scsi_device.h>
41#include <scsi/scsi_host.h>
42#include <scsi/scsi_transport_fc.h>
43
James Smartda0436e2009-05-22 14:51:39 -040044#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050045#include "lpfc_hw.h"
46#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040047#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040048#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050049#include "lpfc_disc.h"
dea31012005-04-17 16:05:31 -050050#include "lpfc.h"
James Smart895427b2017-02-12 13:52:30 -080051#include "lpfc_scsi.h"
52#include "lpfc_nvme.h"
dea31012005-04-17 16:05:31 -050053#include "lpfc_logmsg.h"
54#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050055#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050056#include "lpfc_version.h"
James Smart12f44452016-07-06 12:36:03 -070057#include "lpfc_ids.h"
dea31012005-04-17 16:05:31 -050058
James Smart81301a92008-12-04 22:39:46 -050059char *_dump_buf_data;
60unsigned long _dump_buf_data_order;
61char *_dump_buf_dif;
62unsigned long _dump_buf_dif_order;
63spinlock_t _dump_buf_lock;
64
James Smart7bb03bb2013-04-17 20:19:16 -040065/* Used when mapping IRQ vectors in a driver centric manner */
James Smartb246de12013-05-31 17:03:07 -040066uint16_t *lpfc_used_cpu;
67uint32_t lpfc_present_cpu;
James Smart7bb03bb2013-04-17 20:19:16 -040068
dea31012005-04-17 16:05:31 -050069static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
70static int lpfc_post_rcv_buf(struct lpfc_hba *);
James Smart5350d872011-10-10 21:33:49 -040071static int lpfc_sli4_queue_verify(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040072static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
73static int lpfc_setup_endian_order(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040074static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040075static void lpfc_free_els_sgl_list(struct lpfc_hba *);
James Smartf358dd02017-02-12 13:52:34 -080076static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *);
James Smart8a9d2e82012-05-09 21:16:12 -040077static void lpfc_init_sgl_list(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040078static int lpfc_init_active_sgl_array(struct lpfc_hba *);
79static void lpfc_free_active_sgl(struct lpfc_hba *);
80static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
81static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
82static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
83static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
84static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
James Smart618a5232012-06-12 13:54:36 -040085static void lpfc_sli4_disable_intr(struct lpfc_hba *);
86static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
James Smart1ba981f2014-02-20 09:56:45 -050087static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
dea31012005-04-17 16:05:31 -050088
89static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050090static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -050091static DEFINE_IDR(lpfc_hba_index);
James Smartf358dd02017-02-12 13:52:34 -080092#define LPFC_NVMET_BUF_POST 254
dea31012005-04-17 16:05:31 -050093
James Smarte59058c2008-08-24 21:49:00 -040094/**
James Smart3621a712009-04-06 18:47:14 -040095 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
James Smarte59058c2008-08-24 21:49:00 -040096 * @phba: pointer to lpfc hba data structure.
97 *
98 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
99 * mailbox command. It retrieves the revision information from the HBA and
100 * collects the Vital Product Data (VPD) about the HBA for preparing the
101 * configuration of the HBA.
102 *
103 * Return codes:
104 * 0 - success.
105 * -ERESTART - requests the SLI layer to reset the HBA and try again.
106 * Any other value - indicates an error.
107 **/
dea31012005-04-17 16:05:31 -0500108int
James Smart2e0fef82007-06-17 19:56:36 -0500109lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500110{
111 lpfc_vpd_t *vp = &phba->vpd;
112 int i = 0, rc;
113 LPFC_MBOXQ_t *pmb;
114 MAILBOX_t *mb;
115 char *lpfc_vpd_data = NULL;
116 uint16_t offset = 0;
117 static char licensed[56] =
118 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -0400119 static int init_key = 1;
dea31012005-04-17 16:05:31 -0500120
121 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
122 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500123 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500124 return -ENOMEM;
125 }
126
James Smart04c68492009-05-22 14:52:52 -0400127 mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -0500128 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -0500129
130 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -0400131 if (init_key) {
132 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -0500133
James Smart65a29c12006-07-06 15:50:50 -0400134 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
135 *ptext = cpu_to_be32(*ptext);
136 init_key = 0;
137 }
dea31012005-04-17 16:05:31 -0500138
139 lpfc_read_nv(phba, pmb);
140 memset((char*)mb->un.varRDnvp.rsvd3, 0,
141 sizeof (mb->un.varRDnvp.rsvd3));
142 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
143 sizeof (licensed));
144
145 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
146
147 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500148 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400149 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500150 "error, mbxCmd x%x READ_NVPARM, "
151 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500152 mb->mbxCommand, mb->mbxStatus);
153 mempool_free(pmb, phba->mbox_mem_pool);
154 return -ERESTART;
155 }
156 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500157 sizeof(phba->wwnn));
158 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
159 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500160 }
161
James Smart92d7f7b2007-06-17 19:56:38 -0500162 phba->sli3_options = 0x0;
163
dea31012005-04-17 16:05:31 -0500164 /* Setup and issue mailbox READ REV command */
165 lpfc_read_rev(phba, pmb);
166 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
167 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500168 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400169 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500170 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500171 mb->mbxCommand, mb->mbxStatus);
172 mempool_free( pmb, phba->mbox_mem_pool);
173 return -ERESTART;
174 }
175
James Smart92d7f7b2007-06-17 19:56:38 -0500176
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500177 /*
178 * The value of rr must be 1 since the driver set the cv field to 1.
179 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500180 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500181 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500182 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500183 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400184 "0440 Adapter failed to init, READ_REV has "
185 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500186 mempool_free(pmb, phba->mbox_mem_pool);
187 return -ERESTART;
dea31012005-04-17 16:05:31 -0500188 }
189
James Smart495a7142008-06-14 22:52:59 -0400190 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
191 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500192 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400193 }
James Smarted957682007-06-17 19:56:37 -0500194
dea31012005-04-17 16:05:31 -0500195 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500196 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500197 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500198 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
199 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
200 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
201 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500202 vp->rev.biuRev = mb->un.varRdRev.biuRev;
203 vp->rev.smRev = mb->un.varRdRev.smRev;
204 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
205 vp->rev.endecRev = mb->un.varRdRev.endecRev;
206 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
207 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
208 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
209 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
210 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
211 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
212
James Smart92d7f7b2007-06-17 19:56:38 -0500213 /* If the sli feature level is less then 9, we must
214 * tear down all RPIs and VPIs on link down if NPIV
215 * is enabled.
216 */
217 if (vp->rev.feaLevelHigh < 9)
218 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
219
dea31012005-04-17 16:05:31 -0500220 if (lpfc_is_LC_HBA(phba->pcidev->device))
221 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
222 sizeof (phba->RandomData));
223
dea31012005-04-17 16:05:31 -0500224 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500225 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
226 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400227 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500228 do {
James Smarta0c87cb2009-07-19 10:01:10 -0400229 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
dea31012005-04-17 16:05:31 -0500230 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
231
232 if (rc != MBX_SUCCESS) {
233 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400234 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500235 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500236 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500237 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500238 }
James Smart04c68492009-05-22 14:52:52 -0400239 /* dump mem may return a zero when finished or we got a
240 * mailbox error, either way we are done.
241 */
242 if (mb->un.varDmp.word_cnt == 0)
243 break;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500244 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
245 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400246 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
247 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500248 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500249 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500250 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
251 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500252
253 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500254out_free_mbox:
255 mempool_free(pmb, phba->mbox_mem_pool);
256 return 0;
257}
258
James Smarte59058c2008-08-24 21:49:00 -0400259/**
James Smart3621a712009-04-06 18:47:14 -0400260 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
James Smarte59058c2008-08-24 21:49:00 -0400261 * @phba: pointer to lpfc hba data structure.
262 * @pmboxq: pointer to the driver internal queue element for mailbox command.
263 *
264 * This is the completion handler for driver's configuring asynchronous event
265 * mailbox command to the device. If the mailbox command returns successfully,
266 * it will set internal async event support flag to 1; otherwise, it will
267 * set internal async event support flag to 0.
268 **/
James Smart57127f12007-10-27 13:37:05 -0400269static void
270lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
271{
James Smart04c68492009-05-22 14:52:52 -0400272 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
James Smart57127f12007-10-27 13:37:05 -0400273 phba->temp_sensor_support = 1;
274 else
275 phba->temp_sensor_support = 0;
276 mempool_free(pmboxq, phba->mbox_mem_pool);
277 return;
278}
279
James Smarte59058c2008-08-24 21:49:00 -0400280/**
James Smart3621a712009-04-06 18:47:14 -0400281 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
James Smart97207482008-12-04 22:39:19 -0500282 * @phba: pointer to lpfc hba data structure.
283 * @pmboxq: pointer to the driver internal queue element for mailbox command.
284 *
285 * This is the completion handler for dump mailbox command for getting
286 * wake up parameters. When this command complete, the response contain
287 * Option rom version of the HBA. This function translate the version number
288 * into a human readable string and store it in OptionROMVersion.
289 **/
290static void
291lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
292{
293 struct prog_id *prg;
294 uint32_t prog_id_word;
295 char dist = ' ';
296 /* character array used for decoding dist type. */
297 char dist_char[] = "nabx";
298
James Smart04c68492009-05-22 14:52:52 -0400299 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
James Smart9f1e1b52008-12-04 22:39:40 -0500300 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500301 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500302 }
James Smart97207482008-12-04 22:39:19 -0500303
304 prg = (struct prog_id *) &prog_id_word;
305
306 /* word 7 contain option rom version */
James Smart04c68492009-05-22 14:52:52 -0400307 prog_id_word = pmboxq->u.mb.un.varWords[7];
James Smart97207482008-12-04 22:39:19 -0500308
309 /* Decode the Option rom version word to a readable string */
310 if (prg->dist < 4)
311 dist = dist_char[prg->dist];
312
313 if ((prg->dist == 3) && (prg->num == 0))
James Smarta2fc4aef2014-09-03 12:57:55 -0400314 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
James Smart97207482008-12-04 22:39:19 -0500315 prg->ver, prg->rev, prg->lev);
316 else
James Smarta2fc4aef2014-09-03 12:57:55 -0400317 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
James Smart97207482008-12-04 22:39:19 -0500318 prg->ver, prg->rev, prg->lev,
319 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500320 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500321 return;
322}
323
324/**
James Smart05580562011-05-24 11:40:48 -0400325 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
326 * cfg_soft_wwnn, cfg_soft_wwpn
327 * @vport: pointer to lpfc vport data structure.
328 *
329 *
330 * Return codes
331 * None.
332 **/
333void
334lpfc_update_vport_wwn(struct lpfc_vport *vport)
335{
336 /* If the soft name exists then update it using the service params */
337 if (vport->phba->cfg_soft_wwnn)
338 u64_to_wwn(vport->phba->cfg_soft_wwnn,
339 vport->fc_sparam.nodeName.u.wwn);
340 if (vport->phba->cfg_soft_wwpn)
341 u64_to_wwn(vport->phba->cfg_soft_wwpn,
342 vport->fc_sparam.portName.u.wwn);
343
344 /*
345 * If the name is empty or there exists a soft name
346 * then copy the service params name, otherwise use the fc name
347 */
348 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
349 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
350 sizeof(struct lpfc_name));
351 else
352 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
353 sizeof(struct lpfc_name));
354
355 if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn)
356 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
357 sizeof(struct lpfc_name));
358 else
359 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
360 sizeof(struct lpfc_name));
361}
362
363/**
James Smart3621a712009-04-06 18:47:14 -0400364 * lpfc_config_port_post - Perform lpfc initialization after config port
James Smarte59058c2008-08-24 21:49:00 -0400365 * @phba: pointer to lpfc hba data structure.
366 *
367 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
368 * command call. It performs all internal resource and state setups on the
369 * port: post IOCB buffers, enable appropriate host interrupt attentions,
370 * ELS ring timers, etc.
371 *
372 * Return codes
373 * 0 - success.
374 * Any other value - error.
375 **/
dea31012005-04-17 16:05:31 -0500376int
James Smart2e0fef82007-06-17 19:56:36 -0500377lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500378{
James Smart2e0fef82007-06-17 19:56:36 -0500379 struct lpfc_vport *vport = phba->pport;
James Smarta257bf92009-04-06 18:48:10 -0400380 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500381 LPFC_MBOXQ_t *pmb;
382 MAILBOX_t *mb;
383 struct lpfc_dmabuf *mp;
384 struct lpfc_sli *psli = &phba->sli;
385 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500386 int i, j;
387 int rc;
dea31012005-04-17 16:05:31 -0500388
James Smart7af67052007-10-27 13:38:11 -0400389 spin_lock_irq(&phba->hbalock);
390 /*
391 * If the Config port completed correctly the HBA is not
392 * over heated any more.
393 */
394 if (phba->over_temp_state == HBA_OVER_TEMP)
395 phba->over_temp_state = HBA_NORMAL_TEMP;
396 spin_unlock_irq(&phba->hbalock);
397
dea31012005-04-17 16:05:31 -0500398 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
399 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500400 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500401 return -ENOMEM;
402 }
James Smart04c68492009-05-22 14:52:52 -0400403 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500404
dea31012005-04-17 16:05:31 -0500405 /* Get login parameters for NID. */
James Smart9f1177a2010-02-26 14:12:57 -0500406 rc = lpfc_read_sparam(phba, pmb, 0);
407 if (rc) {
408 mempool_free(pmb, phba->mbox_mem_pool);
409 return -ENOMEM;
410 }
411
James Smarted957682007-06-17 19:56:37 -0500412 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500413 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500414 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400415 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500416 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500417 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500418 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500419 mp = (struct lpfc_dmabuf *) pmb->context1;
James Smart9f1177a2010-02-26 14:12:57 -0500420 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500421 lpfc_mbuf_free(phba, mp->virt, mp->phys);
422 kfree(mp);
423 return -EIO;
424 }
425
426 mp = (struct lpfc_dmabuf *) pmb->context1;
427
James Smart2e0fef82007-06-17 19:56:36 -0500428 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500429 lpfc_mbuf_free(phba, mp->virt, mp->phys);
430 kfree(mp);
431 pmb->context1 = NULL;
James Smart05580562011-05-24 11:40:48 -0400432 lpfc_update_vport_wwn(vport);
James Smarta257bf92009-04-06 18:48:10 -0400433
434 /* Update the fc_host data structures with new wwn. */
435 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
436 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart21e9a0a2009-05-22 14:53:21 -0400437 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smarta257bf92009-04-06 18:48:10 -0400438
dea31012005-04-17 16:05:31 -0500439 /* If no serial number in VPD data, use low 6 bytes of WWNN */
440 /* This should be consolidated into parse_vpd ? - mr */
441 if (phba->SerialNumber[0] == 0) {
442 uint8_t *outptr;
443
James Smart2e0fef82007-06-17 19:56:36 -0500444 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500445 for (i = 0; i < 12; i++) {
446 status = *outptr++;
447 j = ((status & 0xf0) >> 4);
448 if (j <= 9)
449 phba->SerialNumber[i] =
450 (char)((uint8_t) 0x30 + (uint8_t) j);
451 else
452 phba->SerialNumber[i] =
453 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
454 i++;
455 j = (status & 0xf);
456 if (j <= 9)
457 phba->SerialNumber[i] =
458 (char)((uint8_t) 0x30 + (uint8_t) j);
459 else
460 phba->SerialNumber[i] =
461 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
462 }
463 }
464
dea31012005-04-17 16:05:31 -0500465 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500466 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500467 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500468 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400469 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500470 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500471 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500472 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500473 mempool_free( pmb, phba->mbox_mem_pool);
474 return -EIO;
475 }
476
James Smarta0c87cb2009-07-19 10:01:10 -0400477 /* Check if the port is disabled */
478 lpfc_sli_read_link_ste(phba);
479
dea31012005-04-17 16:05:31 -0500480 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -0400481 i = (mb->un.varRdConfig.max_xri + 1);
482 if (phba->cfg_hba_queue_depth > i) {
483 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
484 "3359 HBA queue depth changed from %d to %d\n",
485 phba->cfg_hba_queue_depth, i);
486 phba->cfg_hba_queue_depth = i;
487 }
488
489 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
490 i = (mb->un.varRdConfig.max_xri >> 3);
491 if (phba->pport->cfg_lun_queue_depth > i) {
492 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
493 "3360 LUN queue depth changed from %d to %d\n",
494 phba->pport->cfg_lun_queue_depth, i);
495 phba->pport->cfg_lun_queue_depth = i;
496 }
dea31012005-04-17 16:05:31 -0500497
498 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500499
500 /* Get the default values for Model Name and Description */
501 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
502
James Smart2e0fef82007-06-17 19:56:36 -0500503 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500504
James Smart0b727fe2007-10-27 13:37:25 -0400505 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smart895427b2017-02-12 13:52:30 -0800506 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
507 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
508 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
509 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500510
511 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500512 if (phba->sli_rev != 3)
513 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500514
James Smart93996272008-08-24 21:50:30 -0400515 /*
516 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
517 */
518 if (phba->intr_type == MSIX) {
519 rc = lpfc_config_msi(phba, pmb);
520 if (rc) {
521 mempool_free(pmb, phba->mbox_mem_pool);
522 return -EIO;
523 }
524 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
525 if (rc != MBX_SUCCESS) {
526 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
527 "0352 Config MSI mailbox command "
528 "failed, mbxCmd x%x, mbxStatus x%x\n",
James Smart04c68492009-05-22 14:52:52 -0400529 pmb->u.mb.mbxCommand,
530 pmb->u.mb.mbxStatus);
James Smart93996272008-08-24 21:50:30 -0400531 mempool_free(pmb, phba->mbox_mem_pool);
532 return -EIO;
533 }
534 }
535
James Smart04c68492009-05-22 14:52:52 -0400536 spin_lock_irq(&phba->hbalock);
James Smart93996272008-08-24 21:50:30 -0400537 /* Initialize ERATT handling flag */
538 phba->hba_flag &= ~HBA_ERATT_HANDLED;
539
dea31012005-04-17 16:05:31 -0500540 /* Enable appropriate host interrupts */
James Smart9940b972011-03-11 16:06:12 -0500541 if (lpfc_readl(phba->HCregaddr, &status)) {
542 spin_unlock_irq(&phba->hbalock);
543 return -EIO;
544 }
dea31012005-04-17 16:05:31 -0500545 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
546 if (psli->num_rings > 0)
547 status |= HC_R0INT_ENA;
548 if (psli->num_rings > 1)
549 status |= HC_R1INT_ENA;
550 if (psli->num_rings > 2)
551 status |= HC_R2INT_ENA;
552 if (psli->num_rings > 3)
553 status |= HC_R3INT_ENA;
554
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500555 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
556 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400557 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500558
dea31012005-04-17 16:05:31 -0500559 writel(status, phba->HCregaddr);
560 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500561 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500562
James Smart93996272008-08-24 21:50:30 -0400563 /* Set up ring-0 (ELS) timer */
564 timeout = phba->fc_ratov * 2;
James Smart256ec0d2013-04-17 20:14:58 -0400565 mod_timer(&vport->els_tmofunc,
566 jiffies + msecs_to_jiffies(1000 * timeout));
James Smart93996272008-08-24 21:50:30 -0400567 /* Set up heart beat (HB) timer */
James Smart256ec0d2013-04-17 20:14:58 -0400568 mod_timer(&phba->hb_tmofunc,
569 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -0500570 phba->hb_outstanding = 0;
571 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400572 /* Set up error attention (ERATT) polling timer */
James Smart256ec0d2013-04-17 20:14:58 -0400573 mod_timer(&phba->eratt_poll,
James Smart65791f12016-07-06 12:35:56 -0700574 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
dea31012005-04-17 16:05:31 -0500575
James Smarta0c87cb2009-07-19 10:01:10 -0400576 if (phba->hba_flag & LINK_DISABLED) {
577 lpfc_printf_log(phba,
578 KERN_ERR, LOG_INIT,
579 "2598 Adapter Link is disabled.\n");
580 lpfc_down_link(phba, pmb);
581 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
582 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
583 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
584 lpfc_printf_log(phba,
585 KERN_ERR, LOG_INIT,
586 "2599 Adapter failed to issue DOWN_LINK"
587 " mbox command rc 0x%x\n", rc);
588
589 mempool_free(pmb, phba->mbox_mem_pool);
590 return -EIO;
591 }
James Smarte40a02c2010-02-26 14:13:54 -0500592 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
James Smart026abb82011-12-13 13:20:45 -0500593 mempool_free(pmb, phba->mbox_mem_pool);
594 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
595 if (rc)
596 return rc;
dea31012005-04-17 16:05:31 -0500597 }
598 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400599 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500600 if (!pmb) {
601 phba->link_state = LPFC_HBA_ERROR;
602 return -ENOMEM;
603 }
604
James Smart57127f12007-10-27 13:37:05 -0400605 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
606 pmb->mbox_cmpl = lpfc_config_async_cmpl;
607 pmb->vport = phba->pport;
608 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500609
James Smart57127f12007-10-27 13:37:05 -0400610 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
611 lpfc_printf_log(phba,
612 KERN_ERR,
613 LOG_INIT,
614 "0456 Adapter failed to issue "
James Smarte4e74272009-07-19 10:01:38 -0400615 "ASYNCEVT_ENABLE mbox status x%x\n",
James Smart57127f12007-10-27 13:37:05 -0400616 rc);
617 mempool_free(pmb, phba->mbox_mem_pool);
618 }
James Smart97207482008-12-04 22:39:19 -0500619
620 /* Get Option rom version */
621 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500622 if (!pmb) {
623 phba->link_state = LPFC_HBA_ERROR;
624 return -ENOMEM;
625 }
626
James Smart97207482008-12-04 22:39:19 -0500627 lpfc_dump_wakeup_param(phba, pmb);
628 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
629 pmb->vport = phba->pport;
630 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
631
632 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
633 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
James Smarte4e74272009-07-19 10:01:38 -0400634 "to get Option ROM version status x%x\n", rc);
James Smart97207482008-12-04 22:39:19 -0500635 mempool_free(pmb, phba->mbox_mem_pool);
636 }
637
James Smartd7c255b2008-08-24 21:50:00 -0400638 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400639}
640
James Smarte59058c2008-08-24 21:49:00 -0400641/**
James Smart84d1b002010-02-12 14:42:33 -0500642 * lpfc_hba_init_link - Initialize the FC link
643 * @phba: pointer to lpfc hba data structure.
James Smart6e7288d2010-06-07 15:23:35 -0400644 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500645 *
646 * This routine will issue the INIT_LINK mailbox command call.
647 * It is available to other drivers through the lpfc_hba data
648 * structure for use as a delayed link up mechanism with the
649 * module parameter lpfc_suppress_link_up.
650 *
651 * Return code
652 * 0 - success
653 * Any other value - error
654 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400655static int
James Smart6e7288d2010-06-07 15:23:35 -0400656lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500657{
James Smart1b511972011-12-13 13:23:09 -0500658 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
659}
660
661/**
662 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
663 * @phba: pointer to lpfc hba data structure.
664 * @fc_topology: desired fc topology.
665 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
666 *
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 **/
676int
677lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
678 uint32_t flag)
679{
James Smart84d1b002010-02-12 14:42:33 -0500680 struct lpfc_vport *vport = phba->pport;
681 LPFC_MBOXQ_t *pmb;
682 MAILBOX_t *mb;
683 int rc;
684
685 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
686 if (!pmb) {
687 phba->link_state = LPFC_HBA_ERROR;
688 return -ENOMEM;
689 }
690 mb = &pmb->u.mb;
691 pmb->vport = vport;
692
James Smart026abb82011-12-13 13:20:45 -0500693 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
694 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
695 !(phba->lmt & LMT_1Gb)) ||
696 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
697 !(phba->lmt & LMT_2Gb)) ||
698 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
699 !(phba->lmt & LMT_4Gb)) ||
700 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
701 !(phba->lmt & LMT_8Gb)) ||
702 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
703 !(phba->lmt & LMT_10Gb)) ||
704 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
James Smartd38dd522015-08-31 16:48:17 -0400705 !(phba->lmt & LMT_16Gb)) ||
706 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
707 !(phba->lmt & LMT_32Gb))) {
James Smart026abb82011-12-13 13:20:45 -0500708 /* Reset link speed to auto */
709 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
710 "1302 Invalid speed for this board:%d "
711 "Reset link speed to auto.\n",
712 phba->cfg_link_speed);
713 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
714 }
James Smart1b511972011-12-13 13:23:09 -0500715 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
James Smart84d1b002010-02-12 14:42:33 -0500716 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart1b511972011-12-13 13:23:09 -0500717 if (phba->sli_rev < LPFC_SLI_REV4)
718 lpfc_set_loopback_flag(phba);
James Smart6e7288d2010-06-07 15:23:35 -0400719 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart76a95d72010-11-20 23:11:48 -0500720 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
James Smart84d1b002010-02-12 14:42:33 -0500721 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
722 "0498 Adapter failed to init, mbxCmd x%x "
723 "INIT_LINK, mbxStatus x%x\n",
724 mb->mbxCommand, mb->mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -0500725 if (phba->sli_rev <= LPFC_SLI_REV3) {
726 /* Clear all interrupt enable conditions */
727 writel(0, phba->HCregaddr);
728 readl(phba->HCregaddr); /* flush */
729 /* Clear all pending interrupts */
730 writel(0xffffffff, phba->HAregaddr);
731 readl(phba->HAregaddr); /* flush */
732 }
James Smart84d1b002010-02-12 14:42:33 -0500733 phba->link_state = LPFC_HBA_ERROR;
James Smart6e7288d2010-06-07 15:23:35 -0400734 if (rc != MBX_BUSY || flag == MBX_POLL)
James Smart84d1b002010-02-12 14:42:33 -0500735 mempool_free(pmb, phba->mbox_mem_pool);
736 return -EIO;
737 }
James Smarte40a02c2010-02-26 14:13:54 -0500738 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
James Smart6e7288d2010-06-07 15:23:35 -0400739 if (flag == MBX_POLL)
740 mempool_free(pmb, phba->mbox_mem_pool);
James Smart84d1b002010-02-12 14:42:33 -0500741
742 return 0;
743}
744
745/**
746 * lpfc_hba_down_link - this routine downs the FC link
James Smart6e7288d2010-06-07 15:23:35 -0400747 * @phba: pointer to lpfc hba data structure.
748 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500749 *
750 * This routine will issue the DOWN_LINK mailbox command call.
751 * It is available to other drivers through the lpfc_hba data
752 * structure for use to stop the link.
753 *
754 * Return code
755 * 0 - success
756 * Any other value - error
757 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400758static int
James Smart6e7288d2010-06-07 15:23:35 -0400759lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500760{
761 LPFC_MBOXQ_t *pmb;
762 int rc;
763
764 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
765 if (!pmb) {
766 phba->link_state = LPFC_HBA_ERROR;
767 return -ENOMEM;
768 }
769
770 lpfc_printf_log(phba,
771 KERN_ERR, LOG_INIT,
772 "0491 Adapter Link is disabled.\n");
773 lpfc_down_link(phba, pmb);
774 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart6e7288d2010-06-07 15:23:35 -0400775 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart84d1b002010-02-12 14:42:33 -0500776 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
777 lpfc_printf_log(phba,
778 KERN_ERR, LOG_INIT,
779 "2522 Adapter failed to issue DOWN_LINK"
780 " mbox command rc 0x%x\n", rc);
781
782 mempool_free(pmb, phba->mbox_mem_pool);
783 return -EIO;
784 }
James Smart6e7288d2010-06-07 15:23:35 -0400785 if (flag == MBX_POLL)
786 mempool_free(pmb, phba->mbox_mem_pool);
787
James Smart84d1b002010-02-12 14:42:33 -0500788 return 0;
789}
790
791/**
James Smart3621a712009-04-06 18:47:14 -0400792 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400793 * @phba: pointer to lpfc HBA data structure.
794 *
795 * This routine will do LPFC uninitialization before the HBA is reset when
796 * bringing down the SLI Layer.
797 *
798 * Return codes
799 * 0 - success.
800 * Any other value - error.
801 **/
dea31012005-04-17 16:05:31 -0500802int
James Smart2e0fef82007-06-17 19:56:36 -0500803lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500804{
James Smart1b32f6a2008-02-08 18:49:39 -0500805 struct lpfc_vport **vports;
806 int i;
James Smart3772a992009-05-22 14:50:54 -0400807
808 if (phba->sli_rev <= LPFC_SLI_REV3) {
809 /* Disable interrupts */
810 writel(0, phba->HCregaddr);
811 readl(phba->HCregaddr); /* flush */
812 }
dea31012005-04-17 16:05:31 -0500813
James Smart1b32f6a2008-02-08 18:49:39 -0500814 if (phba->pport->load_flag & FC_UNLOADING)
815 lpfc_cleanup_discovery_resources(phba->pport);
816 else {
817 vports = lpfc_create_vport_work_array(phba);
818 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -0400819 for (i = 0; i <= phba->max_vports &&
820 vports[i] != NULL; i++)
James Smart1b32f6a2008-02-08 18:49:39 -0500821 lpfc_cleanup_discovery_resources(vports[i]);
822 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500823 }
824 return 0;
dea31012005-04-17 16:05:31 -0500825}
826
James Smarte59058c2008-08-24 21:49:00 -0400827/**
James Smart68e814f2014-05-21 08:04:59 -0400828 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
829 * rspiocb which got deferred
830 *
831 * @phba: pointer to lpfc HBA data structure.
832 *
833 * This routine will cleanup completed slow path events after HBA is reset
834 * when bringing down the SLI Layer.
835 *
836 *
837 * Return codes
838 * void.
839 **/
840static void
841lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
842{
843 struct lpfc_iocbq *rspiocbq;
844 struct hbq_dmabuf *dmabuf;
845 struct lpfc_cq_event *cq_event;
846
847 spin_lock_irq(&phba->hbalock);
848 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
849 spin_unlock_irq(&phba->hbalock);
850
851 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
852 /* Get the response iocb from the head of work queue */
853 spin_lock_irq(&phba->hbalock);
854 list_remove_head(&phba->sli4_hba.sp_queue_event,
855 cq_event, struct lpfc_cq_event, list);
856 spin_unlock_irq(&phba->hbalock);
857
858 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
859 case CQE_CODE_COMPL_WQE:
860 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
861 cq_event);
862 lpfc_sli_release_iocbq(phba, rspiocbq);
863 break;
864 case CQE_CODE_RECEIVE:
865 case CQE_CODE_RECEIVE_V1:
866 dmabuf = container_of(cq_event, struct hbq_dmabuf,
867 cq_event);
868 lpfc_in_buf_free(phba, &dmabuf->dbuf);
869 }
870 }
871}
872
873/**
James Smartbcece5f2014-04-04 13:51:34 -0400874 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
875 * @phba: pointer to lpfc HBA data structure.
876 *
877 * This routine will cleanup posted ELS buffers after the HBA is reset
878 * when bringing down the SLI Layer.
879 *
880 *
881 * Return codes
882 * void.
883 **/
884static void
885lpfc_hba_free_post_buf(struct lpfc_hba *phba)
886{
887 struct lpfc_sli *psli = &phba->sli;
888 struct lpfc_sli_ring *pring;
889 struct lpfc_dmabuf *mp, *next_mp;
James Smart07eab622014-04-04 13:51:44 -0400890 LIST_HEAD(buflist);
891 int count;
James Smartbcece5f2014-04-04 13:51:34 -0400892
893 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
894 lpfc_sli_hbqbuf_free_all(phba);
895 else {
896 /* Cleanup preposted buffers on the ELS ring */
James Smart895427b2017-02-12 13:52:30 -0800897 pring = &psli->sli3_ring[LPFC_ELS_RING];
James Smart07eab622014-04-04 13:51:44 -0400898 spin_lock_irq(&phba->hbalock);
899 list_splice_init(&pring->postbufq, &buflist);
900 spin_unlock_irq(&phba->hbalock);
901
902 count = 0;
903 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
James Smartbcece5f2014-04-04 13:51:34 -0400904 list_del(&mp->list);
James Smart07eab622014-04-04 13:51:44 -0400905 count++;
James Smartbcece5f2014-04-04 13:51:34 -0400906 lpfc_mbuf_free(phba, mp->virt, mp->phys);
907 kfree(mp);
908 }
James Smart07eab622014-04-04 13:51:44 -0400909
910 spin_lock_irq(&phba->hbalock);
911 pring->postbufq_cnt -= count;
James Smartbcece5f2014-04-04 13:51:34 -0400912 spin_unlock_irq(&phba->hbalock);
913 }
914}
915
916/**
917 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
918 * @phba: pointer to lpfc HBA data structure.
919 *
920 * This routine will cleanup the txcmplq after the HBA is reset when bringing
921 * down the SLI Layer.
922 *
923 * Return codes
924 * void
925 **/
926static void
927lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
928{
929 struct lpfc_sli *psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -0800930 struct lpfc_queue *qp = NULL;
James Smartbcece5f2014-04-04 13:51:34 -0400931 struct lpfc_sli_ring *pring;
932 LIST_HEAD(completions);
933 int i;
934
James Smart895427b2017-02-12 13:52:30 -0800935 if (phba->sli_rev != LPFC_SLI_REV4) {
936 for (i = 0; i < psli->num_rings; i++) {
937 pring = &psli->sli3_ring[i];
James Smartbcece5f2014-04-04 13:51:34 -0400938 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -0800939 /* At this point in time the HBA is either reset or DOA
940 * Nothing should be on txcmplq as it will
941 * NEVER complete.
942 */
943 list_splice_init(&pring->txcmplq, &completions);
944 pring->txcmplq_cnt = 0;
James Smartbcece5f2014-04-04 13:51:34 -0400945 spin_unlock_irq(&phba->hbalock);
946
James Smart895427b2017-02-12 13:52:30 -0800947 lpfc_sli_abort_iocb_ring(phba, pring);
948 }
James Smartbcece5f2014-04-04 13:51:34 -0400949 /* Cancel all the IOCBs from the completions list */
James Smart895427b2017-02-12 13:52:30 -0800950 lpfc_sli_cancel_iocbs(phba, &completions,
951 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
952 return;
953 }
954 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
955 pring = qp->pring;
956 if (!pring)
957 continue;
958 spin_lock_irq(&pring->ring_lock);
959 list_splice_init(&pring->txcmplq, &completions);
960 pring->txcmplq_cnt = 0;
961 spin_unlock_irq(&pring->ring_lock);
James Smartbcece5f2014-04-04 13:51:34 -0400962 lpfc_sli_abort_iocb_ring(phba, pring);
963 }
James Smart895427b2017-02-12 13:52:30 -0800964 /* Cancel all the IOCBs from the completions list */
965 lpfc_sli_cancel_iocbs(phba, &completions,
966 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smartbcece5f2014-04-04 13:51:34 -0400967}
968
969/**
James Smart3772a992009-05-22 14:50:54 -0400970 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smartbcece5f2014-04-04 13:51:34 -0400971 int i;
James Smarte59058c2008-08-24 21:49:00 -0400972 * @phba: pointer to lpfc HBA data structure.
973 *
974 * This routine will do uninitialization after the HBA is reset when bring
975 * down the SLI Layer.
976 *
977 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200978 * 0 - success.
James Smarte59058c2008-08-24 21:49:00 -0400979 * Any other value - error.
980 **/
James Smart3772a992009-05-22 14:50:54 -0400981static int
982lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500983{
James Smartbcece5f2014-04-04 13:51:34 -0400984 lpfc_hba_free_post_buf(phba);
985 lpfc_hba_clean_txcmplq(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500986 return 0;
987}
James Smart5af5eee2010-10-22 11:06:38 -0400988
James Smartda0436e2009-05-22 14:51:39 -0400989/**
990 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
991 * @phba: pointer to lpfc HBA data structure.
992 *
993 * This routine will do uninitialization after the HBA is reset when bring
994 * down the SLI Layer.
995 *
996 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200997 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -0400998 * Any other value - error.
999 **/
1000static int
1001lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1002{
1003 struct lpfc_scsi_buf *psb, *psb_next;
1004 LIST_HEAD(aborts);
James Smart895427b2017-02-12 13:52:30 -08001005 LIST_HEAD(nvme_aborts);
James Smartda0436e2009-05-22 14:51:39 -04001006 unsigned long iflag = 0;
James Smart0f65ff62010-02-26 14:14:23 -05001007 struct lpfc_sglq *sglq_entry = NULL;
1008
James Smart895427b2017-02-12 13:52:30 -08001009
1010 lpfc_sli_hbqbuf_free_all(phba);
James Smartbcece5f2014-04-04 13:51:34 -04001011 lpfc_hba_clean_txcmplq(phba);
1012
James Smartda0436e2009-05-22 14:51:39 -04001013 /* At this point in time the HBA is either reset or DOA. Either
1014 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
James Smart895427b2017-02-12 13:52:30 -08001015 * on the lpfc_els_sgl_list so that it can either be freed if the
James Smartda0436e2009-05-22 14:51:39 -04001016 * driver is unloading or reposted if the driver is restarting
1017 * the port.
1018 */
James Smart895427b2017-02-12 13:52:30 -08001019 spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */
James Smartda0436e2009-05-22 14:51:39 -04001020 /* scsl_buf_list */
James Smart895427b2017-02-12 13:52:30 -08001021 /* sgl_list_lock required because worker thread uses this
James Smartda0436e2009-05-22 14:51:39 -04001022 * list.
1023 */
James Smart895427b2017-02-12 13:52:30 -08001024 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05001025 list_for_each_entry(sglq_entry,
1026 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1027 sglq_entry->state = SGL_FREED;
James Smartf358dd02017-02-12 13:52:34 -08001028 list_for_each_entry(sglq_entry,
1029 &phba->sli4_hba.lpfc_abts_nvmet_sgl_list, list)
1030 sglq_entry->state = SGL_FREED;
James Smart0f65ff62010-02-26 14:14:23 -05001031
James Smartda0436e2009-05-22 14:51:39 -04001032 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
James Smart895427b2017-02-12 13:52:30 -08001033 &phba->sli4_hba.lpfc_els_sgl_list);
1034
James Smartf358dd02017-02-12 13:52:34 -08001035 if (phba->sli4_hba.nvme_wq)
1036 list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_sgl_list,
1037 &phba->sli4_hba.lpfc_nvmet_sgl_list);
1038
James Smart895427b2017-02-12 13:52:30 -08001039 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04001040 /* abts_scsi_buf_list_lock required because worker thread uses this
1041 * list.
1042 */
James Smart895427b2017-02-12 13:52:30 -08001043 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
1044 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1045 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
1046 &aborts);
1047 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1048 }
1049
1050 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1051 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1052 list_splice_init(&phba->sli4_hba.lpfc_abts_nvme_buf_list,
1053 &nvme_aborts);
1054 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1055 }
1056
James Smartda0436e2009-05-22 14:51:39 -04001057 spin_unlock_irq(&phba->hbalock);
1058
1059 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1060 psb->pCmd = NULL;
1061 psb->status = IOSTAT_SUCCESS;
1062 }
James Smarta40fc5f2013-04-17 20:17:40 -04001063 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1064 list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
1065 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
James Smart68e814f2014-05-21 08:04:59 -04001066
James Smart895427b2017-02-12 13:52:30 -08001067 list_for_each_entry_safe(psb, psb_next, &nvme_aborts, list) {
1068 psb->pCmd = NULL;
1069 psb->status = IOSTAT_SUCCESS;
1070 }
1071 spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag);
1072 list_splice(&nvme_aborts, &phba->lpfc_nvme_buf_list_put);
1073 spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag);
1074
James Smart68e814f2014-05-21 08:04:59 -04001075 lpfc_sli4_free_sp_events(phba);
James Smartda0436e2009-05-22 14:51:39 -04001076 return 0;
1077}
1078
1079/**
1080 * lpfc_hba_down_post - Wrapper func for hba down post routine
1081 * @phba: pointer to lpfc HBA data structure.
1082 *
1083 * This routine wraps the actual SLI3 or SLI4 routine for performing
1084 * uninitialization after the HBA is reset when bring down the SLI Layer.
1085 *
1086 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001087 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001088 * Any other value - error.
1089 **/
1090int
1091lpfc_hba_down_post(struct lpfc_hba *phba)
1092{
1093 return (*phba->lpfc_hba_down_post)(phba);
1094}
Jamie Wellnitz41415862006-02-28 19:25:27 -05001095
James Smarte59058c2008-08-24 21:49:00 -04001096/**
James Smart3621a712009-04-06 18:47:14 -04001097 * lpfc_hb_timeout - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001098 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1099 *
1100 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1101 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1102 * work-port-events bitmap and the worker thread is notified. This timeout
1103 * event will be used by the worker thread to invoke the actual timeout
1104 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1105 * be performed in the timeout handler and the HBA timeout event bit shall
1106 * be cleared by the worker thread after it has taken the event bitmap out.
1107 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001108static void
James Smart858c9f62007-06-17 19:56:39 -05001109lpfc_hb_timeout(unsigned long ptr)
1110{
1111 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001112 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -05001113 unsigned long iflag;
1114
1115 phba = (struct lpfc_hba *)ptr;
James Smart93996272008-08-24 21:50:30 -04001116
1117 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -05001118 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001119 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1120 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -05001121 phba->pport->work_port_events |= WORKER_HB_TMO;
1122 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1123
James Smart93996272008-08-24 21:50:30 -04001124 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -04001125 if (!tmo_posted)
1126 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -05001127 return;
1128}
1129
James Smarte59058c2008-08-24 21:49:00 -04001130/**
James Smart19ca7602010-11-20 23:11:55 -05001131 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1132 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1133 *
1134 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1135 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1136 * work-port-events bitmap and the worker thread is notified. This timeout
1137 * event will be used by the worker thread to invoke the actual timeout
1138 * handler routine, lpfc_rrq_handler. Any periodical operations will
1139 * be performed in the timeout handler and the RRQ timeout event bit shall
1140 * be cleared by the worker thread after it has taken the event bitmap out.
1141 **/
1142static void
1143lpfc_rrq_timeout(unsigned long ptr)
1144{
1145 struct lpfc_hba *phba;
James Smart19ca7602010-11-20 23:11:55 -05001146 unsigned long iflag;
1147
1148 phba = (struct lpfc_hba *)ptr;
1149 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001150 if (!(phba->pport->load_flag & FC_UNLOADING))
1151 phba->hba_flag |= HBA_RRQ_ACTIVE;
1152 else
1153 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
James Smart19ca7602010-11-20 23:11:55 -05001154 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001155
1156 if (!(phba->pport->load_flag & FC_UNLOADING))
1157 lpfc_worker_wake_up(phba);
James Smart19ca7602010-11-20 23:11:55 -05001158}
1159
1160/**
James Smart3621a712009-04-06 18:47:14 -04001161 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -04001162 * @phba: pointer to lpfc hba data structure.
1163 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1164 *
1165 * This is the callback function to the lpfc heart-beat mailbox command.
1166 * If configured, the lpfc driver issues the heart-beat mailbox command to
1167 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1168 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1169 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1170 * heart-beat outstanding state. Once the mailbox command comes back and
1171 * no error conditions detected, the heart-beat mailbox command timer is
1172 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1173 * state is cleared for the next heart-beat. If the timer expired with the
1174 * heart-beat outstanding state set, the driver will put the HBA offline.
1175 **/
James Smart858c9f62007-06-17 19:56:39 -05001176static void
1177lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1178{
1179 unsigned long drvr_flag;
1180
1181 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1182 phba->hb_outstanding = 0;
1183 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1184
James Smart93996272008-08-24 21:50:30 -04001185 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -05001186 mempool_free(pmboxq, phba->mbox_mem_pool);
1187 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1188 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -04001189 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -05001190 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001191 jiffies +
1192 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001193 return;
1194}
1195
James Smarte59058c2008-08-24 21:49:00 -04001196/**
James Smart3621a712009-04-06 18:47:14 -04001197 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001198 * @phba: pointer to lpfc hba data structure.
1199 *
1200 * This is the actual HBA-timer timeout handler to be invoked by the worker
1201 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1202 * handler performs any periodic operations needed for the device. If such
1203 * periodic event has already been attended to either in the interrupt handler
1204 * or by processing slow-ring or fast-ring events within the HBA-timer
1205 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1206 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1207 * is configured and there is no heart-beat mailbox command outstanding, a
1208 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1209 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1210 * to offline.
1211 **/
James Smart858c9f62007-06-17 19:56:39 -05001212void
1213lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1214{
James Smart45ed1192009-10-02 15:17:02 -04001215 struct lpfc_vport **vports;
James Smart858c9f62007-06-17 19:56:39 -05001216 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -05001217 struct lpfc_dmabuf *buf_ptr;
James Smart45ed1192009-10-02 15:17:02 -04001218 int retval, i;
James Smart858c9f62007-06-17 19:56:39 -05001219 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -05001220 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -05001221
James Smart45ed1192009-10-02 15:17:02 -04001222 vports = lpfc_create_vport_work_array(phba);
1223 if (vports != NULL)
James Smart4258e982015-12-16 18:11:58 -05001224 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart45ed1192009-10-02 15:17:02 -04001225 lpfc_rcv_seq_check_edtov(vports[i]);
James Smart4258e982015-12-16 18:11:58 -05001226 lpfc_fdmi_num_disc_check(vports[i]);
1227 }
James Smart45ed1192009-10-02 15:17:02 -04001228 lpfc_destroy_vport_work_array(phba, vports);
1229
James Smart858c9f62007-06-17 19:56:39 -05001230 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -04001231 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -05001232 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1233 return;
1234
1235 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -05001236
James Smart256ec0d2013-04-17 20:14:58 -04001237 if (time_after(phba->last_completion_time +
1238 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1239 jiffies)) {
James Smart858c9f62007-06-17 19:56:39 -05001240 spin_unlock_irq(&phba->pport->work_port_lock);
1241 if (!phba->hb_outstanding)
1242 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001243 jiffies +
1244 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001245 else
1246 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001247 jiffies +
1248 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001249 return;
1250 }
1251 spin_unlock_irq(&phba->pport->work_port_lock);
1252
James Smart0ff10d42008-01-11 01:52:36 -05001253 if (phba->elsbuf_cnt &&
1254 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1255 spin_lock_irq(&phba->hbalock);
1256 list_splice_init(&phba->elsbuf, &completions);
1257 phba->elsbuf_cnt = 0;
1258 phba->elsbuf_prev_cnt = 0;
1259 spin_unlock_irq(&phba->hbalock);
1260
1261 while (!list_empty(&completions)) {
1262 list_remove_head(&completions, buf_ptr,
1263 struct lpfc_dmabuf, list);
1264 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1265 kfree(buf_ptr);
1266 }
1267 }
1268 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1269
James Smart858c9f62007-06-17 19:56:39 -05001270 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -05001271 if (phba->cfg_enable_hba_heartbeat) {
1272 if (!phba->hb_outstanding) {
James Smartbc739052010-08-04 16:11:18 -04001273 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1274 (list_empty(&psli->mboxq))) {
1275 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1276 GFP_KERNEL);
1277 if (!pmboxq) {
1278 mod_timer(&phba->hb_tmofunc,
1279 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001280 msecs_to_jiffies(1000 *
1281 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001282 return;
1283 }
James Smart13815c82008-01-11 01:52:48 -05001284
James Smartbc739052010-08-04 16:11:18 -04001285 lpfc_heart_beat(phba, pmboxq);
1286 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1287 pmboxq->vport = phba->pport;
1288 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1289 MBX_NOWAIT);
James Smart13815c82008-01-11 01:52:48 -05001290
James Smartbc739052010-08-04 16:11:18 -04001291 if (retval != MBX_BUSY &&
1292 retval != MBX_SUCCESS) {
1293 mempool_free(pmboxq,
1294 phba->mbox_mem_pool);
1295 mod_timer(&phba->hb_tmofunc,
1296 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001297 msecs_to_jiffies(1000 *
1298 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001299 return;
1300 }
1301 phba->skipped_hb = 0;
1302 phba->hb_outstanding = 1;
1303 } else if (time_before_eq(phba->last_completion_time,
1304 phba->skipped_hb)) {
1305 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1306 "2857 Last completion time not "
1307 " updated in %d ms\n",
1308 jiffies_to_msecs(jiffies
1309 - phba->last_completion_time));
1310 } else
1311 phba->skipped_hb = jiffies;
1312
James Smart858c9f62007-06-17 19:56:39 -05001313 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001314 jiffies +
1315 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001316 return;
James Smart13815c82008-01-11 01:52:48 -05001317 } else {
1318 /*
1319 * If heart beat timeout called with hb_outstanding set
James Smartdcf2a4e2010-09-29 11:18:53 -04001320 * we need to give the hb mailbox cmd a chance to
1321 * complete or TMO.
James Smart13815c82008-01-11 01:52:48 -05001322 */
James Smartdcf2a4e2010-09-29 11:18:53 -04001323 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1324 "0459 Adapter heartbeat still out"
1325 "standing:last compl time was %d ms.\n",
1326 jiffies_to_msecs(jiffies
1327 - phba->last_completion_time));
1328 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001329 jiffies +
1330 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001331 }
James Smart4258e982015-12-16 18:11:58 -05001332 } else {
1333 mod_timer(&phba->hb_tmofunc,
1334 jiffies +
1335 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001336 }
1337}
1338
James Smarte59058c2008-08-24 21:49:00 -04001339/**
James Smart3621a712009-04-06 18:47:14 -04001340 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -04001341 * @phba: pointer to lpfc hba data structure.
1342 *
1343 * This routine is called to bring the HBA offline when HBA hardware error
1344 * other than Port Error 6 has been detected.
1345 **/
James Smart09372822008-01-11 01:52:54 -05001346static void
1347lpfc_offline_eratt(struct lpfc_hba *phba)
1348{
1349 struct lpfc_sli *psli = &phba->sli;
1350
1351 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001352 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -05001353 spin_unlock_irq(&phba->hbalock);
James Smart618a5232012-06-12 13:54:36 -04001354 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart09372822008-01-11 01:52:54 -05001355
1356 lpfc_offline(phba);
1357 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001358 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001359 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001360 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001361 lpfc_hba_down_post(phba);
1362 lpfc_sli_brdready(phba, HS_MBRDY);
1363 lpfc_unblock_mgmt_io(phba);
1364 phba->link_state = LPFC_HBA_ERROR;
1365 return;
1366}
1367
James Smarte59058c2008-08-24 21:49:00 -04001368/**
James Smartda0436e2009-05-22 14:51:39 -04001369 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1370 * @phba: pointer to lpfc hba data structure.
1371 *
1372 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1373 * other than Port Error 6 has been detected.
1374 **/
James Smarta88dbb62013-04-17 20:18:39 -04001375void
James Smartda0436e2009-05-22 14:51:39 -04001376lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1377{
James Smart946727d2015-04-07 15:07:09 -04001378 spin_lock_irq(&phba->hbalock);
1379 phba->link_state = LPFC_HBA_ERROR;
1380 spin_unlock_irq(&phba->hbalock);
1381
James Smart618a5232012-06-12 13:54:36 -04001382 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smartda0436e2009-05-22 14:51:39 -04001383 lpfc_offline(phba);
James Smartda0436e2009-05-22 14:51:39 -04001384 lpfc_hba_down_post(phba);
James Smartda0436e2009-05-22 14:51:39 -04001385 lpfc_unblock_mgmt_io(phba);
James Smartda0436e2009-05-22 14:51:39 -04001386}
1387
1388/**
James Smarta257bf92009-04-06 18:48:10 -04001389 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1390 * @phba: pointer to lpfc hba data structure.
1391 *
1392 * This routine is invoked to handle the deferred HBA hardware error
1393 * conditions. This type of error is indicated by HBA by setting ER1
1394 * and another ER bit in the host status register. The driver will
1395 * wait until the ER1 bit clears before handling the error condition.
1396 **/
1397static void
1398lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1399{
1400 uint32_t old_host_status = phba->work_hs;
James Smarta257bf92009-04-06 18:48:10 -04001401 struct lpfc_sli *psli = &phba->sli;
1402
James Smartf4b4c682009-05-22 14:53:12 -04001403 /* If the pci channel is offline, ignore possible errors,
1404 * since we cannot communicate with the pci card anyway.
1405 */
1406 if (pci_channel_offline(phba->pcidev)) {
1407 spin_lock_irq(&phba->hbalock);
1408 phba->hba_flag &= ~DEFER_ERATT;
1409 spin_unlock_irq(&phba->hbalock);
1410 return;
1411 }
1412
James Smarta257bf92009-04-06 18:48:10 -04001413 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1414 "0479 Deferred Adapter Hardware Error "
1415 "Data: x%x x%x x%x\n",
1416 phba->work_hs,
1417 phba->work_status[0], phba->work_status[1]);
1418
1419 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001420 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001421 spin_unlock_irq(&phba->hbalock);
1422
1423
1424 /*
1425 * Firmware stops when it triggred erratt. That could cause the I/Os
1426 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1427 * SCSI layer retry it after re-establishing link.
1428 */
James Smartdb55fba2014-04-04 13:52:02 -04001429 lpfc_sli_abort_fcp_rings(phba);
James Smarta257bf92009-04-06 18:48:10 -04001430
1431 /*
1432 * There was a firmware error. Take the hba offline and then
1433 * attempt to restart it.
1434 */
James Smart618a5232012-06-12 13:54:36 -04001435 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smarta257bf92009-04-06 18:48:10 -04001436 lpfc_offline(phba);
1437
1438 /* Wait for the ER1 bit to clear.*/
1439 while (phba->work_hs & HS_FFER1) {
1440 msleep(100);
James Smart9940b972011-03-11 16:06:12 -05001441 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1442 phba->work_hs = UNPLUG_ERR ;
1443 break;
1444 }
James Smarta257bf92009-04-06 18:48:10 -04001445 /* If driver is unloading let the worker thread continue */
1446 if (phba->pport->load_flag & FC_UNLOADING) {
1447 phba->work_hs = 0;
1448 break;
1449 }
1450 }
1451
1452 /*
1453 * This is to ptrotect against a race condition in which
1454 * first write to the host attention register clear the
1455 * host status register.
1456 */
1457 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1458 phba->work_hs = old_host_status & ~HS_FFER1;
1459
James Smart3772a992009-05-22 14:50:54 -04001460 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001461 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001462 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001463 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1464 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1465}
1466
James Smart3772a992009-05-22 14:50:54 -04001467static void
1468lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1469{
1470 struct lpfc_board_event_header board_event;
1471 struct Scsi_Host *shost;
1472
1473 board_event.event_type = FC_REG_BOARD_EVENT;
1474 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1475 shost = lpfc_shost_from_vport(phba->pport);
1476 fc_host_post_vendor_event(shost, fc_get_event_number(),
1477 sizeof(board_event),
1478 (char *) &board_event,
1479 LPFC_NL_VENDOR_ID);
1480}
1481
James Smarta257bf92009-04-06 18:48:10 -04001482/**
James Smart3772a992009-05-22 14:50:54 -04001483 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001484 * @phba: pointer to lpfc hba data structure.
1485 *
1486 * This routine is invoked to handle the following HBA hardware error
1487 * conditions:
1488 * 1 - HBA error attention interrupt
1489 * 2 - DMA ring index out of range
1490 * 3 - Mailbox command came back as unknown
1491 **/
James Smart3772a992009-05-22 14:50:54 -04001492static void
1493lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001494{
James Smart2e0fef82007-06-17 19:56:36 -05001495 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001496 struct lpfc_sli *psli = &phba->sli;
James Smartd2873e42006-08-18 17:46:43 -04001497 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001498 unsigned long temperature;
1499 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001500 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001501
Linas Vepstas8d63f372007-02-14 14:28:36 -06001502 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001503 * since we cannot communicate with the pci card anyway.
1504 */
1505 if (pci_channel_offline(phba->pcidev)) {
1506 spin_lock_irq(&phba->hbalock);
1507 phba->hba_flag &= ~DEFER_ERATT;
1508 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001509 return;
James Smart3772a992009-05-22 14:50:54 -04001510 }
1511
James Smart13815c82008-01-11 01:52:48 -05001512 /* If resets are disabled then leave the HBA alone and return */
1513 if (!phba->cfg_enable_hba_reset)
1514 return;
dea31012005-04-17 16:05:31 -05001515
James Smartea2151b2008-09-07 11:52:10 -04001516 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001517 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001518
James Smarta257bf92009-04-06 18:48:10 -04001519 if (phba->hba_flag & DEFER_ERATT)
1520 lpfc_handle_deferred_eratt(phba);
1521
James Smartdcf2a4e2010-09-29 11:18:53 -04001522 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1523 if (phba->work_hs & HS_FFER6)
1524 /* Re-establishing Link */
1525 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1526 "1301 Re-establishing Link "
1527 "Data: x%x x%x x%x\n",
1528 phba->work_hs, phba->work_status[0],
1529 phba->work_status[1]);
1530 if (phba->work_hs & HS_FFER8)
1531 /* Device Zeroization */
1532 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1533 "2861 Host Authentication device "
1534 "zeroization Data:x%x x%x x%x\n",
1535 phba->work_hs, phba->work_status[0],
1536 phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001537
James Smart92d7f7b2007-06-17 19:56:38 -05001538 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001539 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001540 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001541
1542 /*
1543 * Firmware stops when it triggled erratt with HS_FFER6.
1544 * That could cause the I/Os dropped by the firmware.
1545 * Error iocb (I/O) on txcmplq and let the SCSI layer
1546 * retry it after re-establishing link.
1547 */
James Smartdb55fba2014-04-04 13:52:02 -04001548 lpfc_sli_abort_fcp_rings(phba);
dea31012005-04-17 16:05:31 -05001549
dea31012005-04-17 16:05:31 -05001550 /*
1551 * There was a firmware error. Take the hba offline and then
1552 * attempt to restart it.
1553 */
James Smart618a5232012-06-12 13:54:36 -04001554 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
dea31012005-04-17 16:05:31 -05001555 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001556 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001557 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001558 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001559 return;
1560 }
James Smart46fa3112007-04-25 09:51:45 -04001561 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001562 } else if (phba->work_hs & HS_CRIT_TEMP) {
1563 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1564 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1565 temp_event_data.event_code = LPFC_CRIT_TEMP;
1566 temp_event_data.data = (uint32_t)temperature;
1567
1568 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001569 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001570 "(%ld), taking this port offline "
1571 "Data: x%x x%x x%x\n",
1572 temperature, phba->work_hs,
1573 phba->work_status[0], phba->work_status[1]);
1574
1575 shost = lpfc_shost_from_vport(phba->pport);
1576 fc_host_post_vendor_event(shost, fc_get_event_number(),
1577 sizeof(temp_event_data),
1578 (char *) &temp_event_data,
1579 SCSI_NL_VID_TYPE_PCI
1580 | PCI_VENDOR_ID_EMULEX);
1581
James Smart7af67052007-10-27 13:38:11 -04001582 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001583 phba->over_temp_state = HBA_OVER_TEMP;
1584 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001585 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001586
dea31012005-04-17 16:05:31 -05001587 } else {
1588 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001589 * failure is a value other than FFER6. Do not call the offline
1590 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001591 */
1592 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001593 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001594 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001595 phba->work_hs,
dea31012005-04-17 16:05:31 -05001596 phba->work_status[0], phba->work_status[1]);
1597
James Smartd2873e42006-08-18 17:46:43 -04001598 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001599 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001600 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001601 sizeof(event_data), (char *) &event_data,
1602 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1603
James Smart09372822008-01-11 01:52:54 -05001604 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001605 }
James Smart93996272008-08-24 21:50:30 -04001606 return;
dea31012005-04-17 16:05:31 -05001607}
1608
James Smarte59058c2008-08-24 21:49:00 -04001609/**
James Smart618a5232012-06-12 13:54:36 -04001610 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1611 * @phba: pointer to lpfc hba data structure.
1612 * @mbx_action: flag for mailbox shutdown action.
1613 *
1614 * This routine is invoked to perform an SLI4 port PCI function reset in
1615 * response to port status register polling attention. It waits for port
1616 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1617 * During this process, interrupt vectors are freed and later requested
1618 * for handling possible port resource change.
1619 **/
1620static int
James Smarte10b2022014-02-20 09:57:43 -05001621lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1622 bool en_rn_msg)
James Smart618a5232012-06-12 13:54:36 -04001623{
1624 int rc;
1625 uint32_t intr_mode;
1626
James Smart65791f12016-07-06 12:35:56 -07001627 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1628 LPFC_SLI_INTF_IF_TYPE_2) {
1629 /*
1630 * On error status condition, driver need to wait for port
1631 * ready before performing reset.
1632 */
1633 rc = lpfc_sli4_pdev_status_reg_wait(phba);
James Smart0e916ee2016-07-06 12:36:06 -07001634 if (rc)
James Smart65791f12016-07-06 12:35:56 -07001635 return rc;
James Smart618a5232012-06-12 13:54:36 -04001636 }
James Smart0e916ee2016-07-06 12:36:06 -07001637
James Smart65791f12016-07-06 12:35:56 -07001638 /* need reset: attempt for port recovery */
1639 if (en_rn_msg)
1640 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1641 "2887 Reset Needed: Attempting Port "
1642 "Recovery...\n");
1643 lpfc_offline_prep(phba, mbx_action);
1644 lpfc_offline(phba);
1645 /* release interrupt for possible resource change */
1646 lpfc_sli4_disable_intr(phba);
1647 lpfc_sli_brdrestart(phba);
1648 /* request and enable interrupt */
1649 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1650 if (intr_mode == LPFC_INTR_ERROR) {
1651 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1652 "3175 Failed to enable interrupt\n");
1653 return -EIO;
1654 }
1655 phba->intr_mode = intr_mode;
1656 rc = lpfc_online(phba);
1657 if (rc == 0)
1658 lpfc_unblock_mgmt_io(phba);
1659
James Smart618a5232012-06-12 13:54:36 -04001660 return rc;
1661}
1662
1663/**
James Smartda0436e2009-05-22 14:51:39 -04001664 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1665 * @phba: pointer to lpfc hba data structure.
1666 *
1667 * This routine is invoked to handle the SLI4 HBA hardware error attention
1668 * conditions.
1669 **/
1670static void
1671lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1672{
1673 struct lpfc_vport *vport = phba->pport;
1674 uint32_t event_data;
1675 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001676 uint32_t if_type;
James Smart2e90f4b2011-12-13 13:22:37 -05001677 struct lpfc_register portstat_reg = {0};
1678 uint32_t reg_err1, reg_err2;
1679 uint32_t uerrlo_reg, uemasklo_reg;
James Smart65791f12016-07-06 12:35:56 -07001680 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
James Smarte10b2022014-02-20 09:57:43 -05001681 bool en_rn_msg = true;
James Smart946727d2015-04-07 15:07:09 -04001682 struct temp_event temp_event_data;
James Smart65791f12016-07-06 12:35:56 -07001683 struct lpfc_register portsmphr_reg;
1684 int rc, i;
James Smartda0436e2009-05-22 14:51:39 -04001685
1686 /* If the pci channel is offline, ignore possible errors, since
1687 * we cannot communicate with the pci card anyway.
1688 */
1689 if (pci_channel_offline(phba->pcidev))
1690 return;
James Smartda0436e2009-05-22 14:51:39 -04001691
James Smart65791f12016-07-06 12:35:56 -07001692 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
James Smart2fcee4b2010-12-15 17:57:46 -05001693 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1694 switch (if_type) {
1695 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart2e90f4b2011-12-13 13:22:37 -05001696 pci_rd_rc1 = lpfc_readl(
1697 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1698 &uerrlo_reg);
1699 pci_rd_rc2 = lpfc_readl(
1700 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1701 &uemasklo_reg);
1702 /* consider PCI bus read error as pci_channel_offline */
1703 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1704 return;
James Smart65791f12016-07-06 12:35:56 -07001705 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
1706 lpfc_sli4_offline_eratt(phba);
1707 return;
1708 }
1709 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1710 "7623 Checking UE recoverable");
1711
1712 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
1713 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1714 &portsmphr_reg.word0))
1715 continue;
1716
1717 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
1718 &portsmphr_reg);
1719 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1720 LPFC_PORT_SEM_UE_RECOVERABLE)
1721 break;
1722 /*Sleep for 1Sec, before checking SEMAPHORE */
1723 msleep(1000);
1724 }
1725
1726 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1727 "4827 smphr_port_status x%x : Waited %dSec",
1728 smphr_port_status, i);
1729
1730 /* Recoverable UE, reset the HBA device */
1731 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1732 LPFC_PORT_SEM_UE_RECOVERABLE) {
1733 for (i = 0; i < 20; i++) {
1734 msleep(1000);
1735 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1736 &portsmphr_reg.word0) &&
1737 (LPFC_POST_STAGE_PORT_READY ==
1738 bf_get(lpfc_port_smphr_port_status,
1739 &portsmphr_reg))) {
1740 rc = lpfc_sli4_port_sta_fn_reset(phba,
1741 LPFC_MBX_NO_WAIT, en_rn_msg);
1742 if (rc == 0)
1743 return;
1744 lpfc_printf_log(phba,
1745 KERN_ERR, LOG_INIT,
1746 "4215 Failed to recover UE");
1747 break;
1748 }
1749 }
1750 }
1751 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1752 "7624 Firmware not ready: Failing UE recovery,"
1753 " waited %dSec", i);
James Smart2fcee4b2010-12-15 17:57:46 -05001754 lpfc_sli4_offline_eratt(phba);
1755 break;
James Smart946727d2015-04-07 15:07:09 -04001756
James Smart2fcee4b2010-12-15 17:57:46 -05001757 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2e90f4b2011-12-13 13:22:37 -05001758 pci_rd_rc1 = lpfc_readl(
1759 phba->sli4_hba.u.if_type2.STATUSregaddr,
1760 &portstat_reg.word0);
1761 /* consider PCI bus read error as pci_channel_offline */
James Smart6b5151f2012-01-18 16:24:06 -05001762 if (pci_rd_rc1 == -EIO) {
1763 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1764 "3151 PCI bus read access failure: x%x\n",
1765 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
James Smart2e90f4b2011-12-13 13:22:37 -05001766 return;
James Smart6b5151f2012-01-18 16:24:06 -05001767 }
James Smart2e90f4b2011-12-13 13:22:37 -05001768 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1769 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
James Smart2fcee4b2010-12-15 17:57:46 -05001770 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
James Smart2fcee4b2010-12-15 17:57:46 -05001771 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1772 "2889 Port Overtemperature event, "
James Smart946727d2015-04-07 15:07:09 -04001773 "taking port offline Data: x%x x%x\n",
1774 reg_err1, reg_err2);
1775
James Smart310429e2016-07-06 12:35:54 -07001776 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04001777 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1778 temp_event_data.event_code = LPFC_CRIT_TEMP;
1779 temp_event_data.data = 0xFFFFFFFF;
1780
1781 shost = lpfc_shost_from_vport(phba->pport);
1782 fc_host_post_vendor_event(shost, fc_get_event_number(),
1783 sizeof(temp_event_data),
1784 (char *)&temp_event_data,
1785 SCSI_NL_VID_TYPE_PCI
1786 | PCI_VENDOR_ID_EMULEX);
1787
James Smart2fcee4b2010-12-15 17:57:46 -05001788 spin_lock_irq(&phba->hbalock);
1789 phba->over_temp_state = HBA_OVER_TEMP;
1790 spin_unlock_irq(&phba->hbalock);
1791 lpfc_sli4_offline_eratt(phba);
James Smart946727d2015-04-07 15:07:09 -04001792 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001793 }
James Smart2e90f4b2011-12-13 13:22:37 -05001794 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smarte10b2022014-02-20 09:57:43 -05001795 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
James Smart2e90f4b2011-12-13 13:22:37 -05001796 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte10b2022014-02-20 09:57:43 -05001797 "3143 Port Down: Firmware Update "
1798 "Detected\n");
1799 en_rn_msg = false;
1800 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smart2e90f4b2011-12-13 13:22:37 -05001801 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1802 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1803 "3144 Port Down: Debug Dump\n");
1804 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1805 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1806 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1807 "3145 Port Down: Provisioning\n");
James Smart618a5232012-06-12 13:54:36 -04001808
James Smart946727d2015-04-07 15:07:09 -04001809 /* If resets are disabled then leave the HBA alone and return */
1810 if (!phba->cfg_enable_hba_reset)
1811 return;
1812
James Smart618a5232012-06-12 13:54:36 -04001813 /* Check port status register for function reset */
James Smarte10b2022014-02-20 09:57:43 -05001814 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1815 en_rn_msg);
James Smart618a5232012-06-12 13:54:36 -04001816 if (rc == 0) {
1817 /* don't report event on forced debug dump */
1818 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1819 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1820 return;
1821 else
1822 break;
James Smart2fcee4b2010-12-15 17:57:46 -05001823 }
James Smart618a5232012-06-12 13:54:36 -04001824 /* fall through for not able to recover */
James Smart6b5151f2012-01-18 16:24:06 -05001825 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1826 "3152 Unrecoverable error, bring the port "
1827 "offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05001828 lpfc_sli4_offline_eratt(phba);
1829 break;
1830 case LPFC_SLI_INTF_IF_TYPE_1:
1831 default:
1832 break;
1833 }
James Smart2e90f4b2011-12-13 13:22:37 -05001834 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1835 "3123 Report dump event to upper layer\n");
1836 /* Send an internal error event to mgmt application */
1837 lpfc_board_errevt_to_mgmt(phba);
1838
1839 event_data = FC_REG_DUMP_EVENT;
1840 shost = lpfc_shost_from_vport(vport);
1841 fc_host_post_vendor_event(shost, fc_get_event_number(),
1842 sizeof(event_data), (char *) &event_data,
1843 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
James Smartda0436e2009-05-22 14:51:39 -04001844}
1845
1846/**
1847 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1848 * @phba: pointer to lpfc HBA data structure.
1849 *
1850 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1851 * routine from the API jump table function pointer from the lpfc_hba struct.
1852 *
1853 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001854 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001855 * Any other value - error.
1856 **/
1857void
1858lpfc_handle_eratt(struct lpfc_hba *phba)
1859{
1860 (*phba->lpfc_handle_eratt)(phba);
1861}
1862
1863/**
James Smart3621a712009-04-06 18:47:14 -04001864 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04001865 * @phba: pointer to lpfc hba data structure.
1866 *
1867 * This routine is invoked from the worker thread to handle a HBA host
James Smart895427b2017-02-12 13:52:30 -08001868 * attention link event. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04001869 **/
dea31012005-04-17 16:05:31 -05001870void
James Smart2e0fef82007-06-17 19:56:36 -05001871lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001872{
James Smart2e0fef82007-06-17 19:56:36 -05001873 struct lpfc_vport *vport = phba->pport;
1874 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001875 LPFC_MBOXQ_t *pmb;
1876 volatile uint32_t control;
1877 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05001878 int rc = 0;
dea31012005-04-17 16:05:31 -05001879
1880 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001881 if (!pmb) {
1882 rc = 1;
dea31012005-04-17 16:05:31 -05001883 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05001884 }
dea31012005-04-17 16:05:31 -05001885
1886 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001887 if (!mp) {
1888 rc = 2;
dea31012005-04-17 16:05:31 -05001889 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05001890 }
dea31012005-04-17 16:05:31 -05001891
1892 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05001893 if (!mp->virt) {
1894 rc = 3;
dea31012005-04-17 16:05:31 -05001895 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05001896 }
dea31012005-04-17 16:05:31 -05001897
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001898 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04001899 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05001900
1901 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05001902 lpfc_read_topology(phba, pmb, mp);
1903 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05001904 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04001905 /* Block ELS IOCBs until we have processed this mbox command */
James Smart895427b2017-02-12 13:52:30 -08001906 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04001907 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05001908 if (rc == MBX_NOT_FINISHED) {
1909 rc = 4;
James Smart14691152006-12-02 13:34:28 -05001910 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05001911 }
dea31012005-04-17 16:05:31 -05001912
1913 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05001914 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001915 writel(HA_LATT, phba->HAregaddr);
1916 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001917 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001918
1919 return;
1920
James Smart14691152006-12-02 13:34:28 -05001921lpfc_handle_latt_free_mbuf:
James Smart895427b2017-02-12 13:52:30 -08001922 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05001923 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05001924lpfc_handle_latt_free_mp:
1925 kfree(mp);
1926lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04001927 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001928lpfc_handle_latt_err_exit:
1929 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001930 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001931 psli->sli_flag |= LPFC_PROCESS_LA;
1932 control = readl(phba->HCregaddr);
1933 control |= HC_LAINT_ENA;
1934 writel(control, phba->HCregaddr);
1935 readl(phba->HCregaddr); /* flush */
1936
1937 /* Clear Link Attention in HA REG */
1938 writel(HA_LATT, phba->HAregaddr);
1939 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001940 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001941 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001942 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001943
James Smart09372822008-01-11 01:52:54 -05001944 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1945 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05001946
1947 return;
1948}
1949
James Smarte59058c2008-08-24 21:49:00 -04001950/**
James Smart3621a712009-04-06 18:47:14 -04001951 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04001952 * @phba: pointer to lpfc hba data structure.
1953 * @vpd: pointer to the vital product data.
1954 * @len: length of the vital product data in bytes.
1955 *
1956 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1957 * an array of characters. In this routine, the ModelName, ProgramType, and
1958 * ModelDesc, etc. fields of the phba data structure will be populated.
1959 *
1960 * Return codes
1961 * 0 - pointer to the VPD passed in is NULL
1962 * 1 - success
1963 **/
James Smart3772a992009-05-22 14:50:54 -04001964int
James Smart2e0fef82007-06-17 19:56:36 -05001965lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05001966{
1967 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05001968 int Length;
dea31012005-04-17 16:05:31 -05001969 int i, j;
1970 int finished = 0;
1971 int index = 0;
1972
1973 if (!vpd)
1974 return 0;
1975
1976 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05001977 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001978 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001979 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
1980 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001981 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05001982 switch (vpd[index]) {
1983 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001984 case 0x91:
dea31012005-04-17 16:05:31 -05001985 index += 1;
1986 lenlo = vpd[index];
1987 index += 1;
1988 lenhi = vpd[index];
1989 index += 1;
1990 i = ((((unsigned short)lenhi) << 8) + lenlo);
1991 index += i;
1992 break;
1993 case 0x90:
1994 index += 1;
1995 lenlo = vpd[index];
1996 index += 1;
1997 lenhi = vpd[index];
1998 index += 1;
1999 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002000 if (Length > len - index)
2001 Length = len - index;
dea31012005-04-17 16:05:31 -05002002 while (Length > 0) {
2003 /* Look for Serial Number */
2004 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
2005 index += 2;
2006 i = vpd[index];
2007 index += 1;
2008 j = 0;
2009 Length -= (3+i);
2010 while(i--) {
2011 phba->SerialNumber[j++] = vpd[index++];
2012 if (j == 31)
2013 break;
2014 }
2015 phba->SerialNumber[j] = 0;
2016 continue;
2017 }
2018 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
2019 phba->vpd_flag |= VPD_MODEL_DESC;
2020 index += 2;
2021 i = vpd[index];
2022 index += 1;
2023 j = 0;
2024 Length -= (3+i);
2025 while(i--) {
2026 phba->ModelDesc[j++] = vpd[index++];
2027 if (j == 255)
2028 break;
2029 }
2030 phba->ModelDesc[j] = 0;
2031 continue;
2032 }
2033 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
2034 phba->vpd_flag |= VPD_MODEL_NAME;
2035 index += 2;
2036 i = vpd[index];
2037 index += 1;
2038 j = 0;
2039 Length -= (3+i);
2040 while(i--) {
2041 phba->ModelName[j++] = vpd[index++];
2042 if (j == 79)
2043 break;
2044 }
2045 phba->ModelName[j] = 0;
2046 continue;
2047 }
2048 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2049 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2050 index += 2;
2051 i = vpd[index];
2052 index += 1;
2053 j = 0;
2054 Length -= (3+i);
2055 while(i--) {
2056 phba->ProgramType[j++] = vpd[index++];
2057 if (j == 255)
2058 break;
2059 }
2060 phba->ProgramType[j] = 0;
2061 continue;
2062 }
2063 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2064 phba->vpd_flag |= VPD_PORT;
2065 index += 2;
2066 i = vpd[index];
2067 index += 1;
2068 j = 0;
2069 Length -= (3+i);
2070 while(i--) {
James Smartcd1c8302011-10-10 21:33:25 -04002071 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2072 (phba->sli4_hba.pport_name_sta ==
2073 LPFC_SLI4_PPNAME_GET)) {
2074 j++;
2075 index++;
2076 } else
2077 phba->Port[j++] = vpd[index++];
2078 if (j == 19)
2079 break;
dea31012005-04-17 16:05:31 -05002080 }
James Smartcd1c8302011-10-10 21:33:25 -04002081 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2082 (phba->sli4_hba.pport_name_sta ==
2083 LPFC_SLI4_PPNAME_NON))
2084 phba->Port[j] = 0;
dea31012005-04-17 16:05:31 -05002085 continue;
2086 }
2087 else {
2088 index += 2;
2089 i = vpd[index];
2090 index += 1;
2091 index += i;
2092 Length -= (3 + i);
2093 }
2094 }
2095 finished = 0;
2096 break;
2097 case 0x78:
2098 finished = 1;
2099 break;
2100 default:
2101 index ++;
2102 break;
2103 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002104 }
dea31012005-04-17 16:05:31 -05002105
2106 return(1);
2107}
2108
James Smarte59058c2008-08-24 21:49:00 -04002109/**
James Smart3621a712009-04-06 18:47:14 -04002110 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04002111 * @phba: pointer to lpfc hba data structure.
2112 * @mdp: pointer to the data structure to hold the derived model name.
2113 * @descp: pointer to the data structure to hold the derived description.
2114 *
2115 * This routine retrieves HBA's description based on its registered PCI device
2116 * ID. The @descp passed into this function points to an array of 256 chars. It
2117 * shall be returned with the model name, maximum speed, and the host bus type.
2118 * The @mdp passed into this function points to an array of 80 chars. When the
2119 * function returns, the @mdp will be filled with the model name.
2120 **/
dea31012005-04-17 16:05:31 -05002121static void
James Smart2e0fef82007-06-17 19:56:36 -05002122lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05002123{
2124 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05002125 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002126 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04002127 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04002128 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002129 struct {
James Smarta747c9c2009-11-18 15:41:10 -05002130 char *name;
2131 char *bus;
2132 char *function;
2133 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002134
2135 if (mdp && mdp[0] != '\0'
2136 && descp && descp[0] != '\0')
2137 return;
2138
James Smartd38dd522015-08-31 16:48:17 -04002139 if (phba->lmt & LMT_32Gb)
2140 max_speed = 32;
2141 else if (phba->lmt & LMT_16Gb)
James Smartc0c11512011-05-24 11:41:34 -04002142 max_speed = 16;
2143 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002144 max_speed = 10;
2145 else if (phba->lmt & LMT_8Gb)
2146 max_speed = 8;
2147 else if (phba->lmt & LMT_4Gb)
2148 max_speed = 4;
2149 else if (phba->lmt & LMT_2Gb)
2150 max_speed = 2;
James Smart4169d862012-09-29 11:32:09 -04002151 else if (phba->lmt & LMT_1Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002152 max_speed = 1;
James Smart4169d862012-09-29 11:32:09 -04002153 else
2154 max_speed = 0;
dea31012005-04-17 16:05:31 -05002155
2156 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05002157
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002158 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002159 case PCI_DEVICE_ID_FIREFLY:
James Smart12222f42014-05-21 08:05:19 -04002160 m = (typeof(m)){"LP6000", "PCI",
2161 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002162 break;
dea31012005-04-17 16:05:31 -05002163 case PCI_DEVICE_ID_SUPERFLY:
2164 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart12222f42014-05-21 08:05:19 -04002165 m = (typeof(m)){"LP7000", "PCI", ""};
dea31012005-04-17 16:05:31 -05002166 else
James Smart12222f42014-05-21 08:05:19 -04002167 m = (typeof(m)){"LP7000E", "PCI", ""};
2168 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002169 break;
2170 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002171 m = (typeof(m)){"LP8000", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002172 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002173 break;
2174 case PCI_DEVICE_ID_CENTAUR:
2175 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart12222f42014-05-21 08:05:19 -04002176 m = (typeof(m)){"LP9002", "PCI", ""};
dea31012005-04-17 16:05:31 -05002177 else
James Smart12222f42014-05-21 08:05:19 -04002178 m = (typeof(m)){"LP9000", "PCI", ""};
2179 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002180 break;
2181 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002182 m = (typeof(m)){"LP952", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002183 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002184 break;
2185 case PCI_DEVICE_ID_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05002186 m = (typeof(m)){"LP9802", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002187 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002188 break;
2189 case PCI_DEVICE_ID_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05002190 m = (typeof(m)){"LP10000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002191 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002192 break;
2193 case PCI_DEVICE_ID_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05002194 m = (typeof(m)){"LPX1000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002195 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002196 break;
2197 case PCI_DEVICE_ID_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002198 m = (typeof(m)){"LP982", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002199 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002200 break;
2201 case PCI_DEVICE_ID_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002202 m = (typeof(m)){"LP1050", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002203 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002204 break;
2205 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05002206 m = (typeof(m)){"LP11000", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002207 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002208 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002209 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002210 m = (typeof(m)){"LP11000-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002211 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002212 break;
2213 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002214 m = (typeof(m)){"LP11002-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002215 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002216 break;
2217 case PCI_DEVICE_ID_NEPTUNE:
James Smart12222f42014-05-21 08:05:19 -04002218 m = (typeof(m)){"LPe1000", "PCIe",
2219 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002220 break;
2221 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart12222f42014-05-21 08:05:19 -04002222 m = (typeof(m)){"LPe1000-SP", "PCIe",
2223 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002224 break;
2225 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart12222f42014-05-21 08:05:19 -04002226 m = (typeof(m)){"LPe1002-SP", "PCIe",
2227 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002228 break;
dea31012005-04-17 16:05:31 -05002229 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05002230 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002231 break;
2232 case PCI_DEVICE_ID_BSMB:
James Smart12222f42014-05-21 08:05:19 -04002233 m = (typeof(m)){"LP111", "PCI-X2",
2234 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002235 break;
2236 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05002237 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002238 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002239 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002240 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002241 break;
2242 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002243 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04002244 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002245 break;
dea31012005-04-17 16:05:31 -05002246 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05002247 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002248 break;
2249 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05002250 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002251 break;
2252 case PCI_DEVICE_ID_LP101:
James Smart12222f42014-05-21 08:05:19 -04002253 m = (typeof(m)){"LP101", "PCI-X",
2254 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002255 break;
2256 case PCI_DEVICE_ID_LP10000S:
James Smart12222f42014-05-21 08:05:19 -04002257 m = (typeof(m)){"LP10000-S", "PCI",
2258 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002259 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002260 case PCI_DEVICE_ID_LP11000S:
James Smart12222f42014-05-21 08:05:19 -04002261 m = (typeof(m)){"LP11000-S", "PCI-X2",
2262 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05002263 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002264 case PCI_DEVICE_ID_LPE11000S:
James Smart12222f42014-05-21 08:05:19 -04002265 m = (typeof(m)){"LPe11000-S", "PCIe",
2266 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002267 break;
James Smartb87eab32007-04-25 09:53:28 -04002268 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05002269 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002270 break;
2271 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05002272 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002273 break;
2274 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05002275 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002276 break;
2277 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002278 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002279 break;
2280 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002281 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002282 break;
2283 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05002284 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002285 break;
James Smart84774a42008-08-24 21:50:06 -04002286 case PCI_DEVICE_ID_HORNET:
James Smart12222f42014-05-21 08:05:19 -04002287 m = (typeof(m)){"LP21000", "PCIe",
2288 "Obsolete, Unsupported FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002289 GE = 1;
2290 break;
2291 case PCI_DEVICE_ID_PROTEUS_VF:
James Smarta747c9c2009-11-18 15:41:10 -05002292 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002293 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002294 break;
2295 case PCI_DEVICE_ID_PROTEUS_PF:
James Smarta747c9c2009-11-18 15:41:10 -05002296 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002297 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002298 break;
2299 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05002300 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002301 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002302 break;
James Smartda0436e2009-05-22 14:51:39 -04002303 case PCI_DEVICE_ID_TIGERSHARK:
2304 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002305 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04002306 break;
James Smarta747c9c2009-11-18 15:41:10 -05002307 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04002308 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002309 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2310 break;
2311 case PCI_DEVICE_ID_FALCON:
2312 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2313 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04002314 break;
James Smart98fc5dd2010-06-07 15:24:29 -04002315 case PCI_DEVICE_ID_BALIUS:
2316 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
James Smart12222f42014-05-21 08:05:19 -04002317 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart98fc5dd2010-06-07 15:24:29 -04002318 break;
James Smart085c6472010-11-20 23:11:37 -05002319 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04002320 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05002321 break;
James Smart12222f42014-05-21 08:05:19 -04002322 case PCI_DEVICE_ID_LANCER_FC_VF:
2323 m = (typeof(m)){"LPe16000", "PCIe",
2324 "Obsolete, Unsupported Fibre Channel Adapter"};
2325 break;
James Smart085c6472010-11-20 23:11:37 -05002326 case PCI_DEVICE_ID_LANCER_FCOE:
2327 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04002328 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05002329 break;
James Smart12222f42014-05-21 08:05:19 -04002330 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2331 oneConnect = 1;
2332 m = (typeof(m)){"OCe15100", "PCIe",
2333 "Obsolete, Unsupported FCoE"};
2334 break;
James Smartd38dd522015-08-31 16:48:17 -04002335 case PCI_DEVICE_ID_LANCER_G6_FC:
2336 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2337 break;
James Smartf8cafd32012-08-03 12:42:51 -04002338 case PCI_DEVICE_ID_SKYHAWK:
2339 case PCI_DEVICE_ID_SKYHAWK_VF:
2340 oneConnect = 1;
2341 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2342 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002343 default:
James Smarta747c9c2009-11-18 15:41:10 -05002344 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002345 break;
dea31012005-04-17 16:05:31 -05002346 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002347
2348 if (mdp && mdp[0] == '\0')
2349 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04002350 /*
2351 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04002352 * and we put the port number on the end
2353 */
2354 if (descp && descp[0] == '\0') {
2355 if (oneConnect)
2356 snprintf(descp, 255,
James Smart4169d862012-09-29 11:32:09 -04002357 "Emulex OneConnect %s, %s Initiator %s",
James Smarta747c9c2009-11-18 15:41:10 -05002358 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04002359 phba->Port);
James Smart4169d862012-09-29 11:32:09 -04002360 else if (max_speed == 0)
2361 snprintf(descp, 255,
Sebastian Herbszt290237d2015-08-31 16:48:08 -04002362 "Emulex %s %s %s",
James Smart4169d862012-09-29 11:32:09 -04002363 m.name, m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002364 else
2365 snprintf(descp, 255,
2366 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05002367 m.name, max_speed, (GE) ? "GE" : "Gb",
2368 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002369 }
dea31012005-04-17 16:05:31 -05002370}
2371
James Smarte59058c2008-08-24 21:49:00 -04002372/**
James Smart3621a712009-04-06 18:47:14 -04002373 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04002374 * @phba: pointer to lpfc hba data structure.
2375 * @pring: pointer to a IOCB ring.
2376 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2377 *
2378 * This routine posts a given number of IOCBs with the associated DMA buffer
2379 * descriptors specified by the cnt argument to the given IOCB ring.
2380 *
2381 * Return codes
2382 * The number of IOCBs NOT able to be posted to the IOCB ring.
2383 **/
dea31012005-04-17 16:05:31 -05002384int
James Smart495a7142008-06-14 22:52:59 -04002385lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002386{
2387 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002388 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002389 struct lpfc_dmabuf *mp1, *mp2;
2390
2391 cnt += pring->missbufcnt;
2392
2393 /* While there are buffers to post */
2394 while (cnt > 0) {
2395 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002396 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002397 if (iocb == NULL) {
2398 pring->missbufcnt = cnt;
2399 return cnt;
2400 }
dea31012005-04-17 16:05:31 -05002401 icmd = &iocb->iocb;
2402
2403 /* 2 buffers can be posted per command */
2404 /* Allocate buffer to post */
2405 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2406 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002407 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2408 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002409 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002410 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002411 pring->missbufcnt = cnt;
2412 return cnt;
2413 }
2414
2415 INIT_LIST_HEAD(&mp1->list);
2416 /* Allocate buffer to post */
2417 if (cnt > 1) {
2418 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2419 if (mp2)
2420 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2421 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002422 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002423 kfree(mp2);
dea31012005-04-17 16:05:31 -05002424 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2425 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002426 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002427 pring->missbufcnt = cnt;
2428 return cnt;
2429 }
2430
2431 INIT_LIST_HEAD(&mp2->list);
2432 } else {
2433 mp2 = NULL;
2434 }
2435
2436 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2437 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2438 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2439 icmd->ulpBdeCount = 1;
2440 cnt--;
2441 if (mp2) {
2442 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2443 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2444 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2445 cnt--;
2446 icmd->ulpBdeCount = 2;
2447 }
2448
2449 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2450 icmd->ulpLe = 1;
2451
James Smart3772a992009-05-22 14:50:54 -04002452 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2453 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002454 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2455 kfree(mp1);
2456 cnt++;
2457 if (mp2) {
2458 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2459 kfree(mp2);
2460 cnt++;
2461 }
James Bottomley604a3e32005-10-29 10:28:33 -05002462 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002463 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002464 return cnt;
2465 }
dea31012005-04-17 16:05:31 -05002466 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002467 if (mp2)
dea31012005-04-17 16:05:31 -05002468 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002469 }
2470 pring->missbufcnt = 0;
2471 return 0;
2472}
2473
James Smarte59058c2008-08-24 21:49:00 -04002474/**
James Smart3621a712009-04-06 18:47:14 -04002475 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002476 * @phba: pointer to lpfc hba data structure.
2477 *
2478 * This routine posts initial receive IOCB buffers to the ELS ring. The
2479 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
James Smart895427b2017-02-12 13:52:30 -08002480 * set to 64 IOCBs. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002481 *
2482 * Return codes
2483 * 0 - success (currently always success)
2484 **/
dea31012005-04-17 16:05:31 -05002485static int
James Smart2e0fef82007-06-17 19:56:36 -05002486lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002487{
2488 struct lpfc_sli *psli = &phba->sli;
2489
2490 /* Ring 0, ELS / CT buffers */
James Smart895427b2017-02-12 13:52:30 -08002491 lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002492 /* Ring 2 - FCP no buffers needed */
2493
2494 return 0;
2495}
2496
2497#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2498
James Smarte59058c2008-08-24 21:49:00 -04002499/**
James Smart3621a712009-04-06 18:47:14 -04002500 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002501 * @HashResultPointer: pointer to an array as hash table.
2502 *
2503 * This routine sets up the initial values to the array of hash table entries
2504 * for the LC HBAs.
2505 **/
dea31012005-04-17 16:05:31 -05002506static void
2507lpfc_sha_init(uint32_t * HashResultPointer)
2508{
2509 HashResultPointer[0] = 0x67452301;
2510 HashResultPointer[1] = 0xEFCDAB89;
2511 HashResultPointer[2] = 0x98BADCFE;
2512 HashResultPointer[3] = 0x10325476;
2513 HashResultPointer[4] = 0xC3D2E1F0;
2514}
2515
James Smarte59058c2008-08-24 21:49:00 -04002516/**
James Smart3621a712009-04-06 18:47:14 -04002517 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002518 * @HashResultPointer: pointer to an initial/result hash table.
2519 * @HashWorkingPointer: pointer to an working hash table.
2520 *
2521 * This routine iterates an initial hash table pointed by @HashResultPointer
2522 * with the values from the working hash table pointeed by @HashWorkingPointer.
2523 * The results are putting back to the initial hash table, returned through
2524 * the @HashResultPointer as the result hash table.
2525 **/
dea31012005-04-17 16:05:31 -05002526static void
2527lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2528{
2529 int t;
2530 uint32_t TEMP;
2531 uint32_t A, B, C, D, E;
2532 t = 16;
2533 do {
2534 HashWorkingPointer[t] =
2535 S(1,
2536 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2537 8] ^
2538 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2539 } while (++t <= 79);
2540 t = 0;
2541 A = HashResultPointer[0];
2542 B = HashResultPointer[1];
2543 C = HashResultPointer[2];
2544 D = HashResultPointer[3];
2545 E = HashResultPointer[4];
2546
2547 do {
2548 if (t < 20) {
2549 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2550 } else if (t < 40) {
2551 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2552 } else if (t < 60) {
2553 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2554 } else {
2555 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2556 }
2557 TEMP += S(5, A) + E + HashWorkingPointer[t];
2558 E = D;
2559 D = C;
2560 C = S(30, B);
2561 B = A;
2562 A = TEMP;
2563 } while (++t <= 79);
2564
2565 HashResultPointer[0] += A;
2566 HashResultPointer[1] += B;
2567 HashResultPointer[2] += C;
2568 HashResultPointer[3] += D;
2569 HashResultPointer[4] += E;
2570
2571}
2572
James Smarte59058c2008-08-24 21:49:00 -04002573/**
James Smart3621a712009-04-06 18:47:14 -04002574 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002575 * @RandomChallenge: pointer to the entry of host challenge random number array.
2576 * @HashWorking: pointer to the entry of the working hash array.
2577 *
2578 * This routine calculates the working hash array referred by @HashWorking
2579 * from the challenge random numbers associated with the host, referred by
2580 * @RandomChallenge. The result is put into the entry of the working hash
2581 * array and returned by reference through @HashWorking.
2582 **/
dea31012005-04-17 16:05:31 -05002583static void
2584lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2585{
2586 *HashWorking = (*RandomChallenge ^ *HashWorking);
2587}
2588
James Smarte59058c2008-08-24 21:49:00 -04002589/**
James Smart3621a712009-04-06 18:47:14 -04002590 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002591 * @phba: pointer to lpfc hba data structure.
2592 * @hbainit: pointer to an array of unsigned 32-bit integers.
2593 *
2594 * This routine performs the special handling for LC HBA initialization.
2595 **/
dea31012005-04-17 16:05:31 -05002596void
2597lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2598{
2599 int t;
2600 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002601 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002602
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002603 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002604 if (!HashWorking)
2605 return;
2606
dea31012005-04-17 16:05:31 -05002607 HashWorking[0] = HashWorking[78] = *pwwnn++;
2608 HashWorking[1] = HashWorking[79] = *pwwnn;
2609
2610 for (t = 0; t < 7; t++)
2611 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2612
2613 lpfc_sha_init(hbainit);
2614 lpfc_sha_iterate(hbainit, HashWorking);
2615 kfree(HashWorking);
2616}
2617
James Smarte59058c2008-08-24 21:49:00 -04002618/**
James Smart3621a712009-04-06 18:47:14 -04002619 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002620 * @vport: pointer to a virtual N_Port data structure.
2621 *
2622 * This routine performs the necessary cleanups before deleting the @vport.
2623 * It invokes the discovery state machine to perform necessary state
2624 * transitions and to release the ndlps associated with the @vport. Note,
2625 * the physical port is treated as @vport 0.
2626 **/
James Smart87af33f2007-10-27 13:37:43 -04002627void
James Smart2e0fef82007-06-17 19:56:36 -05002628lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002629{
James Smart87af33f2007-10-27 13:37:43 -04002630 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002631 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002632 int i = 0;
dea31012005-04-17 16:05:31 -05002633
James Smart87af33f2007-10-27 13:37:43 -04002634 if (phba->link_state > LPFC_LINK_DOWN)
2635 lpfc_port_link_failure(vport);
2636
2637 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002638 if (!NLP_CHK_NODE_ACT(ndlp)) {
2639 ndlp = lpfc_enable_node(vport, ndlp,
2640 NLP_STE_UNUSED_NODE);
2641 if (!ndlp)
2642 continue;
2643 spin_lock_irq(&phba->ndlp_lock);
2644 NLP_SET_FREE_REQ(ndlp);
2645 spin_unlock_irq(&phba->ndlp_lock);
2646 /* Trigger the release of the ndlp memory */
2647 lpfc_nlp_put(ndlp);
2648 continue;
2649 }
2650 spin_lock_irq(&phba->ndlp_lock);
2651 if (NLP_CHK_FREE_REQ(ndlp)) {
2652 /* The ndlp should not be in memory free mode already */
2653 spin_unlock_irq(&phba->ndlp_lock);
2654 continue;
2655 } else
2656 /* Indicate request for freeing ndlp memory */
2657 NLP_SET_FREE_REQ(ndlp);
2658 spin_unlock_irq(&phba->ndlp_lock);
2659
James Smart58da1ff2008-04-07 10:15:56 -04002660 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2661 ndlp->nlp_DID == Fabric_DID) {
2662 /* Just free up ndlp with Fabric_DID for vports */
2663 lpfc_nlp_put(ndlp);
2664 continue;
2665 }
2666
James Smarteff4a012012-01-18 16:25:25 -05002667 /* take care of nodes in unused state before the state
2668 * machine taking action.
2669 */
2670 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2671 lpfc_nlp_put(ndlp);
2672 continue;
2673 }
2674
James Smart87af33f2007-10-27 13:37:43 -04002675 if (ndlp->nlp_type & NLP_FABRIC)
2676 lpfc_disc_state_machine(vport, ndlp, NULL,
2677 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002678
James Smarta0f2d3e2017-02-12 13:52:31 -08002679 if (ndlp->nlp_fc4_type & NLP_FC4_NVME) {
2680 /* Remove the NVME transport reference now and
2681 * continue to remove the node.
2682 */
2683 lpfc_nlp_put(ndlp);
2684 }
2685
James Smart87af33f2007-10-27 13:37:43 -04002686 lpfc_disc_state_machine(vport, ndlp, NULL,
2687 NLP_EVT_DEVICE_RM);
2688 }
2689
James Smarta8adb832007-10-27 13:37:53 -04002690 /* At this point, ALL ndlp's should be gone
2691 * because of the previous NLP_EVT_DEVICE_RM.
2692 * Lets wait for this to happen, if needed.
2693 */
James Smart87af33f2007-10-27 13:37:43 -04002694 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002695 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04002696 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04002697 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002698 list_for_each_entry_safe(ndlp, next_ndlp,
2699 &vport->fc_nodes, nlp_listp) {
2700 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2701 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04002702 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05002703 "usgmap:x%x refcnt:%d\n",
2704 ndlp->nlp_DID, (void *)ndlp,
2705 ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01002706 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05002707 }
James Smarta8adb832007-10-27 13:37:53 -04002708 break;
James Smart87af33f2007-10-27 13:37:43 -04002709 }
James Smarta8adb832007-10-27 13:37:53 -04002710
2711 /* Wait for any activity on ndlps to settle */
2712 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002713 }
James Smart1151e3e2011-02-16 12:39:35 -05002714 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002715}
2716
James Smarte59058c2008-08-24 21:49:00 -04002717/**
James Smart3621a712009-04-06 18:47:14 -04002718 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002719 * @vport: pointer to a virtual N_Port data structure.
2720 *
2721 * This routine stops all the timers associated with a @vport. This function
2722 * is invoked before disabling or deleting a @vport. Note that the physical
2723 * port is treated as @vport 0.
2724 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002725void
2726lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002727{
James Smart92d7f7b2007-06-17 19:56:38 -05002728 del_timer_sync(&vport->els_tmofunc);
James Smart92494142011-02-16 12:39:44 -05002729 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002730 lpfc_can_disctmo(vport);
2731 return;
dea31012005-04-17 16:05:31 -05002732}
2733
James Smarte59058c2008-08-24 21:49:00 -04002734/**
James Smartecfd03c2010-02-12 14:41:27 -05002735 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2736 * @phba: pointer to lpfc hba data structure.
2737 *
2738 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2739 * caller of this routine should already hold the host lock.
2740 **/
2741void
2742__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2743{
James Smart5ac6b302010-10-22 11:05:36 -04002744 /* Clear pending FCF rediscovery wait flag */
2745 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2746
James Smartecfd03c2010-02-12 14:41:27 -05002747 /* Now, try to stop the timer */
2748 del_timer(&phba->fcf.redisc_wait);
2749}
2750
2751/**
2752 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2753 * @phba: pointer to lpfc hba data structure.
2754 *
2755 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2756 * checks whether the FCF rediscovery wait timer is pending with the host
2757 * lock held before proceeding with disabling the timer and clearing the
2758 * wait timer pendig flag.
2759 **/
2760void
2761lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2762{
2763 spin_lock_irq(&phba->hbalock);
2764 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2765 /* FCF rediscovery timer already fired or stopped */
2766 spin_unlock_irq(&phba->hbalock);
2767 return;
2768 }
2769 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002770 /* Clear failover in progress flags */
2771 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002772 spin_unlock_irq(&phba->hbalock);
2773}
2774
2775/**
James Smart3772a992009-05-22 14:50:54 -04002776 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002777 * @phba: pointer to lpfc hba data structure.
2778 *
2779 * This routine stops all the timers associated with a HBA. This function is
2780 * invoked before either putting a HBA offline or unloading the driver.
2781 **/
James Smart3772a992009-05-22 14:50:54 -04002782void
2783lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002784{
James Smart51ef4c22007-08-02 11:10:31 -04002785 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05002786 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002787 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002788 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002789 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002790 if (phba->sli_rev == LPFC_SLI_REV4) {
2791 del_timer_sync(&phba->rrq_tmr);
2792 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2793 }
James Smart3772a992009-05-22 14:50:54 -04002794 phba->hb_outstanding = 0;
2795
2796 switch (phba->pci_dev_grp) {
2797 case LPFC_PCI_DEV_LP:
2798 /* Stop any LightPulse device specific driver timers */
2799 del_timer_sync(&phba->fcp_poll_timer);
2800 break;
2801 case LPFC_PCI_DEV_OC:
2802 /* Stop any OneConnect device sepcific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002803 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002804 break;
2805 default:
2806 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2807 "0297 Invalid device group (x%x)\n",
2808 phba->pci_dev_grp);
2809 break;
2810 }
James Smart2e0fef82007-06-17 19:56:36 -05002811 return;
dea31012005-04-17 16:05:31 -05002812}
2813
James Smarte59058c2008-08-24 21:49:00 -04002814/**
James Smart3621a712009-04-06 18:47:14 -04002815 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002816 * @phba: pointer to lpfc hba data structure.
2817 *
2818 * This routine marks a HBA's management interface as blocked. Once the HBA's
2819 * management interface is marked as blocked, all the user space access to
2820 * the HBA, whether they are from sysfs interface or libdfc interface will
2821 * all be blocked. The HBA is set to block the management interface when the
2822 * driver prepares the HBA interface for online or offline.
2823 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01002824static void
James Smart618a5232012-06-12 13:54:36 -04002825lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
Adrian Bunka6ababd2007-11-05 18:07:33 +01002826{
2827 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04002828 uint8_t actcmd = MBX_HEARTBEAT;
2829 unsigned long timeout;
2830
Adrian Bunka6ababd2007-11-05 18:07:33 +01002831 spin_lock_irqsave(&phba->hbalock, iflag);
2832 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart618a5232012-06-12 13:54:36 -04002833 spin_unlock_irqrestore(&phba->hbalock, iflag);
2834 if (mbx_action == LPFC_MBX_NO_WAIT)
2835 return;
2836 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2837 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002838 if (phba->sli.mbox_active) {
James Smart6e7288d2010-06-07 15:23:35 -04002839 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
James Smarta183a152011-10-10 21:32:43 -04002840 /* Determine how long we might wait for the active mailbox
2841 * command to be gracefully completed by firmware.
2842 */
2843 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
2844 phba->sli.mbox_active) * 1000) + jiffies;
2845 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002846 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002847
James Smart6e7288d2010-06-07 15:23:35 -04002848 /* Wait for the outstnading mailbox command to complete */
2849 while (phba->sli.mbox_active) {
2850 /* Check active mailbox complete status every 2ms */
2851 msleep(2);
2852 if (time_after(jiffies, timeout)) {
2853 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2854 "2813 Mgmt IO is Blocked %x "
2855 "- mbox cmd %x still active\n",
2856 phba->sli.sli_flag, actcmd);
2857 break;
2858 }
2859 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002860}
2861
James Smarte59058c2008-08-24 21:49:00 -04002862/**
James Smart6b5151f2012-01-18 16:24:06 -05002863 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
2864 * @phba: pointer to lpfc hba data structure.
2865 *
2866 * Allocate RPIs for all active remote nodes. This is needed whenever
2867 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
2868 * is to fixup the temporary rpi assignments.
2869 **/
2870void
2871lpfc_sli4_node_prep(struct lpfc_hba *phba)
2872{
2873 struct lpfc_nodelist *ndlp, *next_ndlp;
2874 struct lpfc_vport **vports;
2875 int i;
2876
2877 if (phba->sli_rev != LPFC_SLI_REV4)
2878 return;
2879
2880 vports = lpfc_create_vport_work_array(phba);
2881 if (vports != NULL) {
2882 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2883 if (vports[i]->load_flag & FC_UNLOADING)
2884 continue;
2885
2886 list_for_each_entry_safe(ndlp, next_ndlp,
2887 &vports[i]->fc_nodes,
2888 nlp_listp) {
James Smartbe6bb942015-04-07 15:07:22 -04002889 if (NLP_CHK_NODE_ACT(ndlp)) {
James Smart6b5151f2012-01-18 16:24:06 -05002890 ndlp->nlp_rpi =
2891 lpfc_sli4_alloc_rpi(phba);
James Smartbe6bb942015-04-07 15:07:22 -04002892 lpfc_printf_vlog(ndlp->vport, KERN_INFO,
2893 LOG_NODE,
2894 "0009 rpi:%x DID:%x "
2895 "flg:%x map:%x %p\n",
2896 ndlp->nlp_rpi,
2897 ndlp->nlp_DID,
2898 ndlp->nlp_flag,
2899 ndlp->nlp_usg_map,
2900 ndlp);
2901 }
James Smart6b5151f2012-01-18 16:24:06 -05002902 }
2903 }
2904 }
2905 lpfc_destroy_vport_work_array(phba, vports);
2906}
2907
2908/**
James Smart3621a712009-04-06 18:47:14 -04002909 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04002910 * @phba: pointer to lpfc hba data structure.
2911 *
2912 * This routine initializes the HBA and brings a HBA online. During this
2913 * process, the management interface is blocked to prevent user space access
2914 * to the HBA interfering with the driver initialization.
2915 *
2916 * Return codes
2917 * 0 - successful
2918 * 1 - failed
2919 **/
dea31012005-04-17 16:05:31 -05002920int
James Smart2e0fef82007-06-17 19:56:36 -05002921lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002922{
Julia Lawall372bd282008-12-16 16:15:08 +01002923 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04002924 struct lpfc_vport **vports;
2925 int i;
James Smart16a3a202013-04-17 20:14:38 -04002926 bool vpis_cleared = false;
James Smart2e0fef82007-06-17 19:56:36 -05002927
dea31012005-04-17 16:05:31 -05002928 if (!phba)
2929 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01002930 vport = phba->pport;
dea31012005-04-17 16:05:31 -05002931
James Smart2e0fef82007-06-17 19:56:36 -05002932 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05002933 return 0;
2934
James Smarted957682007-06-17 19:56:37 -05002935 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002936 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05002937
James Smart618a5232012-06-12 13:54:36 -04002938 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05002939
James Smartda0436e2009-05-22 14:51:39 -04002940 if (phba->sli_rev == LPFC_SLI_REV4) {
2941 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
2942 lpfc_unblock_mgmt_io(phba);
2943 return 1;
2944 }
James Smart16a3a202013-04-17 20:14:38 -04002945 spin_lock_irq(&phba->hbalock);
2946 if (!phba->sli4_hba.max_cfg_param.vpi_used)
2947 vpis_cleared = true;
2948 spin_unlock_irq(&phba->hbalock);
James Smartda0436e2009-05-22 14:51:39 -04002949 } else {
James Smart895427b2017-02-12 13:52:30 -08002950 lpfc_sli_queue_init(phba);
James Smartda0436e2009-05-22 14:51:39 -04002951 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
2952 lpfc_unblock_mgmt_io(phba);
2953 return 1;
2954 }
James Smart46fa3112007-04-25 09:51:45 -04002955 }
dea31012005-04-17 16:05:31 -05002956
James Smart549e55c2007-08-02 11:09:51 -04002957 vports = lpfc_create_vport_work_array(phba);
Arnd Bergmannaeb66412016-03-14 15:29:44 +01002958 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04002959 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002960 struct Scsi_Host *shost;
2961 shost = lpfc_shost_from_vport(vports[i]);
2962 spin_lock_irq(shost->host_lock);
2963 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
2964 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2965 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart16a3a202013-04-17 20:14:38 -04002966 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart1c6834a2009-07-19 10:01:26 -04002967 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart16a3a202013-04-17 20:14:38 -04002968 if ((vpis_cleared) &&
2969 (vports[i]->port_type !=
2970 LPFC_PHYSICAL_PORT))
2971 vports[i]->vpi = 0;
2972 }
James Smart549e55c2007-08-02 11:09:51 -04002973 spin_unlock_irq(shost->host_lock);
2974 }
Arnd Bergmannaeb66412016-03-14 15:29:44 +01002975 }
2976 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002977
James Smart46fa3112007-04-25 09:51:45 -04002978 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002979 return 0;
2980}
2981
James Smarte59058c2008-08-24 21:49:00 -04002982/**
James Smart3621a712009-04-06 18:47:14 -04002983 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04002984 * @phba: pointer to lpfc hba data structure.
2985 *
2986 * This routine marks a HBA's management interface as not blocked. Once the
2987 * HBA's management interface is marked as not blocked, all the user space
2988 * access to the HBA, whether they are from sysfs interface or libdfc
2989 * interface will be allowed. The HBA is set to block the management interface
2990 * when the driver prepares the HBA interface for online or offline and then
2991 * set to unblock the management interface afterwards.
2992 **/
James Smart46fa3112007-04-25 09:51:45 -04002993void
James Smart46fa3112007-04-25 09:51:45 -04002994lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
2995{
2996 unsigned long iflag;
2997
James Smart2e0fef82007-06-17 19:56:36 -05002998 spin_lock_irqsave(&phba->hbalock, iflag);
2999 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
3000 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04003001}
3002
James Smarte59058c2008-08-24 21:49:00 -04003003/**
James Smart3621a712009-04-06 18:47:14 -04003004 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04003005 * @phba: pointer to lpfc hba data structure.
3006 *
3007 * This routine is invoked to prepare a HBA to be brought offline. It performs
3008 * unregistration login to all the nodes on all vports and flushes the mailbox
3009 * queue to make it ready to be brought offline.
3010 **/
James Smart46fa3112007-04-25 09:51:45 -04003011void
James Smart618a5232012-06-12 13:54:36 -04003012lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04003013{
James Smart2e0fef82007-06-17 19:56:36 -05003014 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04003015 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04003016 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05003017 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04003018 int i;
dea31012005-04-17 16:05:31 -05003019
James Smart2e0fef82007-06-17 19:56:36 -05003020 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003021 return;
dea31012005-04-17 16:05:31 -05003022
James Smart618a5232012-06-12 13:54:36 -04003023 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05003024
3025 lpfc_linkdown(phba);
3026
James Smart87af33f2007-10-27 13:37:43 -04003027 /* Issue an unreg_login to all nodes on all vports */
3028 vports = lpfc_create_vport_work_array(phba);
3029 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003030 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04003031 if (vports[i]->load_flag & FC_UNLOADING)
3032 continue;
James Smart72100cc2010-02-12 14:43:01 -05003033 shost = lpfc_shost_from_vport(vports[i]);
3034 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003035 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003036 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3037 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05003038 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05003039
James Smart87af33f2007-10-27 13:37:43 -04003040 shost = lpfc_shost_from_vport(vports[i]);
3041 list_for_each_entry_safe(ndlp, next_ndlp,
3042 &vports[i]->fc_nodes,
3043 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003044 if (!NLP_CHK_NODE_ACT(ndlp))
3045 continue;
James Smart87af33f2007-10-27 13:37:43 -04003046 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3047 continue;
3048 if (ndlp->nlp_type & NLP_FABRIC) {
3049 lpfc_disc_state_machine(vports[i], ndlp,
3050 NULL, NLP_EVT_DEVICE_RECOVERY);
3051 lpfc_disc_state_machine(vports[i], ndlp,
3052 NULL, NLP_EVT_DEVICE_RM);
3053 }
3054 spin_lock_irq(shost->host_lock);
3055 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart401ee0c2012-03-01 22:35:34 -05003056 spin_unlock_irq(shost->host_lock);
James Smart6b5151f2012-01-18 16:24:06 -05003057 /*
3058 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05003059 * RPI. Get a new RPI when the adapter port
3060 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05003061 */
James Smartbe6bb942015-04-07 15:07:22 -04003062 if (phba->sli_rev == LPFC_SLI_REV4) {
3063 lpfc_printf_vlog(ndlp->vport,
3064 KERN_INFO, LOG_NODE,
3065 "0011 lpfc_offline: "
3066 "ndlp:x%p did %x "
3067 "usgmap:x%x rpi:%x\n",
3068 ndlp, ndlp->nlp_DID,
3069 ndlp->nlp_usg_map,
3070 ndlp->nlp_rpi);
3071
James Smart6b5151f2012-01-18 16:24:06 -05003072 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smartbe6bb942015-04-07 15:07:22 -04003073 }
James Smart87af33f2007-10-27 13:37:43 -04003074 lpfc_unreg_rpi(vports[i], ndlp);
3075 }
3076 }
3077 }
James Smart09372822008-01-11 01:52:54 -05003078 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003079
James Smart618a5232012-06-12 13:54:36 -04003080 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
James Smart46fa3112007-04-25 09:51:45 -04003081}
3082
James Smarte59058c2008-08-24 21:49:00 -04003083/**
James Smart3621a712009-04-06 18:47:14 -04003084 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04003085 * @phba: pointer to lpfc hba data structure.
3086 *
3087 * This routine actually brings a HBA offline. It stops all the timers
3088 * associated with the HBA, brings down the SLI layer, and eventually
3089 * marks the HBA as in offline state for the upper layer protocol.
3090 **/
James Smart46fa3112007-04-25 09:51:45 -04003091void
James Smart2e0fef82007-06-17 19:56:36 -05003092lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04003093{
James Smart549e55c2007-08-02 11:09:51 -04003094 struct Scsi_Host *shost;
3095 struct lpfc_vport **vports;
3096 int i;
James Smart46fa3112007-04-25 09:51:45 -04003097
James Smart549e55c2007-08-02 11:09:51 -04003098 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003099 return;
James Smart688a8862006-07-06 15:49:56 -04003100
James Smartda0436e2009-05-22 14:51:39 -04003101 /* stop port and all timers associated with this hba */
3102 lpfc_stop_port(phba);
James Smart51ef4c22007-08-02 11:10:31 -04003103 vports = lpfc_create_vport_work_array(phba);
3104 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003105 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04003106 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05003107 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05003108 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003109 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05003110 /* Bring down the SLI Layer and cleanup. The HBA is offline
3111 now. */
3112 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003113 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04003114 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003115 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04003116 vports = lpfc_create_vport_work_array(phba);
3117 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003118 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003119 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04003120 spin_lock_irq(shost->host_lock);
3121 vports[i]->work_port_events = 0;
3122 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3123 spin_unlock_irq(shost->host_lock);
3124 }
James Smart09372822008-01-11 01:52:54 -05003125 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003126}
3127
James Smarte59058c2008-08-24 21:49:00 -04003128/**
James Smart3621a712009-04-06 18:47:14 -04003129 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04003130 * @phba: pointer to lpfc hba data structure.
3131 *
3132 * This routine is to free all the SCSI buffers and IOCBs from the driver
3133 * list back to kernel. It is called from lpfc_pci_remove_one to free
3134 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04003135 **/
James Smart8a9d2e82012-05-09 21:16:12 -04003136static void
James Smart2e0fef82007-06-17 19:56:36 -05003137lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003138{
3139 struct lpfc_scsi_buf *sb, *sb_next;
dea31012005-04-17 16:05:31 -05003140
James Smart895427b2017-02-12 13:52:30 -08003141 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3142 return;
3143
James Smart2e0fef82007-06-17 19:56:36 -05003144 spin_lock_irq(&phba->hbalock);
James Smarta40fc5f2013-04-17 20:17:40 -04003145
dea31012005-04-17 16:05:31 -05003146 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smarta40fc5f2013-04-17 20:17:40 -04003147
3148 spin_lock(&phba->scsi_buf_list_put_lock);
3149 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3150 list) {
dea31012005-04-17 16:05:31 -05003151 list_del(&sb->list);
James Smart895427b2017-02-12 13:52:30 -08003152 pci_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05003153 sb->dma_handle);
dea31012005-04-17 16:05:31 -05003154 kfree(sb);
3155 phba->total_scsi_bufs--;
3156 }
James Smarta40fc5f2013-04-17 20:17:40 -04003157 spin_unlock(&phba->scsi_buf_list_put_lock);
3158
3159 spin_lock(&phba->scsi_buf_list_get_lock);
3160 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3161 list) {
3162 list_del(&sb->list);
James Smart895427b2017-02-12 13:52:30 -08003163 pci_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smarta40fc5f2013-04-17 20:17:40 -04003164 sb->dma_handle);
3165 kfree(sb);
3166 phba->total_scsi_bufs--;
3167 }
3168 spin_unlock(&phba->scsi_buf_list_get_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003169 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003170}
James Smart8a9d2e82012-05-09 21:16:12 -04003171/**
James Smart895427b2017-02-12 13:52:30 -08003172 * lpfc_nvme_free - Free all the NVME buffers and IOCBs from driver lists
3173 * @phba: pointer to lpfc hba data structure.
3174 *
3175 * This routine is to free all the NVME buffers and IOCBs from the driver
3176 * list back to kernel. It is called from lpfc_pci_remove_one to free
3177 * the internal resources before the device is removed from the system.
3178 **/
3179static void
3180lpfc_nvme_free(struct lpfc_hba *phba)
3181{
3182 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
James Smart895427b2017-02-12 13:52:30 -08003183
3184 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3185 return;
3186
3187 spin_lock_irq(&phba->hbalock);
3188
3189 /* Release all the lpfc_nvme_bufs maintained by this host. */
3190 spin_lock(&phba->nvme_buf_list_put_lock);
3191 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3192 &phba->lpfc_nvme_buf_list_put, list) {
3193 list_del(&lpfc_ncmd->list);
3194 pci_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
3195 lpfc_ncmd->dma_handle);
3196 kfree(lpfc_ncmd);
3197 phba->total_nvme_bufs--;
3198 }
3199 spin_unlock(&phba->nvme_buf_list_put_lock);
3200
3201 spin_lock(&phba->nvme_buf_list_get_lock);
3202 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3203 &phba->lpfc_nvme_buf_list_get, list) {
3204 list_del(&lpfc_ncmd->list);
3205 pci_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
3206 lpfc_ncmd->dma_handle);
3207 kfree(lpfc_ncmd);
3208 phba->total_nvme_bufs--;
3209 }
3210 spin_unlock(&phba->nvme_buf_list_get_lock);
James Smart895427b2017-02-12 13:52:30 -08003211 spin_unlock_irq(&phba->hbalock);
3212}
3213/**
3214 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
James Smart8a9d2e82012-05-09 21:16:12 -04003215 * @phba: pointer to lpfc hba data structure.
3216 *
3217 * This routine first calculates the sizes of the current els and allocated
3218 * scsi sgl lists, and then goes through all sgls to updates the physical
3219 * XRIs assigned due to port function reset. During port initialization, the
3220 * current els and allocated scsi sgl lists are 0s.
3221 *
3222 * Return codes
3223 * 0 - successful (for now, it always returns 0)
3224 **/
3225int
James Smart895427b2017-02-12 13:52:30 -08003226lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
James Smart8a9d2e82012-05-09 21:16:12 -04003227{
3228 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
James Smart895427b2017-02-12 13:52:30 -08003229 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart8a9d2e82012-05-09 21:16:12 -04003230 LIST_HEAD(els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003231 int rc;
3232
3233 /*
3234 * update on pci function's els xri-sgl list
3235 */
3236 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart895427b2017-02-12 13:52:30 -08003237
James Smart8a9d2e82012-05-09 21:16:12 -04003238 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3239 /* els xri-sgl expanded */
3240 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3241 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3242 "3157 ELS xri-sgl count increased from "
3243 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3244 els_xri_cnt);
3245 /* allocate the additional els sgls */
3246 for (i = 0; i < xri_cnt; i++) {
3247 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3248 GFP_KERNEL);
3249 if (sglq_entry == NULL) {
3250 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3251 "2562 Failure to allocate an "
3252 "ELS sgl entry:%d\n", i);
3253 rc = -ENOMEM;
3254 goto out_free_mem;
3255 }
3256 sglq_entry->buff_type = GEN_BUFF_TYPE;
3257 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3258 &sglq_entry->phys);
3259 if (sglq_entry->virt == NULL) {
3260 kfree(sglq_entry);
3261 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3262 "2563 Failure to allocate an "
3263 "ELS mbuf:%d\n", i);
3264 rc = -ENOMEM;
3265 goto out_free_mem;
3266 }
3267 sglq_entry->sgl = sglq_entry->virt;
3268 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3269 sglq_entry->state = SGL_FREED;
3270 list_add_tail(&sglq_entry->list, &els_sgl_list);
3271 }
James Smart38c20672013-03-01 16:37:44 -05003272 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003273 spin_lock(&phba->sli4_hba.sgl_list_lock);
3274 list_splice_init(&els_sgl_list,
3275 &phba->sli4_hba.lpfc_els_sgl_list);
3276 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart38c20672013-03-01 16:37:44 -05003277 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003278 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3279 /* els xri-sgl shrinked */
3280 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3281 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3282 "3158 ELS xri-sgl count decreased from "
3283 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3284 els_xri_cnt);
3285 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003286 spin_lock(&phba->sli4_hba.sgl_list_lock);
3287 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
3288 &els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003289 /* release extra els sgls from list */
3290 for (i = 0; i < xri_cnt; i++) {
3291 list_remove_head(&els_sgl_list,
3292 sglq_entry, struct lpfc_sglq, list);
3293 if (sglq_entry) {
James Smart895427b2017-02-12 13:52:30 -08003294 __lpfc_mbuf_free(phba, sglq_entry->virt,
3295 sglq_entry->phys);
James Smart8a9d2e82012-05-09 21:16:12 -04003296 kfree(sglq_entry);
3297 }
3298 }
James Smart895427b2017-02-12 13:52:30 -08003299 list_splice_init(&els_sgl_list,
3300 &phba->sli4_hba.lpfc_els_sgl_list);
3301 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003302 spin_unlock_irq(&phba->hbalock);
3303 } else
3304 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3305 "3163 ELS xri-sgl count unchanged: %d\n",
3306 els_xri_cnt);
3307 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3308
3309 /* update xris to els sgls on the list */
3310 sglq_entry = NULL;
3311 sglq_entry_next = NULL;
3312 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
James Smart895427b2017-02-12 13:52:30 -08003313 &phba->sli4_hba.lpfc_els_sgl_list, list) {
James Smart8a9d2e82012-05-09 21:16:12 -04003314 lxri = lpfc_sli4_next_xritag(phba);
3315 if (lxri == NO_XRI) {
3316 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3317 "2400 Failed to allocate xri for "
3318 "ELS sgl\n");
3319 rc = -ENOMEM;
3320 goto out_free_mem;
3321 }
3322 sglq_entry->sli4_lxritag = lxri;
3323 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3324 }
James Smart895427b2017-02-12 13:52:30 -08003325 return 0;
3326
3327out_free_mem:
3328 lpfc_free_els_sgl_list(phba);
3329 return rc;
3330}
3331
3332/**
James Smartf358dd02017-02-12 13:52:34 -08003333 * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping
3334 * @phba: pointer to lpfc hba data structure.
3335 *
3336 * This routine first calculates the sizes of the current els and allocated
3337 * scsi sgl lists, and then goes through all sgls to updates the physical
3338 * XRIs assigned due to port function reset. During port initialization, the
3339 * current els and allocated scsi sgl lists are 0s.
3340 *
3341 * Return codes
3342 * 0 - successful (for now, it always returns 0)
3343 **/
3344int
3345lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba)
3346{
3347 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
3348 uint16_t i, lxri, xri_cnt, els_xri_cnt;
3349 uint16_t nvmet_xri_cnt, tot_cnt;
3350 LIST_HEAD(nvmet_sgl_list);
3351 int rc;
3352
3353 /*
3354 * update on pci function's nvmet xri-sgl list
3355 */
3356 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart2d7dbc42017-02-12 13:52:35 -08003357 nvmet_xri_cnt = phba->cfg_nvmet_mrq * phba->cfg_nvmet_mrq_post;
James Smartf358dd02017-02-12 13:52:34 -08003358 tot_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
James Smart2d7dbc42017-02-12 13:52:35 -08003359 if (nvmet_xri_cnt > tot_cnt) {
3360 phba->cfg_nvmet_mrq_post = tot_cnt / phba->cfg_nvmet_mrq;
3361 nvmet_xri_cnt = phba->cfg_nvmet_mrq * phba->cfg_nvmet_mrq_post;
3362 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3363 "6301 NVMET post-sgl count changed to %d\n",
3364 phba->cfg_nvmet_mrq_post);
3365 }
James Smartf358dd02017-02-12 13:52:34 -08003366
3367 if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) {
3368 /* els xri-sgl expanded */
3369 xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt;
3370 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3371 "6302 NVMET xri-sgl cnt grew from %d to %d\n",
3372 phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt);
3373 /* allocate the additional nvmet sgls */
3374 for (i = 0; i < xri_cnt; i++) {
3375 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3376 GFP_KERNEL);
3377 if (sglq_entry == NULL) {
3378 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3379 "6303 Failure to allocate an "
3380 "NVMET sgl entry:%d\n", i);
3381 rc = -ENOMEM;
3382 goto out_free_mem;
3383 }
3384 sglq_entry->buff_type = NVMET_BUFF_TYPE;
3385 sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0,
3386 &sglq_entry->phys);
3387 if (sglq_entry->virt == NULL) {
3388 kfree(sglq_entry);
3389 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3390 "6304 Failure to allocate an "
3391 "NVMET buf:%d\n", i);
3392 rc = -ENOMEM;
3393 goto out_free_mem;
3394 }
3395 sglq_entry->sgl = sglq_entry->virt;
3396 memset(sglq_entry->sgl, 0,
3397 phba->cfg_sg_dma_buf_size);
3398 sglq_entry->state = SGL_FREED;
3399 list_add_tail(&sglq_entry->list, &nvmet_sgl_list);
3400 }
3401 spin_lock_irq(&phba->hbalock);
3402 spin_lock(&phba->sli4_hba.sgl_list_lock);
3403 list_splice_init(&nvmet_sgl_list,
3404 &phba->sli4_hba.lpfc_nvmet_sgl_list);
3405 spin_unlock(&phba->sli4_hba.sgl_list_lock);
3406 spin_unlock_irq(&phba->hbalock);
3407 } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) {
3408 /* nvmet xri-sgl shrunk */
3409 xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt;
3410 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3411 "6305 NVMET xri-sgl count decreased from "
3412 "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt,
3413 nvmet_xri_cnt);
3414 spin_lock_irq(&phba->hbalock);
3415 spin_lock(&phba->sli4_hba.sgl_list_lock);
3416 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list,
3417 &nvmet_sgl_list);
3418 /* release extra nvmet sgls from list */
3419 for (i = 0; i < xri_cnt; i++) {
3420 list_remove_head(&nvmet_sgl_list,
3421 sglq_entry, struct lpfc_sglq, list);
3422 if (sglq_entry) {
3423 lpfc_nvmet_buf_free(phba, sglq_entry->virt,
3424 sglq_entry->phys);
3425 kfree(sglq_entry);
3426 }
3427 }
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
3433 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3434 "6306 NVMET xri-sgl count unchanged: %d\n",
3435 nvmet_xri_cnt);
3436 phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt;
3437
3438 /* update xris to nvmet sgls on the list */
3439 sglq_entry = NULL;
3440 sglq_entry_next = NULL;
3441 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
3442 &phba->sli4_hba.lpfc_nvmet_sgl_list, list) {
3443 lxri = lpfc_sli4_next_xritag(phba);
3444 if (lxri == NO_XRI) {
3445 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3446 "6307 Failed to allocate xri for "
3447 "NVMET sgl\n");
3448 rc = -ENOMEM;
3449 goto out_free_mem;
3450 }
3451 sglq_entry->sli4_lxritag = lxri;
3452 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3453 }
3454 return 0;
3455
3456out_free_mem:
3457 lpfc_free_nvmet_sgl_list(phba);
3458 return rc;
3459}
3460
3461/**
James Smart895427b2017-02-12 13:52:30 -08003462 * lpfc_sli4_scsi_sgl_update - update xri-sgl sizing and mapping
3463 * @phba: pointer to lpfc hba data structure.
3464 *
3465 * This routine first calculates the sizes of the current els and allocated
3466 * scsi sgl lists, and then goes through all sgls to updates the physical
3467 * XRIs assigned due to port function reset. During port initialization, the
3468 * current els and allocated scsi sgl lists are 0s.
3469 *
3470 * Return codes
3471 * 0 - successful (for now, it always returns 0)
3472 **/
3473int
3474lpfc_sli4_scsi_sgl_update(struct lpfc_hba *phba)
3475{
3476 struct lpfc_scsi_buf *psb, *psb_next;
3477 uint16_t i, lxri, els_xri_cnt, scsi_xri_cnt;
3478 LIST_HEAD(scsi_sgl_list);
3479 int rc;
3480
3481 /*
3482 * update on pci function's els xri-sgl list
3483 */
3484 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3485 phba->total_scsi_bufs = 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003486
3487 /*
3488 * update on pci function's allocated scsi xri-sgl list
3489 */
James Smart8a9d2e82012-05-09 21:16:12 -04003490 /* maximum number of xris available for scsi buffers */
3491 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3492 els_xri_cnt;
3493
James Smart895427b2017-02-12 13:52:30 -08003494 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3495 return 0;
3496
3497 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3498 phba->sli4_hba.scsi_xri_max = /* Split them up */
3499 (phba->sli4_hba.scsi_xri_max *
3500 phba->cfg_xri_split) / 100;
James Smart8a9d2e82012-05-09 21:16:12 -04003501
James Smarta40fc5f2013-04-17 20:17:40 -04003502 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003503 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003504 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3505 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
James Smart164cecd2013-09-06 12:22:38 -04003506 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003507 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003508
3509 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3510 /* max scsi xri shrinked below the allocated scsi buffers */
3511 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3512 phba->sli4_hba.scsi_xri_max;
3513 /* release the extra allocated scsi buffers */
3514 for (i = 0; i < scsi_xri_cnt; i++) {
3515 list_remove_head(&scsi_sgl_list, psb,
3516 struct lpfc_scsi_buf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04003517 if (psb) {
James Smart895427b2017-02-12 13:52:30 -08003518 pci_pool_free(phba->lpfc_sg_dma_buf_pool,
James Smarta2fc4aef2014-09-03 12:57:55 -04003519 psb->data, psb->dma_handle);
3520 kfree(psb);
3521 }
James Smart8a9d2e82012-05-09 21:16:12 -04003522 }
James Smarta40fc5f2013-04-17 20:17:40 -04003523 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003524 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
James Smarta40fc5f2013-04-17 20:17:40 -04003525 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003526 }
3527
3528 /* update xris associated to remaining allocated scsi buffers */
3529 psb = NULL;
3530 psb_next = NULL;
3531 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3532 lxri = lpfc_sli4_next_xritag(phba);
3533 if (lxri == NO_XRI) {
3534 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3535 "2560 Failed to allocate xri for "
3536 "scsi buffer\n");
3537 rc = -ENOMEM;
3538 goto out_free_mem;
3539 }
3540 psb->cur_iocbq.sli4_lxritag = lxri;
3541 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3542 }
James Smarta40fc5f2013-04-17 20:17:40 -04003543 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003544 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003545 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3546 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
James Smart164cecd2013-09-06 12:22:38 -04003547 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003548 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
dea31012005-04-17 16:05:31 -05003549 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003550
3551out_free_mem:
James Smart8a9d2e82012-05-09 21:16:12 -04003552 lpfc_scsi_free(phba);
3553 return rc;
dea31012005-04-17 16:05:31 -05003554}
3555
James Smarte59058c2008-08-24 21:49:00 -04003556/**
James Smart895427b2017-02-12 13:52:30 -08003557 * lpfc_sli4_nvme_sgl_update - update xri-sgl sizing and mapping
3558 * @phba: pointer to lpfc hba data structure.
3559 *
3560 * This routine first calculates the sizes of the current els and allocated
3561 * scsi sgl lists, and then goes through all sgls to updates the physical
3562 * XRIs assigned due to port function reset. During port initialization, the
3563 * current els and allocated scsi sgl lists are 0s.
3564 *
3565 * Return codes
3566 * 0 - successful (for now, it always returns 0)
3567 **/
3568int
3569lpfc_sli4_nvme_sgl_update(struct lpfc_hba *phba)
3570{
3571 struct lpfc_nvme_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
3572 uint16_t i, lxri, els_xri_cnt;
3573 uint16_t nvme_xri_cnt, nvme_xri_max;
3574 LIST_HEAD(nvme_sgl_list);
3575 int rc;
3576
3577 phba->total_nvme_bufs = 0;
3578
3579 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3580 return 0;
3581 /*
3582 * update on pci function's allocated nvme xri-sgl list
3583 */
3584
3585 /* maximum number of xris available for nvme buffers */
3586 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3587 nvme_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3588 phba->sli4_hba.nvme_xri_max = nvme_xri_max;
3589 phba->sli4_hba.nvme_xri_max -= phba->sli4_hba.scsi_xri_max;
3590
3591 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3592 "6074 Current allocated NVME xri-sgl count:%d, "
3593 "maximum NVME xri count:%d\n",
3594 phba->sli4_hba.nvme_xri_cnt,
3595 phba->sli4_hba.nvme_xri_max);
3596
3597 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3598 spin_lock(&phba->nvme_buf_list_put_lock);
3599 list_splice_init(&phba->lpfc_nvme_buf_list_get, &nvme_sgl_list);
3600 list_splice(&phba->lpfc_nvme_buf_list_put, &nvme_sgl_list);
3601 spin_unlock(&phba->nvme_buf_list_put_lock);
3602 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3603
3604 if (phba->sli4_hba.nvme_xri_cnt > phba->sli4_hba.nvme_xri_max) {
3605 /* max nvme xri shrunk below the allocated nvme buffers */
3606 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3607 nvme_xri_cnt = phba->sli4_hba.nvme_xri_cnt -
3608 phba->sli4_hba.nvme_xri_max;
3609 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3610 /* release the extra allocated nvme buffers */
3611 for (i = 0; i < nvme_xri_cnt; i++) {
3612 list_remove_head(&nvme_sgl_list, lpfc_ncmd,
3613 struct lpfc_nvme_buf, list);
3614 if (lpfc_ncmd) {
3615 pci_pool_free(phba->lpfc_sg_dma_buf_pool,
3616 lpfc_ncmd->data,
3617 lpfc_ncmd->dma_handle);
3618 kfree(lpfc_ncmd);
3619 }
3620 }
3621 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3622 phba->sli4_hba.nvme_xri_cnt -= nvme_xri_cnt;
3623 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3624 }
3625
3626 /* update xris associated to remaining allocated nvme buffers */
3627 lpfc_ncmd = NULL;
3628 lpfc_ncmd_next = NULL;
3629 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3630 &nvme_sgl_list, list) {
3631 lxri = lpfc_sli4_next_xritag(phba);
3632 if (lxri == NO_XRI) {
3633 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3634 "6075 Failed to allocate xri for "
3635 "nvme buffer\n");
3636 rc = -ENOMEM;
3637 goto out_free_mem;
3638 }
3639 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
3640 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3641 }
3642 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3643 spin_lock(&phba->nvme_buf_list_put_lock);
3644 list_splice_init(&nvme_sgl_list, &phba->lpfc_nvme_buf_list_get);
3645 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
3646 spin_unlock(&phba->nvme_buf_list_put_lock);
3647 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3648 return 0;
3649
3650out_free_mem:
3651 lpfc_nvme_free(phba);
3652 return rc;
3653}
3654
3655/**
James Smart3621a712009-04-06 18:47:14 -04003656 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04003657 * @phba: pointer to lpfc hba data structure.
3658 * @instance: a unique integer ID to this FC port.
3659 * @dev: pointer to the device data structure.
3660 *
3661 * This routine creates a FC port for the upper layer protocol. The FC port
3662 * can be created on top of either a physical port or a virtual port provided
3663 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3664 * and associates the FC port created before adding the shost into the SCSI
3665 * layer.
3666 *
3667 * Return codes
3668 * @vport - pointer to the virtual N_Port data structure.
3669 * NULL - port create failed.
3670 **/
James Smart2e0fef82007-06-17 19:56:36 -05003671struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04003672lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04003673{
James Smart2e0fef82007-06-17 19:56:36 -05003674 struct lpfc_vport *vport;
James Smart895427b2017-02-12 13:52:30 -08003675 struct Scsi_Host *shost = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003676 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04003677
James Smart895427b2017-02-12 13:52:30 -08003678 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
3679 if (dev != &phba->pcidev->dev) {
3680 shost = scsi_host_alloc(&lpfc_vport_template,
3681 sizeof(struct lpfc_vport));
3682 } else {
3683 if (phba->sli_rev == LPFC_SLI_REV4)
3684 shost = scsi_host_alloc(&lpfc_template,
3685 sizeof(struct lpfc_vport));
3686 else
3687 shost = scsi_host_alloc(&lpfc_template_s3,
3688 sizeof(struct lpfc_vport));
3689 }
3690 } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
3691 shost = scsi_host_alloc(&lpfc_template_nvme,
James Smartea4142f2015-04-07 15:07:13 -04003692 sizeof(struct lpfc_vport));
3693 }
James Smart2e0fef82007-06-17 19:56:36 -05003694 if (!shost)
3695 goto out;
James Smart47a86172007-04-25 09:53:22 -04003696
James Smart2e0fef82007-06-17 19:56:36 -05003697 vport = (struct lpfc_vport *) shost->hostdata;
3698 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05003699 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05003700 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05003701 vport->fc_rscn_flush = 0;
James Smart3de2a652007-08-02 11:09:59 -04003702 lpfc_get_vport_cfgparam(vport);
James Smart895427b2017-02-12 13:52:30 -08003703
James Smart2e0fef82007-06-17 19:56:36 -05003704 shost->unique_id = instance;
3705 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04003706 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05003707 shost->this_id = -1;
3708 shost->max_cmd_len = 16;
James Smart8b0dff12015-05-22 10:42:38 -04003709 shost->nr_hw_queues = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04003710 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05003711 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04003712 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smartda0436e2009-05-22 14:51:39 -04003713 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
3714 }
James Smart81301a92008-12-04 22:39:46 -05003715
James Smart47a86172007-04-25 09:53:22 -04003716 /*
James Smart2e0fef82007-06-17 19:56:36 -05003717 * Set initial can_queue value since 0 is no longer supported and
3718 * scsi_add_host will fail. This will be adjusted later based on the
3719 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04003720 */
James Smart2e0fef82007-06-17 19:56:36 -05003721 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04003722 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05003723 shost->transportt = lpfc_vport_transport_template;
3724 vport->port_type = LPFC_NPIV_PORT;
3725 } else {
3726 shost->transportt = lpfc_transport_template;
3727 vport->port_type = LPFC_PHYSICAL_PORT;
3728 }
James Smart47a86172007-04-25 09:53:22 -04003729
James Smart2e0fef82007-06-17 19:56:36 -05003730 /* Initialize all internally managed lists. */
3731 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04003732 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05003733 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04003734
James Smart2e0fef82007-06-17 19:56:36 -05003735 init_timer(&vport->fc_disctmo);
3736 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003737 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04003738
James Smart2e0fef82007-06-17 19:56:36 -05003739 init_timer(&vport->els_tmofunc);
3740 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003741 vport->els_tmofunc.data = (unsigned long)vport;
James Smart92494142011-02-16 12:39:44 -05003742
3743 init_timer(&vport->delayed_disc_tmo);
3744 vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
3745 vport->delayed_disc_tmo.data = (unsigned long)vport;
3746
James Bottomleyd139b9b2009-11-05 13:33:12 -06003747 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05003748 if (error)
3749 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04003750
James Smart549e55c2007-08-02 11:09:51 -04003751 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003752 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04003753 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003754 return vport;
James Smart47a86172007-04-25 09:53:22 -04003755
James Smart2e0fef82007-06-17 19:56:36 -05003756out_put_shost:
3757 scsi_host_put(shost);
3758out:
3759 return NULL;
James Smart47a86172007-04-25 09:53:22 -04003760}
3761
James Smarte59058c2008-08-24 21:49:00 -04003762/**
James Smart3621a712009-04-06 18:47:14 -04003763 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04003764 * @vport: pointer to an lpfc virtual N_Port data structure.
3765 *
3766 * This routine destroys a FC port from the upper layer protocol. All the
3767 * resources associated with the port are released.
3768 **/
James Smart2e0fef82007-06-17 19:56:36 -05003769void
3770destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04003771{
James Smart92d7f7b2007-06-17 19:56:38 -05003772 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3773 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003774
James Smart858c9f62007-06-17 19:56:39 -05003775 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05003776 fc_remove_host(shost);
3777 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04003778
James Smart92d7f7b2007-06-17 19:56:38 -05003779 spin_lock_irq(&phba->hbalock);
3780 list_del_init(&vport->listentry);
3781 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04003782
James Smart92d7f7b2007-06-17 19:56:38 -05003783 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04003784 return;
James Smart47a86172007-04-25 09:53:22 -04003785}
3786
James Smarte59058c2008-08-24 21:49:00 -04003787/**
James Smart3621a712009-04-06 18:47:14 -04003788 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04003789 *
3790 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3791 * uses the kernel idr facility to perform the task.
3792 *
3793 * Return codes:
3794 * instance - a unique integer ID allocated as the new instance.
3795 * -1 - lpfc get instance failed.
3796 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003797int
3798lpfc_get_instance(void)
3799{
Tejun Heoab516032013-02-27 17:04:44 -08003800 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003801
Tejun Heoab516032013-02-27 17:04:44 -08003802 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
3803 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003804}
3805
James Smarte59058c2008-08-24 21:49:00 -04003806/**
James Smart3621a712009-04-06 18:47:14 -04003807 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04003808 * @shost: pointer to SCSI host data structure.
3809 * @time: elapsed time of the scan in jiffies.
3810 *
3811 * This routine is called by the SCSI layer with a SCSI host to determine
3812 * whether the scan host is finished.
3813 *
3814 * Note: there is no scan_start function as adapter initialization will have
3815 * asynchronously kicked off the link initialization.
3816 *
3817 * Return codes
3818 * 0 - SCSI host scan is not over yet.
3819 * 1 - SCSI host scan is over.
3820 **/
James Smart47a86172007-04-25 09:53:22 -04003821int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
3822{
James Smart2e0fef82007-06-17 19:56:36 -05003823 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3824 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05003825 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04003826
James Smart858c9f62007-06-17 19:56:39 -05003827 spin_lock_irq(shost->host_lock);
3828
James Smart51ef4c22007-08-02 11:10:31 -04003829 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05003830 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003831 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05003832 }
James Smart256ec0d2013-04-17 20:14:58 -04003833 if (time >= msecs_to_jiffies(30 * 1000)) {
James Smart2e0fef82007-06-17 19:56:36 -05003834 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003835 "0461 Scanning longer than 30 "
3836 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003837 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003838 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003839 }
James Smart256ec0d2013-04-17 20:14:58 -04003840 if (time >= msecs_to_jiffies(15 * 1000) &&
3841 phba->link_state <= LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05003842 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003843 "0465 Link down longer than 15 "
3844 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003845 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05003846 goto finished;
James Smart47a86172007-04-25 09:53:22 -04003847 }
3848
James Smart2e0fef82007-06-17 19:56:36 -05003849 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05003850 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003851 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05003852 goto finished;
James Smart256ec0d2013-04-17 20:14:58 -04003853 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
James Smart858c9f62007-06-17 19:56:39 -05003854 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003855 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05003856 goto finished;
3857
3858 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003859
3860finished:
James Smart858c9f62007-06-17 19:56:39 -05003861 spin_unlock_irq(shost->host_lock);
3862 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003863}
3864
James Smarte59058c2008-08-24 21:49:00 -04003865/**
James Smart3621a712009-04-06 18:47:14 -04003866 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04003867 * @shost: pointer to SCSI host data structure.
3868 *
3869 * This routine initializes a given SCSI host attributes on a FC port. The
3870 * SCSI host can be either on top of a physical port or a virtual port.
3871 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003872void lpfc_host_attrib_init(struct Scsi_Host *shost)
3873{
3874 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3875 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003876 /*
James Smart2e0fef82007-06-17 19:56:36 -05003877 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04003878 */
3879
James Smart2e0fef82007-06-17 19:56:36 -05003880 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
3881 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04003882 fc_host_supported_classes(shost) = FC_COS_CLASS3;
3883
3884 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003885 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003886 fc_host_supported_fc4s(shost)[2] = 1;
3887 fc_host_supported_fc4s(shost)[7] = 1;
3888
James Smart92d7f7b2007-06-17 19:56:38 -05003889 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
3890 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04003891
3892 fc_host_supported_speeds(shost) = 0;
James Smartd38dd522015-08-31 16:48:17 -04003893 if (phba->lmt & LMT_32Gb)
3894 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
James Smart88a2cfb2011-07-22 18:36:33 -04003895 if (phba->lmt & LMT_16Gb)
3896 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
James Smart47a86172007-04-25 09:53:22 -04003897 if (phba->lmt & LMT_10Gb)
3898 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04003899 if (phba->lmt & LMT_8Gb)
3900 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04003901 if (phba->lmt & LMT_4Gb)
3902 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
3903 if (phba->lmt & LMT_2Gb)
3904 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
3905 if (phba->lmt & LMT_1Gb)
3906 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
3907
3908 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05003909 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
3910 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04003911
Mike Christie0af5d702010-09-15 16:52:31 -05003912 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
3913
James Smart47a86172007-04-25 09:53:22 -04003914 /* This value is also unchanging */
3915 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003916 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003917 fc_host_active_fc4s(shost)[2] = 1;
3918 fc_host_active_fc4s(shost)[7] = 1;
3919
James Smart92d7f7b2007-06-17 19:56:38 -05003920 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04003921 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04003922 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04003923 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04003924}
dea31012005-04-17 16:05:31 -05003925
James Smarte59058c2008-08-24 21:49:00 -04003926/**
James Smartda0436e2009-05-22 14:51:39 -04003927 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04003928 * @phba: pointer to lpfc hba data structure.
3929 *
James Smartda0436e2009-05-22 14:51:39 -04003930 * This routine is invoked to stop an SLI3 device port, it stops the device
3931 * from generating interrupts and stops the device driver's timers for the
3932 * device.
James Smarte59058c2008-08-24 21:49:00 -04003933 **/
James Smartdb2378e2008-02-08 18:49:51 -05003934static void
James Smartda0436e2009-05-22 14:51:39 -04003935lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05003936{
James Smartda0436e2009-05-22 14:51:39 -04003937 /* Clear all interrupt enable conditions */
3938 writel(0, phba->HCregaddr);
3939 readl(phba->HCregaddr); /* flush */
3940 /* Clear all pending interrupts */
3941 writel(0xffffffff, phba->HAregaddr);
3942 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04003943
James Smartda0436e2009-05-22 14:51:39 -04003944 /* Reset some HBA SLI setup states */
3945 lpfc_stop_hba_timers(phba);
3946 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05003947}
3948
James Smarte59058c2008-08-24 21:49:00 -04003949/**
James Smartda0436e2009-05-22 14:51:39 -04003950 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05003951 * @phba: pointer to lpfc hba data structure.
3952 *
James Smartda0436e2009-05-22 14:51:39 -04003953 * This routine is invoked to stop an SLI4 device port, it stops the device
3954 * from generating interrupts and stops the device driver's timers for the
3955 * device.
3956 **/
3957static void
3958lpfc_stop_port_s4(struct lpfc_hba *phba)
3959{
3960 /* Reset some HBA SLI4 setup states */
3961 lpfc_stop_hba_timers(phba);
3962 phba->pport->work_port_events = 0;
3963 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04003964}
3965
3966/**
3967 * lpfc_stop_port - Wrapper function for stopping hba port
3968 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05003969 *
James Smartda0436e2009-05-22 14:51:39 -04003970 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3971 * the API jump table function pointer from the lpfc_hba struct.
3972 **/
3973void
3974lpfc_stop_port(struct lpfc_hba *phba)
3975{
3976 phba->lpfc_stop_port(phba);
3977}
3978
3979/**
James Smartecfd03c2010-02-12 14:41:27 -05003980 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3981 * @phba: Pointer to hba for which this call is being executed.
3982 *
3983 * This routine starts the timer waiting for the FCF rediscovery to complete.
3984 **/
3985void
3986lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
3987{
3988 unsigned long fcf_redisc_wait_tmo =
3989 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
3990 /* Start fcf rediscovery wait period timer */
3991 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
3992 spin_lock_irq(&phba->hbalock);
3993 /* Allow action to new fcf asynchronous event */
3994 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
3995 /* Mark the FCF rediscovery pending state */
3996 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
3997 spin_unlock_irq(&phba->hbalock);
3998}
3999
4000/**
4001 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
4002 * @ptr: Map to lpfc_hba data structure pointer.
4003 *
4004 * This routine is invoked when waiting for FCF table rediscover has been
4005 * timed out. If new FCF record(s) has (have) been discovered during the
4006 * wait period, a new FCF event shall be added to the FCOE async event
4007 * list, and then worker thread shall be waked up for processing from the
4008 * worker thread context.
4009 **/
Rashika Kheriae399b222014-09-03 12:55:28 -04004010static void
James Smartecfd03c2010-02-12 14:41:27 -05004011lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
4012{
4013 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
4014
4015 /* Don't send FCF rediscovery event if timer cancelled */
4016 spin_lock_irq(&phba->hbalock);
4017 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
4018 spin_unlock_irq(&phba->hbalock);
4019 return;
4020 }
4021 /* Clear FCF rediscovery timer pending flag */
4022 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
4023 /* FCF rediscovery event to worker thread */
4024 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
4025 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004026 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04004027 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05004028 /* wake up worker thread */
4029 lpfc_worker_wake_up(phba);
4030}
4031
4032/**
James Smartda0436e2009-05-22 14:51:39 -04004033 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
4034 * @phba: pointer to lpfc hba data structure.
4035 * @acqe_link: pointer to the async link completion queue entry.
4036 *
4037 * This routine is to parse the SLI4 link-attention link fault code and
4038 * translate it into the base driver's read link attention mailbox command
4039 * status.
4040 *
4041 * Return: Link-attention status in terms of base driver's coding.
4042 **/
4043static uint16_t
4044lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
4045 struct lpfc_acqe_link *acqe_link)
4046{
4047 uint16_t latt_fault;
4048
4049 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
4050 case LPFC_ASYNC_LINK_FAULT_NONE:
4051 case LPFC_ASYNC_LINK_FAULT_LOCAL:
4052 case LPFC_ASYNC_LINK_FAULT_REMOTE:
4053 latt_fault = 0;
4054 break;
4055 default:
4056 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4057 "0398 Invalid link fault code: x%x\n",
4058 bf_get(lpfc_acqe_link_fault, acqe_link));
4059 latt_fault = MBXERR_ERROR;
4060 break;
4061 }
4062 return latt_fault;
4063}
4064
4065/**
4066 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
4067 * @phba: pointer to lpfc hba data structure.
4068 * @acqe_link: pointer to the async link completion queue entry.
4069 *
4070 * This routine is to parse the SLI4 link attention type and translate it
4071 * into the base driver's link attention type coding.
4072 *
4073 * Return: Link attention type in terms of base driver's coding.
4074 **/
4075static uint8_t
4076lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
4077 struct lpfc_acqe_link *acqe_link)
4078{
4079 uint8_t att_type;
4080
4081 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
4082 case LPFC_ASYNC_LINK_STATUS_DOWN:
4083 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05004084 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04004085 break;
4086 case LPFC_ASYNC_LINK_STATUS_UP:
4087 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05004088 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004089 break;
4090 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05004091 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04004092 break;
4093 default:
4094 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4095 "0399 Invalid link attention type: x%x\n",
4096 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05004097 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04004098 break;
4099 }
4100 return att_type;
4101}
4102
4103/**
James Smart8b68cd52012-09-29 11:32:37 -04004104 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
4105 * @phba: pointer to lpfc hba data structure.
4106 *
4107 * This routine is to get an SLI3 FC port's link speed in Mbps.
4108 *
4109 * Return: link speed in terms of Mbps.
4110 **/
4111uint32_t
4112lpfc_sli_port_speed_get(struct lpfc_hba *phba)
4113{
4114 uint32_t link_speed;
4115
4116 if (!lpfc_is_link_up(phba))
4117 return 0;
4118
James Smarta085e872015-12-16 18:12:02 -05004119 if (phba->sli_rev <= LPFC_SLI_REV3) {
4120 switch (phba->fc_linkspeed) {
4121 case LPFC_LINK_SPEED_1GHZ:
4122 link_speed = 1000;
4123 break;
4124 case LPFC_LINK_SPEED_2GHZ:
4125 link_speed = 2000;
4126 break;
4127 case LPFC_LINK_SPEED_4GHZ:
4128 link_speed = 4000;
4129 break;
4130 case LPFC_LINK_SPEED_8GHZ:
4131 link_speed = 8000;
4132 break;
4133 case LPFC_LINK_SPEED_10GHZ:
4134 link_speed = 10000;
4135 break;
4136 case LPFC_LINK_SPEED_16GHZ:
4137 link_speed = 16000;
4138 break;
4139 default:
4140 link_speed = 0;
4141 }
4142 } else {
4143 if (phba->sli4_hba.link_state.logical_speed)
4144 link_speed =
4145 phba->sli4_hba.link_state.logical_speed;
4146 else
4147 link_speed = phba->sli4_hba.link_state.speed;
James Smart8b68cd52012-09-29 11:32:37 -04004148 }
4149 return link_speed;
4150}
4151
4152/**
4153 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
4154 * @phba: pointer to lpfc hba data structure.
4155 * @evt_code: asynchronous event code.
4156 * @speed_code: asynchronous event link speed code.
4157 *
4158 * This routine is to parse the giving SLI4 async event link speed code into
4159 * value of Mbps for the link speed.
4160 *
4161 * Return: link speed in terms of Mbps.
4162 **/
4163static uint32_t
4164lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
4165 uint8_t speed_code)
4166{
4167 uint32_t port_speed;
4168
4169 switch (evt_code) {
4170 case LPFC_TRAILER_CODE_LINK:
4171 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004172 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smart8b68cd52012-09-29 11:32:37 -04004173 port_speed = 0;
4174 break;
James Smart26d830e2015-04-07 15:07:17 -04004175 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004176 port_speed = 10;
4177 break;
James Smart26d830e2015-04-07 15:07:17 -04004178 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004179 port_speed = 100;
4180 break;
James Smart26d830e2015-04-07 15:07:17 -04004181 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004182 port_speed = 1000;
4183 break;
James Smart26d830e2015-04-07 15:07:17 -04004184 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004185 port_speed = 10000;
4186 break;
James Smart26d830e2015-04-07 15:07:17 -04004187 case LPFC_ASYNC_LINK_SPEED_20GBPS:
4188 port_speed = 20000;
4189 break;
4190 case LPFC_ASYNC_LINK_SPEED_25GBPS:
4191 port_speed = 25000;
4192 break;
4193 case LPFC_ASYNC_LINK_SPEED_40GBPS:
4194 port_speed = 40000;
4195 break;
James Smart8b68cd52012-09-29 11:32:37 -04004196 default:
4197 port_speed = 0;
4198 }
4199 break;
4200 case LPFC_TRAILER_CODE_FC:
4201 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004202 case LPFC_FC_LA_SPEED_UNKNOWN:
James Smart8b68cd52012-09-29 11:32:37 -04004203 port_speed = 0;
4204 break;
James Smart26d830e2015-04-07 15:07:17 -04004205 case LPFC_FC_LA_SPEED_1G:
James Smart8b68cd52012-09-29 11:32:37 -04004206 port_speed = 1000;
4207 break;
James Smart26d830e2015-04-07 15:07:17 -04004208 case LPFC_FC_LA_SPEED_2G:
James Smart8b68cd52012-09-29 11:32:37 -04004209 port_speed = 2000;
4210 break;
James Smart26d830e2015-04-07 15:07:17 -04004211 case LPFC_FC_LA_SPEED_4G:
James Smart8b68cd52012-09-29 11:32:37 -04004212 port_speed = 4000;
4213 break;
James Smart26d830e2015-04-07 15:07:17 -04004214 case LPFC_FC_LA_SPEED_8G:
James Smart8b68cd52012-09-29 11:32:37 -04004215 port_speed = 8000;
4216 break;
James Smart26d830e2015-04-07 15:07:17 -04004217 case LPFC_FC_LA_SPEED_10G:
James Smart8b68cd52012-09-29 11:32:37 -04004218 port_speed = 10000;
4219 break;
James Smart26d830e2015-04-07 15:07:17 -04004220 case LPFC_FC_LA_SPEED_16G:
James Smart8b68cd52012-09-29 11:32:37 -04004221 port_speed = 16000;
4222 break;
James Smartd38dd522015-08-31 16:48:17 -04004223 case LPFC_FC_LA_SPEED_32G:
4224 port_speed = 32000;
4225 break;
James Smart8b68cd52012-09-29 11:32:37 -04004226 default:
4227 port_speed = 0;
4228 }
4229 break;
4230 default:
4231 port_speed = 0;
4232 }
4233 return port_speed;
4234}
4235
4236/**
James Smart70f3c072010-12-15 17:57:33 -05004237 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04004238 * @phba: pointer to lpfc hba data structure.
4239 * @acqe_link: pointer to the async link completion queue entry.
4240 *
James Smart70f3c072010-12-15 17:57:33 -05004241 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04004242 **/
4243static void
4244lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
4245 struct lpfc_acqe_link *acqe_link)
4246{
4247 struct lpfc_dmabuf *mp;
4248 LPFC_MBOXQ_t *pmb;
4249 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05004250 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04004251 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05004252 int rc;
James Smartda0436e2009-05-22 14:51:39 -04004253
4254 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05004255 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04004256 return;
James Smart32b97932009-07-19 10:01:21 -04004257 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004258 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4259 if (!pmb) {
4260 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4261 "0395 The mboxq allocation failed\n");
4262 return;
4263 }
4264 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4265 if (!mp) {
4266 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4267 "0396 The lpfc_dmabuf allocation failed\n");
4268 goto out_free_pmb;
4269 }
4270 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4271 if (!mp->virt) {
4272 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4273 "0397 The mbuf allocation failed\n");
4274 goto out_free_dmabuf;
4275 }
4276
4277 /* Cleanup any outstanding ELS commands */
4278 lpfc_els_flush_all_cmd(phba);
4279
4280 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004281 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smartda0436e2009-05-22 14:51:39 -04004282
4283 /* Update link event statistics */
4284 phba->sli.slistat.link_event++;
4285
James Smart76a95d72010-11-20 23:11:48 -05004286 /* Create lpfc_handle_latt mailbox command from link ACQE */
4287 lpfc_read_topology(phba, pmb, mp);
4288 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04004289 pmb->vport = phba->pport;
4290
James Smartda0436e2009-05-22 14:51:39 -04004291 /* Keep the link status for extra SLI4 state machine reference */
4292 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004293 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
4294 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04004295 phba->sli4_hba.link_state.duplex =
4296 bf_get(lpfc_acqe_link_duplex, acqe_link);
4297 phba->sli4_hba.link_state.status =
4298 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05004299 phba->sli4_hba.link_state.type =
4300 bf_get(lpfc_acqe_link_type, acqe_link);
4301 phba->sli4_hba.link_state.number =
4302 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04004303 phba->sli4_hba.link_state.fault =
4304 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05004305 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004306 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
4307
James Smart70f3c072010-12-15 17:57:33 -05004308 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04004309 "2900 Async FC/FCoE Link event - Speed:%dGBit "
4310 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
4311 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05004312 phba->sli4_hba.link_state.speed,
4313 phba->sli4_hba.link_state.topology,
4314 phba->sli4_hba.link_state.status,
4315 phba->sli4_hba.link_state.type,
4316 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004317 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004318 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05004319 /*
4320 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
4321 * topology info. Note: Optional for non FC-AL ports.
4322 */
4323 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
4324 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4325 if (rc == MBX_NOT_FINISHED)
4326 goto out_free_dmabuf;
4327 return;
4328 }
4329 /*
4330 * For FCoE Mode: fill in all the topology information we need and call
4331 * the READ_TOPOLOGY completion routine to continue without actually
4332 * sending the READ_TOPOLOGY mailbox command to the port.
4333 */
4334 /* Parse and translate status field */
4335 mb = &pmb->u.mb;
4336 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
4337
4338 /* Parse and translate link attention fields */
4339 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
4340 la->eventTag = acqe_link->event_tag;
4341 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
4342 bf_set(lpfc_mbx_read_top_link_spd, la,
James Smarta085e872015-12-16 18:12:02 -05004343 (bf_get(lpfc_acqe_link_speed, acqe_link)));
James Smart76a95d72010-11-20 23:11:48 -05004344
4345 /* Fake the the following irrelvant fields */
4346 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
4347 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
4348 bf_set(lpfc_mbx_read_top_il, la, 0);
4349 bf_set(lpfc_mbx_read_top_pb, la, 0);
4350 bf_set(lpfc_mbx_read_top_fa, la, 0);
4351 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04004352
4353 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05004354 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04004355
4356 return;
4357
4358out_free_dmabuf:
4359 kfree(mp);
4360out_free_pmb:
4361 mempool_free(pmb, phba->mbox_mem_pool);
4362}
4363
4364/**
James Smart70f3c072010-12-15 17:57:33 -05004365 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
4366 * @phba: pointer to lpfc hba data structure.
4367 * @acqe_fc: pointer to the async fc completion queue entry.
4368 *
4369 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
4370 * that the event was received and then issue a read_topology mailbox command so
4371 * that the rest of the driver will treat it the same as SLI3.
4372 **/
4373static void
4374lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
4375{
4376 struct lpfc_dmabuf *mp;
4377 LPFC_MBOXQ_t *pmb;
James Smart7bdedb32016-07-06 12:36:00 -07004378 MAILBOX_t *mb;
4379 struct lpfc_mbx_read_top *la;
James Smart70f3c072010-12-15 17:57:33 -05004380 int rc;
4381
4382 if (bf_get(lpfc_trailer_type, acqe_fc) !=
4383 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
4384 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4385 "2895 Non FC link Event detected.(%d)\n",
4386 bf_get(lpfc_trailer_type, acqe_fc));
4387 return;
4388 }
4389 /* Keep the link status for extra SLI4 state machine reference */
4390 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004391 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
4392 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05004393 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
4394 phba->sli4_hba.link_state.topology =
4395 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
4396 phba->sli4_hba.link_state.status =
4397 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
4398 phba->sli4_hba.link_state.type =
4399 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
4400 phba->sli4_hba.link_state.number =
4401 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
4402 phba->sli4_hba.link_state.fault =
4403 bf_get(lpfc_acqe_link_fault, acqe_fc);
4404 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004405 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart70f3c072010-12-15 17:57:33 -05004406 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4407 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4408 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4409 "%dMbps Fault:%d\n",
4410 phba->sli4_hba.link_state.speed,
4411 phba->sli4_hba.link_state.topology,
4412 phba->sli4_hba.link_state.status,
4413 phba->sli4_hba.link_state.type,
4414 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004415 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004416 phba->sli4_hba.link_state.fault);
4417 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4418 if (!pmb) {
4419 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4420 "2897 The mboxq allocation failed\n");
4421 return;
4422 }
4423 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4424 if (!mp) {
4425 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4426 "2898 The lpfc_dmabuf allocation failed\n");
4427 goto out_free_pmb;
4428 }
4429 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4430 if (!mp->virt) {
4431 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4432 "2899 The mbuf allocation failed\n");
4433 goto out_free_dmabuf;
4434 }
4435
4436 /* Cleanup any outstanding ELS commands */
4437 lpfc_els_flush_all_cmd(phba);
4438
4439 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004440 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smart70f3c072010-12-15 17:57:33 -05004441
4442 /* Update link event statistics */
4443 phba->sli.slistat.link_event++;
4444
4445 /* Create lpfc_handle_latt mailbox command from link ACQE */
4446 lpfc_read_topology(phba, pmb, mp);
4447 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4448 pmb->vport = phba->pport;
4449
James Smart7bdedb32016-07-06 12:36:00 -07004450 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
4451 /* Parse and translate status field */
4452 mb = &pmb->u.mb;
4453 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba,
4454 (void *)acqe_fc);
4455
4456 /* Parse and translate link attention fields */
4457 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
4458 la->eventTag = acqe_fc->event_tag;
4459 bf_set(lpfc_mbx_read_top_att_type, la,
4460 LPFC_FC_LA_TYPE_LINK_DOWN);
4461
4462 /* Invoke the mailbox command callback function */
4463 lpfc_mbx_cmpl_read_topology(phba, pmb);
4464
4465 return;
4466 }
4467
James Smart70f3c072010-12-15 17:57:33 -05004468 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4469 if (rc == MBX_NOT_FINISHED)
4470 goto out_free_dmabuf;
4471 return;
4472
4473out_free_dmabuf:
4474 kfree(mp);
4475out_free_pmb:
4476 mempool_free(pmb, phba->mbox_mem_pool);
4477}
4478
4479/**
4480 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4481 * @phba: pointer to lpfc hba data structure.
4482 * @acqe_fc: pointer to the async SLI completion queue entry.
4483 *
4484 * This routine is to handle the SLI4 asynchronous SLI events.
4485 **/
4486static void
4487lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
4488{
James Smart4b8bae02012-06-12 13:55:07 -04004489 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04004490 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04004491 uint8_t status;
James Smart946727d2015-04-07 15:07:09 -04004492 uint8_t evt_type;
James Smart448193b2015-12-16 18:12:05 -05004493 uint8_t operational = 0;
James Smart946727d2015-04-07 15:07:09 -04004494 struct temp_event temp_event_data;
James Smart4b8bae02012-06-12 13:55:07 -04004495 struct lpfc_acqe_misconfigured_event *misconfigured;
James Smart946727d2015-04-07 15:07:09 -04004496 struct Scsi_Host *shost;
James Smart4b8bae02012-06-12 13:55:07 -04004497
James Smart946727d2015-04-07 15:07:09 -04004498 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
4499
James Smart448193b2015-12-16 18:12:05 -05004500 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4501 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4502 "x%08x SLI Event Type:%d\n",
4503 acqe_sli->event_data1, acqe_sli->event_data2,
4504 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004505
4506 port_name = phba->Port[0];
4507 if (port_name == 0x00)
4508 port_name = '?'; /* get port name is empty */
4509
James Smart946727d2015-04-07 15:07:09 -04004510 switch (evt_type) {
4511 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
4512 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4513 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
4514 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4515
4516 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4517 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4518 acqe_sli->event_data1, port_name);
4519
James Smart310429e2016-07-06 12:35:54 -07004520 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04004521 shost = lpfc_shost_from_vport(phba->pport);
4522 fc_host_post_vendor_event(shost, fc_get_event_number(),
4523 sizeof(temp_event_data),
4524 (char *)&temp_event_data,
4525 SCSI_NL_VID_TYPE_PCI
4526 | PCI_VENDOR_ID_EMULEX);
4527 break;
4528 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
4529 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4530 temp_event_data.event_code = LPFC_NORMAL_TEMP;
4531 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4532
4533 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4534 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4535 acqe_sli->event_data1, port_name);
4536
4537 shost = lpfc_shost_from_vport(phba->pport);
4538 fc_host_post_vendor_event(shost, fc_get_event_number(),
4539 sizeof(temp_event_data),
4540 (char *)&temp_event_data,
4541 SCSI_NL_VID_TYPE_PCI
4542 | PCI_VENDOR_ID_EMULEX);
4543 break;
4544 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
4545 misconfigured = (struct lpfc_acqe_misconfigured_event *)
James Smart4b8bae02012-06-12 13:55:07 -04004546 &acqe_sli->event_data1;
4547
James Smart946727d2015-04-07 15:07:09 -04004548 /* fetch the status for this port */
4549 switch (phba->sli4_hba.lnk_info.lnk_no) {
4550 case LPFC_LINK_NUMBER_0:
James Smart448193b2015-12-16 18:12:05 -05004551 status = bf_get(lpfc_sli_misconfigured_port0_state,
4552 &misconfigured->theEvent);
4553 operational = bf_get(lpfc_sli_misconfigured_port0_op,
James Smart4b8bae02012-06-12 13:55:07 -04004554 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004555 break;
4556 case LPFC_LINK_NUMBER_1:
James Smart448193b2015-12-16 18:12:05 -05004557 status = bf_get(lpfc_sli_misconfigured_port1_state,
4558 &misconfigured->theEvent);
4559 operational = bf_get(lpfc_sli_misconfigured_port1_op,
James Smart4b8bae02012-06-12 13:55:07 -04004560 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004561 break;
4562 case LPFC_LINK_NUMBER_2:
James Smart448193b2015-12-16 18:12:05 -05004563 status = bf_get(lpfc_sli_misconfigured_port2_state,
4564 &misconfigured->theEvent);
4565 operational = bf_get(lpfc_sli_misconfigured_port2_op,
James Smart4b8bae02012-06-12 13:55:07 -04004566 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004567 break;
4568 case LPFC_LINK_NUMBER_3:
James Smart448193b2015-12-16 18:12:05 -05004569 status = bf_get(lpfc_sli_misconfigured_port3_state,
4570 &misconfigured->theEvent);
4571 operational = bf_get(lpfc_sli_misconfigured_port3_op,
James Smart4b8bae02012-06-12 13:55:07 -04004572 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004573 break;
4574 default:
James Smart448193b2015-12-16 18:12:05 -05004575 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4576 "3296 "
4577 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
4578 "event: Invalid link %d",
4579 phba->sli4_hba.lnk_info.lnk_no);
4580 return;
James Smart946727d2015-04-07 15:07:09 -04004581 }
James Smart4b8bae02012-06-12 13:55:07 -04004582
James Smart448193b2015-12-16 18:12:05 -05004583 /* Skip if optic state unchanged */
4584 if (phba->sli4_hba.lnk_info.optic_state == status)
4585 return;
4586
James Smart946727d2015-04-07 15:07:09 -04004587 switch (status) {
4588 case LPFC_SLI_EVENT_STATUS_VALID:
James Smart448193b2015-12-16 18:12:05 -05004589 sprintf(message, "Physical Link is functional");
4590 break;
James Smart946727d2015-04-07 15:07:09 -04004591 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
4592 sprintf(message, "Optics faulted/incorrectly "
4593 "installed/not installed - Reseat optics, "
4594 "if issue not resolved, replace.");
4595 break;
4596 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
4597 sprintf(message,
4598 "Optics of two types installed - Remove one "
4599 "optic or install matching pair of optics.");
4600 break;
4601 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
4602 sprintf(message, "Incompatible optics - Replace with "
James Smart292098b2012-09-29 11:31:41 -04004603 "compatible optics for card to function.");
James Smart946727d2015-04-07 15:07:09 -04004604 break;
James Smart448193b2015-12-16 18:12:05 -05004605 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
4606 sprintf(message, "Unqualified optics - Replace with "
4607 "Avago optics for Warranty and Technical "
4608 "Support - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08004609 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05004610 break;
4611 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
4612 sprintf(message, "Uncertified optics - Replace with "
4613 "Avago-certified optics to enable link "
4614 "operation - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08004615 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05004616 break;
James Smart946727d2015-04-07 15:07:09 -04004617 default:
4618 /* firmware is reporting a status we don't know about */
4619 sprintf(message, "Unknown event status x%02x", status);
4620 break;
4621 }
James Smart448193b2015-12-16 18:12:05 -05004622 phba->sli4_hba.lnk_info.optic_state = status;
James Smart946727d2015-04-07 15:07:09 -04004623 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart448193b2015-12-16 18:12:05 -05004624 "3176 Port Name %c %s\n", port_name, message);
James Smart946727d2015-04-07 15:07:09 -04004625 break;
4626 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
4627 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4628 "3192 Remote DPort Test Initiated - "
4629 "Event Data1:x%08x Event Data2: x%08x\n",
4630 acqe_sli->event_data1, acqe_sli->event_data2);
James Smart4b8bae02012-06-12 13:55:07 -04004631 break;
4632 default:
James Smart946727d2015-04-07 15:07:09 -04004633 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4634 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
4635 "x%08x SLI Event Type:%d\n",
4636 acqe_sli->event_data1, acqe_sli->event_data2,
4637 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004638 break;
4639 }
James Smart70f3c072010-12-15 17:57:33 -05004640}
4641
4642/**
James Smartfc2b9892010-02-26 14:15:29 -05004643 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
4644 * @vport: pointer to vport data structure.
4645 *
4646 * This routine is to perform Clear Virtual Link (CVL) on a vport in
4647 * response to a CVL event.
4648 *
4649 * Return the pointer to the ndlp with the vport if successful, otherwise
4650 * return NULL.
4651 **/
4652static struct lpfc_nodelist *
4653lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
4654{
4655 struct lpfc_nodelist *ndlp;
4656 struct Scsi_Host *shost;
4657 struct lpfc_hba *phba;
4658
4659 if (!vport)
4660 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05004661 phba = vport->phba;
4662 if (!phba)
4663 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04004664 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4665 if (!ndlp) {
4666 /* Cannot find existing Fabric ndlp, so allocate a new one */
4667 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4668 if (!ndlp)
4669 return 0;
4670 lpfc_nlp_init(vport, ndlp, Fabric_DID);
4671 /* Set the node type */
4672 ndlp->nlp_type |= NLP_FABRIC;
4673 /* Put ndlp onto node list */
4674 lpfc_enqueue_node(vport, ndlp);
4675 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4676 /* re-setup ndlp without removing from node list */
4677 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4678 if (!ndlp)
4679 return 0;
4680 }
James Smart63e801c2010-11-20 23:14:19 -05004681 if ((phba->pport->port_state < LPFC_FLOGI) &&
4682 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004683 return NULL;
4684 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05004685 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
4686 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004687 return NULL;
4688 shost = lpfc_shost_from_vport(vport);
4689 if (!shost)
4690 return NULL;
4691 lpfc_linkdown_port(vport);
4692 lpfc_cleanup_pending_mbox(vport);
4693 spin_lock_irq(shost->host_lock);
4694 vport->fc_flag |= FC_VPORT_CVL_RCVD;
4695 spin_unlock_irq(shost->host_lock);
4696
4697 return ndlp;
4698}
4699
4700/**
4701 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4702 * @vport: pointer to lpfc hba data structure.
4703 *
4704 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4705 * response to a FCF dead event.
4706 **/
4707static void
4708lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
4709{
4710 struct lpfc_vport **vports;
4711 int i;
4712
4713 vports = lpfc_create_vport_work_array(phba);
4714 if (vports)
4715 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4716 lpfc_sli4_perform_vport_cvl(vports[i]);
4717 lpfc_destroy_vport_work_array(phba, vports);
4718}
4719
4720/**
James Smart76a95d72010-11-20 23:11:48 -05004721 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04004722 * @phba: pointer to lpfc hba data structure.
4723 * @acqe_link: pointer to the async fcoe completion queue entry.
4724 *
4725 * This routine is to handle the SLI4 asynchronous fcoe event.
4726 **/
4727static void
James Smart76a95d72010-11-20 23:11:48 -05004728lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05004729 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04004730{
James Smart70f3c072010-12-15 17:57:33 -05004731 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004732 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04004733 struct lpfc_vport *vport;
4734 struct lpfc_nodelist *ndlp;
4735 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05004736 int active_vlink_present;
4737 struct lpfc_vport **vports;
4738 int i;
James Smartda0436e2009-05-22 14:51:39 -04004739
James Smart70f3c072010-12-15 17:57:33 -05004740 phba->fc_eventTag = acqe_fip->event_tag;
4741 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004742 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05004743 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
4744 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
4745 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04004746 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4747 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004748 "2546 New FCF event, evt_tag:x%x, "
4749 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004750 acqe_fip->event_tag,
4751 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04004752 else
4753 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
4754 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004755 "2788 FCF param modified event, "
4756 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004757 acqe_fip->event_tag,
4758 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04004759 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004760 /*
4761 * During period of FCF discovery, read the FCF
4762 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04004763 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05004764 */
4765 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4766 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004767 "2779 Read FCF (x%x) for updating "
4768 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05004769 acqe_fip->index);
4770 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004771 }
James Smart38b92ef2010-08-04 16:11:39 -04004772
4773 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04004774 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04004775 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04004776 spin_unlock_irq(&phba->hbalock);
4777 break;
4778 }
4779 /* If fast FCF failover rescan event is pending, do nothing */
4780 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
4781 spin_unlock_irq(&phba->hbalock);
4782 break;
4783 }
4784
James Smartc2b97122013-05-31 17:05:36 -04004785 /* If the FCF has been in discovered state, do nothing. */
4786 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
James Smart3804dc82010-07-14 15:31:37 -04004787 spin_unlock_irq(&phba->hbalock);
4788 break;
4789 }
4790 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04004791
James Smart0c9ab6f2010-02-26 14:15:57 -05004792 /* Otherwise, scan the entire FCF table and re-discover SAN */
4793 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004794 "2770 Start FCF table scan per async FCF "
4795 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004796 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004797 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
4798 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04004799 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004800 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4801 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04004802 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04004803 break;
4804
James Smart70f3c072010-12-15 17:57:33 -05004805 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04004806 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04004807 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004808 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
4809 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004810 break;
4811
James Smart70f3c072010-12-15 17:57:33 -05004812 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05004813 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004814 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004815 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05004816 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04004817 /*
4818 * If we are in the middle of FCF failover process, clear
4819 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04004820 */
James Smartfc2b9892010-02-26 14:15:29 -05004821 spin_lock_irq(&phba->hbalock);
James Smarta1cadfe2016-07-06 12:36:02 -07004822 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
4823 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
James Smartfc2b9892010-02-26 14:15:29 -05004824 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004825 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05004826 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004827 break;
4828 }
James Smart38b92ef2010-08-04 16:11:39 -04004829 spin_unlock_irq(&phba->hbalock);
4830
4831 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05004832 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04004833 break;
4834
4835 /*
4836 * Otherwise, request the port to rediscover the entire FCF
4837 * table for a fast recovery from case that the current FCF
4838 * is no longer valid as we are not in the middle of FCF
4839 * failover process already.
4840 */
James Smartc2b97122013-05-31 17:05:36 -04004841 spin_lock_irq(&phba->hbalock);
4842 /* Mark the fast failover process in progress */
4843 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
4844 spin_unlock_irq(&phba->hbalock);
4845
4846 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
4847 "2771 Start FCF fast failover process due to "
4848 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
4849 "\n", acqe_fip->event_tag, acqe_fip->index);
4850 rc = lpfc_sli4_redisc_fcf_table(phba);
4851 if (rc) {
4852 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4853 LOG_DISCOVERY,
4854 "2772 Issue FCF rediscover mabilbox "
4855 "command failed, fail through to FCF "
4856 "dead event\n");
4857 spin_lock_irq(&phba->hbalock);
4858 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
4859 spin_unlock_irq(&phba->hbalock);
4860 /*
4861 * Last resort will fail over by treating this
4862 * as a link down to FCF registration.
4863 */
4864 lpfc_sli4_fcf_dead_failthrough(phba);
4865 } else {
4866 /* Reset FCF roundrobin bmask for new discovery */
4867 lpfc_sli4_clear_fcf_rr_bmask(phba);
4868 /*
4869 * Handling fast FCF failover to a DEAD FCF event is
4870 * considered equalivant to receiving CVL to all vports.
4871 */
4872 lpfc_sli4_perform_all_vport_cvl(phba);
4873 }
James Smartda0436e2009-05-22 14:51:39 -04004874 break;
James Smart70f3c072010-12-15 17:57:33 -05004875 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05004876 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004877 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04004878 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05004879 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04004880
James Smart6669f9b2009-10-02 15:16:45 -04004881 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04004882 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004883 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004884 if (!ndlp)
4885 break;
James Smart695a8142010-01-26 23:08:03 -05004886 active_vlink_present = 0;
4887
4888 vports = lpfc_create_vport_work_array(phba);
4889 if (vports) {
4890 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
4891 i++) {
4892 if ((!(vports[i]->fc_flag &
4893 FC_VPORT_CVL_RCVD)) &&
4894 (vports[i]->port_state > LPFC_FDISC)) {
4895 active_vlink_present = 1;
4896 break;
4897 }
4898 }
4899 lpfc_destroy_vport_work_array(phba, vports);
4900 }
4901
James Smartcc823552015-05-21 13:55:26 -04004902 /*
4903 * Don't re-instantiate if vport is marked for deletion.
4904 * If we are here first then vport_delete is going to wait
4905 * for discovery to complete.
4906 */
4907 if (!(vport->load_flag & FC_UNLOADING) &&
4908 active_vlink_present) {
James Smart695a8142010-01-26 23:08:03 -05004909 /*
4910 * If there are other active VLinks present,
4911 * re-instantiate the Vlink using FDISC.
4912 */
James Smart256ec0d2013-04-17 20:14:58 -04004913 mod_timer(&ndlp->nlp_delayfunc,
4914 jiffies + msecs_to_jiffies(1000));
James Smartfc2b9892010-02-26 14:15:29 -05004915 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004916 spin_lock_irq(shost->host_lock);
4917 ndlp->nlp_flag |= NLP_DELAY_TMO;
4918 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05004919 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
4920 vport->port_state = LPFC_FDISC;
4921 } else {
James Smartecfd03c2010-02-12 14:41:27 -05004922 /*
4923 * Otherwise, we request port to rediscover
4924 * the entire FCF table for a fast recovery
4925 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05004926 * is no longer valid if we are not already
4927 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05004928 */
James Smartfc2b9892010-02-26 14:15:29 -05004929 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004930 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05004931 spin_unlock_irq(&phba->hbalock);
4932 break;
4933 }
4934 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05004935 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004936 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004937 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4938 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004939 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05004940 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05004941 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05004942 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004943 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4944 LOG_DISCOVERY,
4945 "2774 Issue FCF rediscover "
4946 "mabilbox command failed, "
4947 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05004948 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004949 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004950 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05004951 /*
4952 * Last resort will be re-try on the
4953 * the current registered FCF entry.
4954 */
4955 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04004956 } else
4957 /*
4958 * Reset FCF roundrobin bmask for new
4959 * discovery.
4960 */
James Smart7d791df2011-07-22 18:37:52 -04004961 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04004962 }
4963 break;
James Smartda0436e2009-05-22 14:51:39 -04004964 default:
4965 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4966 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05004967 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004968 break;
4969 }
4970}
4971
4972/**
4973 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
4974 * @phba: pointer to lpfc hba data structure.
4975 * @acqe_link: pointer to the async dcbx completion queue entry.
4976 *
4977 * This routine is to handle the SLI4 asynchronous dcbx event.
4978 **/
4979static void
4980lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
4981 struct lpfc_acqe_dcbx *acqe_dcbx)
4982{
James Smart4d9ab992009-10-02 15:16:39 -04004983 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004984 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4985 "0290 The SLI4 DCBX asynchronous event is not "
4986 "handled yet\n");
4987}
4988
4989/**
James Smartb19a0612010-04-06 14:48:51 -04004990 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
4991 * @phba: pointer to lpfc hba data structure.
4992 * @acqe_link: pointer to the async grp5 completion queue entry.
4993 *
4994 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
4995 * is an asynchronous notified of a logical link speed change. The Port
4996 * reports the logical link speed in units of 10Mbps.
4997 **/
4998static void
4999lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
5000 struct lpfc_acqe_grp5 *acqe_grp5)
5001{
5002 uint16_t prev_ll_spd;
5003
5004 phba->fc_eventTag = acqe_grp5->event_tag;
5005 phba->fcoe_eventtag = acqe_grp5->event_tag;
5006 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
5007 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04005008 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04005009 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5010 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04005011 "from %dMbps to %dMbps\n", prev_ll_spd,
5012 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04005013}
5014
5015/**
James Smartda0436e2009-05-22 14:51:39 -04005016 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
5017 * @phba: pointer to lpfc hba data structure.
5018 *
5019 * This routine is invoked by the worker thread to process all the pending
5020 * SLI4 asynchronous events.
5021 **/
5022void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
5023{
5024 struct lpfc_cq_event *cq_event;
5025
5026 /* First, declare the async event has been handled */
5027 spin_lock_irq(&phba->hbalock);
5028 phba->hba_flag &= ~ASYNC_EVENT;
5029 spin_unlock_irq(&phba->hbalock);
5030 /* Now, handle all the async events */
5031 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
5032 /* Get the first event from the head of the event queue */
5033 spin_lock_irq(&phba->hbalock);
5034 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
5035 cq_event, struct lpfc_cq_event, list);
5036 spin_unlock_irq(&phba->hbalock);
5037 /* Process the asynchronous event */
5038 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
5039 case LPFC_TRAILER_CODE_LINK:
5040 lpfc_sli4_async_link_evt(phba,
5041 &cq_event->cqe.acqe_link);
5042 break;
5043 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05005044 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04005045 break;
5046 case LPFC_TRAILER_CODE_DCBX:
5047 lpfc_sli4_async_dcbx_evt(phba,
5048 &cq_event->cqe.acqe_dcbx);
5049 break;
James Smartb19a0612010-04-06 14:48:51 -04005050 case LPFC_TRAILER_CODE_GRP5:
5051 lpfc_sli4_async_grp5_evt(phba,
5052 &cq_event->cqe.acqe_grp5);
5053 break;
James Smart70f3c072010-12-15 17:57:33 -05005054 case LPFC_TRAILER_CODE_FC:
5055 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
5056 break;
5057 case LPFC_TRAILER_CODE_SLI:
5058 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
5059 break;
James Smartda0436e2009-05-22 14:51:39 -04005060 default:
5061 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5062 "1804 Invalid asynchrous event code: "
5063 "x%x\n", bf_get(lpfc_trailer_code,
5064 &cq_event->cqe.mcqe_cmpl));
5065 break;
5066 }
5067 /* Free the completion event processed to the free pool */
5068 lpfc_sli4_cq_event_release(phba, cq_event);
5069 }
5070}
5071
5072/**
James Smartecfd03c2010-02-12 14:41:27 -05005073 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
5074 * @phba: pointer to lpfc hba data structure.
5075 *
5076 * This routine is invoked by the worker thread to process FCF table
5077 * rediscovery pending completion event.
5078 **/
5079void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
5080{
5081 int rc;
5082
5083 spin_lock_irq(&phba->hbalock);
5084 /* Clear FCF rediscovery timeout event */
5085 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
5086 /* Clear driver fast failover FCF record flag */
5087 phba->fcf.failover_rec.flag = 0;
5088 /* Set state for FCF fast failover */
5089 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
5090 spin_unlock_irq(&phba->hbalock);
5091
5092 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05005093 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04005094 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05005095 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05005096 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05005097 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
5098 "2747 Issue FCF scan read FCF mailbox "
5099 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05005100}
5101
5102/**
James Smartda0436e2009-05-22 14:51:39 -04005103 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
5104 * @phba: pointer to lpfc hba data structure.
5105 * @dev_grp: The HBA PCI-Device group number.
5106 *
5107 * This routine is invoked to set up the per HBA PCI-Device group function
5108 * API jump table entries.
5109 *
5110 * Return: 0 if success, otherwise -ENODEV
5111 **/
5112int
5113lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05005114{
5115 int rc;
5116
James Smartda0436e2009-05-22 14:51:39 -04005117 /* Set up lpfc PCI-device group */
5118 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05005119
James Smartda0436e2009-05-22 14:51:39 -04005120 /* The LPFC_PCI_DEV_OC uses SLI4 */
5121 if (dev_grp == LPFC_PCI_DEV_OC)
5122 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05005123
James Smartda0436e2009-05-22 14:51:39 -04005124 /* Set up device INIT API function jump table */
5125 rc = lpfc_init_api_table_setup(phba, dev_grp);
5126 if (rc)
5127 return -ENODEV;
5128 /* Set up SCSI API function jump table */
5129 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
5130 if (rc)
5131 return -ENODEV;
5132 /* Set up SLI API function jump table */
5133 rc = lpfc_sli_api_table_setup(phba, dev_grp);
5134 if (rc)
5135 return -ENODEV;
5136 /* Set up MBOX API function jump table */
5137 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
5138 if (rc)
5139 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05005140
James Smartda0436e2009-05-22 14:51:39 -04005141 return 0;
James Smart5b75da22008-12-04 22:39:35 -05005142}
5143
5144/**
James Smart3621a712009-04-06 18:47:14 -04005145 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05005146 * @phba: pointer to lpfc hba data structure.
5147 * @intr_mode: active interrupt mode adopted.
5148 *
5149 * This routine it invoked to log the currently used active interrupt mode
5150 * to the device.
James Smart3772a992009-05-22 14:50:54 -04005151 **/
5152static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05005153{
5154 switch (intr_mode) {
5155 case 0:
5156 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5157 "0470 Enable INTx interrupt mode.\n");
5158 break;
5159 case 1:
5160 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5161 "0481 Enabled MSI interrupt mode.\n");
5162 break;
5163 case 2:
5164 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5165 "0480 Enabled MSI-X interrupt mode.\n");
5166 break;
5167 default:
5168 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5169 "0482 Illegal interrupt mode.\n");
5170 break;
5171 }
5172 return;
5173}
5174
James Smart5b75da22008-12-04 22:39:35 -05005175/**
James Smart3772a992009-05-22 14:50:54 -04005176 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05005177 * @phba: pointer to lpfc hba data structure.
5178 *
James Smart3772a992009-05-22 14:50:54 -04005179 * This routine is invoked to enable the PCI device that is common to all
5180 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05005181 *
5182 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005183 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005184 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05005185 **/
James Smart3772a992009-05-22 14:50:54 -04005186static int
5187lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05005188{
James Smart3772a992009-05-22 14:50:54 -04005189 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05005190
James Smart3772a992009-05-22 14:50:54 -04005191 /* Obtain PCI device reference */
5192 if (!phba->pcidev)
5193 goto out_error;
5194 else
5195 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04005196 /* Enable PCI device */
5197 if (pci_enable_device_mem(pdev))
5198 goto out_error;
5199 /* Request PCI resource for the device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005200 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
James Smart3772a992009-05-22 14:50:54 -04005201 goto out_disable_device;
5202 /* Set up device as PCI master and save state for EEH */
5203 pci_set_master(pdev);
5204 pci_try_set_mwi(pdev);
5205 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05005206
James Smart05580562011-05-24 11:40:48 -04005207 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
Jon Mason453193e2013-09-11 15:38:13 -07005208 if (pci_is_pcie(pdev))
James Smart05580562011-05-24 11:40:48 -04005209 pdev->needs_freset = 1;
5210
James Smart3772a992009-05-22 14:50:54 -04005211 return 0;
James Smart5b75da22008-12-04 22:39:35 -05005212
James Smart3772a992009-05-22 14:50:54 -04005213out_disable_device:
5214 pci_disable_device(pdev);
5215out_error:
James Smart079b5c92011-08-21 21:48:49 -04005216 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005217 "1401 Failed to enable pci device\n");
James Smart3772a992009-05-22 14:50:54 -04005218 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05005219}
5220
5221/**
James Smart3772a992009-05-22 14:50:54 -04005222 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05005223 * @phba: pointer to lpfc hba data structure.
5224 *
James Smart3772a992009-05-22 14:50:54 -04005225 * This routine is invoked to disable the PCI device that is common to all
5226 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05005227 **/
5228static void
James Smart3772a992009-05-22 14:50:54 -04005229lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05005230{
James Smart3772a992009-05-22 14:50:54 -04005231 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05005232
James Smart3772a992009-05-22 14:50:54 -04005233 /* Obtain PCI device reference */
5234 if (!phba->pcidev)
5235 return;
5236 else
5237 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04005238 /* Release PCI resource and disable PCI device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005239 pci_release_mem_regions(pdev);
James Smart3772a992009-05-22 14:50:54 -04005240 pci_disable_device(pdev);
James Smart5b75da22008-12-04 22:39:35 -05005241
5242 return;
5243}
5244
5245/**
James Smart3772a992009-05-22 14:50:54 -04005246 * lpfc_reset_hba - Reset a hba
5247 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04005248 *
James Smart3772a992009-05-22 14:50:54 -04005249 * This routine is invoked to reset a hba device. It brings the HBA
5250 * offline, performs a board restart, and then brings the board back
5251 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
5252 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04005253 **/
James Smart3772a992009-05-22 14:50:54 -04005254void
5255lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05005256{
James Smart3772a992009-05-22 14:50:54 -04005257 /* If resets are disabled then set error state and return. */
5258 if (!phba->cfg_enable_hba_reset) {
5259 phba->link_state = LPFC_HBA_ERROR;
5260 return;
5261 }
James Smartee620212014-04-04 13:51:53 -04005262 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
5263 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
5264 else
5265 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart3772a992009-05-22 14:50:54 -04005266 lpfc_offline(phba);
5267 lpfc_sli_brdrestart(phba);
5268 lpfc_online(phba);
5269 lpfc_unblock_mgmt_io(phba);
5270}
dea31012005-04-17 16:05:31 -05005271
James Smart3772a992009-05-22 14:50:54 -04005272/**
James Smart0a96e972011-07-22 18:37:28 -04005273 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
5274 * @phba: pointer to lpfc hba data structure.
5275 *
5276 * This function enables the PCI SR-IOV virtual functions to a physical
5277 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5278 * enable the number of virtual functions to the physical function. As
5279 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5280 * API call does not considered as an error condition for most of the device.
5281 **/
5282uint16_t
5283lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
5284{
5285 struct pci_dev *pdev = phba->pcidev;
5286 uint16_t nr_virtfn;
5287 int pos;
5288
James Smart0a96e972011-07-22 18:37:28 -04005289 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
5290 if (pos == 0)
5291 return 0;
5292
5293 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
5294 return nr_virtfn;
5295}
5296
5297/**
James Smart912e3ac2011-05-24 11:42:11 -04005298 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
5299 * @phba: pointer to lpfc hba data structure.
5300 * @nr_vfn: number of virtual functions to be enabled.
5301 *
5302 * This function enables the PCI SR-IOV virtual functions to a physical
5303 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5304 * enable the number of virtual functions to the physical function. As
5305 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5306 * API call does not considered as an error condition for most of the device.
5307 **/
5308int
5309lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
5310{
5311 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04005312 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04005313 int rc;
5314
James Smart0a96e972011-07-22 18:37:28 -04005315 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
5316 if (nr_vfn > max_nr_vfn) {
5317 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5318 "3057 Requested vfs (%d) greater than "
5319 "supported vfs (%d)", nr_vfn, max_nr_vfn);
5320 return -EINVAL;
5321 }
5322
James Smart912e3ac2011-05-24 11:42:11 -04005323 rc = pci_enable_sriov(pdev, nr_vfn);
5324 if (rc) {
5325 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5326 "2806 Failed to enable sriov on this device "
5327 "with vfn number nr_vf:%d, rc:%d\n",
5328 nr_vfn, rc);
5329 } else
5330 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5331 "2807 Successful enable sriov on this device "
5332 "with vfn number nr_vf:%d\n", nr_vfn);
5333 return rc;
5334}
5335
5336/**
James Smart895427b2017-02-12 13:52:30 -08005337 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
James Smart3772a992009-05-22 14:50:54 -04005338 * @phba: pointer to lpfc hba data structure.
5339 *
James Smart895427b2017-02-12 13:52:30 -08005340 * This routine is invoked to set up the driver internal resources before the
5341 * device specific resource setup to support the HBA device it attached to.
James Smart3772a992009-05-22 14:50:54 -04005342 *
5343 * Return codes
James Smart895427b2017-02-12 13:52:30 -08005344 * 0 - successful
5345 * other values - error
James Smart3772a992009-05-22 14:50:54 -04005346 **/
5347static int
James Smart895427b2017-02-12 13:52:30 -08005348lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
James Smart3772a992009-05-22 14:50:54 -04005349{
James Smart895427b2017-02-12 13:52:30 -08005350 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05005351
James Smart3772a992009-05-22 14:50:54 -04005352 /*
James Smart895427b2017-02-12 13:52:30 -08005353 * Driver resources common to all SLI revisions
James Smart3772a992009-05-22 14:50:54 -04005354 */
James Smart895427b2017-02-12 13:52:30 -08005355 atomic_set(&phba->fast_event_count, 0);
5356 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005357
James Smart895427b2017-02-12 13:52:30 -08005358 /* Initialize ndlp management spinlock */
5359 spin_lock_init(&phba->ndlp_lock);
James Smart3772a992009-05-22 14:50:54 -04005360
James Smart895427b2017-02-12 13:52:30 -08005361 INIT_LIST_HEAD(&phba->port_list);
5362 INIT_LIST_HEAD(&phba->work_list);
5363 init_waitqueue_head(&phba->wait_4_mlo_m_q);
5364
5365 /* Initialize the wait queue head for the kernel thread */
5366 init_waitqueue_head(&phba->work_waitq);
5367
5368 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartf358dd02017-02-12 13:52:34 -08005369 "1403 Protocols supported %s %s %s\n",
James Smart895427b2017-02-12 13:52:30 -08005370 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
5371 "SCSI" : " "),
5372 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
James Smartf358dd02017-02-12 13:52:34 -08005373 "NVME" : " "),
5374 (phba->nvmet_support ? "NVMET" : " "));
James Smart895427b2017-02-12 13:52:30 -08005375
5376 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5377 /* Initialize the scsi buffer list used by driver for scsi IO */
5378 spin_lock_init(&phba->scsi_buf_list_get_lock);
5379 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5380 spin_lock_init(&phba->scsi_buf_list_put_lock);
5381 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
5382 }
5383
5384 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
5385 (phba->nvmet_support == 0)) {
5386 /* Initialize the NVME buffer list used by driver for NVME IO */
5387 spin_lock_init(&phba->nvme_buf_list_get_lock);
5388 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_get);
5389 spin_lock_init(&phba->nvme_buf_list_put_lock);
5390 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
5391 }
5392
5393 /* Initialize the fabric iocb list */
5394 INIT_LIST_HEAD(&phba->fabric_iocb_list);
5395
5396 /* Initialize list to save ELS buffers */
5397 INIT_LIST_HEAD(&phba->elsbuf);
5398
5399 /* Initialize FCF connection rec list */
5400 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
5401
5402 /* Initialize OAS configuration list */
5403 spin_lock_init(&phba->devicelock);
5404 INIT_LIST_HEAD(&phba->luns);
5405
James Smart3772a992009-05-22 14:50:54 -04005406 /* MBOX heartbeat timer */
5407 init_timer(&psli->mbox_tmo);
5408 psli->mbox_tmo.function = lpfc_mbox_timeout;
5409 psli->mbox_tmo.data = (unsigned long) phba;
James Smart3772a992009-05-22 14:50:54 -04005410 /* Fabric block timer */
5411 init_timer(&phba->fabric_block_timer);
5412 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
5413 phba->fabric_block_timer.data = (unsigned long) phba;
5414 /* EA polling mode timer */
5415 init_timer(&phba->eratt_poll);
5416 phba->eratt_poll.function = lpfc_poll_eratt;
5417 phba->eratt_poll.data = (unsigned long) phba;
James Smart895427b2017-02-12 13:52:30 -08005418 /* Heartbeat timer */
5419 init_timer(&phba->hb_tmofunc);
5420 phba->hb_tmofunc.function = lpfc_hb_timeout;
5421 phba->hb_tmofunc.data = (unsigned long)phba;
5422
5423 return 0;
5424}
5425
5426/**
5427 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
5428 * @phba: pointer to lpfc hba data structure.
5429 *
5430 * This routine is invoked to set up the driver internal resources specific to
5431 * support the SLI-3 HBA device it attached to.
5432 *
5433 * Return codes
5434 * 0 - successful
5435 * other values - error
5436 **/
5437static int
5438lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
5439{
5440 int rc;
5441
5442 /*
5443 * Initialize timers used by driver
5444 */
5445
5446 /* FCP polling mode timer */
5447 init_timer(&phba->fcp_poll_timer);
5448 phba->fcp_poll_timer.function = lpfc_poll_timeout;
5449 phba->fcp_poll_timer.data = (unsigned long) phba;
James Smart3772a992009-05-22 14:50:54 -04005450
5451 /* Host attention work mask setup */
5452 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
5453 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
5454
5455 /* Get all the module params for configuring this host */
5456 lpfc_get_cfgparam(phba);
James Smart895427b2017-02-12 13:52:30 -08005457 /* Set up phase-1 common device driver resources */
5458
5459 rc = lpfc_setup_driver_resource_phase1(phba);
5460 if (rc)
5461 return -ENODEV;
5462
James Smart49198b32010-04-06 15:04:33 -04005463 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
5464 phba->menlo_flag |= HBA_MENLO_SUPPORT;
5465 /* check for menlo minimum sg count */
5466 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
5467 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
5468 }
5469
James Smart895427b2017-02-12 13:52:30 -08005470 if (!phba->sli.sli3_ring)
5471 phba->sli.sli3_ring = kzalloc(LPFC_SLI3_MAX_RING *
James Smart2a76a282012-08-03 12:35:54 -04005472 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
James Smart895427b2017-02-12 13:52:30 -08005473 if (!phba->sli.sli3_ring)
James Smart2a76a282012-08-03 12:35:54 -04005474 return -ENOMEM;
5475
James Smart3772a992009-05-22 14:50:54 -04005476 /*
James Smart96f70772013-04-17 20:16:15 -04005477 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smart3772a992009-05-22 14:50:54 -04005478 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart3772a992009-05-22 14:50:54 -04005479 */
James Smart3772a992009-05-22 14:50:54 -04005480
James Smart96f70772013-04-17 20:16:15 -04005481 /* Initialize the host templates the configured values. */
James Smart3772a992009-05-22 14:50:54 -04005482 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
Bodo Stroesser5f406fa2015-08-31 16:48:10 -04005483 lpfc_template_s3.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart3772a992009-05-22 14:50:54 -04005484
James Smart96f70772013-04-17 20:16:15 -04005485 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
5486 if (phba->cfg_enable_bg) {
5487 /*
5488 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5489 * the FCP rsp, and a BDE for each. Sice we have no control
5490 * over how many protection data segments the SCSI Layer
5491 * will hand us (ie: there could be one for every block
5492 * in the IO), we just allocate enough BDEs to accomidate
5493 * our max amount and we need to limit lpfc_sg_seg_cnt to
5494 * minimize the risk of running out.
5495 */
5496 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5497 sizeof(struct fcp_rsp) +
5498 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
5499
5500 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
5501 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
5502
5503 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
5504 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
5505 } else {
5506 /*
5507 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5508 * the FCP rsp, a BDE for each, and a BDE for up to
5509 * cfg_sg_seg_cnt data segments.
5510 */
5511 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5512 sizeof(struct fcp_rsp) +
5513 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
5514
5515 /* Total BDEs in BPL for scsi_sg_list */
5516 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5517 }
5518
5519 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5520 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
5521 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5522 phba->cfg_total_seg_cnt);
5523
James Smart3772a992009-05-22 14:50:54 -04005524 phba->max_vpi = LPFC_MAX_VPI;
5525 /* This will be set to correct value after config_port mbox */
5526 phba->max_vports = 0;
5527
5528 /*
5529 * Initialize the SLI Layer to run with lpfc HBAs.
5530 */
5531 lpfc_sli_setup(phba);
James Smart895427b2017-02-12 13:52:30 -08005532 lpfc_sli_queue_init(phba);
James Smart3772a992009-05-22 14:50:54 -04005533
5534 /* Allocate device driver memory */
5535 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
5536 return -ENOMEM;
5537
James Smart912e3ac2011-05-24 11:42:11 -04005538 /*
5539 * Enable sr-iov virtual functions if supported and configured
5540 * through the module parameter.
5541 */
5542 if (phba->cfg_sriov_nr_virtfn > 0) {
5543 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5544 phba->cfg_sriov_nr_virtfn);
5545 if (rc) {
5546 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5547 "2808 Requested number of SR-IOV "
5548 "virtual functions (%d) is not "
5549 "supported\n",
5550 phba->cfg_sriov_nr_virtfn);
5551 phba->cfg_sriov_nr_virtfn = 0;
5552 }
5553 }
5554
James Smart3772a992009-05-22 14:50:54 -04005555 return 0;
5556}
5557
5558/**
5559 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
5560 * @phba: pointer to lpfc hba data structure.
5561 *
5562 * This routine is invoked to unset the driver internal resources set up
5563 * specific for supporting the SLI-3 HBA device it attached to.
5564 **/
5565static void
5566lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
5567{
5568 /* Free device driver memory allocated */
5569 lpfc_mem_free_all(phba);
5570
5571 return;
5572}
5573
5574/**
James Smartda0436e2009-05-22 14:51:39 -04005575 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
5576 * @phba: pointer to lpfc hba data structure.
5577 *
5578 * This routine is invoked to set up the driver internal resources specific to
5579 * support the SLI-4 HBA device it attached to.
5580 *
5581 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005582 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04005583 * other values - error
5584 **/
5585static int
5586lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5587{
James Smart28baac72010-02-12 14:42:03 -05005588 LPFC_MBOXQ_t *mboxq;
James Smartf358dd02017-02-12 13:52:34 -08005589 MAILBOX_t *mb;
James Smart895427b2017-02-12 13:52:30 -08005590 int rc, i, max_buf_size;
James Smart28baac72010-02-12 14:42:03 -05005591 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
5592 struct lpfc_mqe *mqe;
James Smart09294d42013-04-17 20:16:05 -04005593 int longs;
James Smart1ba981f2014-02-20 09:56:45 -05005594 int fof_vectors = 0;
James Smartf358dd02017-02-12 13:52:34 -08005595 uint64_t wwn;
James Smartda0436e2009-05-22 14:51:39 -04005596
James Smart895427b2017-02-12 13:52:30 -08005597 phba->sli4_hba.num_online_cpu = num_online_cpus();
5598 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
5599 phba->sli4_hba.curr_disp_cpu = 0;
5600
James Smart716d3bc2013-09-06 12:18:28 -04005601 /* Get all the module params for configuring this host */
5602 lpfc_get_cfgparam(phba);
5603
James Smart895427b2017-02-12 13:52:30 -08005604 /* Set up phase-1 common device driver resources */
5605 rc = lpfc_setup_driver_resource_phase1(phba);
5606 if (rc)
5607 return -ENODEV;
5608
James Smartda0436e2009-05-22 14:51:39 -04005609 /* Before proceed, wait for POST done and device ready */
5610 rc = lpfc_sli4_post_status_check(phba);
5611 if (rc)
5612 return -ENODEV;
5613
5614 /*
5615 * Initialize timers used by driver
5616 */
5617
James Smart19ca7602010-11-20 23:11:55 -05005618 init_timer(&phba->rrq_tmr);
5619 phba->rrq_tmr.function = lpfc_rrq_timeout;
5620 phba->rrq_tmr.data = (unsigned long)phba;
James Smartda0436e2009-05-22 14:51:39 -04005621
James Smartecfd03c2010-02-12 14:41:27 -05005622 /* FCF rediscover timer */
5623 init_timer(&phba->fcf.redisc_wait);
5624 phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
5625 phba->fcf.redisc_wait.data = (unsigned long)phba;
5626
James Smartda0436e2009-05-22 14:51:39 -04005627 /*
James Smart7ad20aa2011-05-24 11:44:28 -04005628 * Control structure for handling external multi-buffer mailbox
5629 * command pass-through.
5630 */
5631 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
5632 sizeof(struct lpfc_mbox_ext_buf_ctx));
5633 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
5634
James Smartda0436e2009-05-22 14:51:39 -04005635 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04005636
James Smartda0436e2009-05-22 14:51:39 -04005637 /* This will be set to correct value after the read_config mbox */
5638 phba->max_vports = 0;
5639
5640 /* Program the default value of vlan_id and fc_map */
5641 phba->valid_vlan = 0;
5642 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5643 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5644 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5645
5646 /*
James Smart2a76a282012-08-03 12:35:54 -04005647 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
James Smart895427b2017-02-12 13:52:30 -08005648 * we will associate a new ring, for each EQ/CQ/WQ tuple.
5649 * The WQ create will allocate the ring.
James Smart2a76a282012-08-03 12:35:54 -04005650 */
James Smart085c6472010-11-20 23:11:37 -05005651
James Smart09294d42013-04-17 20:16:05 -04005652 /*
5653 * It doesn't matter what family our adapter is in, we are
5654 * limited to 2 Pages, 512 SGEs, for our SGL.
5655 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
5656 */
5657 max_buf_size = (2 * SLI4_PAGE_SIZE);
5658 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2)
5659 phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2;
James Smart09294d42013-04-17 20:16:05 -04005660
James Smartda0436e2009-05-22 14:51:39 -04005661 /*
James Smart895427b2017-02-12 13:52:30 -08005662 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
5663 * used to create the sg_dma_buf_pool must be calculated.
James Smart28baac72010-02-12 14:42:03 -05005664 */
James Smart96f70772013-04-17 20:16:15 -04005665 if (phba->cfg_enable_bg) {
5666 /*
James Smart895427b2017-02-12 13:52:30 -08005667 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
5668 * the FCP rsp, and a SGE. Sice we have no control
5669 * over how many protection segments the SCSI Layer
James Smart96f70772013-04-17 20:16:15 -04005670 * will hand us (ie: there could be one for every block
James Smart895427b2017-02-12 13:52:30 -08005671 * in the IO), just allocate enough SGEs to accomidate
5672 * our max amount and we need to limit lpfc_sg_seg_cnt
5673 * to minimize the risk of running out.
James Smart96f70772013-04-17 20:16:15 -04005674 */
5675 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08005676 sizeof(struct fcp_rsp) + max_buf_size;
James Smart96f70772013-04-17 20:16:15 -04005677
5678 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
5679 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
5680
5681 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
James Smart895427b2017-02-12 13:52:30 -08005682 phba->cfg_sg_seg_cnt =
5683 LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
James Smart96f70772013-04-17 20:16:15 -04005684 } else {
5685 /*
James Smart895427b2017-02-12 13:52:30 -08005686 * The scsi_buf for a regular I/O holds the FCP cmnd,
James Smart96f70772013-04-17 20:16:15 -04005687 * the FCP rsp, a SGE for each, and a SGE for up to
5688 * cfg_sg_seg_cnt data segments.
5689 */
5690 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08005691 sizeof(struct fcp_rsp) +
5692 ((phba->cfg_sg_seg_cnt + 2) *
5693 sizeof(struct sli4_sge));
James Smart96f70772013-04-17 20:16:15 -04005694
5695 /* Total SGEs for scsi_sg_list */
5696 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
James Smart895427b2017-02-12 13:52:30 -08005697
James Smart96f70772013-04-17 20:16:15 -04005698 /*
James Smart895427b2017-02-12 13:52:30 -08005699 * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only
5700 * need to post 1 page for the SGL.
James Smart96f70772013-04-17 20:16:15 -04005701 */
James Smart085c6472010-11-20 23:11:37 -05005702 }
James Smartacd68592012-01-18 16:25:09 -05005703
James Smart96f70772013-04-17 20:16:15 -04005704 /* Initialize the host templates with the updated values. */
5705 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5706 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5707
5708 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
5709 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
5710 else
5711 phba->cfg_sg_dma_buf_size =
5712 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
5713
5714 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5715 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
5716 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5717 phba->cfg_total_seg_cnt);
James Smartda0436e2009-05-22 14:51:39 -04005718
5719 /* Initialize buffer queue management fields */
James Smart895427b2017-02-12 13:52:30 -08005720 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
James Smartda0436e2009-05-22 14:51:39 -04005721 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
5722 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
5723
5724 /*
5725 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
5726 */
James Smart895427b2017-02-12 13:52:30 -08005727 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5728 /* Initialize the Abort scsi buffer list used by driver */
5729 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
5730 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
5731 }
5732
5733 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
5734 /* Initialize the Abort nvme buffer list used by driver */
5735 spin_lock_init(&phba->sli4_hba.abts_nvme_buf_list_lock);
5736 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
5737 }
5738
James Smartda0436e2009-05-22 14:51:39 -04005739 /* This abort list used by worker thread */
James Smart895427b2017-02-12 13:52:30 -08005740 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
James Smartf358dd02017-02-12 13:52:34 -08005741 spin_lock_init(&phba->sli4_hba.nvmet_io_lock);
James Smartda0436e2009-05-22 14:51:39 -04005742
5743 /*
James Smart6d368e52011-05-24 11:44:12 -04005744 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04005745 */
5746
5747 /* Driver internel slow-path CQ Event pool */
5748 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
5749 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04005750 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04005751 /* Asynchronous event CQ Event work queue list */
5752 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
5753 /* Fast-path XRI aborted CQ Event work queue list */
5754 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
5755 /* Slow-path XRI aborted CQ Event work queue list */
5756 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
5757 /* Receive queue CQ Event work queue list */
5758 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
5759
James Smart6d368e52011-05-24 11:44:12 -04005760 /* Initialize extent block lists. */
5761 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
5762 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
5763 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
5764 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
5765
James Smart448193b2015-12-16 18:12:05 -05005766 /* initialize optic_state to 0xFF */
5767 phba->sli4_hba.lnk_info.optic_state = 0xff;
5768
James Smartda0436e2009-05-22 14:51:39 -04005769 /* Allocate device driver memory */
5770 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
5771 if (rc)
5772 return -ENOMEM;
5773
James Smart2fcee4b2010-12-15 17:57:46 -05005774 /* IF Type 2 ports get initialized now. */
5775 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5776 LPFC_SLI_INTF_IF_TYPE_2) {
5777 rc = lpfc_pci_function_reset(phba);
James Smart895427b2017-02-12 13:52:30 -08005778 if (unlikely(rc)) {
5779 rc = -ENODEV;
5780 goto out_free_mem;
5781 }
James Smart946727d2015-04-07 15:07:09 -04005782 phba->temp_sensor_support = 1;
James Smart2fcee4b2010-12-15 17:57:46 -05005783 }
5784
James Smartda0436e2009-05-22 14:51:39 -04005785 /* Create the bootstrap mailbox command */
5786 rc = lpfc_create_bootstrap_mbox(phba);
5787 if (unlikely(rc))
5788 goto out_free_mem;
5789
5790 /* Set up the host's endian order with the device. */
5791 rc = lpfc_setup_endian_order(phba);
5792 if (unlikely(rc))
5793 goto out_free_bsmbx;
5794
5795 /* Set up the hba's configuration parameters. */
5796 rc = lpfc_sli4_read_config(phba);
5797 if (unlikely(rc))
5798 goto out_free_bsmbx;
James Smartcff261f2013-12-17 20:29:47 -05005799 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
5800 if (unlikely(rc))
5801 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005802
James Smart2fcee4b2010-12-15 17:57:46 -05005803 /* IF Type 0 ports get initialized now. */
5804 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5805 LPFC_SLI_INTF_IF_TYPE_0) {
5806 rc = lpfc_pci_function_reset(phba);
5807 if (unlikely(rc))
5808 goto out_free_bsmbx;
5809 }
James Smartda0436e2009-05-22 14:51:39 -04005810
James Smartcb5172e2010-03-15 11:25:07 -04005811 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
5812 GFP_KERNEL);
5813 if (!mboxq) {
5814 rc = -ENOMEM;
5815 goto out_free_bsmbx;
5816 }
5817
James Smartf358dd02017-02-12 13:52:34 -08005818 /* Check for NVMET being configured */
James Smart895427b2017-02-12 13:52:30 -08005819 phba->nvmet_support = 0;
James Smartf358dd02017-02-12 13:52:34 -08005820 if (lpfc_enable_nvmet_cnt) {
5821
5822 /* First get WWN of HBA instance */
5823 lpfc_read_nv(phba, mboxq);
5824 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5825 if (rc != MBX_SUCCESS) {
5826 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5827 "6016 Mailbox failed , mbxCmd x%x "
5828 "READ_NV, mbxStatus x%x\n",
5829 bf_get(lpfc_mqe_command, &mboxq->u.mqe),
5830 bf_get(lpfc_mqe_status, &mboxq->u.mqe));
5831 rc = -EIO;
5832 goto out_free_bsmbx;
5833 }
5834 mb = &mboxq->u.mb;
5835 memcpy(&wwn, (char *)mb->un.varRDnvp.nodename,
5836 sizeof(uint64_t));
5837 wwn = cpu_to_be64(wwn);
5838 phba->sli4_hba.wwnn.u.name = wwn;
5839 memcpy(&wwn, (char *)mb->un.varRDnvp.portname,
5840 sizeof(uint64_t));
5841 /* wwn is WWPN of HBA instance */
5842 wwn = cpu_to_be64(wwn);
5843 phba->sli4_hba.wwpn.u.name = wwn;
5844
5845 /* Check to see if it matches any module parameter */
5846 for (i = 0; i < lpfc_enable_nvmet_cnt; i++) {
5847 if (wwn == lpfc_enable_nvmet[i]) {
5848 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5849 "6017 NVME Target %016llx\n",
5850 wwn);
5851 phba->nvmet_support = 1; /* a match */
5852 }
5853 }
5854 }
James Smart895427b2017-02-12 13:52:30 -08005855
5856 lpfc_nvme_mod_param_dep(phba);
5857
James Smartfedd3b72011-02-16 12:39:24 -05005858 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04005859 lpfc_supported_pages(mboxq);
5860 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05005861 if (!rc) {
5862 mqe = &mboxq->u.mqe;
5863 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
5864 LPFC_MAX_SUPPORTED_PAGES);
5865 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
5866 switch (pn_page[i]) {
5867 case LPFC_SLI4_PARAMETERS:
5868 phba->sli4_hba.pc_sli4_params.supported = 1;
5869 break;
5870 default:
5871 break;
5872 }
5873 }
5874 /* Read the port's SLI4 Parameters capabilities if supported. */
5875 if (phba->sli4_hba.pc_sli4_params.supported)
5876 rc = lpfc_pc_sli4_params_get(phba, mboxq);
5877 if (rc) {
5878 mempool_free(mboxq, phba->mbox_mem_pool);
5879 rc = -EIO;
5880 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04005881 }
5882 }
James Smart65791f12016-07-06 12:35:56 -07005883
James Smartfedd3b72011-02-16 12:39:24 -05005884 /*
5885 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04005886 * If this call fails, it isn't critical unless the SLI4 parameters come
5887 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05005888 */
James Smart6d368e52011-05-24 11:44:12 -04005889 rc = lpfc_get_sli4_parameters(phba, mboxq);
5890 if (rc) {
5891 if (phba->sli4_hba.extents_in_use &&
5892 phba->sli4_hba.rpi_hdrs_in_use) {
5893 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5894 "2999 Unsupported SLI4 Parameters "
5895 "Extents and RPI headers enabled.\n");
James Smart6d368e52011-05-24 11:44:12 -04005896 }
James Smart895427b2017-02-12 13:52:30 -08005897 mempool_free(mboxq, phba->mbox_mem_pool);
5898 goto out_free_bsmbx;
James Smart6d368e52011-05-24 11:44:12 -04005899 }
James Smart895427b2017-02-12 13:52:30 -08005900
James Smartcb5172e2010-03-15 11:25:07 -04005901 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -05005902
5903 /* Verify OAS is supported */
5904 lpfc_sli4_oas_verify(phba);
5905 if (phba->cfg_fof)
5906 fof_vectors = 1;
5907
James Smart5350d872011-10-10 21:33:49 -04005908 /* Verify all the SLI4 queues */
5909 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04005910 if (rc)
5911 goto out_free_bsmbx;
5912
5913 /* Create driver internal CQE event pool */
5914 rc = lpfc_sli4_cq_event_pool_create(phba);
5915 if (rc)
James Smart5350d872011-10-10 21:33:49 -04005916 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005917
James Smart8a9d2e82012-05-09 21:16:12 -04005918 /* Initialize sgl lists per host */
5919 lpfc_init_sgl_list(phba);
5920
5921 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04005922 rc = lpfc_init_active_sgl_array(phba);
5923 if (rc) {
5924 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5925 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04005926 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04005927 }
James Smartda0436e2009-05-22 14:51:39 -04005928 rc = lpfc_sli4_init_rpi_hdrs(phba);
5929 if (rc) {
5930 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5931 "1432 Failed to initialize rpi headers.\n");
5932 goto out_free_active_sgl;
5933 }
5934
James Smarta93ff372010-10-22 11:06:08 -04005935 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05005936 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
5937 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
5938 GFP_KERNEL);
5939 if (!phba->fcf.fcf_rr_bmask) {
5940 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5941 "2759 Failed allocate memory for FCF round "
5942 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04005943 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05005944 goto out_remove_rpi_hdrs;
5945 }
5946
James Smart895427b2017-02-12 13:52:30 -08005947 phba->sli4_hba.hba_eq_hdl = kcalloc(fof_vectors + phba->io_channel_irqs,
5948 sizeof(struct lpfc_hba_eq_hdl),
5949 GFP_KERNEL);
5950 if (!phba->sli4_hba.hba_eq_hdl) {
James Smart67d12732012-08-03 12:36:13 -04005951 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5952 "2572 Failed allocate memory for "
5953 "fast-path per-EQ handle array\n");
5954 rc = -ENOMEM;
5955 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04005956 }
5957
James Smart895427b2017-02-12 13:52:30 -08005958 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_present_cpu,
5959 sizeof(struct lpfc_vector_map_info),
5960 GFP_KERNEL);
James Smart7bb03bb2013-04-17 20:19:16 -04005961 if (!phba->sli4_hba.cpu_map) {
5962 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5963 "3327 Failed allocate memory for msi-x "
5964 "interrupt vector mapping\n");
5965 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08005966 goto out_free_hba_eq_hdl;
James Smart7bb03bb2013-04-17 20:19:16 -04005967 }
James Smartb246de12013-05-31 17:03:07 -04005968 if (lpfc_used_cpu == NULL) {
James Smart895427b2017-02-12 13:52:30 -08005969 lpfc_used_cpu = kcalloc(lpfc_present_cpu, sizeof(uint16_t),
5970 GFP_KERNEL);
James Smartb246de12013-05-31 17:03:07 -04005971 if (!lpfc_used_cpu) {
5972 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5973 "3335 Failed allocate memory for msi-x "
5974 "interrupt vector mapping\n");
5975 kfree(phba->sli4_hba.cpu_map);
5976 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08005977 goto out_free_hba_eq_hdl;
James Smartb246de12013-05-31 17:03:07 -04005978 }
5979 for (i = 0; i < lpfc_present_cpu; i++)
5980 lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
5981 }
5982
James Smart912e3ac2011-05-24 11:42:11 -04005983 /*
5984 * Enable sr-iov virtual functions if supported and configured
5985 * through the module parameter.
5986 */
5987 if (phba->cfg_sriov_nr_virtfn > 0) {
5988 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5989 phba->cfg_sriov_nr_virtfn);
5990 if (rc) {
5991 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5992 "3020 Requested number of SR-IOV "
5993 "virtual functions (%d) is not "
5994 "supported\n",
5995 phba->cfg_sriov_nr_virtfn);
5996 phba->cfg_sriov_nr_virtfn = 0;
5997 }
5998 }
5999
James Smart5248a742011-07-22 18:37:06 -04006000 return 0;
James Smartda0436e2009-05-22 14:51:39 -04006001
James Smart895427b2017-02-12 13:52:30 -08006002out_free_hba_eq_hdl:
6003 kfree(phba->sli4_hba.hba_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05006004out_free_fcf_rr_bmask:
6005 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04006006out_remove_rpi_hdrs:
6007 lpfc_sli4_remove_rpi_hdrs(phba);
6008out_free_active_sgl:
6009 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04006010out_destroy_cq_event_pool:
6011 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04006012out_free_bsmbx:
6013 lpfc_destroy_bootstrap_mbox(phba);
6014out_free_mem:
6015 lpfc_mem_free(phba);
6016 return rc;
6017}
6018
6019/**
6020 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
6021 * @phba: pointer to lpfc hba data structure.
6022 *
6023 * This routine is invoked to unset the driver internal resources set up
6024 * specific for supporting the SLI-4 HBA device it attached to.
6025 **/
6026static void
6027lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
6028{
6029 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6030
James Smart7bb03bb2013-04-17 20:19:16 -04006031 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
6032 kfree(phba->sli4_hba.cpu_map);
6033 phba->sli4_hba.num_present_cpu = 0;
6034 phba->sli4_hba.num_online_cpu = 0;
James Smart76fd07a2014-02-20 09:57:18 -05006035 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04006036
James Smartda0436e2009-05-22 14:51:39 -04006037 /* Free memory allocated for fast-path work queue handles */
James Smart895427b2017-02-12 13:52:30 -08006038 kfree(phba->sli4_hba.hba_eq_hdl);
James Smartda0436e2009-05-22 14:51:39 -04006039
6040 /* Free the allocated rpi headers. */
6041 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04006042 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04006043
James Smart0c9ab6f2010-02-26 14:15:57 -05006044 /* Free eligible FCF index bmask */
6045 kfree(phba->fcf.fcf_rr_bmask);
6046
James Smartda0436e2009-05-22 14:51:39 -04006047 /* Free the ELS sgl list */
6048 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04006049 lpfc_free_els_sgl_list(phba);
James Smartf358dd02017-02-12 13:52:34 -08006050 lpfc_free_nvmet_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04006051
James Smartda0436e2009-05-22 14:51:39 -04006052 /* Free the completion queue EQ event pool */
6053 lpfc_sli4_cq_event_release_all(phba);
6054 lpfc_sli4_cq_event_pool_destroy(phba);
6055
James Smart6d368e52011-05-24 11:44:12 -04006056 /* Release resource identifiers. */
6057 lpfc_sli4_dealloc_resource_identifiers(phba);
6058
James Smartda0436e2009-05-22 14:51:39 -04006059 /* Free the bsmbx region. */
6060 lpfc_destroy_bootstrap_mbox(phba);
6061
6062 /* Free the SLI Layer memory with SLI4 HBAs */
6063 lpfc_mem_free_all(phba);
6064
6065 /* Free the current connect table */
6066 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04006067 &phba->fcf_conn_rec_list, list) {
6068 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04006069 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04006070 }
James Smartda0436e2009-05-22 14:51:39 -04006071
6072 return;
6073}
6074
6075/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006076 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04006077 * @phba: The hba struct for which this call is being executed.
6078 * @dev_grp: The HBA PCI-Device group number.
6079 *
6080 * This routine sets up the device INIT interface API function jump table
6081 * in @phba struct.
6082 *
6083 * Returns: 0 - success, -ENODEV - failure.
6084 **/
6085int
6086lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
6087{
James Smart84d1b002010-02-12 14:42:33 -05006088 phba->lpfc_hba_init_link = lpfc_hba_init_link;
6089 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05006090 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04006091 switch (dev_grp) {
6092 case LPFC_PCI_DEV_LP:
6093 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
6094 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
6095 phba->lpfc_stop_port = lpfc_stop_port_s3;
6096 break;
James Smartda0436e2009-05-22 14:51:39 -04006097 case LPFC_PCI_DEV_OC:
6098 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
6099 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
6100 phba->lpfc_stop_port = lpfc_stop_port_s4;
6101 break;
James Smart3772a992009-05-22 14:50:54 -04006102 default:
6103 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6104 "1431 Invalid HBA PCI-device group: 0x%x\n",
6105 dev_grp);
6106 return -ENODEV;
6107 break;
6108 }
6109 return 0;
6110}
6111
6112/**
James Smart3772a992009-05-22 14:50:54 -04006113 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
6114 * @phba: pointer to lpfc hba data structure.
6115 *
6116 * This routine is invoked to set up the driver internal resources after the
6117 * device specific resource setup to support the HBA device it attached to.
6118 *
6119 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006120 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006121 * other values - error
6122 **/
6123static int
6124lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
6125{
6126 int error;
6127
6128 /* Startup the kernel thread for this host adapter. */
6129 phba->worker_thread = kthread_run(lpfc_do_work, phba,
6130 "lpfc_worker_%d", phba->brd_no);
6131 if (IS_ERR(phba->worker_thread)) {
6132 error = PTR_ERR(phba->worker_thread);
6133 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006134 }
6135
James Smart3772a992009-05-22 14:50:54 -04006136 return 0;
6137}
6138
6139/**
6140 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
6141 * @phba: pointer to lpfc hba data structure.
6142 *
6143 * This routine is invoked to unset the driver internal resources set up after
6144 * the device specific resource setup for supporting the HBA device it
6145 * attached to.
6146 **/
6147static void
6148lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
6149{
6150 /* Stop kernel worker thread */
6151 kthread_stop(phba->worker_thread);
6152}
6153
6154/**
6155 * lpfc_free_iocb_list - Free iocb list.
6156 * @phba: pointer to lpfc hba data structure.
6157 *
6158 * This routine is invoked to free the driver's IOCB list and memory.
6159 **/
6160static void
6161lpfc_free_iocb_list(struct lpfc_hba *phba)
6162{
6163 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
6164
6165 spin_lock_irq(&phba->hbalock);
6166 list_for_each_entry_safe(iocbq_entry, iocbq_next,
6167 &phba->lpfc_iocb_list, list) {
6168 list_del(&iocbq_entry->list);
6169 kfree(iocbq_entry);
6170 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006171 }
James Smart3772a992009-05-22 14:50:54 -04006172 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006173
James Smart3772a992009-05-22 14:50:54 -04006174 return;
6175}
dea31012005-04-17 16:05:31 -05006176
James Smart3772a992009-05-22 14:50:54 -04006177/**
6178 * lpfc_init_iocb_list - Allocate and initialize iocb list.
6179 * @phba: pointer to lpfc hba data structure.
6180 *
6181 * This routine is invoked to allocate and initizlize the driver's IOCB
6182 * list and set up the IOCB tag array accordingly.
6183 *
6184 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006185 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006186 * other values - error
6187 **/
6188static int
6189lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
6190{
6191 struct lpfc_iocbq *iocbq_entry = NULL;
6192 uint16_t iotag;
6193 int i;
dea31012005-04-17 16:05:31 -05006194
6195 /* Initialize and populate the iocb list per host. */
6196 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04006197 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07006198 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05006199 if (iocbq_entry == NULL) {
6200 printk(KERN_ERR "%s: only allocated %d iocbs of "
6201 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07006202 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05006203 goto out_free_iocbq;
6204 }
6205
James Bottomley604a3e32005-10-29 10:28:33 -05006206 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
6207 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04006208 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05006209 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04006210 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05006211 goto out_free_iocbq;
6212 }
James Smart6d368e52011-05-24 11:44:12 -04006213 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04006214 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05006215
6216 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006217 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
6218 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05006219 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006220 }
6221
James Smart3772a992009-05-22 14:50:54 -04006222 return 0;
6223
6224out_free_iocbq:
6225 lpfc_free_iocb_list(phba);
6226
6227 return -ENOMEM;
6228}
6229
6230/**
James Smart8a9d2e82012-05-09 21:16:12 -04006231 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04006232 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04006233 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04006234 *
James Smart8a9d2e82012-05-09 21:16:12 -04006235 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04006236 **/
James Smart8a9d2e82012-05-09 21:16:12 -04006237void
6238lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04006239{
6240 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04006241
6242 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
6243 list_del(&sglq_entry->list);
6244 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
6245 kfree(sglq_entry);
6246 }
6247}
6248
6249/**
6250 * lpfc_free_els_sgl_list - Free els sgl list.
6251 * @phba: pointer to lpfc hba data structure.
6252 *
6253 * This routine is invoked to free the driver's els sgl list and memory.
6254 **/
6255static void
6256lpfc_free_els_sgl_list(struct lpfc_hba *phba)
6257{
James Smartda0436e2009-05-22 14:51:39 -04006258 LIST_HEAD(sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04006259
James Smart8a9d2e82012-05-09 21:16:12 -04006260 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04006261 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08006262 spin_lock(&phba->sli4_hba.sgl_list_lock);
6263 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
6264 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04006265 spin_unlock_irq(&phba->hbalock);
6266
James Smart8a9d2e82012-05-09 21:16:12 -04006267 /* Now free the sgl list */
6268 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04006269}
6270
6271/**
James Smartf358dd02017-02-12 13:52:34 -08006272 * lpfc_free_nvmet_sgl_list - Free nvmet sgl list.
6273 * @phba: pointer to lpfc hba data structure.
6274 *
6275 * This routine is invoked to free the driver's nvmet sgl list and memory.
6276 **/
6277static void
6278lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba)
6279{
6280 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6281 LIST_HEAD(sglq_list);
6282
6283 /* Retrieve all nvmet sgls from driver list */
6284 spin_lock_irq(&phba->hbalock);
6285 spin_lock(&phba->sli4_hba.sgl_list_lock);
6286 list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list);
6287 spin_unlock(&phba->sli4_hba.sgl_list_lock);
6288 spin_unlock_irq(&phba->hbalock);
6289
6290 /* Now free the sgl list */
6291 list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) {
6292 list_del(&sglq_entry->list);
6293 lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys);
6294 kfree(sglq_entry);
6295 }
6296}
6297
6298/**
James Smartda0436e2009-05-22 14:51:39 -04006299 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
6300 * @phba: pointer to lpfc hba data structure.
6301 *
6302 * This routine is invoked to allocate the driver's active sgl memory.
6303 * This array will hold the sglq_entry's for active IOs.
6304 **/
6305static int
6306lpfc_init_active_sgl_array(struct lpfc_hba *phba)
6307{
6308 int size;
6309 size = sizeof(struct lpfc_sglq *);
6310 size *= phba->sli4_hba.max_cfg_param.max_xri;
6311
6312 phba->sli4_hba.lpfc_sglq_active_list =
6313 kzalloc(size, GFP_KERNEL);
6314 if (!phba->sli4_hba.lpfc_sglq_active_list)
6315 return -ENOMEM;
6316 return 0;
6317}
6318
6319/**
6320 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
6321 * @phba: pointer to lpfc hba data structure.
6322 *
6323 * This routine is invoked to walk through the array of active sglq entries
6324 * and free all of the resources.
6325 * This is just a place holder for now.
6326 **/
6327static void
6328lpfc_free_active_sgl(struct lpfc_hba *phba)
6329{
6330 kfree(phba->sli4_hba.lpfc_sglq_active_list);
6331}
6332
6333/**
6334 * lpfc_init_sgl_list - Allocate and initialize sgl list.
6335 * @phba: pointer to lpfc hba data structure.
6336 *
6337 * This routine is invoked to allocate and initizlize the driver's sgl
6338 * list and set up the sgl xritag tag array accordingly.
6339 *
James Smartda0436e2009-05-22 14:51:39 -04006340 **/
James Smart8a9d2e82012-05-09 21:16:12 -04006341static void
James Smartda0436e2009-05-22 14:51:39 -04006342lpfc_init_sgl_list(struct lpfc_hba *phba)
6343{
James Smartda0436e2009-05-22 14:51:39 -04006344 /* Initialize and populate the sglq list per host/VF. */
James Smart895427b2017-02-12 13:52:30 -08006345 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
James Smartda0436e2009-05-22 14:51:39 -04006346 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -08006347 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list);
6348 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_sgl_list);
James Smartda0436e2009-05-22 14:51:39 -04006349
James Smart8a9d2e82012-05-09 21:16:12 -04006350 /* els xri-sgl book keeping */
6351 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04006352
James Smart8a9d2e82012-05-09 21:16:12 -04006353 /* scsi xri-buffer book keeping */
James Smartda0436e2009-05-22 14:51:39 -04006354 phba->sli4_hba.scsi_xri_cnt = 0;
James Smart895427b2017-02-12 13:52:30 -08006355
6356 /* nvme xri-buffer book keeping */
6357 phba->sli4_hba.nvme_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04006358}
6359
6360/**
6361 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
6362 * @phba: pointer to lpfc hba data structure.
6363 *
6364 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04006365 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04006366 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04006367 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
6368 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04006369 *
6370 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006371 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04006372 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04006373 **/
6374int
6375lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
6376{
6377 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04006378 struct lpfc_rpi_hdr *rpi_hdr;
6379
6380 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05006381 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04006382 return rc;
James Smart6d368e52011-05-24 11:44:12 -04006383 if (phba->sli4_hba.extents_in_use)
6384 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04006385
6386 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
6387 if (!rpi_hdr) {
6388 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6389 "0391 Error during rpi post operation\n");
6390 lpfc_sli4_remove_rpis(phba);
6391 rc = -ENODEV;
6392 }
6393
6394 return rc;
6395}
6396
6397/**
6398 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
6399 * @phba: pointer to lpfc hba data structure.
6400 *
6401 * This routine is invoked to allocate a single 4KB memory region to
6402 * support rpis and stores them in the phba. This single region
6403 * provides support for up to 64 rpis. The region is used globally
6404 * by the device.
6405 *
6406 * Returns:
6407 * A valid rpi hdr on success.
6408 * A NULL pointer on any failure.
6409 **/
6410struct lpfc_rpi_hdr *
6411lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
6412{
6413 uint16_t rpi_limit, curr_rpi_range;
6414 struct lpfc_dmabuf *dmabuf;
6415 struct lpfc_rpi_hdr *rpi_hdr;
James Smart9589b0622011-04-16 11:03:17 -04006416 uint32_t rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04006417
James Smart6d368e52011-05-24 11:44:12 -04006418 /*
6419 * If the SLI4 port supports extents, posting the rpi header isn't
6420 * required. Set the expected maximum count and let the actual value
6421 * get set when extents are fully allocated.
6422 */
6423 if (!phba->sli4_hba.rpi_hdrs_in_use)
6424 return NULL;
6425 if (phba->sli4_hba.extents_in_use)
6426 return NULL;
6427
6428 /* The limit on the logical index is just the max_rpi count. */
James Smartda0436e2009-05-22 14:51:39 -04006429 rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
James Smart6d368e52011-05-24 11:44:12 -04006430 phba->sli4_hba.max_cfg_param.max_rpi - 1;
James Smartda0436e2009-05-22 14:51:39 -04006431
6432 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006433 /*
6434 * Establish the starting RPI in this header block. The starting
6435 * rpi is normalized to a zero base because the physical rpi is
6436 * port based.
6437 */
James Smart97f2ecf2012-03-01 22:35:23 -05006438 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04006439 spin_unlock_irq(&phba->hbalock);
6440
6441 /*
6442 * The port has a limited number of rpis. The increment here
6443 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
6444 * and to allow the full max_rpi range per port.
6445 */
6446 if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
James Smart9589b0622011-04-16 11:03:17 -04006447 rpi_count = rpi_limit - curr_rpi_range;
6448 else
6449 rpi_count = LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04006450
James Smart6d368e52011-05-24 11:44:12 -04006451 if (!rpi_count)
6452 return NULL;
James Smartda0436e2009-05-22 14:51:39 -04006453 /*
6454 * First allocate the protocol header region for the port. The
6455 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
6456 */
6457 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6458 if (!dmabuf)
6459 return NULL;
6460
Joe Perches1aee3832014-09-03 12:56:12 -04006461 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
6462 LPFC_HDR_TEMPLATE_SIZE,
6463 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04006464 if (!dmabuf->virt) {
6465 rpi_hdr = NULL;
6466 goto err_free_dmabuf;
6467 }
6468
James Smartda0436e2009-05-22 14:51:39 -04006469 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
6470 rpi_hdr = NULL;
6471 goto err_free_coherent;
6472 }
6473
6474 /* Save the rpi header data for cleanup later. */
6475 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
6476 if (!rpi_hdr)
6477 goto err_free_coherent;
6478
6479 rpi_hdr->dmabuf = dmabuf;
6480 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
6481 rpi_hdr->page_count = 1;
6482 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006483
6484 /* The rpi_hdr stores the logical index only. */
6485 rpi_hdr->start_rpi = curr_rpi_range;
James Smartda0436e2009-05-22 14:51:39 -04006486 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
6487
6488 /*
James Smart6d368e52011-05-24 11:44:12 -04006489 * The next_rpi stores the next logical module-64 rpi value used
6490 * to post physical rpis in subsequent rpi postings.
James Smartda0436e2009-05-22 14:51:39 -04006491 */
James Smart9589b0622011-04-16 11:03:17 -04006492 phba->sli4_hba.next_rpi += rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04006493 spin_unlock_irq(&phba->hbalock);
6494 return rpi_hdr;
6495
6496 err_free_coherent:
6497 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
6498 dmabuf->virt, dmabuf->phys);
6499 err_free_dmabuf:
6500 kfree(dmabuf);
6501 return NULL;
6502}
6503
6504/**
6505 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
6506 * @phba: pointer to lpfc hba data structure.
6507 *
6508 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04006509 * to support rpis for SLI4 ports not supporting extents. This routine
6510 * presumes the caller has released all rpis consumed by fabric or port
6511 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04006512 **/
6513void
6514lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
6515{
6516 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
6517
James Smart6d368e52011-05-24 11:44:12 -04006518 if (!phba->sli4_hba.rpi_hdrs_in_use)
6519 goto exit;
6520
James Smartda0436e2009-05-22 14:51:39 -04006521 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
6522 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
6523 list_del(&rpi_hdr->list);
6524 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
6525 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
6526 kfree(rpi_hdr->dmabuf);
6527 kfree(rpi_hdr);
6528 }
James Smart6d368e52011-05-24 11:44:12 -04006529 exit:
6530 /* There are no rpis available to the port now. */
6531 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04006532}
6533
6534/**
James Smart3772a992009-05-22 14:50:54 -04006535 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
6536 * @pdev: pointer to pci device data structure.
6537 *
6538 * This routine is invoked to allocate the driver hba data structure for an
6539 * HBA device. If the allocation is successful, the phba reference to the
6540 * PCI device data structure is set.
6541 *
6542 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006543 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04006544 * NULL - error
6545 **/
6546static struct lpfc_hba *
6547lpfc_hba_alloc(struct pci_dev *pdev)
6548{
6549 struct lpfc_hba *phba;
6550
6551 /* Allocate memory for HBA structure */
6552 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
6553 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02006554 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04006555 return NULL;
6556 }
6557
6558 /* Set reference to PCI device in HBA structure */
6559 phba->pcidev = pdev;
6560
6561 /* Assign an unused board number */
6562 phba->brd_no = lpfc_get_instance();
6563 if (phba->brd_no < 0) {
6564 kfree(phba);
6565 return NULL;
6566 }
James Smart65791f12016-07-06 12:35:56 -07006567 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
James Smart3772a992009-05-22 14:50:54 -04006568
James Smart4fede782010-01-26 23:08:55 -05006569 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04006570 INIT_LIST_HEAD(&phba->ct_ev_waiters);
6571
James Smart3772a992009-05-22 14:50:54 -04006572 return phba;
6573}
6574
6575/**
6576 * lpfc_hba_free - Free driver hba data structure with a device.
6577 * @phba: pointer to lpfc hba data structure.
6578 *
6579 * This routine is invoked to free the driver hba data structure with an
6580 * HBA device.
6581 **/
6582static void
6583lpfc_hba_free(struct lpfc_hba *phba)
6584{
6585 /* Release the driver assigned board number */
6586 idr_remove(&lpfc_hba_index, phba->brd_no);
6587
James Smart895427b2017-02-12 13:52:30 -08006588 /* Free memory allocated with sli3 rings */
6589 kfree(phba->sli.sli3_ring);
6590 phba->sli.sli3_ring = NULL;
James Smart2a76a282012-08-03 12:35:54 -04006591
James Smart3772a992009-05-22 14:50:54 -04006592 kfree(phba);
6593 return;
6594}
6595
6596/**
6597 * lpfc_create_shost - Create hba physical port with associated scsi host.
6598 * @phba: pointer to lpfc hba data structure.
6599 *
6600 * This routine is invoked to create HBA physical port and associate a SCSI
6601 * host with it.
6602 *
6603 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006604 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006605 * other values - error
6606 **/
6607static int
6608lpfc_create_shost(struct lpfc_hba *phba)
6609{
6610 struct lpfc_vport *vport;
6611 struct Scsi_Host *shost;
6612
6613 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05006614 phba->fc_edtov = FF_DEF_EDTOV;
6615 phba->fc_ratov = FF_DEF_RATOV;
6616 phba->fc_altov = FF_DEF_ALTOV;
6617 phba->fc_arbtov = FF_DEF_ARBTOV;
6618
James Smartd7c47992010-06-08 18:31:54 -04006619 atomic_set(&phba->sdev_cnt, 0);
James Smart3de2a652007-08-02 11:09:59 -04006620 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05006621 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04006622 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05006623
6624 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05006625 phba->pport = vport;
James Smart2ea259e2017-02-12 13:52:27 -08006626
James Smartf358dd02017-02-12 13:52:34 -08006627 if (phba->nvmet_support) {
6628 /* Only 1 vport (pport) will support NVME target */
6629 if (phba->txrdy_payload_pool == NULL) {
6630 phba->txrdy_payload_pool = pci_pool_create(
6631 "txrdy_pool", phba->pcidev,
6632 TXRDY_PAYLOAD_LEN, 16, 0);
6633 if (phba->txrdy_payload_pool) {
6634 phba->targetport = NULL;
6635 phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME;
6636 lpfc_printf_log(phba, KERN_INFO,
6637 LOG_INIT | LOG_NVME_DISC,
6638 "6076 NVME Target Found\n");
6639 }
6640 }
6641 }
6642
James Smart858c9f62007-06-17 19:56:39 -05006643 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04006644 /* Put reference to SCSI host to driver's device private data */
6645 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05006646
James Smart4258e982015-12-16 18:11:58 -05006647 /*
6648 * At this point we are fully registered with PSA. In addition,
6649 * any initial discovery should be completed.
6650 */
6651 vport->load_flag |= FC_ALLOW_FDMI;
James Smart8663cbb2016-03-31 14:12:33 -07006652 if (phba->cfg_enable_SmartSAN ||
6653 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -05006654
6655 /* Setup appropriate attribute masks */
6656 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -07006657 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -05006658 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
6659 else
6660 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
6661 }
James Smart3772a992009-05-22 14:50:54 -04006662 return 0;
6663}
dea31012005-04-17 16:05:31 -05006664
James Smart3772a992009-05-22 14:50:54 -04006665/**
6666 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
6667 * @phba: pointer to lpfc hba data structure.
6668 *
6669 * This routine is invoked to destroy HBA physical port and the associated
6670 * SCSI host.
6671 **/
6672static void
6673lpfc_destroy_shost(struct lpfc_hba *phba)
6674{
6675 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04006676
James Smart3772a992009-05-22 14:50:54 -04006677 /* Destroy physical port that associated with the SCSI host */
6678 destroy_port(vport);
6679
6680 return;
6681}
6682
6683/**
6684 * lpfc_setup_bg - Setup Block guard structures and debug areas.
6685 * @phba: pointer to lpfc hba data structure.
6686 * @shost: the shost to be used to detect Block guard settings.
6687 *
6688 * This routine sets up the local Block guard protocol settings for @shost.
6689 * This routine also allocates memory for debugging bg buffers.
6690 **/
6691static void
6692lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
6693{
James Smartbbeb79b2012-06-12 13:54:27 -04006694 uint32_t old_mask;
6695 uint32_t old_guard;
6696
James Smart3772a992009-05-22 14:50:54 -04006697 int pagecnt = 10;
James Smartb3b98b72016-10-13 15:06:06 -07006698 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
James Smart3772a992009-05-22 14:50:54 -04006699 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6700 "1478 Registering BlockGuard with the "
6701 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04006702
James Smartb3b98b72016-10-13 15:06:06 -07006703 old_mask = phba->cfg_prot_mask;
6704 old_guard = phba->cfg_prot_guard;
James Smartbbeb79b2012-06-12 13:54:27 -04006705
6706 /* Only allow supported values */
James Smartb3b98b72016-10-13 15:06:06 -07006707 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
James Smartbbeb79b2012-06-12 13:54:27 -04006708 SHOST_DIX_TYPE0_PROTECTION |
6709 SHOST_DIX_TYPE1_PROTECTION);
James Smartb3b98b72016-10-13 15:06:06 -07006710 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
6711 SHOST_DIX_GUARD_CRC);
James Smartbbeb79b2012-06-12 13:54:27 -04006712
6713 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
James Smartb3b98b72016-10-13 15:06:06 -07006714 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
6715 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
James Smartbbeb79b2012-06-12 13:54:27 -04006716
James Smartb3b98b72016-10-13 15:06:06 -07006717 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
6718 if ((old_mask != phba->cfg_prot_mask) ||
6719 (old_guard != phba->cfg_prot_guard))
James Smartbbeb79b2012-06-12 13:54:27 -04006720 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6721 "1475 Registering BlockGuard with the "
6722 "SCSI layer: mask %d guard %d\n",
James Smartb3b98b72016-10-13 15:06:06 -07006723 phba->cfg_prot_mask,
6724 phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04006725
James Smartb3b98b72016-10-13 15:06:06 -07006726 scsi_host_set_prot(shost, phba->cfg_prot_mask);
6727 scsi_host_set_guard(shost, phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04006728 } else
6729 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6730 "1479 Not Registering BlockGuard with the SCSI "
6731 "layer, Bad protection parameters: %d %d\n",
6732 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04006733 }
James Smartbbeb79b2012-06-12 13:54:27 -04006734
James Smart81301a92008-12-04 22:39:46 -05006735 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05006736 while (pagecnt) {
6737 spin_lock_init(&_dump_buf_lock);
6738 _dump_buf_data =
6739 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6740 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04006741 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6742 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04006743 "_dump_buf_data at 0x%p\n",
6744 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05006745 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04006746 memset(_dump_buf_data, 0,
6747 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05006748 break;
James Smart3772a992009-05-22 14:50:54 -04006749 } else
James Smart81301a92008-12-04 22:39:46 -05006750 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05006751 }
James Smart81301a92008-12-04 22:39:46 -05006752 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04006753 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6754 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04006755 "memory for hexdump\n");
6756 } else
James Smart6a9c52c2009-10-02 15:16:51 -04006757 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6758 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05006759 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05006760 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05006761 while (pagecnt) {
6762 _dump_buf_dif =
6763 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6764 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04006765 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6766 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04006767 "_dump_buf_dif at 0x%p\n",
6768 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05006769 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04006770 memset(_dump_buf_dif, 0,
6771 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05006772 break;
James Smart3772a992009-05-22 14:50:54 -04006773 } else
James Smart81301a92008-12-04 22:39:46 -05006774 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05006775 }
James Smart81301a92008-12-04 22:39:46 -05006776 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04006777 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6778 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04006779 "memory for hexdump\n");
6780 } else
James Smart6a9c52c2009-10-02 15:16:51 -04006781 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6782 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04006783 _dump_buf_dif);
6784}
6785
6786/**
6787 * lpfc_post_init_setup - Perform necessary device post initialization setup.
6788 * @phba: pointer to lpfc hba data structure.
6789 *
6790 * This routine is invoked to perform all the necessary post initialization
6791 * setup for the device.
6792 **/
6793static void
6794lpfc_post_init_setup(struct lpfc_hba *phba)
6795{
6796 struct Scsi_Host *shost;
6797 struct lpfc_adapter_event_header adapter_event;
6798
6799 /* Get the default values for Model Name and Description */
6800 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
6801
6802 /*
6803 * hba setup may have changed the hba_queue_depth so we need to
6804 * adjust the value of can_queue.
6805 */
6806 shost = pci_get_drvdata(phba->pcidev);
6807 shost->can_queue = phba->cfg_hba_queue_depth - 10;
6808 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
6809 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05006810
6811 lpfc_host_attrib_init(shost);
6812
James Smart2e0fef82007-06-17 19:56:36 -05006813 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
6814 spin_lock_irq(shost->host_lock);
6815 lpfc_poll_start_timer(phba);
6816 spin_unlock_irq(shost->host_lock);
6817 }
James Smart8f6d98d2006-08-01 07:34:00 -04006818
James Smart93996272008-08-24 21:50:30 -04006819 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6820 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04006821 /* Send board arrival event to upper layer */
6822 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
6823 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
6824 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04006825 sizeof(adapter_event),
6826 (char *) &adapter_event,
6827 LPFC_NL_VENDOR_ID);
6828 return;
6829}
6830
6831/**
6832 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
6833 * @phba: pointer to lpfc hba data structure.
6834 *
6835 * This routine is invoked to set up the PCI device memory space for device
6836 * with SLI-3 interface spec.
6837 *
6838 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006839 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006840 * other values - error
6841 **/
6842static int
6843lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
6844{
6845 struct pci_dev *pdev;
6846 unsigned long bar0map_len, bar2map_len;
6847 int i, hbq_count;
6848 void *ptr;
6849 int error = -ENODEV;
6850
6851 /* Obtain PCI device reference */
6852 if (!phba->pcidev)
6853 return error;
6854 else
6855 pdev = phba->pcidev;
6856
6857 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05006858 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
6859 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
6860 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
6861 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smart3772a992009-05-22 14:50:54 -04006862 return error;
Michael Reed8e685972009-09-18 12:02:05 -05006863 }
6864 }
James Smart3772a992009-05-22 14:50:54 -04006865
6866 /* Get the bus address of Bar0 and Bar2 and the number of bytes
6867 * required by each mapping.
6868 */
6869 phba->pci_bar0_map = pci_resource_start(pdev, 0);
6870 bar0map_len = pci_resource_len(pdev, 0);
6871
6872 phba->pci_bar2_map = pci_resource_start(pdev, 2);
6873 bar2map_len = pci_resource_len(pdev, 2);
6874
6875 /* Map HBA SLIM to a kernel virtual address. */
6876 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
6877 if (!phba->slim_memmap_p) {
6878 dev_printk(KERN_ERR, &pdev->dev,
6879 "ioremap failed for SLIM memory.\n");
6880 goto out;
6881 }
6882
6883 /* Map HBA Control Registers to a kernel virtual address. */
6884 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
6885 if (!phba->ctrl_regs_memmap_p) {
6886 dev_printk(KERN_ERR, &pdev->dev,
6887 "ioremap failed for HBA control registers.\n");
6888 goto out_iounmap_slim;
6889 }
6890
6891 /* Allocate memory for SLI-2 structures */
Joe Perches1aee3832014-09-03 12:56:12 -04006892 phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6893 &phba->slim2p.phys, GFP_KERNEL);
James Smart3772a992009-05-22 14:50:54 -04006894 if (!phba->slim2p.virt)
6895 goto out_iounmap;
6896
James Smart3772a992009-05-22 14:50:54 -04006897 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04006898 phba->mbox_ext = (phba->slim2p.virt +
6899 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04006900 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
6901 phba->IOCBs = (phba->slim2p.virt +
6902 offsetof(struct lpfc_sli2_slim, IOCBs));
6903
6904 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
6905 lpfc_sli_hbq_size(),
6906 &phba->hbqslimp.phys,
6907 GFP_KERNEL);
6908 if (!phba->hbqslimp.virt)
6909 goto out_free_slim;
6910
6911 hbq_count = lpfc_sli_hbq_count();
6912 ptr = phba->hbqslimp.virt;
6913 for (i = 0; i < hbq_count; ++i) {
6914 phba->hbqs[i].hbq_virt = ptr;
6915 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
6916 ptr += (lpfc_hbq_defs[i]->entry_count *
6917 sizeof(struct lpfc_hbq_entry));
6918 }
6919 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
6920 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
6921
6922 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
6923
James Smart3772a992009-05-22 14:50:54 -04006924 phba->MBslimaddr = phba->slim_memmap_p;
6925 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
6926 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
6927 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
6928 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04006929
dea31012005-04-17 16:05:31 -05006930 return 0;
6931
dea31012005-04-17 16:05:31 -05006932out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04006933 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6934 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05006935out_iounmap:
6936 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006937out_iounmap_slim:
dea31012005-04-17 16:05:31 -05006938 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05006939out:
6940 return error;
6941}
6942
James Smarte59058c2008-08-24 21:49:00 -04006943/**
James Smart3772a992009-05-22 14:50:54 -04006944 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
6945 * @phba: pointer to lpfc hba data structure.
6946 *
6947 * This routine is invoked to unset the PCI device memory space for device
6948 * with SLI-3 interface spec.
6949 **/
6950static void
6951lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
6952{
6953 struct pci_dev *pdev;
6954
6955 /* Obtain PCI device reference */
6956 if (!phba->pcidev)
6957 return;
6958 else
6959 pdev = phba->pcidev;
6960
6961 /* Free coherent DMA memory allocated */
6962 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
6963 phba->hbqslimp.virt, phba->hbqslimp.phys);
6964 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6965 phba->slim2p.virt, phba->slim2p.phys);
6966
6967 /* I/O memory unmap */
6968 iounmap(phba->ctrl_regs_memmap_p);
6969 iounmap(phba->slim_memmap_p);
6970
6971 return;
6972}
6973
6974/**
James Smartda0436e2009-05-22 14:51:39 -04006975 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
6976 * @phba: pointer to lpfc hba data structure.
6977 *
6978 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
6979 * done and check status.
6980 *
6981 * Return 0 if successful, otherwise -ENODEV.
6982 **/
6983int
6984lpfc_sli4_post_status_check(struct lpfc_hba *phba)
6985{
James Smart2fcee4b2010-12-15 17:57:46 -05006986 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
6987 struct lpfc_register reg_data;
6988 int i, port_error = 0;
6989 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04006990
James Smart9940b972011-03-11 16:06:12 -05006991 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
6992 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05006993 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04006994 return -ENODEV;
6995
James Smartda0436e2009-05-22 14:51:39 -04006996 /* Wait up to 30 seconds for the SLI Port POST done and ready */
6997 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05006998 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
6999 &portsmphr_reg.word0) ||
7000 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007001 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04007002 port_error = -ENODEV;
7003 break;
7004 }
James Smart2fcee4b2010-12-15 17:57:46 -05007005 if (LPFC_POST_STAGE_PORT_READY ==
7006 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04007007 break;
James Smartda0436e2009-05-22 14:51:39 -04007008 msleep(10);
7009 }
7010
James Smart2fcee4b2010-12-15 17:57:46 -05007011 /*
7012 * If there was a port error during POST, then don't proceed with
7013 * other register reads as the data may not be valid. Just exit.
7014 */
7015 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04007016 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05007017 "1408 Port Failed POST - portsmphr=0x%x, "
7018 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
7019 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
7020 portsmphr_reg.word0,
7021 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
7022 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
7023 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
7024 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
7025 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
7026 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
7027 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
7028 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
7029 } else {
James Smart28baac72010-02-12 14:42:03 -05007030 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05007031 "2534 Device Info: SLIFamily=0x%x, "
7032 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
7033 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05007034 bf_get(lpfc_sli_intf_sli_family,
7035 &phba->sli4_hba.sli_intf),
7036 bf_get(lpfc_sli_intf_slirev,
7037 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05007038 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05007039 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05007040 bf_get(lpfc_sli_intf_sli_hint1,
7041 &phba->sli4_hba.sli_intf),
7042 bf_get(lpfc_sli_intf_sli_hint2,
7043 &phba->sli4_hba.sli_intf),
7044 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05007045 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05007046 /*
7047 * Check for other Port errors during the initialization
7048 * process. Fail the load if the port did not come up
7049 * correctly.
7050 */
7051 if_type = bf_get(lpfc_sli_intf_if_type,
7052 &phba->sli4_hba.sli_intf);
7053 switch (if_type) {
7054 case LPFC_SLI_INTF_IF_TYPE_0:
7055 phba->sli4_hba.ue_mask_lo =
7056 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
7057 phba->sli4_hba.ue_mask_hi =
7058 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
7059 uerrlo_reg.word0 =
7060 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
7061 uerrhi_reg.word0 =
7062 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
7063 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
7064 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
7065 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7066 "1422 Unrecoverable Error "
7067 "Detected during POST "
7068 "uerr_lo_reg=0x%x, "
7069 "uerr_hi_reg=0x%x, "
7070 "ue_mask_lo_reg=0x%x, "
7071 "ue_mask_hi_reg=0x%x\n",
7072 uerrlo_reg.word0,
7073 uerrhi_reg.word0,
7074 phba->sli4_hba.ue_mask_lo,
7075 phba->sli4_hba.ue_mask_hi);
7076 port_error = -ENODEV;
7077 }
7078 break;
7079 case LPFC_SLI_INTF_IF_TYPE_2:
7080 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05007081 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
7082 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04007083 (bf_get(lpfc_sliport_status_err, &reg_data) &&
7084 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05007085 phba->work_status[0] =
7086 readl(phba->sli4_hba.u.if_type2.
7087 ERR1regaddr);
7088 phba->work_status[1] =
7089 readl(phba->sli4_hba.u.if_type2.
7090 ERR2regaddr);
7091 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05007092 "2888 Unrecoverable port error "
7093 "following POST: port status reg "
7094 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05007095 "error 1=0x%x, error 2=0x%x\n",
7096 reg_data.word0,
7097 portsmphr_reg.word0,
7098 phba->work_status[0],
7099 phba->work_status[1]);
7100 port_error = -ENODEV;
7101 }
7102 break;
7103 case LPFC_SLI_INTF_IF_TYPE_1:
7104 default:
7105 break;
7106 }
James Smart28baac72010-02-12 14:42:03 -05007107 }
James Smartda0436e2009-05-22 14:51:39 -04007108 return port_error;
7109}
7110
7111/**
7112 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
7113 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05007114 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04007115 *
7116 * This routine is invoked to set up SLI4 BAR0 PCI config space register
7117 * memory map.
7118 **/
7119static void
James Smart2fcee4b2010-12-15 17:57:46 -05007120lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04007121{
James Smart2fcee4b2010-12-15 17:57:46 -05007122 switch (if_type) {
7123 case LPFC_SLI_INTF_IF_TYPE_0:
7124 phba->sli4_hba.u.if_type0.UERRLOregaddr =
7125 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
7126 phba->sli4_hba.u.if_type0.UERRHIregaddr =
7127 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
7128 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
7129 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
7130 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
7131 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
7132 phba->sli4_hba.SLIINTFregaddr =
7133 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7134 break;
7135 case LPFC_SLI_INTF_IF_TYPE_2:
7136 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007137 phba->sli4_hba.conf_regs_memmap_p +
7138 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007139 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007140 phba->sli4_hba.conf_regs_memmap_p +
7141 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007142 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007143 phba->sli4_hba.conf_regs_memmap_p +
7144 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007145 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007146 phba->sli4_hba.conf_regs_memmap_p +
7147 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007148 phba->sli4_hba.SLIINTFregaddr =
7149 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
7150 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04007151 phba->sli4_hba.conf_regs_memmap_p +
7152 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05007153 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05007154 phba->sli4_hba.conf_regs_memmap_p +
7155 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05007156 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05007157 phba->sli4_hba.conf_regs_memmap_p +
7158 LPFC_ULP0_WQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05007159 phba->sli4_hba.EQCQDBregaddr =
7160 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
7161 phba->sli4_hba.MQDBregaddr =
7162 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
7163 phba->sli4_hba.BMBXregaddr =
7164 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
7165 break;
7166 case LPFC_SLI_INTF_IF_TYPE_1:
7167 default:
7168 dev_printk(KERN_ERR, &phba->pcidev->dev,
7169 "FATAL - unsupported SLI4 interface type - %d\n",
7170 if_type);
7171 break;
7172 }
James Smartda0436e2009-05-22 14:51:39 -04007173}
7174
7175/**
7176 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
7177 * @phba: pointer to lpfc hba data structure.
7178 *
7179 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
7180 * memory map.
7181 **/
7182static void
7183lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
7184{
James Smart2fcee4b2010-12-15 17:57:46 -05007185 phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
7186 LPFC_SLIPORT_IF0_SMPHR;
James Smartda0436e2009-05-22 14:51:39 -04007187 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05007188 LPFC_HST_ISR0;
James Smartda0436e2009-05-22 14:51:39 -04007189 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05007190 LPFC_HST_IMR0;
James Smartda0436e2009-05-22 14:51:39 -04007191 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05007192 LPFC_HST_ISCR0;
James Smartda0436e2009-05-22 14:51:39 -04007193}
7194
7195/**
7196 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
7197 * @phba: pointer to lpfc hba data structure.
7198 * @vf: virtual function number
7199 *
7200 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
7201 * based on the given viftual function number, @vf.
7202 *
7203 * Return 0 if successful, otherwise -ENODEV.
7204 **/
7205static int
7206lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
7207{
7208 if (vf > LPFC_VIR_FUNC_MAX)
7209 return -ENODEV;
7210
7211 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05007212 vf * LPFC_VFR_PAGE_SIZE +
7213 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04007214 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05007215 vf * LPFC_VFR_PAGE_SIZE +
7216 LPFC_ULP0_WQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04007217 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7218 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
7219 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7220 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
7221 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7222 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
7223 return 0;
7224}
7225
7226/**
7227 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
7228 * @phba: pointer to lpfc hba data structure.
7229 *
7230 * This routine is invoked to create the bootstrap mailbox
7231 * region consistent with the SLI-4 interface spec. This
7232 * routine allocates all memory necessary to communicate
7233 * mailbox commands to the port and sets up all alignment
7234 * needs. No locks are expected to be held when calling
7235 * this routine.
7236 *
7237 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007238 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04007239 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04007240 **/
7241static int
7242lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
7243{
7244 uint32_t bmbx_size;
7245 struct lpfc_dmabuf *dmabuf;
7246 struct dma_address *dma_address;
7247 uint32_t pa_addr;
7248 uint64_t phys_addr;
7249
7250 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
7251 if (!dmabuf)
7252 return -ENOMEM;
7253
7254 /*
7255 * The bootstrap mailbox region is comprised of 2 parts
7256 * plus an alignment restriction of 16 bytes.
7257 */
7258 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
Joe Perches1aee3832014-09-03 12:56:12 -04007259 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
7260 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04007261 if (!dmabuf->virt) {
7262 kfree(dmabuf);
7263 return -ENOMEM;
7264 }
James Smartda0436e2009-05-22 14:51:39 -04007265
7266 /*
7267 * Initialize the bootstrap mailbox pointers now so that the register
7268 * operations are simple later. The mailbox dma address is required
7269 * to be 16-byte aligned. Also align the virtual memory as each
7270 * maibox is copied into the bmbx mailbox region before issuing the
7271 * command to the port.
7272 */
7273 phba->sli4_hba.bmbx.dmabuf = dmabuf;
7274 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
7275
7276 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
7277 LPFC_ALIGN_16_BYTE);
7278 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
7279 LPFC_ALIGN_16_BYTE);
7280
7281 /*
7282 * Set the high and low physical addresses now. The SLI4 alignment
7283 * requirement is 16 bytes and the mailbox is posted to the port
7284 * as two 30-bit addresses. The other data is a bit marking whether
7285 * the 30-bit address is the high or low address.
7286 * Upcast bmbx aphys to 64bits so shift instruction compiles
7287 * clean on 32 bit machines.
7288 */
7289 dma_address = &phba->sli4_hba.bmbx.dma_address;
7290 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
7291 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
7292 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
7293 LPFC_BMBX_BIT1_ADDR_HI);
7294
7295 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
7296 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
7297 LPFC_BMBX_BIT1_ADDR_LO);
7298 return 0;
7299}
7300
7301/**
7302 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
7303 * @phba: pointer to lpfc hba data structure.
7304 *
7305 * This routine is invoked to teardown the bootstrap mailbox
7306 * region and release all host resources. This routine requires
7307 * the caller to ensure all mailbox commands recovered, no
7308 * additional mailbox comands are sent, and interrupts are disabled
7309 * before calling this routine.
7310 *
7311 **/
7312static void
7313lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
7314{
7315 dma_free_coherent(&phba->pcidev->dev,
7316 phba->sli4_hba.bmbx.bmbx_size,
7317 phba->sli4_hba.bmbx.dmabuf->virt,
7318 phba->sli4_hba.bmbx.dmabuf->phys);
7319
7320 kfree(phba->sli4_hba.bmbx.dmabuf);
7321 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
7322}
7323
7324/**
7325 * lpfc_sli4_read_config - Get the config parameters.
7326 * @phba: pointer to lpfc hba data structure.
7327 *
7328 * This routine is invoked to read the configuration parameters from the HBA.
7329 * The configuration parameters are used to set the base and maximum values
7330 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
7331 * allocation for the port.
7332 *
7333 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007334 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007335 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007336 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007337 **/
James Smartff78d8f2011-12-13 13:21:35 -05007338int
James Smartda0436e2009-05-22 14:51:39 -04007339lpfc_sli4_read_config(struct lpfc_hba *phba)
7340{
7341 LPFC_MBOXQ_t *pmb;
7342 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04007343 union lpfc_sli4_cfg_shdr *shdr;
7344 uint32_t shdr_status, shdr_add_status;
7345 struct lpfc_mbx_get_func_cfg *get_func_cfg;
7346 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04007347 char *pdesc_0;
James Smartc6918162016-10-13 15:06:16 -07007348 uint16_t forced_link_speed;
7349 uint32_t if_type;
James Smart8aa134a2012-08-14 14:25:29 -04007350 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04007351
7352 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7353 if (!pmb) {
7354 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7355 "2011 Unable to allocate memory for issuing "
7356 "SLI_CONFIG_SPECIAL mailbox command\n");
7357 return -ENOMEM;
7358 }
7359
7360 lpfc_read_config(phba, pmb);
7361
7362 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
7363 if (rc != MBX_SUCCESS) {
7364 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7365 "2012 Mailbox failed , mbxCmd x%x "
7366 "READ_CONFIG, mbxStatus x%x\n",
7367 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7368 bf_get(lpfc_mqe_status, &pmb->u.mqe));
7369 rc = -EIO;
7370 } else {
7371 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05007372 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
7373 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
7374 phba->sli4_hba.lnk_info.lnk_tp =
7375 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
7376 phba->sli4_hba.lnk_info.lnk_no =
7377 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
7378 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7379 "3081 lnk_type:%d, lnk_numb:%d\n",
7380 phba->sli4_hba.lnk_info.lnk_tp,
7381 phba->sli4_hba.lnk_info.lnk_no);
7382 } else
7383 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
7384 "3082 Mailbox (x%x) returned ldv:x0\n",
7385 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart6d368e52011-05-24 11:44:12 -04007386 phba->sli4_hba.extents_in_use =
7387 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04007388 phba->sli4_hba.max_cfg_param.max_xri =
7389 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
7390 phba->sli4_hba.max_cfg_param.xri_base =
7391 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
7392 phba->sli4_hba.max_cfg_param.max_vpi =
7393 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
7394 phba->sli4_hba.max_cfg_param.vpi_base =
7395 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
7396 phba->sli4_hba.max_cfg_param.max_rpi =
7397 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
7398 phba->sli4_hba.max_cfg_param.rpi_base =
7399 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
7400 phba->sli4_hba.max_cfg_param.max_vfi =
7401 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
7402 phba->sli4_hba.max_cfg_param.vfi_base =
7403 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
7404 phba->sli4_hba.max_cfg_param.max_fcfi =
7405 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04007406 phba->sli4_hba.max_cfg_param.max_eq =
7407 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
7408 phba->sli4_hba.max_cfg_param.max_rq =
7409 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
7410 phba->sli4_hba.max_cfg_param.max_wq =
7411 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
7412 phba->sli4_hba.max_cfg_param.max_cq =
7413 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
7414 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
7415 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
7416 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
7417 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05007418 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
7419 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04007420 phba->max_vports = phba->max_vpi;
7421 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04007422 "2003 cfg params Extents? %d "
7423 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04007424 "VPI(B:%d M:%d) "
7425 "VFI(B:%d M:%d) "
7426 "RPI(B:%d M:%d) "
James Smart2ea259e2017-02-12 13:52:27 -08007427 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n",
James Smart6d368e52011-05-24 11:44:12 -04007428 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04007429 phba->sli4_hba.max_cfg_param.xri_base,
7430 phba->sli4_hba.max_cfg_param.max_xri,
7431 phba->sli4_hba.max_cfg_param.vpi_base,
7432 phba->sli4_hba.max_cfg_param.max_vpi,
7433 phba->sli4_hba.max_cfg_param.vfi_base,
7434 phba->sli4_hba.max_cfg_param.max_vfi,
7435 phba->sli4_hba.max_cfg_param.rpi_base,
7436 phba->sli4_hba.max_cfg_param.max_rpi,
James Smart2ea259e2017-02-12 13:52:27 -08007437 phba->sli4_hba.max_cfg_param.max_fcfi,
7438 phba->sli4_hba.max_cfg_param.max_eq,
7439 phba->sli4_hba.max_cfg_param.max_cq,
7440 phba->sli4_hba.max_cfg_param.max_wq,
7441 phba->sli4_hba.max_cfg_param.max_rq);
7442
James Smartda0436e2009-05-22 14:51:39 -04007443 }
James Smart912e3ac2011-05-24 11:42:11 -04007444
7445 if (rc)
7446 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04007447
James Smartc6918162016-10-13 15:06:16 -07007448 /* Update link speed if forced link speed is supported */
7449 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7450 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
7451 forced_link_speed =
7452 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
7453 if (forced_link_speed) {
7454 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
7455
7456 switch (forced_link_speed) {
7457 case LINK_SPEED_1G:
7458 phba->cfg_link_speed =
7459 LPFC_USER_LINK_SPEED_1G;
7460 break;
7461 case LINK_SPEED_2G:
7462 phba->cfg_link_speed =
7463 LPFC_USER_LINK_SPEED_2G;
7464 break;
7465 case LINK_SPEED_4G:
7466 phba->cfg_link_speed =
7467 LPFC_USER_LINK_SPEED_4G;
7468 break;
7469 case LINK_SPEED_8G:
7470 phba->cfg_link_speed =
7471 LPFC_USER_LINK_SPEED_8G;
7472 break;
7473 case LINK_SPEED_10G:
7474 phba->cfg_link_speed =
7475 LPFC_USER_LINK_SPEED_10G;
7476 break;
7477 case LINK_SPEED_16G:
7478 phba->cfg_link_speed =
7479 LPFC_USER_LINK_SPEED_16G;
7480 break;
7481 case LINK_SPEED_32G:
7482 phba->cfg_link_speed =
7483 LPFC_USER_LINK_SPEED_32G;
7484 break;
7485 case 0xffff:
7486 phba->cfg_link_speed =
7487 LPFC_USER_LINK_SPEED_AUTO;
7488 break;
7489 default:
7490 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7491 "0047 Unrecognized link "
7492 "speed : %d\n",
7493 forced_link_speed);
7494 phba->cfg_link_speed =
7495 LPFC_USER_LINK_SPEED_AUTO;
7496 }
7497 }
7498 }
7499
James Smartda0436e2009-05-22 14:51:39 -04007500 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -04007501 length = phba->sli4_hba.max_cfg_param.max_xri -
7502 lpfc_sli4_get_els_iocb_cnt(phba);
7503 if (phba->cfg_hba_queue_depth > length) {
7504 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7505 "3361 HBA queue depth changed from %d to %d\n",
7506 phba->cfg_hba_queue_depth, length);
7507 phba->cfg_hba_queue_depth = length;
7508 }
James Smart912e3ac2011-05-24 11:42:11 -04007509
7510 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
7511 LPFC_SLI_INTF_IF_TYPE_2)
7512 goto read_cfg_out;
7513
7514 /* get the pf# and vf# for SLI4 if_type 2 port */
7515 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
7516 sizeof(struct lpfc_sli4_cfg_mhdr));
7517 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
7518 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
7519 length, LPFC_SLI4_MBX_EMBED);
7520
James Smart8aa134a2012-08-14 14:25:29 -04007521 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04007522 shdr = (union lpfc_sli4_cfg_shdr *)
7523 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
7524 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7525 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04007526 if (rc2 || shdr_status || shdr_add_status) {
James Smart912e3ac2011-05-24 11:42:11 -04007527 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7528 "3026 Mailbox failed , mbxCmd x%x "
7529 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
7530 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7531 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04007532 goto read_cfg_out;
7533 }
7534
7535 /* search for fc_fcoe resrouce descriptor */
7536 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
James Smart912e3ac2011-05-24 11:42:11 -04007537
James Smart8aa134a2012-08-14 14:25:29 -04007538 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
7539 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
7540 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
7541 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
7542 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
7543 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
7544 goto read_cfg_out;
7545
James Smart912e3ac2011-05-24 11:42:11 -04007546 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04007547 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04007548 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04007549 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04007550 phba->sli4_hba.iov.pf_number =
7551 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
7552 phba->sli4_hba.iov.vf_number =
7553 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
7554 break;
7555 }
7556 }
7557
7558 if (i < LPFC_RSRC_DESC_MAX_NUM)
7559 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7560 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
7561 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
7562 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04007563 else
James Smart912e3ac2011-05-24 11:42:11 -04007564 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7565 "3028 GET_FUNCTION_CONFIG: failed to find "
7566 "Resrouce Descriptor:x%x\n",
7567 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04007568
7569read_cfg_out:
7570 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04007571 return rc;
7572}
7573
7574/**
James Smart2fcee4b2010-12-15 17:57:46 -05007575 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04007576 * @phba: pointer to lpfc hba data structure.
7577 *
James Smart2fcee4b2010-12-15 17:57:46 -05007578 * This routine is invoked to setup the port-side endian order when
7579 * the port if_type is 0. This routine has no function for other
7580 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04007581 *
7582 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007583 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007584 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007585 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007586 **/
7587static int
7588lpfc_setup_endian_order(struct lpfc_hba *phba)
7589{
7590 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05007591 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04007592 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
7593 HOST_ENDIAN_HIGH_WORD1};
7594
James Smart2fcee4b2010-12-15 17:57:46 -05007595 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7596 switch (if_type) {
7597 case LPFC_SLI_INTF_IF_TYPE_0:
7598 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7599 GFP_KERNEL);
7600 if (!mboxq) {
7601 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7602 "0492 Unable to allocate memory for "
7603 "issuing SLI_CONFIG_SPECIAL mailbox "
7604 "command\n");
7605 return -ENOMEM;
7606 }
James Smartda0436e2009-05-22 14:51:39 -04007607
James Smart2fcee4b2010-12-15 17:57:46 -05007608 /*
7609 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
7610 * two words to contain special data values and no other data.
7611 */
7612 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
7613 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
7614 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7615 if (rc != MBX_SUCCESS) {
7616 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7617 "0493 SLI_CONFIG_SPECIAL mailbox "
7618 "failed with status x%x\n",
7619 rc);
7620 rc = -EIO;
7621 }
7622 mempool_free(mboxq, phba->mbox_mem_pool);
7623 break;
7624 case LPFC_SLI_INTF_IF_TYPE_2:
7625 case LPFC_SLI_INTF_IF_TYPE_1:
7626 default:
7627 break;
James Smartda0436e2009-05-22 14:51:39 -04007628 }
James Smartda0436e2009-05-22 14:51:39 -04007629 return rc;
7630}
7631
7632/**
James Smart895427b2017-02-12 13:52:30 -08007633 * lpfc_sli4_queue_verify - Verify and update EQ counts
James Smartda0436e2009-05-22 14:51:39 -04007634 * @phba: pointer to lpfc hba data structure.
7635 *
James Smart895427b2017-02-12 13:52:30 -08007636 * This routine is invoked to check the user settable queue counts for EQs.
7637 * After this routine is called the counts will be set to valid values that
James Smart5350d872011-10-10 21:33:49 -04007638 * adhere to the constraints of the system's interrupt vectors and the port's
7639 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04007640 *
7641 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007642 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007643 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007644 **/
7645static int
James Smart5350d872011-10-10 21:33:49 -04007646lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04007647{
James Smart895427b2017-02-12 13:52:30 -08007648 int io_channel;
James Smart1ba981f2014-02-20 09:56:45 -05007649 int fof_vectors = phba->cfg_fof ? 1 : 0;
James Smartda0436e2009-05-22 14:51:39 -04007650
7651 /*
James Smart67d12732012-08-03 12:36:13 -04007652 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04007653 * device parameters
7654 */
7655
James Smart67d12732012-08-03 12:36:13 -04007656 /* Sanity check on HBA EQ parameters */
James Smart895427b2017-02-12 13:52:30 -08007657 io_channel = phba->io_channel_irqs;
James Smartda0436e2009-05-22 14:51:39 -04007658
James Smart895427b2017-02-12 13:52:30 -08007659 if (phba->sli4_hba.num_online_cpu < io_channel) {
James Smart82c3e9b2012-09-29 11:29:50 -04007660 lpfc_printf_log(phba,
7661 KERN_ERR, LOG_INIT,
James Smart90695ee2012-08-14 14:25:36 -04007662 "3188 Reducing IO channels to match number of "
James Smart7bb03bb2013-04-17 20:19:16 -04007663 "online CPUs: from %d to %d\n",
James Smart895427b2017-02-12 13:52:30 -08007664 io_channel, phba->sli4_hba.num_online_cpu);
7665 io_channel = phba->sli4_hba.num_online_cpu;
James Smart90695ee2012-08-14 14:25:36 -04007666 }
7667
James Smart895427b2017-02-12 13:52:30 -08007668 if (io_channel + fof_vectors > phba->sli4_hba.max_cfg_param.max_eq) {
James Smart82c3e9b2012-09-29 11:29:50 -04007669 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7670 "2575 Reducing IO channels to match number of "
7671 "available EQs: from %d to %d\n",
James Smart895427b2017-02-12 13:52:30 -08007672 io_channel,
James Smart82c3e9b2012-09-29 11:29:50 -04007673 phba->sli4_hba.max_cfg_param.max_eq);
James Smart895427b2017-02-12 13:52:30 -08007674 io_channel = phba->sli4_hba.max_cfg_param.max_eq - fof_vectors;
James Smartda0436e2009-05-22 14:51:39 -04007675 }
James Smart67d12732012-08-03 12:36:13 -04007676
James Smart895427b2017-02-12 13:52:30 -08007677 /* The actual number of FCP / NVME event queues adopted */
7678 if (io_channel != phba->io_channel_irqs)
7679 phba->io_channel_irqs = io_channel;
7680 if (phba->cfg_fcp_io_channel > io_channel)
7681 phba->cfg_fcp_io_channel = io_channel;
7682 if (phba->cfg_nvme_io_channel > io_channel)
7683 phba->cfg_nvme_io_channel = io_channel;
James Smart2d7dbc42017-02-12 13:52:35 -08007684 if (phba->cfg_nvme_io_channel < phba->cfg_nvmet_mrq)
7685 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
James Smart895427b2017-02-12 13:52:30 -08007686
7687 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2d7dbc42017-02-12 13:52:35 -08007688 "2574 IO channels: irqs %d fcp %d nvme %d MRQ: %d\n",
James Smart895427b2017-02-12 13:52:30 -08007689 phba->io_channel_irqs, phba->cfg_fcp_io_channel,
James Smart2d7dbc42017-02-12 13:52:35 -08007690 phba->cfg_nvme_io_channel, phba->cfg_nvmet_mrq);
James Smartda0436e2009-05-22 14:51:39 -04007691
James Smartda0436e2009-05-22 14:51:39 -04007692 /* Get EQ depth from module parameter, fake the default for now */
7693 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
7694 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
7695
James Smart5350d872011-10-10 21:33:49 -04007696 /* Get CQ depth from module parameter, fake the default for now */
7697 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
7698 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart5350d872011-10-10 21:33:49 -04007699 return 0;
James Smart895427b2017-02-12 13:52:30 -08007700}
7701
7702static int
7703lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx)
7704{
7705 struct lpfc_queue *qdesc;
7706 int cnt;
7707
7708 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7709 phba->sli4_hba.cq_ecount);
7710 if (!qdesc) {
7711 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7712 "0508 Failed allocate fast-path NVME CQ (%d)\n",
7713 wqidx);
7714 return 1;
7715 }
7716 phba->sli4_hba.nvme_cq[wqidx] = qdesc;
7717
7718 cnt = LPFC_NVME_WQSIZE;
7719 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_WQE128_SIZE, cnt);
7720 if (!qdesc) {
7721 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7722 "0509 Failed allocate fast-path NVME WQ (%d)\n",
7723 wqidx);
7724 return 1;
7725 }
7726 phba->sli4_hba.nvme_wq[wqidx] = qdesc;
7727 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
7728 return 0;
7729}
7730
7731static int
7732lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx)
7733{
7734 struct lpfc_queue *qdesc;
7735 uint32_t wqesize;
7736
7737 /* Create Fast Path FCP CQs */
7738 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7739 phba->sli4_hba.cq_ecount);
7740 if (!qdesc) {
7741 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7742 "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx);
7743 return 1;
7744 }
7745 phba->sli4_hba.fcp_cq[wqidx] = qdesc;
7746
7747 /* Create Fast Path FCP WQs */
7748 wqesize = (phba->fcp_embed_io) ?
7749 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
7750 qdesc = lpfc_sli4_queue_alloc(phba, wqesize, phba->sli4_hba.wq_ecount);
7751 if (!qdesc) {
7752 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7753 "0503 Failed allocate fast-path FCP WQ (%d)\n",
7754 wqidx);
7755 return 1;
7756 }
7757 phba->sli4_hba.fcp_wq[wqidx] = qdesc;
7758 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
7759 return 0;
James Smart5350d872011-10-10 21:33:49 -04007760}
7761
7762/**
7763 * lpfc_sli4_queue_create - Create all the SLI4 queues
7764 * @phba: pointer to lpfc hba data structure.
7765 *
7766 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
7767 * operation. For each SLI4 queue type, the parameters such as queue entry
7768 * count (queue depth) shall be taken from the module parameter. For now,
7769 * we just use some constant number as place holder.
7770 *
7771 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07007772 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04007773 * -ENOMEM - No availble memory
7774 * -EIO - The mailbox failed to complete successfully.
7775 **/
7776int
7777lpfc_sli4_queue_create(struct lpfc_hba *phba)
7778{
7779 struct lpfc_queue *qdesc;
James Smart2d7dbc42017-02-12 13:52:35 -08007780 int idx, io_channel, max;
James Smart5350d872011-10-10 21:33:49 -04007781
7782 /*
James Smart67d12732012-08-03 12:36:13 -04007783 * Create HBA Record arrays.
James Smart895427b2017-02-12 13:52:30 -08007784 * Both NVME and FCP will share that same vectors / EQs
James Smart5350d872011-10-10 21:33:49 -04007785 */
James Smart895427b2017-02-12 13:52:30 -08007786 io_channel = phba->io_channel_irqs;
7787 if (!io_channel)
James Smart67d12732012-08-03 12:36:13 -04007788 return -ERANGE;
James Smart5350d872011-10-10 21:33:49 -04007789
James Smart67d12732012-08-03 12:36:13 -04007790 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
7791 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
7792 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
7793 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
7794 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
7795 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
James Smart895427b2017-02-12 13:52:30 -08007796 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
7797 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
7798 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
7799 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart67d12732012-08-03 12:36:13 -04007800
James Smart895427b2017-02-12 13:52:30 -08007801 phba->sli4_hba.hba_eq = kcalloc(io_channel,
7802 sizeof(struct lpfc_queue *),
7803 GFP_KERNEL);
James Smart67d12732012-08-03 12:36:13 -04007804 if (!phba->sli4_hba.hba_eq) {
James Smartda0436e2009-05-22 14:51:39 -04007805 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007806 "2576 Failed allocate memory for "
7807 "fast-path EQ record array\n");
James Smartda0436e2009-05-22 14:51:39 -04007808 goto out_error;
7809 }
James Smart67d12732012-08-03 12:36:13 -04007810
James Smart895427b2017-02-12 13:52:30 -08007811 if (phba->cfg_fcp_io_channel) {
7812 phba->sli4_hba.fcp_cq = kcalloc(phba->cfg_fcp_io_channel,
7813 sizeof(struct lpfc_queue *),
7814 GFP_KERNEL);
7815 if (!phba->sli4_hba.fcp_cq) {
7816 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7817 "2577 Failed allocate memory for "
7818 "fast-path CQ record array\n");
7819 goto out_error;
7820 }
7821 phba->sli4_hba.fcp_wq = kcalloc(phba->cfg_fcp_io_channel,
7822 sizeof(struct lpfc_queue *),
7823 GFP_KERNEL);
7824 if (!phba->sli4_hba.fcp_wq) {
7825 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7826 "2578 Failed allocate memory for "
7827 "fast-path FCP WQ record array\n");
7828 goto out_error;
7829 }
7830 /*
7831 * Since the first EQ can have multiple CQs associated with it,
7832 * this array is used to quickly see if we have a FCP fast-path
7833 * CQ match.
7834 */
7835 phba->sli4_hba.fcp_cq_map = kcalloc(phba->cfg_fcp_io_channel,
7836 sizeof(uint16_t),
7837 GFP_KERNEL);
7838 if (!phba->sli4_hba.fcp_cq_map) {
7839 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7840 "2545 Failed allocate memory for "
7841 "fast-path CQ map\n");
7842 goto out_error;
7843 }
James Smart67d12732012-08-03 12:36:13 -04007844 }
7845
James Smart895427b2017-02-12 13:52:30 -08007846 if (phba->cfg_nvme_io_channel) {
7847 phba->sli4_hba.nvme_cq = kcalloc(phba->cfg_nvme_io_channel,
7848 sizeof(struct lpfc_queue *),
7849 GFP_KERNEL);
7850 if (!phba->sli4_hba.nvme_cq) {
7851 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7852 "6077 Failed allocate memory for "
7853 "fast-path CQ record array\n");
7854 goto out_error;
7855 }
7856
James Smart895427b2017-02-12 13:52:30 -08007857 phba->sli4_hba.nvme_wq = kcalloc(phba->cfg_nvme_io_channel,
7858 sizeof(struct lpfc_queue *),
7859 GFP_KERNEL);
7860 if (!phba->sli4_hba.nvme_wq) {
7861 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7862 "2581 Failed allocate memory for "
7863 "fast-path NVME WQ record array\n");
7864 goto out_error;
7865 }
7866
7867 /*
7868 * Since the first EQ can have multiple CQs associated with it,
7869 * this array is used to quickly see if we have a NVME fast-path
7870 * CQ match.
7871 */
7872 phba->sli4_hba.nvme_cq_map = kcalloc(phba->cfg_nvme_io_channel,
7873 sizeof(uint16_t),
7874 GFP_KERNEL);
7875 if (!phba->sli4_hba.nvme_cq_map) {
7876 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7877 "6078 Failed allocate memory for "
7878 "fast-path CQ map\n");
7879 goto out_error;
7880 }
James Smart2d7dbc42017-02-12 13:52:35 -08007881
7882 if (phba->nvmet_support) {
7883 phba->sli4_hba.nvmet_cqset = kcalloc(
7884 phba->cfg_nvmet_mrq,
7885 sizeof(struct lpfc_queue *),
7886 GFP_KERNEL);
7887 if (!phba->sli4_hba.nvmet_cqset) {
7888 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7889 "3121 Fail allocate memory for "
7890 "fast-path CQ set array\n");
7891 goto out_error;
7892 }
7893 phba->sli4_hba.nvmet_mrq_hdr = kcalloc(
7894 phba->cfg_nvmet_mrq,
7895 sizeof(struct lpfc_queue *),
7896 GFP_KERNEL);
7897 if (!phba->sli4_hba.nvmet_mrq_hdr) {
7898 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7899 "3122 Fail allocate memory for "
7900 "fast-path RQ set hdr array\n");
7901 goto out_error;
7902 }
7903 phba->sli4_hba.nvmet_mrq_data = kcalloc(
7904 phba->cfg_nvmet_mrq,
7905 sizeof(struct lpfc_queue *),
7906 GFP_KERNEL);
7907 if (!phba->sli4_hba.nvmet_mrq_data) {
7908 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7909 "3124 Fail allocate memory for "
7910 "fast-path RQ set data array\n");
7911 goto out_error;
7912 }
7913 }
James Smart67d12732012-08-03 12:36:13 -04007914 }
James Smartda0436e2009-05-22 14:51:39 -04007915
James Smart895427b2017-02-12 13:52:30 -08007916 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
James Smart67d12732012-08-03 12:36:13 -04007917
James Smart895427b2017-02-12 13:52:30 -08007918 /* Create HBA Event Queues (EQs) */
7919 for (idx = 0; idx < io_channel; idx++) {
James Smart67d12732012-08-03 12:36:13 -04007920 /* Create EQs */
James Smartda0436e2009-05-22 14:51:39 -04007921 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
7922 phba->sli4_hba.eq_ecount);
7923 if (!qdesc) {
7924 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007925 "0497 Failed allocate EQ (%d)\n", idx);
7926 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007927 }
James Smart67d12732012-08-03 12:36:13 -04007928 phba->sli4_hba.hba_eq[idx] = qdesc;
James Smartda0436e2009-05-22 14:51:39 -04007929 }
7930
James Smart895427b2017-02-12 13:52:30 -08007931 /* FCP and NVME io channels are not required to be balanced */
7932
7933 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
7934 if (lpfc_alloc_fcp_wq_cq(phba, idx))
7935 goto out_error;
7936
7937 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
7938 if (lpfc_alloc_nvme_wq_cq(phba, idx))
7939 goto out_error;
James Smart67d12732012-08-03 12:36:13 -04007940
James Smart2d7dbc42017-02-12 13:52:35 -08007941 /* allocate MRQ CQs */
7942 max = phba->cfg_nvme_io_channel;
7943 if (max < phba->cfg_nvmet_mrq)
7944 max = phba->cfg_nvmet_mrq;
7945
7946 for (idx = 0; idx < max; idx++)
7947 if (lpfc_alloc_nvme_wq_cq(phba, idx))
7948 goto out_error;
7949
7950 if (phba->nvmet_support) {
7951 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
7952 qdesc = lpfc_sli4_queue_alloc(phba,
7953 phba->sli4_hba.cq_esize,
7954 phba->sli4_hba.cq_ecount);
7955 if (!qdesc) {
7956 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7957 "3142 Failed allocate NVME "
7958 "CQ Set (%d)\n", idx);
7959 goto out_error;
7960 }
7961 phba->sli4_hba.nvmet_cqset[idx] = qdesc;
7962 }
7963 }
7964
James Smartda0436e2009-05-22 14:51:39 -04007965 /*
James Smart67d12732012-08-03 12:36:13 -04007966 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04007967 */
7968
James Smartda0436e2009-05-22 14:51:39 -04007969 /* Create slow-path Mailbox Command Complete Queue */
7970 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7971 phba->sli4_hba.cq_ecount);
7972 if (!qdesc) {
7973 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7974 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04007975 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007976 }
7977 phba->sli4_hba.mbx_cq = qdesc;
7978
7979 /* Create slow-path ELS Complete Queue */
7980 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7981 phba->sli4_hba.cq_ecount);
7982 if (!qdesc) {
7983 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7984 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -04007985 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007986 }
7987 phba->sli4_hba.els_cq = qdesc;
7988
James Smartda0436e2009-05-22 14:51:39 -04007989
James Smart5350d872011-10-10 21:33:49 -04007990 /*
James Smart67d12732012-08-03 12:36:13 -04007991 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04007992 */
James Smartda0436e2009-05-22 14:51:39 -04007993
7994 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04007995
7996 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
7997 phba->sli4_hba.mq_ecount);
7998 if (!qdesc) {
7999 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8000 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04008001 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008002 }
8003 phba->sli4_hba.mbx_wq = qdesc;
8004
8005 /*
James Smart67d12732012-08-03 12:36:13 -04008006 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04008007 */
James Smartda0436e2009-05-22 14:51:39 -04008008
8009 /* Create slow-path ELS Work Queue */
8010 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
8011 phba->sli4_hba.wq_ecount);
8012 if (!qdesc) {
8013 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8014 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04008015 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008016 }
8017 phba->sli4_hba.els_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08008018 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8019
8020 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
8021 /* Create NVME LS Complete Queue */
8022 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
8023 phba->sli4_hba.cq_ecount);
8024 if (!qdesc) {
8025 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8026 "6079 Failed allocate NVME LS CQ\n");
8027 goto out_error;
8028 }
8029 phba->sli4_hba.nvmels_cq = qdesc;
8030
8031 /* Create NVME LS Work Queue */
8032 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
8033 phba->sli4_hba.wq_ecount);
8034 if (!qdesc) {
8035 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8036 "6080 Failed allocate NVME LS WQ\n");
8037 goto out_error;
8038 }
8039 phba->sli4_hba.nvmels_wq = qdesc;
8040 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
8041 }
James Smartda0436e2009-05-22 14:51:39 -04008042
James Smartda0436e2009-05-22 14:51:39 -04008043 /*
8044 * Create Receive Queue (RQ)
8045 */
James Smartda0436e2009-05-22 14:51:39 -04008046
8047 /* Create Receive Queue for header */
8048 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
8049 phba->sli4_hba.rq_ecount);
8050 if (!qdesc) {
8051 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8052 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04008053 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008054 }
8055 phba->sli4_hba.hdr_rq = qdesc;
8056
8057 /* Create Receive Queue for data */
8058 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
8059 phba->sli4_hba.rq_ecount);
8060 if (!qdesc) {
8061 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8062 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04008063 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04008064 }
8065 phba->sli4_hba.dat_rq = qdesc;
8066
James Smart2d7dbc42017-02-12 13:52:35 -08008067 if (phba->nvmet_support) {
8068 for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) {
8069 /* Create NVMET Receive Queue for header */
8070 qdesc = lpfc_sli4_queue_alloc(phba,
8071 phba->sli4_hba.rq_esize,
8072 phba->sli4_hba.rq_ecount);
8073 if (!qdesc) {
8074 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8075 "3146 Failed allocate "
8076 "receive HRQ\n");
8077 goto out_error;
8078 }
8079 phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc;
8080
8081 /* Only needed for header of RQ pair */
8082 qdesc->rqbp = kzalloc(sizeof(struct lpfc_rqb),
8083 GFP_KERNEL);
8084 if (qdesc->rqbp == NULL) {
8085 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8086 "6131 Failed allocate "
8087 "Header RQBP\n");
8088 goto out_error;
8089 }
8090
8091 /* Create NVMET Receive Queue for data */
8092 qdesc = lpfc_sli4_queue_alloc(phba,
8093 phba->sli4_hba.rq_esize,
8094 phba->sli4_hba.rq_ecount);
8095 if (!qdesc) {
8096 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8097 "3156 Failed allocate "
8098 "receive DRQ\n");
8099 goto out_error;
8100 }
8101 phba->sli4_hba.nvmet_mrq_data[idx] = qdesc;
8102 }
8103 }
8104
James Smart1ba981f2014-02-20 09:56:45 -05008105 /* Create the Queues needed for Flash Optimized Fabric operations */
8106 if (phba->cfg_fof)
8107 lpfc_fof_queue_create(phba);
James Smartda0436e2009-05-22 14:51:39 -04008108 return 0;
8109
James Smartda0436e2009-05-22 14:51:39 -04008110out_error:
James Smart67d12732012-08-03 12:36:13 -04008111 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04008112 return -ENOMEM;
8113}
8114
James Smart895427b2017-02-12 13:52:30 -08008115static inline void
8116__lpfc_sli4_release_queue(struct lpfc_queue **qp)
8117{
8118 if (*qp != NULL) {
8119 lpfc_sli4_queue_free(*qp);
8120 *qp = NULL;
8121 }
8122}
8123
8124static inline void
8125lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
8126{
8127 int idx;
8128
8129 if (*qs == NULL)
8130 return;
8131
8132 for (idx = 0; idx < max; idx++)
8133 __lpfc_sli4_release_queue(&(*qs)[idx]);
8134
8135 kfree(*qs);
8136 *qs = NULL;
8137}
8138
8139static inline void
8140lpfc_sli4_release_queue_map(uint16_t **qmap)
8141{
8142 if (*qmap != NULL) {
8143 kfree(*qmap);
8144 *qmap = NULL;
8145 }
8146}
8147
James Smartda0436e2009-05-22 14:51:39 -04008148/**
8149 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
8150 * @phba: pointer to lpfc hba data structure.
8151 *
8152 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
8153 * operation.
8154 *
8155 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008156 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008157 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008158 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008159 **/
James Smart5350d872011-10-10 21:33:49 -04008160void
James Smartda0436e2009-05-22 14:51:39 -04008161lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
8162{
James Smart1ba981f2014-02-20 09:56:45 -05008163 if (phba->cfg_fof)
8164 lpfc_fof_queue_destroy(phba);
8165
James Smart895427b2017-02-12 13:52:30 -08008166 /* Release HBA eqs */
8167 lpfc_sli4_release_queues(&phba->sli4_hba.hba_eq, phba->io_channel_irqs);
James Smart67d12732012-08-03 12:36:13 -04008168
James Smart895427b2017-02-12 13:52:30 -08008169 /* Release FCP cqs */
8170 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_cq,
8171 phba->cfg_fcp_io_channel);
James Smart67d12732012-08-03 12:36:13 -04008172
James Smart895427b2017-02-12 13:52:30 -08008173 /* Release FCP wqs */
8174 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_wq,
8175 phba->cfg_fcp_io_channel);
James Smart67d12732012-08-03 12:36:13 -04008176
8177 /* Release FCP CQ mapping array */
James Smart895427b2017-02-12 13:52:30 -08008178 lpfc_sli4_release_queue_map(&phba->sli4_hba.fcp_cq_map);
8179
8180 /* Release NVME cqs */
8181 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_cq,
8182 phba->cfg_nvme_io_channel);
8183
8184 /* Release NVME wqs */
8185 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_wq,
8186 phba->cfg_nvme_io_channel);
8187
8188 /* Release NVME CQ mapping array */
8189 lpfc_sli4_release_queue_map(&phba->sli4_hba.nvme_cq_map);
James Smartda0436e2009-05-22 14:51:39 -04008190
James Smart2d7dbc42017-02-12 13:52:35 -08008191 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset,
8192 phba->cfg_nvmet_mrq);
8193
8194 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr,
8195 phba->cfg_nvmet_mrq);
8196 lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data,
8197 phba->cfg_nvmet_mrq);
8198
James Smartda0436e2009-05-22 14:51:39 -04008199 /* Release mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08008200 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
James Smartda0436e2009-05-22 14:51:39 -04008201
8202 /* Release ELS work queue */
James Smart895427b2017-02-12 13:52:30 -08008203 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
8204
8205 /* Release ELS work queue */
8206 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
James Smartda0436e2009-05-22 14:51:39 -04008207
8208 /* Release unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08008209 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
8210 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
James Smartda0436e2009-05-22 14:51:39 -04008211
James Smartda0436e2009-05-22 14:51:39 -04008212 /* Release ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08008213 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
8214
8215 /* Release NVME LS complete queue */
8216 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
James Smartda0436e2009-05-22 14:51:39 -04008217
8218 /* Release mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08008219 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
8220
8221 /* Everything on this list has been freed */
8222 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
8223}
8224
8225int
8226lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq,
8227 struct lpfc_queue *drq, int count)
8228{
8229 int rc, i;
8230 struct lpfc_rqe hrqe;
8231 struct lpfc_rqe drqe;
8232 struct lpfc_rqb *rqbp;
8233 struct rqb_dmabuf *rqb_buffer;
8234 LIST_HEAD(rqb_buf_list);
8235
8236 rqbp = hrq->rqbp;
8237 for (i = 0; i < count; i++) {
8238 rqb_buffer = (rqbp->rqb_alloc_buffer)(phba);
8239 if (!rqb_buffer)
8240 break;
8241 rqb_buffer->hrq = hrq;
8242 rqb_buffer->drq = drq;
8243 list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list);
8244 }
8245 while (!list_empty(&rqb_buf_list)) {
8246 list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf,
8247 hbuf.list);
8248
8249 hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys);
8250 hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys);
8251 drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys);
8252 drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys);
8253 rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe);
8254 if (rc < 0) {
8255 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
8256 } else {
8257 list_add_tail(&rqb_buffer->hbuf.list,
8258 &rqbp->rqb_buffer_list);
8259 rqbp->buffer_count++;
8260 }
8261 }
8262 return 1;
8263}
8264
8265int
8266lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
8267{
8268 struct lpfc_rqb *rqbp;
8269 struct lpfc_dmabuf *h_buf;
8270 struct rqb_dmabuf *rqb_buffer;
8271
8272 rqbp = rq->rqbp;
8273 while (!list_empty(&rqbp->rqb_buffer_list)) {
8274 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
8275 struct lpfc_dmabuf, list);
8276
8277 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
8278 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
8279 rqbp->buffer_count--;
8280 }
8281 return 1;
8282}
8283
8284static int
8285lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
8286 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
8287 int qidx, uint32_t qtype)
8288{
8289 struct lpfc_sli_ring *pring;
8290 int rc;
8291
8292 if (!eq || !cq || !wq) {
8293 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8294 "6085 Fast-path %s (%d) not allocated\n",
8295 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
8296 return -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04008297 }
James Smartda0436e2009-05-22 14:51:39 -04008298
James Smart895427b2017-02-12 13:52:30 -08008299 /* create the Cq first */
8300 rc = lpfc_cq_create(phba, cq, eq,
8301 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
8302 if (rc) {
8303 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8304 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
8305 qidx, (uint32_t)rc);
8306 return rc;
8307 }
8308
8309 if (qtype != LPFC_MBOX) {
8310 /* Setup nvme_cq_map for fast lookup */
8311 if (cq_map)
8312 *cq_map = cq->queue_id;
8313
8314 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8315 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
8316 qidx, cq->queue_id, qidx, eq->queue_id);
8317
8318 /* create the wq */
8319 rc = lpfc_wq_create(phba, wq, cq, qtype);
8320 if (rc) {
8321 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8322 "6123 Fail setup fastpath WQ (%d), rc = 0x%x\n",
8323 qidx, (uint32_t)rc);
8324 /* no need to tear down cq - caller will do so */
8325 return rc;
8326 }
8327
8328 /* Bind this CQ/WQ to the NVME ring */
8329 pring = wq->pring;
8330 pring->sli.sli4.wqp = (void *)wq;
8331 cq->pring = pring;
8332
8333 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8334 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
8335 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
8336 } else {
8337 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
8338 if (rc) {
8339 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8340 "0539 Failed setup of slow-path MQ: "
8341 "rc = 0x%x\n", rc);
8342 /* no need to tear down cq - caller will do so */
8343 return rc;
8344 }
8345
8346 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8347 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
8348 phba->sli4_hba.mbx_wq->queue_id,
8349 phba->sli4_hba.mbx_cq->queue_id);
8350 }
8351
8352 return 0;
James Smartda0436e2009-05-22 14:51:39 -04008353}
8354
8355/**
8356 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
8357 * @phba: pointer to lpfc hba data structure.
8358 *
8359 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
8360 * operation.
8361 *
8362 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008363 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008364 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008365 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008366 **/
8367int
8368lpfc_sli4_queue_setup(struct lpfc_hba *phba)
8369{
James Smart962bc512013-01-03 15:44:00 -05008370 uint32_t shdr_status, shdr_add_status;
8371 union lpfc_sli4_cfg_shdr *shdr;
8372 LPFC_MBOXQ_t *mboxq;
James Smart895427b2017-02-12 13:52:30 -08008373 int qidx;
8374 uint32_t length, io_channel;
8375 int rc = -ENOMEM;
James Smart962bc512013-01-03 15:44:00 -05008376
8377 /* Check for dual-ULP support */
8378 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8379 if (!mboxq) {
8380 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8381 "3249 Unable to allocate memory for "
8382 "QUERY_FW_CFG mailbox command\n");
8383 return -ENOMEM;
8384 }
8385 length = (sizeof(struct lpfc_mbx_query_fw_config) -
8386 sizeof(struct lpfc_sli4_cfg_mhdr));
8387 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8388 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
8389 length, LPFC_SLI4_MBX_EMBED);
8390
8391 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8392
8393 shdr = (union lpfc_sli4_cfg_shdr *)
8394 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
8395 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8396 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
8397 if (shdr_status || shdr_add_status || rc) {
8398 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8399 "3250 QUERY_FW_CFG mailbox failed with status "
8400 "x%x add_status x%x, mbx status x%x\n",
8401 shdr_status, shdr_add_status, rc);
8402 if (rc != MBX_TIMEOUT)
8403 mempool_free(mboxq, phba->mbox_mem_pool);
8404 rc = -ENXIO;
8405 goto out_error;
8406 }
8407
8408 phba->sli4_hba.fw_func_mode =
8409 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
8410 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
8411 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
James Smart8b017a32015-05-21 13:55:18 -04008412 phba->sli4_hba.physical_port =
8413 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
James Smart962bc512013-01-03 15:44:00 -05008414 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8415 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
8416 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
8417 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
8418
8419 if (rc != MBX_TIMEOUT)
8420 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04008421
8422 /*
James Smart67d12732012-08-03 12:36:13 -04008423 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04008424 */
James Smart895427b2017-02-12 13:52:30 -08008425 io_channel = phba->io_channel_irqs;
James Smartda0436e2009-05-22 14:51:39 -04008426
James Smart67d12732012-08-03 12:36:13 -04008427 /* Set up HBA event queue */
James Smart895427b2017-02-12 13:52:30 -08008428 if (io_channel && !phba->sli4_hba.hba_eq) {
James Smart2e90f4b2011-12-13 13:22:37 -05008429 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8430 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05008431 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04008432 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05008433 }
James Smart895427b2017-02-12 13:52:30 -08008434 for (qidx = 0; qidx < io_channel; qidx++) {
8435 if (!phba->sli4_hba.hba_eq[qidx]) {
James Smartda0436e2009-05-22 14:51:39 -04008436 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8437 "0522 Fast-path EQ (%d) not "
James Smart895427b2017-02-12 13:52:30 -08008438 "allocated\n", qidx);
James Smart1b511972011-12-13 13:23:09 -05008439 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008440 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008441 }
James Smart895427b2017-02-12 13:52:30 -08008442 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[qidx],
8443 phba->cfg_fcp_imax);
James Smartda0436e2009-05-22 14:51:39 -04008444 if (rc) {
8445 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8446 "0523 Failed setup of fast-path EQ "
James Smart895427b2017-02-12 13:52:30 -08008447 "(%d), rc = 0x%x\n", qidx,
James Smarta2fc4aef2014-09-03 12:57:55 -04008448 (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08008449 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008450 }
8451 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008452 "2584 HBA EQ setup: queue[%d]-id=%d\n",
8453 qidx, phba->sli4_hba.hba_eq[qidx]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04008454 }
8455
James Smart895427b2017-02-12 13:52:30 -08008456 if (phba->cfg_nvme_io_channel) {
8457 if (!phba->sli4_hba.nvme_cq || !phba->sli4_hba.nvme_wq) {
James Smart67d12732012-08-03 12:36:13 -04008458 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008459 "6084 Fast-path NVME %s array not allocated\n",
8460 (phba->sli4_hba.nvme_cq) ? "CQ" : "WQ");
James Smart67d12732012-08-03 12:36:13 -04008461 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008462 goto out_destroy;
James Smart67d12732012-08-03 12:36:13 -04008463 }
8464
James Smart895427b2017-02-12 13:52:30 -08008465 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
8466 rc = lpfc_create_wq_cq(phba,
8467 phba->sli4_hba.hba_eq[
8468 qidx % io_channel],
8469 phba->sli4_hba.nvme_cq[qidx],
8470 phba->sli4_hba.nvme_wq[qidx],
8471 &phba->sli4_hba.nvme_cq_map[qidx],
8472 qidx, LPFC_NVME);
8473 if (rc) {
8474 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8475 "6123 Failed to setup fastpath "
8476 "NVME WQ/CQ (%d), rc = 0x%x\n",
8477 qidx, (uint32_t)rc);
8478 goto out_destroy;
8479 }
8480 }
James Smart67d12732012-08-03 12:36:13 -04008481 }
8482
James Smart895427b2017-02-12 13:52:30 -08008483 if (phba->cfg_fcp_io_channel) {
8484 /* Set up fast-path FCP Response Complete Queue */
8485 if (!phba->sli4_hba.fcp_cq || !phba->sli4_hba.fcp_wq) {
James Smart67d12732012-08-03 12:36:13 -04008486 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008487 "3148 Fast-path FCP %s array not allocated\n",
8488 phba->sli4_hba.fcp_cq ? "WQ" : "CQ");
James Smart67d12732012-08-03 12:36:13 -04008489 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008490 goto out_destroy;
James Smart67d12732012-08-03 12:36:13 -04008491 }
8492
James Smart895427b2017-02-12 13:52:30 -08008493 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
8494 rc = lpfc_create_wq_cq(phba,
8495 phba->sli4_hba.hba_eq[
8496 qidx % io_channel],
8497 phba->sli4_hba.fcp_cq[qidx],
8498 phba->sli4_hba.fcp_wq[qidx],
8499 &phba->sli4_hba.fcp_cq_map[qidx],
8500 qidx, LPFC_FCP);
8501 if (rc) {
8502 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8503 "0535 Failed to setup fastpath "
8504 "FCP WQ/CQ (%d), rc = 0x%x\n",
8505 qidx, (uint32_t)rc);
8506 goto out_destroy;
8507 }
8508 }
James Smart67d12732012-08-03 12:36:13 -04008509 }
James Smartda0436e2009-05-22 14:51:39 -04008510
8511 /*
James Smart895427b2017-02-12 13:52:30 -08008512 * Set up Slow Path Complete Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04008513 */
8514
James Smart895427b2017-02-12 13:52:30 -08008515 /* Set up slow-path MBOX CQ/MQ */
8516
8517 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
James Smartda0436e2009-05-22 14:51:39 -04008518 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008519 "0528 %s not allocated\n",
8520 phba->sli4_hba.mbx_cq ?
8521 "Mailbox WQ" : "Mailbox CQ");
James Smart1b511972011-12-13 13:23:09 -05008522 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008523 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008524 }
James Smart895427b2017-02-12 13:52:30 -08008525
8526 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8527 phba->sli4_hba.mbx_cq,
8528 phba->sli4_hba.mbx_wq,
8529 NULL, 0, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04008530 if (rc) {
8531 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008532 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
8533 (uint32_t)rc);
8534 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008535 }
James Smart2d7dbc42017-02-12 13:52:35 -08008536 if (phba->nvmet_support) {
8537 if (!phba->sli4_hba.nvmet_cqset) {
8538 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8539 "3165 Fast-path NVME CQ Set "
8540 "array not allocated\n");
8541 rc = -ENOMEM;
8542 goto out_destroy;
8543 }
8544 if (phba->cfg_nvmet_mrq > 1) {
8545 rc = lpfc_cq_create_set(phba,
8546 phba->sli4_hba.nvmet_cqset,
8547 phba->sli4_hba.hba_eq,
8548 LPFC_WCQ, LPFC_NVMET);
8549 if (rc) {
8550 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8551 "3164 Failed setup of NVME CQ "
8552 "Set, rc = 0x%x\n",
8553 (uint32_t)rc);
8554 goto out_destroy;
8555 }
8556 } else {
8557 /* Set up NVMET Receive Complete Queue */
8558 rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0],
8559 phba->sli4_hba.hba_eq[0],
8560 LPFC_WCQ, LPFC_NVMET);
8561 if (rc) {
8562 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8563 "6089 Failed setup NVMET CQ: "
8564 "rc = 0x%x\n", (uint32_t)rc);
8565 goto out_destroy;
8566 }
8567 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8568 "6090 NVMET CQ setup: cq-id=%d, "
8569 "parent eq-id=%d\n",
8570 phba->sli4_hba.nvmet_cqset[0]->queue_id,
8571 phba->sli4_hba.hba_eq[0]->queue_id);
8572 }
8573 }
James Smartda0436e2009-05-22 14:51:39 -04008574
James Smart895427b2017-02-12 13:52:30 -08008575 /* Set up slow-path ELS WQ/CQ */
8576 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
James Smartda0436e2009-05-22 14:51:39 -04008577 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008578 "0530 ELS %s not allocated\n",
8579 phba->sli4_hba.els_cq ? "WQ" : "CQ");
James Smart1b511972011-12-13 13:23:09 -05008580 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008581 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008582 }
James Smart895427b2017-02-12 13:52:30 -08008583 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8584 phba->sli4_hba.els_cq,
8585 phba->sli4_hba.els_wq,
8586 NULL, 0, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04008587 if (rc) {
8588 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008589 "0529 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
8590 (uint32_t)rc);
8591 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008592 }
8593 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8594 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
8595 phba->sli4_hba.els_wq->queue_id,
8596 phba->sli4_hba.els_cq->queue_id);
8597
James Smart895427b2017-02-12 13:52:30 -08008598 if (phba->cfg_nvme_io_channel) {
8599 /* Set up NVME LS Complete Queue */
8600 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
8601 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8602 "6091 LS %s not allocated\n",
8603 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
8604 rc = -ENOMEM;
8605 goto out_destroy;
8606 }
8607 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8608 phba->sli4_hba.nvmels_cq,
8609 phba->sli4_hba.nvmels_wq,
8610 NULL, 0, LPFC_NVME_LS);
8611 if (rc) {
8612 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8613 "0529 Failed setup of NVVME LS WQ/CQ: "
8614 "rc = 0x%x\n", (uint32_t)rc);
8615 goto out_destroy;
8616 }
8617
8618 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8619 "6096 ELS WQ setup: wq-id=%d, "
8620 "parent cq-id=%d\n",
8621 phba->sli4_hba.nvmels_wq->queue_id,
8622 phba->sli4_hba.nvmels_cq->queue_id);
8623 }
8624
James Smart2d7dbc42017-02-12 13:52:35 -08008625 /*
8626 * Create NVMET Receive Queue (RQ)
8627 */
8628 if (phba->nvmet_support) {
8629 if ((!phba->sli4_hba.nvmet_cqset) ||
8630 (!phba->sli4_hba.nvmet_mrq_hdr) ||
8631 (!phba->sli4_hba.nvmet_mrq_data)) {
8632 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8633 "6130 MRQ CQ Queues not "
8634 "allocated\n");
8635 rc = -ENOMEM;
8636 goto out_destroy;
8637 }
8638 if (phba->cfg_nvmet_mrq > 1) {
8639 rc = lpfc_mrq_create(phba,
8640 phba->sli4_hba.nvmet_mrq_hdr,
8641 phba->sli4_hba.nvmet_mrq_data,
8642 phba->sli4_hba.nvmet_cqset,
8643 LPFC_NVMET);
8644 if (rc) {
8645 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8646 "6098 Failed setup of NVMET "
8647 "MRQ: rc = 0x%x\n",
8648 (uint32_t)rc);
8649 goto out_destroy;
8650 }
8651
8652 } else {
8653 rc = lpfc_rq_create(phba,
8654 phba->sli4_hba.nvmet_mrq_hdr[0],
8655 phba->sli4_hba.nvmet_mrq_data[0],
8656 phba->sli4_hba.nvmet_cqset[0],
8657 LPFC_NVMET);
8658 if (rc) {
8659 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8660 "6057 Failed setup of NVMET "
8661 "Receive Queue: rc = 0x%x\n",
8662 (uint32_t)rc);
8663 goto out_destroy;
8664 }
8665
8666 lpfc_printf_log(
8667 phba, KERN_INFO, LOG_INIT,
8668 "6099 NVMET RQ setup: hdr-rq-id=%d, "
8669 "dat-rq-id=%d parent cq-id=%d\n",
8670 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id,
8671 phba->sli4_hba.nvmet_mrq_data[0]->queue_id,
8672 phba->sli4_hba.nvmet_cqset[0]->queue_id);
8673
8674 }
8675 }
8676
James Smartda0436e2009-05-22 14:51:39 -04008677 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
8678 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8679 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05008680 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008681 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008682 }
James Smart73d91e52011-10-10 21:32:10 -04008683
8684 lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
8685 lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
8686
James Smartda0436e2009-05-22 14:51:39 -04008687 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04008688 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04008689 if (rc) {
8690 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8691 "0541 Failed setup of Receive Queue: "
James Smarta2fc4aef2014-09-03 12:57:55 -04008692 "rc = 0x%x\n", (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08008693 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008694 }
James Smart73d91e52011-10-10 21:32:10 -04008695
James Smartda0436e2009-05-22 14:51:39 -04008696 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8697 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
8698 "parent cq-id=%d\n",
8699 phba->sli4_hba.hdr_rq->queue_id,
8700 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04008701 phba->sli4_hba.els_cq->queue_id);
James Smart1ba981f2014-02-20 09:56:45 -05008702
8703 if (phba->cfg_fof) {
8704 rc = lpfc_fof_queue_setup(phba);
8705 if (rc) {
8706 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8707 "0549 Failed setup of FOF Queues: "
8708 "rc = 0x%x\n", rc);
James Smart895427b2017-02-12 13:52:30 -08008709 goto out_destroy;
James Smart1ba981f2014-02-20 09:56:45 -05008710 }
8711 }
James Smart2c9c5a02015-04-07 15:07:15 -04008712
8713 /*
8714 * Configure EQ delay multipier for interrupt coalescing using
8715 * MODIFY_EQ_DELAY for all EQs created, LPFC_MAX_EQ_DELAY at a time.
8716 */
James Smart895427b2017-02-12 13:52:30 -08008717 for (qidx = 0; qidx < io_channel; qidx += LPFC_MAX_EQ_DELAY)
8718 lpfc_modify_hba_eq_delay(phba, qidx);
James Smartda0436e2009-05-22 14:51:39 -04008719 return 0;
8720
James Smart895427b2017-02-12 13:52:30 -08008721out_destroy:
8722 lpfc_sli4_queue_unset(phba);
James Smartda0436e2009-05-22 14:51:39 -04008723out_error:
8724 return rc;
8725}
8726
8727/**
8728 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
8729 * @phba: pointer to lpfc hba data structure.
8730 *
8731 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
8732 * operation.
8733 *
8734 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008735 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008736 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008737 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008738 **/
8739void
8740lpfc_sli4_queue_unset(struct lpfc_hba *phba)
8741{
James Smart895427b2017-02-12 13:52:30 -08008742 int qidx;
James Smartda0436e2009-05-22 14:51:39 -04008743
James Smart1ba981f2014-02-20 09:56:45 -05008744 /* Unset the queues created for Flash Optimized Fabric operations */
8745 if (phba->cfg_fof)
8746 lpfc_fof_queue_destroy(phba);
James Smart895427b2017-02-12 13:52:30 -08008747
James Smartda0436e2009-05-22 14:51:39 -04008748 /* Unset mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08008749 if (phba->sli4_hba.mbx_wq)
8750 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
8751
8752 /* Unset NVME LS work queue */
8753 if (phba->sli4_hba.nvmels_wq)
8754 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
8755
James Smartda0436e2009-05-22 14:51:39 -04008756 /* Unset ELS work queue */
James Smart895427b2017-02-12 13:52:30 -08008757 if (phba->sli4_hba.els_cq)
8758 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
8759
James Smartda0436e2009-05-22 14:51:39 -04008760 /* Unset unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08008761 if (phba->sli4_hba.hdr_rq)
8762 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
8763 phba->sli4_hba.dat_rq);
8764
James Smartda0436e2009-05-22 14:51:39 -04008765 /* Unset FCP work queue */
James Smart895427b2017-02-12 13:52:30 -08008766 if (phba->sli4_hba.fcp_wq)
8767 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
8768 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[qidx]);
8769
8770 /* Unset NVME work queue */
8771 if (phba->sli4_hba.nvme_wq) {
8772 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
8773 lpfc_wq_destroy(phba, phba->sli4_hba.nvme_wq[qidx]);
James Smart67d12732012-08-03 12:36:13 -04008774 }
James Smart895427b2017-02-12 13:52:30 -08008775
James Smartda0436e2009-05-22 14:51:39 -04008776 /* Unset mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08008777 if (phba->sli4_hba.mbx_cq)
8778 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
8779
James Smartda0436e2009-05-22 14:51:39 -04008780 /* Unset ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08008781 if (phba->sli4_hba.els_cq)
8782 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
8783
8784 /* Unset NVME LS complete queue */
8785 if (phba->sli4_hba.nvmels_cq)
8786 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
8787
8788 /* Unset NVME response complete queue */
8789 if (phba->sli4_hba.nvme_cq)
8790 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
8791 lpfc_cq_destroy(phba, phba->sli4_hba.nvme_cq[qidx]);
8792
James Smart2d7dbc42017-02-12 13:52:35 -08008793 /* Unset NVMET MRQ queue */
8794 if (phba->sli4_hba.nvmet_mrq_hdr) {
8795 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
8796 lpfc_rq_destroy(phba,
8797 phba->sli4_hba.nvmet_mrq_hdr[qidx],
8798 phba->sli4_hba.nvmet_mrq_data[qidx]);
8799 }
8800
8801 /* Unset NVMET CQ Set complete queue */
8802 if (phba->sli4_hba.nvmet_cqset) {
8803 for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++)
8804 lpfc_cq_destroy(phba,
8805 phba->sli4_hba.nvmet_cqset[qidx]);
8806 }
8807
James Smartda0436e2009-05-22 14:51:39 -04008808 /* Unset FCP response complete queue */
James Smart895427b2017-02-12 13:52:30 -08008809 if (phba->sli4_hba.fcp_cq)
8810 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
8811 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[qidx]);
8812
James Smartda0436e2009-05-22 14:51:39 -04008813 /* Unset fast-path event queue */
James Smart895427b2017-02-12 13:52:30 -08008814 if (phba->sli4_hba.hba_eq)
8815 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++)
8816 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[qidx]);
James Smartda0436e2009-05-22 14:51:39 -04008817}
8818
8819/**
8820 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
8821 * @phba: pointer to lpfc hba data structure.
8822 *
8823 * This routine is invoked to allocate and set up a pool of completion queue
8824 * events. The body of the completion queue event is a completion queue entry
8825 * CQE. For now, this pool is used for the interrupt service routine to queue
8826 * the following HBA completion queue events for the worker thread to process:
8827 * - Mailbox asynchronous events
8828 * - Receive queue completion unsolicited events
8829 * Later, this can be used for all the slow-path events.
8830 *
8831 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008832 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008833 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04008834 **/
8835static int
8836lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
8837{
8838 struct lpfc_cq_event *cq_event;
8839 int i;
8840
8841 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
8842 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
8843 if (!cq_event)
8844 goto out_pool_create_fail;
8845 list_add_tail(&cq_event->list,
8846 &phba->sli4_hba.sp_cqe_event_pool);
8847 }
8848 return 0;
8849
8850out_pool_create_fail:
8851 lpfc_sli4_cq_event_pool_destroy(phba);
8852 return -ENOMEM;
8853}
8854
8855/**
8856 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
8857 * @phba: pointer to lpfc hba data structure.
8858 *
8859 * This routine is invoked to free the pool of completion queue events at
8860 * driver unload time. Note that, it is the responsibility of the driver
8861 * cleanup routine to free all the outstanding completion-queue events
8862 * allocated from this pool back into the pool before invoking this routine
8863 * to destroy the pool.
8864 **/
8865static void
8866lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
8867{
8868 struct lpfc_cq_event *cq_event, *next_cq_event;
8869
8870 list_for_each_entry_safe(cq_event, next_cq_event,
8871 &phba->sli4_hba.sp_cqe_event_pool, list) {
8872 list_del(&cq_event->list);
8873 kfree(cq_event);
8874 }
8875}
8876
8877/**
8878 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
8879 * @phba: pointer to lpfc hba data structure.
8880 *
8881 * This routine is the lock free version of the API invoked to allocate a
8882 * completion-queue event from the free pool.
8883 *
8884 * Return: Pointer to the newly allocated completion-queue event if successful
8885 * NULL otherwise.
8886 **/
8887struct lpfc_cq_event *
8888__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
8889{
8890 struct lpfc_cq_event *cq_event = NULL;
8891
8892 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
8893 struct lpfc_cq_event, list);
8894 return cq_event;
8895}
8896
8897/**
8898 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
8899 * @phba: pointer to lpfc hba data structure.
8900 *
8901 * This routine is the lock version of the API invoked to allocate a
8902 * completion-queue event from the free pool.
8903 *
8904 * Return: Pointer to the newly allocated completion-queue event if successful
8905 * NULL otherwise.
8906 **/
8907struct lpfc_cq_event *
8908lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
8909{
8910 struct lpfc_cq_event *cq_event;
8911 unsigned long iflags;
8912
8913 spin_lock_irqsave(&phba->hbalock, iflags);
8914 cq_event = __lpfc_sli4_cq_event_alloc(phba);
8915 spin_unlock_irqrestore(&phba->hbalock, iflags);
8916 return cq_event;
8917}
8918
8919/**
8920 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
8921 * @phba: pointer to lpfc hba data structure.
8922 * @cq_event: pointer to the completion queue event to be freed.
8923 *
8924 * This routine is the lock free version of the API invoked to release a
8925 * completion-queue event back into the free pool.
8926 **/
8927void
8928__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
8929 struct lpfc_cq_event *cq_event)
8930{
8931 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
8932}
8933
8934/**
8935 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
8936 * @phba: pointer to lpfc hba data structure.
8937 * @cq_event: pointer to the completion queue event to be freed.
8938 *
8939 * This routine is the lock version of the API invoked to release a
8940 * completion-queue event back into the free pool.
8941 **/
8942void
8943lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
8944 struct lpfc_cq_event *cq_event)
8945{
8946 unsigned long iflags;
8947 spin_lock_irqsave(&phba->hbalock, iflags);
8948 __lpfc_sli4_cq_event_release(phba, cq_event);
8949 spin_unlock_irqrestore(&phba->hbalock, iflags);
8950}
8951
8952/**
8953 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
8954 * @phba: pointer to lpfc hba data structure.
8955 *
8956 * This routine is to free all the pending completion-queue events to the
8957 * back into the free pool for device reset.
8958 **/
8959static void
8960lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
8961{
8962 LIST_HEAD(cqelist);
8963 struct lpfc_cq_event *cqe;
8964 unsigned long iflags;
8965
8966 /* Retrieve all the pending WCQEs from pending WCQE lists */
8967 spin_lock_irqsave(&phba->hbalock, iflags);
8968 /* Pending FCP XRI abort events */
8969 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
8970 &cqelist);
8971 /* Pending ELS XRI abort events */
8972 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
8973 &cqelist);
8974 /* Pending asynnc events */
8975 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
8976 &cqelist);
8977 spin_unlock_irqrestore(&phba->hbalock, iflags);
8978
8979 while (!list_empty(&cqelist)) {
8980 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
8981 lpfc_sli4_cq_event_release(phba, cqe);
8982 }
8983}
8984
8985/**
8986 * lpfc_pci_function_reset - Reset pci function.
8987 * @phba: pointer to lpfc hba data structure.
8988 *
8989 * This routine is invoked to request a PCI function reset. It will destroys
8990 * all resources assigned to the PCI function which originates this request.
8991 *
8992 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008993 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008994 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008995 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008996 **/
8997int
8998lpfc_pci_function_reset(struct lpfc_hba *phba)
8999{
9000 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05009001 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04009002 uint32_t shdr_status, shdr_add_status;
James Smart2f6fa2c2014-09-03 12:57:08 -04009003 uint32_t rdy_chk;
9004 uint32_t port_reset = 0;
James Smartda0436e2009-05-22 14:51:39 -04009005 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05009006 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -05009007 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -04009008
James Smart2fcee4b2010-12-15 17:57:46 -05009009 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9010 switch (if_type) {
9011 case LPFC_SLI_INTF_IF_TYPE_0:
9012 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
9013 GFP_KERNEL);
9014 if (!mboxq) {
9015 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9016 "0494 Unable to allocate memory for "
9017 "issuing SLI_FUNCTION_RESET mailbox "
9018 "command\n");
9019 return -ENOMEM;
9020 }
9021
9022 /* Setup PCI function reset mailbox-ioctl command */
9023 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9024 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
9025 LPFC_SLI4_MBX_EMBED);
9026 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9027 shdr = (union lpfc_sli4_cfg_shdr *)
9028 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
9029 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
9030 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
9031 &shdr->response);
9032 if (rc != MBX_TIMEOUT)
9033 mempool_free(mboxq, phba->mbox_mem_pool);
9034 if (shdr_status || shdr_add_status || rc) {
9035 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9036 "0495 SLI_FUNCTION_RESET mailbox "
9037 "failed with status x%x add_status x%x,"
9038 " mbx status x%x\n",
9039 shdr_status, shdr_add_status, rc);
9040 rc = -ENXIO;
9041 }
9042 break;
9043 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2f6fa2c2014-09-03 12:57:08 -04009044wait:
9045 /*
9046 * Poll the Port Status Register and wait for RDY for
9047 * up to 30 seconds. If the port doesn't respond, treat
9048 * it as an error.
9049 */
James Smart77d093f2015-04-07 15:07:08 -04009050 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
James Smart2f6fa2c2014-09-03 12:57:08 -04009051 if (lpfc_readl(phba->sli4_hba.u.if_type2.
9052 STATUSregaddr, &reg_data.word0)) {
9053 rc = -ENODEV;
9054 goto out;
9055 }
9056 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
9057 break;
9058 msleep(20);
9059 }
9060
9061 if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
9062 phba->work_status[0] = readl(
9063 phba->sli4_hba.u.if_type2.ERR1regaddr);
9064 phba->work_status[1] = readl(
9065 phba->sli4_hba.u.if_type2.ERR2regaddr);
9066 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9067 "2890 Port not ready, port status reg "
9068 "0x%x error 1=0x%x, error 2=0x%x\n",
9069 reg_data.word0,
9070 phba->work_status[0],
9071 phba->work_status[1]);
9072 rc = -ENODEV;
9073 goto out;
9074 }
9075
9076 if (!port_reset) {
9077 /*
9078 * Reset the port now
9079 */
James Smart2fcee4b2010-12-15 17:57:46 -05009080 reg_data.word0 = 0;
9081 bf_set(lpfc_sliport_ctrl_end, &reg_data,
9082 LPFC_SLIPORT_LITTLE_ENDIAN);
9083 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
9084 LPFC_SLIPORT_INIT_PORT);
9085 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
9086 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -05009087 /* flush */
James Smart2b81f942012-03-01 22:37:18 -05009088 pci_read_config_word(phba->pcidev,
9089 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -05009090
James Smart2f6fa2c2014-09-03 12:57:08 -04009091 port_reset = 1;
9092 msleep(20);
9093 goto wait;
9094 } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
9095 rc = -ENODEV;
9096 goto out;
James Smart2fcee4b2010-12-15 17:57:46 -05009097 }
9098 break;
James Smart2f6fa2c2014-09-03 12:57:08 -04009099
James Smart2fcee4b2010-12-15 17:57:46 -05009100 case LPFC_SLI_INTF_IF_TYPE_1:
9101 default:
9102 break;
James Smartda0436e2009-05-22 14:51:39 -04009103 }
9104
James Smart73d91e52011-10-10 21:32:10 -04009105out:
James Smart2fcee4b2010-12-15 17:57:46 -05009106 /* Catch the not-ready port failure after a port reset. */
James Smart2f6fa2c2014-09-03 12:57:08 -04009107 if (rc) {
James Smart229adb02013-04-17 20:16:51 -04009108 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9109 "3317 HBA not functional: IP Reset Failed "
James Smart2f6fa2c2014-09-03 12:57:08 -04009110 "try: echo fw_reset > board_mode\n");
James Smart2fcee4b2010-12-15 17:57:46 -05009111 rc = -ENODEV;
James Smart229adb02013-04-17 20:16:51 -04009112 }
James Smart2fcee4b2010-12-15 17:57:46 -05009113
James Smartda0436e2009-05-22 14:51:39 -04009114 return rc;
9115}
9116
9117/**
James Smartda0436e2009-05-22 14:51:39 -04009118 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
9119 * @phba: pointer to lpfc hba data structure.
9120 *
9121 * This routine is invoked to set up the PCI device memory space for device
9122 * with SLI-4 interface spec.
9123 *
9124 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009125 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009126 * other values - error
9127 **/
9128static int
9129lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
9130{
9131 struct pci_dev *pdev;
9132 unsigned long bar0map_len, bar1map_len, bar2map_len;
9133 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05009134 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04009135
9136 /* Obtain PCI device reference */
9137 if (!phba->pcidev)
9138 return error;
9139 else
9140 pdev = phba->pcidev;
9141
9142 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05009143 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
9144 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
9145 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
9146 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smartda0436e2009-05-22 14:51:39 -04009147 return error;
Michael Reed8e685972009-09-18 12:02:05 -05009148 }
9149 }
James Smartda0436e2009-05-22 14:51:39 -04009150
James Smart2fcee4b2010-12-15 17:57:46 -05009151 /*
9152 * The BARs and register set definitions and offset locations are
9153 * dependent on the if_type.
9154 */
9155 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
9156 &phba->sli4_hba.sli_intf.word0)) {
9157 return error;
9158 }
9159
9160 /* There is no SLI3 failback for SLI4 devices. */
9161 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
9162 LPFC_SLI_INTF_VALID) {
9163 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9164 "2894 SLI_INTF reg contents invalid "
9165 "sli_intf reg 0x%x\n",
9166 phba->sli4_hba.sli_intf.word0);
9167 return error;
9168 }
9169
9170 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
9171 /*
9172 * Get the bus address of SLI4 device Bar regions and the
9173 * number of bytes required by each mapping. The mapping of the
9174 * particular PCI BARs regions is dependent on the type of
9175 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04009176 */
James Smartf5ca6f22013-09-06 12:21:09 -04009177 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
9178 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
9179 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
James Smart2fcee4b2010-12-15 17:57:46 -05009180
9181 /*
9182 * Map SLI4 PCI Config Space Register base to a kernel virtual
9183 * addr
9184 */
9185 phba->sli4_hba.conf_regs_memmap_p =
9186 ioremap(phba->pci_bar0_map, bar0map_len);
9187 if (!phba->sli4_hba.conf_regs_memmap_p) {
9188 dev_printk(KERN_ERR, &pdev->dev,
9189 "ioremap failed for SLI4 PCI config "
9190 "registers.\n");
9191 goto out;
9192 }
James Smartf5ca6f22013-09-06 12:21:09 -04009193 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05009194 /* Set up BAR0 PCI config space register memory map */
9195 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05009196 } else {
9197 phba->pci_bar0_map = pci_resource_start(pdev, 1);
9198 bar0map_len = pci_resource_len(pdev, 1);
James Smart2fcee4b2010-12-15 17:57:46 -05009199 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
9200 dev_printk(KERN_ERR, &pdev->dev,
9201 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
9202 goto out;
9203 }
9204 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04009205 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05009206 if (!phba->sli4_hba.conf_regs_memmap_p) {
9207 dev_printk(KERN_ERR, &pdev->dev,
9208 "ioremap failed for SLI4 PCI config "
9209 "registers.\n");
9210 goto out;
9211 }
9212 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04009213 }
9214
James Smartc31098c2011-04-16 11:03:33 -04009215 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04009216 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
James Smart2fcee4b2010-12-15 17:57:46 -05009217 /*
9218 * Map SLI4 if type 0 HBA Control Register base to a kernel
9219 * virtual address and setup the registers.
9220 */
James Smartf5ca6f22013-09-06 12:21:09 -04009221 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
9222 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
James Smart2fcee4b2010-12-15 17:57:46 -05009223 phba->sli4_hba.ctrl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04009224 ioremap(phba->pci_bar1_map, bar1map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05009225 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
9226 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04009227 "ioremap failed for SLI4 HBA control registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05009228 goto out_iounmap_conf;
9229 }
James Smartf5ca6f22013-09-06 12:21:09 -04009230 phba->pci_bar2_memmap_p = phba->sli4_hba.ctrl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05009231 lpfc_sli4_bar1_register_memmap(phba);
James Smartda0436e2009-05-22 14:51:39 -04009232 }
9233
James Smartc31098c2011-04-16 11:03:33 -04009234 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04009235 (pci_resource_start(pdev, PCI_64BIT_BAR4))) {
James Smart2fcee4b2010-12-15 17:57:46 -05009236 /*
9237 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
9238 * virtual address and setup the registers.
9239 */
James Smartf5ca6f22013-09-06 12:21:09 -04009240 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
9241 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
James Smart2fcee4b2010-12-15 17:57:46 -05009242 phba->sli4_hba.drbl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04009243 ioremap(phba->pci_bar2_map, bar2map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05009244 if (!phba->sli4_hba.drbl_regs_memmap_p) {
9245 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04009246 "ioremap failed for SLI4 HBA doorbell registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05009247 goto out_iounmap_ctrl;
9248 }
James Smartf5ca6f22013-09-06 12:21:09 -04009249 phba->pci_bar4_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05009250 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
9251 if (error)
9252 goto out_iounmap_all;
James Smartda0436e2009-05-22 14:51:39 -04009253 }
9254
James Smartda0436e2009-05-22 14:51:39 -04009255 return 0;
9256
9257out_iounmap_all:
9258 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9259out_iounmap_ctrl:
9260 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9261out_iounmap_conf:
9262 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9263out:
9264 return error;
9265}
9266
9267/**
9268 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
9269 * @phba: pointer to lpfc hba data structure.
9270 *
9271 * This routine is invoked to unset the PCI device memory space for device
9272 * with SLI-4 interface spec.
9273 **/
9274static void
9275lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
9276{
James Smart2e90f4b2011-12-13 13:22:37 -05009277 uint32_t if_type;
9278 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -04009279
James Smart2e90f4b2011-12-13 13:22:37 -05009280 switch (if_type) {
9281 case LPFC_SLI_INTF_IF_TYPE_0:
9282 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
9283 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
9284 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9285 break;
9286 case LPFC_SLI_INTF_IF_TYPE_2:
9287 iounmap(phba->sli4_hba.conf_regs_memmap_p);
9288 break;
9289 case LPFC_SLI_INTF_IF_TYPE_1:
9290 default:
9291 dev_printk(KERN_ERR, &phba->pcidev->dev,
9292 "FATAL - unsupported SLI4 interface type - %d\n",
9293 if_type);
9294 break;
9295 }
James Smartda0436e2009-05-22 14:51:39 -04009296}
9297
9298/**
James Smart3772a992009-05-22 14:50:54 -04009299 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
9300 * @phba: pointer to lpfc hba data structure.
9301 *
9302 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009303 * with SLI-3 interface specs.
James Smart3772a992009-05-22 14:50:54 -04009304 *
9305 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009306 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009307 * other values - error
9308 **/
9309static int
9310lpfc_sli_enable_msix(struct lpfc_hba *phba)
9311{
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009312 int rc;
James Smart3772a992009-05-22 14:50:54 -04009313 LPFC_MBOXQ_t *pmb;
9314
9315 /* Set up MSI-X multi-message vectors */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009316 rc = pci_alloc_irq_vectors(phba->pcidev,
9317 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
9318 if (rc < 0) {
James Smart3772a992009-05-22 14:50:54 -04009319 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9320 "0420 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009321 goto vec_fail_out;
James Smart3772a992009-05-22 14:50:54 -04009322 }
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009323
James Smart3772a992009-05-22 14:50:54 -04009324 /*
9325 * Assign MSI-X vectors to interrupt handlers
9326 */
9327
9328 /* vector-0 is associated to slow-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009329 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
James Smarted243d32015-05-21 13:55:25 -04009330 &lpfc_sli_sp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04009331 LPFC_SP_DRIVER_HANDLER_NAME, phba);
9332 if (rc) {
9333 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9334 "0421 MSI-X slow-path request_irq failed "
9335 "(%d)\n", rc);
9336 goto msi_fail_out;
9337 }
9338
9339 /* vector-1 is associated to fast-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009340 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
James Smarted243d32015-05-21 13:55:25 -04009341 &lpfc_sli_fp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04009342 LPFC_FP_DRIVER_HANDLER_NAME, phba);
9343
9344 if (rc) {
9345 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9346 "0429 MSI-X fast-path request_irq failed "
9347 "(%d)\n", rc);
9348 goto irq_fail_out;
9349 }
9350
9351 /*
9352 * Configure HBA MSI-X attention conditions to messages
9353 */
9354 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9355
9356 if (!pmb) {
9357 rc = -ENOMEM;
9358 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9359 "0474 Unable to allocate memory for issuing "
9360 "MBOX_CONFIG_MSI command\n");
9361 goto mem_fail_out;
9362 }
9363 rc = lpfc_config_msi(phba, pmb);
9364 if (rc)
9365 goto mbx_fail_out;
9366 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
9367 if (rc != MBX_SUCCESS) {
9368 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
9369 "0351 Config MSI mailbox command failed, "
9370 "mbxCmd x%x, mbxStatus x%x\n",
9371 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
9372 goto mbx_fail_out;
9373 }
9374
9375 /* Free memory allocated for mailbox command */
9376 mempool_free(pmb, phba->mbox_mem_pool);
9377 return rc;
9378
9379mbx_fail_out:
9380 /* Free memory allocated for mailbox command */
9381 mempool_free(pmb, phba->mbox_mem_pool);
9382
9383mem_fail_out:
9384 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009385 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
James Smart3772a992009-05-22 14:50:54 -04009386
9387irq_fail_out:
9388 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009389 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
James Smart3772a992009-05-22 14:50:54 -04009390
9391msi_fail_out:
9392 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009393 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009394
9395vec_fail_out:
James Smart3772a992009-05-22 14:50:54 -04009396 return rc;
9397}
9398
9399/**
James Smart3772a992009-05-22 14:50:54 -04009400 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
9401 * @phba: pointer to lpfc hba data structure.
9402 *
9403 * This routine is invoked to enable the MSI interrupt mode to device with
9404 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
9405 * enable the MSI vector. The device driver is responsible for calling the
9406 * request_irq() to register MSI vector with a interrupt the handler, which
9407 * is done in this function.
9408 *
9409 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009410 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009411 * other values - error
9412 */
9413static int
9414lpfc_sli_enable_msi(struct lpfc_hba *phba)
9415{
9416 int rc;
9417
9418 rc = pci_enable_msi(phba->pcidev);
9419 if (!rc)
9420 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9421 "0462 PCI enable MSI mode success.\n");
9422 else {
9423 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9424 "0471 PCI enable MSI mode failed (%d)\n", rc);
9425 return rc;
9426 }
9427
9428 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04009429 0, LPFC_DRIVER_NAME, phba);
James Smart3772a992009-05-22 14:50:54 -04009430 if (rc) {
9431 pci_disable_msi(phba->pcidev);
9432 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9433 "0478 MSI request_irq failed (%d)\n", rc);
9434 }
9435 return rc;
9436}
9437
9438/**
James Smart3772a992009-05-22 14:50:54 -04009439 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
9440 * @phba: pointer to lpfc hba data structure.
9441 *
9442 * This routine is invoked to enable device interrupt and associate driver's
9443 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
9444 * spec. Depends on the interrupt mode configured to the driver, the driver
9445 * will try to fallback from the configured interrupt mode to an interrupt
9446 * mode which is supported by the platform, kernel, and device in the order
9447 * of:
9448 * MSI-X -> MSI -> IRQ.
9449 *
9450 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009451 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009452 * other values - error
9453 **/
9454static uint32_t
9455lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9456{
9457 uint32_t intr_mode = LPFC_INTR_ERROR;
9458 int retval;
9459
9460 if (cfg_mode == 2) {
9461 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
9462 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
9463 if (!retval) {
9464 /* Now, try to enable MSI-X interrupt mode */
9465 retval = lpfc_sli_enable_msix(phba);
9466 if (!retval) {
9467 /* Indicate initialization to MSI-X mode */
9468 phba->intr_type = MSIX;
9469 intr_mode = 2;
9470 }
9471 }
9472 }
9473
9474 /* Fallback to MSI if MSI-X initialization failed */
9475 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9476 retval = lpfc_sli_enable_msi(phba);
9477 if (!retval) {
9478 /* Indicate initialization to MSI mode */
9479 phba->intr_type = MSI;
9480 intr_mode = 1;
9481 }
9482 }
9483
9484 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9485 if (phba->intr_type == NONE) {
9486 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
9487 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9488 if (!retval) {
9489 /* Indicate initialization to INTx mode */
9490 phba->intr_type = INTx;
9491 intr_mode = 0;
9492 }
9493 }
9494 return intr_mode;
9495}
9496
9497/**
9498 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
9499 * @phba: pointer to lpfc hba data structure.
9500 *
9501 * This routine is invoked to disable device interrupt and disassociate the
9502 * driver's interrupt handler(s) from interrupt vector(s) to device with
9503 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
9504 * release the interrupt vector(s) for the message signaled interrupt.
9505 **/
9506static void
9507lpfc_sli_disable_intr(struct lpfc_hba *phba)
9508{
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009509 int nr_irqs, i;
9510
James Smart3772a992009-05-22 14:50:54 -04009511 if (phba->intr_type == MSIX)
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009512 nr_irqs = LPFC_MSIX_VECTORS;
9513 else
9514 nr_irqs = 1;
9515
9516 for (i = 0; i < nr_irqs; i++)
9517 free_irq(pci_irq_vector(phba->pcidev, i), phba);
9518 pci_free_irq_vectors(phba->pcidev);
James Smart3772a992009-05-22 14:50:54 -04009519
9520 /* Reset interrupt management states */
9521 phba->intr_type = NONE;
9522 phba->sli.slistat.sli_intr = 0;
James Smart3772a992009-05-22 14:50:54 -04009523}
9524
9525/**
James Smart895427b2017-02-12 13:52:30 -08009526 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
James Smart7bb03bb2013-04-17 20:19:16 -04009527 * @phba: pointer to lpfc hba data structure.
James Smart895427b2017-02-12 13:52:30 -08009528 * @vectors: number of msix vectors allocated.
James Smart7bb03bb2013-04-17 20:19:16 -04009529 *
James Smart895427b2017-02-12 13:52:30 -08009530 * The routine will figure out the CPU affinity assignment for every
9531 * MSI-X vector allocated for the HBA. The hba_eq_hdl will be updated
9532 * with a pointer to the CPU mask that defines ALL the CPUs this vector
9533 * can be associated with. If the vector can be unquely associated with
9534 * a single CPU, that CPU will be recorded in hba_eq_hdl[index].cpu.
9535 * In addition, the CPU to IO channel mapping will be calculated
9536 * and the phba->sli4_hba.cpu_map array will reflect this.
James Smart7bb03bb2013-04-17 20:19:16 -04009537 */
James Smart895427b2017-02-12 13:52:30 -08009538static void
9539lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
James Smart7bb03bb2013-04-17 20:19:16 -04009540{
9541 struct lpfc_vector_map_info *cpup;
James Smart895427b2017-02-12 13:52:30 -08009542 int index = 0;
9543 int vec = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04009544 int cpu;
James Smart7bb03bb2013-04-17 20:19:16 -04009545#ifdef CONFIG_X86
9546 struct cpuinfo_x86 *cpuinfo;
9547#endif
James Smart7bb03bb2013-04-17 20:19:16 -04009548
9549 /* Init cpu_map array */
9550 memset(phba->sli4_hba.cpu_map, 0xff,
9551 (sizeof(struct lpfc_vector_map_info) *
James Smart895427b2017-02-12 13:52:30 -08009552 phba->sli4_hba.num_present_cpu));
James Smart7bb03bb2013-04-17 20:19:16 -04009553
9554 /* Update CPU map with physical id and core id of each CPU */
9555 cpup = phba->sli4_hba.cpu_map;
9556 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
9557#ifdef CONFIG_X86
9558 cpuinfo = &cpu_data(cpu);
9559 cpup->phys_id = cpuinfo->phys_proc_id;
9560 cpup->core_id = cpuinfo->cpu_core_id;
9561#else
9562 /* No distinction between CPUs for other platforms */
9563 cpup->phys_id = 0;
9564 cpup->core_id = 0;
9565#endif
James Smart895427b2017-02-12 13:52:30 -08009566 cpup->channel_id = index; /* For now round robin */
9567 cpup->irq = pci_irq_vector(phba->pcidev, vec);
9568 vec++;
9569 if (vec >= vectors)
9570 vec = 0;
9571 index++;
9572 if (index >= phba->cfg_fcp_io_channel)
9573 index = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04009574 cpup++;
9575 }
James Smart7bb03bb2013-04-17 20:19:16 -04009576}
9577
9578
9579/**
James Smartda0436e2009-05-22 14:51:39 -04009580 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
9581 * @phba: pointer to lpfc hba data structure.
9582 *
9583 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009584 * with SLI-4 interface spec.
James Smartda0436e2009-05-22 14:51:39 -04009585 *
9586 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009587 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009588 * other values - error
9589 **/
9590static int
9591lpfc_sli4_enable_msix(struct lpfc_hba *phba)
9592{
James Smart75baf692010-06-08 18:31:21 -04009593 int vectors, rc, index;
James Smartda0436e2009-05-22 14:51:39 -04009594
9595 /* Set up MSI-X multi-message vectors */
James Smart895427b2017-02-12 13:52:30 -08009596 vectors = phba->io_channel_irqs;
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009597 if (phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05009598 vectors++;
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009599
James Smartf358dd02017-02-12 13:52:34 -08009600 rc = pci_alloc_irq_vectors(phba->pcidev,
9601 (phba->nvmet_support) ? 1 : 2,
9602 vectors, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY);
Alexander Gordeev4f871e12014-09-03 12:56:29 -04009603 if (rc < 0) {
James Smartda0436e2009-05-22 14:51:39 -04009604 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9605 "0484 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009606 goto vec_fail_out;
James Smartda0436e2009-05-22 14:51:39 -04009607 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -04009608 vectors = rc;
James Smart75baf692010-06-08 18:31:21 -04009609
James Smart7bb03bb2013-04-17 20:19:16 -04009610 /* Assign MSI-X vectors to interrupt handlers */
James Smart67d12732012-08-03 12:36:13 -04009611 for (index = 0; index < vectors; index++) {
James Smart4305f182012-08-03 12:36:33 -04009612 memset(&phba->sli4_hba.handler_name[index], 0, 16);
James Smarta2fc4aef2014-09-03 12:57:55 -04009613 snprintf((char *)&phba->sli4_hba.handler_name[index],
9614 LPFC_SLI4_HANDLER_NAME_SZ,
James Smart4305f182012-08-03 12:36:33 -04009615 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -04009616
James Smart895427b2017-02-12 13:52:30 -08009617 phba->sli4_hba.hba_eq_hdl[index].idx = index;
9618 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
9619 atomic_set(&phba->sli4_hba.hba_eq_hdl[index].hba_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -05009620 if (phba->cfg_fof && (index == (vectors - 1)))
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009621 rc = request_irq(pci_irq_vector(phba->pcidev, index),
James Smarted243d32015-05-21 13:55:25 -04009622 &lpfc_sli4_fof_intr_handler, 0,
James Smart1ba981f2014-02-20 09:56:45 -05009623 (char *)&phba->sli4_hba.handler_name[index],
James Smart895427b2017-02-12 13:52:30 -08009624 &phba->sli4_hba.hba_eq_hdl[index]);
James Smart1ba981f2014-02-20 09:56:45 -05009625 else
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009626 rc = request_irq(pci_irq_vector(phba->pcidev, index),
James Smarted243d32015-05-21 13:55:25 -04009627 &lpfc_sli4_hba_intr_handler, 0,
James Smart4305f182012-08-03 12:36:33 -04009628 (char *)&phba->sli4_hba.handler_name[index],
James Smart895427b2017-02-12 13:52:30 -08009629 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -04009630 if (rc) {
9631 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9632 "0486 MSI-X fast-path (%d) "
9633 "request_irq failed (%d)\n", index, rc);
9634 goto cfg_fail_out;
9635 }
9636 }
9637
James Smart1ba981f2014-02-20 09:56:45 -05009638 if (phba->cfg_fof)
9639 vectors--;
9640
James Smart895427b2017-02-12 13:52:30 -08009641 if (vectors != phba->io_channel_irqs) {
James Smart82c3e9b2012-09-29 11:29:50 -04009642 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9643 "3238 Reducing IO channels to match number of "
9644 "MSI-X vectors, requested %d got %d\n",
James Smart895427b2017-02-12 13:52:30 -08009645 phba->io_channel_irqs, vectors);
9646 if (phba->cfg_fcp_io_channel > vectors)
9647 phba->cfg_fcp_io_channel = vectors;
9648 if (phba->cfg_nvme_io_channel > vectors)
9649 phba->cfg_nvme_io_channel = vectors;
9650 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
9651 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
9652 else
9653 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
James Smart82c3e9b2012-09-29 11:29:50 -04009654 }
James Smart895427b2017-02-12 13:52:30 -08009655 lpfc_cpu_affinity_check(phba, vectors);
James Smart7bb03bb2013-04-17 20:19:16 -04009656
James Smartda0436e2009-05-22 14:51:39 -04009657 return rc;
9658
9659cfg_fail_out:
9660 /* free the irq already requested */
James Smart895427b2017-02-12 13:52:30 -08009661 for (--index; index >= 0; index--)
9662 free_irq(pci_irq_vector(phba->pcidev, index),
9663 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -04009664
James Smartda0436e2009-05-22 14:51:39 -04009665 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009666 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009667
9668vec_fail_out:
James Smartda0436e2009-05-22 14:51:39 -04009669 return rc;
9670}
9671
9672/**
James Smartda0436e2009-05-22 14:51:39 -04009673 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
9674 * @phba: pointer to lpfc hba data structure.
9675 *
9676 * This routine is invoked to enable the MSI interrupt mode to device with
9677 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
9678 * to enable the MSI vector. The device driver is responsible for calling
9679 * the request_irq() to register MSI vector with a interrupt the handler,
9680 * which is done in this function.
9681 *
9682 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009683 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009684 * other values - error
9685 **/
9686static int
9687lpfc_sli4_enable_msi(struct lpfc_hba *phba)
9688{
9689 int rc, index;
9690
9691 rc = pci_enable_msi(phba->pcidev);
9692 if (!rc)
9693 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9694 "0487 PCI enable MSI mode success.\n");
9695 else {
9696 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9697 "0488 PCI enable MSI mode failed (%d)\n", rc);
9698 return rc;
9699 }
9700
9701 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04009702 0, LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -04009703 if (rc) {
9704 pci_disable_msi(phba->pcidev);
9705 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9706 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -04009707 return rc;
James Smartda0436e2009-05-22 14:51:39 -04009708 }
9709
James Smart895427b2017-02-12 13:52:30 -08009710 for (index = 0; index < phba->io_channel_irqs; index++) {
9711 phba->sli4_hba.hba_eq_hdl[index].idx = index;
9712 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smartda0436e2009-05-22 14:51:39 -04009713 }
9714
James Smart1ba981f2014-02-20 09:56:45 -05009715 if (phba->cfg_fof) {
James Smart895427b2017-02-12 13:52:30 -08009716 phba->sli4_hba.hba_eq_hdl[index].idx = index;
9717 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smart1ba981f2014-02-20 09:56:45 -05009718 }
James Smart75baf692010-06-08 18:31:21 -04009719 return 0;
James Smartda0436e2009-05-22 14:51:39 -04009720}
9721
9722/**
James Smartda0436e2009-05-22 14:51:39 -04009723 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
9724 * @phba: pointer to lpfc hba data structure.
9725 *
9726 * This routine is invoked to enable device interrupt and associate driver's
9727 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
9728 * interface spec. Depends on the interrupt mode configured to the driver,
9729 * the driver will try to fallback from the configured interrupt mode to an
9730 * interrupt mode which is supported by the platform, kernel, and device in
9731 * the order of:
9732 * MSI-X -> MSI -> IRQ.
9733 *
9734 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009735 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009736 * other values - error
9737 **/
9738static uint32_t
9739lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9740{
9741 uint32_t intr_mode = LPFC_INTR_ERROR;
James Smart895427b2017-02-12 13:52:30 -08009742 int retval, idx;
James Smartda0436e2009-05-22 14:51:39 -04009743
9744 if (cfg_mode == 2) {
9745 /* Preparation before conf_msi mbox cmd */
9746 retval = 0;
9747 if (!retval) {
9748 /* Now, try to enable MSI-X interrupt mode */
9749 retval = lpfc_sli4_enable_msix(phba);
9750 if (!retval) {
9751 /* Indicate initialization to MSI-X mode */
9752 phba->intr_type = MSIX;
9753 intr_mode = 2;
9754 }
9755 }
9756 }
9757
9758 /* Fallback to MSI if MSI-X initialization failed */
9759 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9760 retval = lpfc_sli4_enable_msi(phba);
9761 if (!retval) {
9762 /* Indicate initialization to MSI mode */
9763 phba->intr_type = MSI;
9764 intr_mode = 1;
9765 }
9766 }
9767
9768 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9769 if (phba->intr_type == NONE) {
9770 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
9771 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9772 if (!retval) {
James Smart895427b2017-02-12 13:52:30 -08009773 struct lpfc_hba_eq_hdl *eqhdl;
9774
James Smartda0436e2009-05-22 14:51:39 -04009775 /* Indicate initialization to INTx mode */
9776 phba->intr_type = INTx;
9777 intr_mode = 0;
James Smart895427b2017-02-12 13:52:30 -08009778
9779 for (idx = 0; idx < phba->io_channel_irqs; idx++) {
9780 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
9781 eqhdl->idx = idx;
9782 eqhdl->phba = phba;
9783 atomic_set(&eqhdl->hba_eq_in_use, 1);
James Smartda0436e2009-05-22 14:51:39 -04009784 }
James Smart1ba981f2014-02-20 09:56:45 -05009785 if (phba->cfg_fof) {
James Smart895427b2017-02-12 13:52:30 -08009786 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
9787 eqhdl->idx = idx;
9788 eqhdl->phba = phba;
9789 atomic_set(&eqhdl->hba_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -05009790 }
James Smartda0436e2009-05-22 14:51:39 -04009791 }
9792 }
9793 return intr_mode;
9794}
9795
9796/**
9797 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
9798 * @phba: pointer to lpfc hba data structure.
9799 *
9800 * This routine is invoked to disable device interrupt and disassociate
9801 * the driver's interrupt handler(s) from interrupt vector(s) to device
9802 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
9803 * will release the interrupt vector(s) for the message signaled interrupt.
9804 **/
9805static void
9806lpfc_sli4_disable_intr(struct lpfc_hba *phba)
9807{
9808 /* Disable the currently initialized interrupt mode */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009809 if (phba->intr_type == MSIX) {
9810 int index;
9811
9812 /* Free up MSI-X multi-message vectors */
James Smart895427b2017-02-12 13:52:30 -08009813 for (index = 0; index < phba->io_channel_irqs; index++)
9814 free_irq(pci_irq_vector(phba->pcidev, index),
9815 &phba->sli4_hba.hba_eq_hdl[index]);
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009816
9817 if (phba->cfg_fof)
James Smart895427b2017-02-12 13:52:30 -08009818 free_irq(pci_irq_vector(phba->pcidev, index),
9819 &phba->sli4_hba.hba_eq_hdl[index]);
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009820 } else {
James Smartda0436e2009-05-22 14:51:39 -04009821 free_irq(phba->pcidev->irq, phba);
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009822 }
9823
9824 pci_free_irq_vectors(phba->pcidev);
James Smartda0436e2009-05-22 14:51:39 -04009825
9826 /* Reset interrupt management states */
9827 phba->intr_type = NONE;
9828 phba->sli.slistat.sli_intr = 0;
James Smartda0436e2009-05-22 14:51:39 -04009829}
9830
9831/**
James Smart3772a992009-05-22 14:50:54 -04009832 * lpfc_unset_hba - Unset SLI3 hba device initialization
9833 * @phba: pointer to lpfc hba data structure.
9834 *
9835 * This routine is invoked to unset the HBA device initialization steps to
9836 * a device with SLI-3 interface spec.
9837 **/
9838static void
9839lpfc_unset_hba(struct lpfc_hba *phba)
9840{
9841 struct lpfc_vport *vport = phba->pport;
9842 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9843
9844 spin_lock_irq(shost->host_lock);
9845 vport->load_flag |= FC_UNLOADING;
9846 spin_unlock_irq(shost->host_lock);
9847
James Smart72859902012-01-18 16:25:38 -05009848 kfree(phba->vpi_bmask);
9849 kfree(phba->vpi_ids);
9850
James Smart3772a992009-05-22 14:50:54 -04009851 lpfc_stop_hba_timers(phba);
9852
9853 phba->pport->work_port_events = 0;
9854
9855 lpfc_sli_hba_down(phba);
9856
9857 lpfc_sli_brdrestart(phba);
9858
9859 lpfc_sli_disable_intr(phba);
9860
9861 return;
9862}
9863
9864/**
James Smart5af5eee2010-10-22 11:06:38 -04009865 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
9866 * @phba: Pointer to HBA context object.
9867 *
9868 * This function is called in the SLI4 code path to wait for completion
9869 * of device's XRIs exchange busy. It will check the XRI exchange busy
9870 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
9871 * that, it will check the XRI exchange busy on outstanding FCP and ELS
9872 * I/Os every 30 seconds, log error message, and wait forever. Only when
9873 * all XRI exchange busy complete, the driver unload shall proceed with
9874 * invoking the function reset ioctl mailbox command to the CNA and the
9875 * the rest of the driver unload resource release.
9876 **/
9877static void
9878lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
9879{
9880 int wait_time = 0;
James Smart895427b2017-02-12 13:52:30 -08009881 int nvme_xri_cmpl = 1;
9882 int fcp_xri_cmpl = 1;
James Smart5af5eee2010-10-22 11:06:38 -04009883 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -08009884 int nvmet_xri_cmpl =
9885 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_sgl_list);
James Smart5af5eee2010-10-22 11:06:38 -04009886
James Smart895427b2017-02-12 13:52:30 -08009887 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
9888 fcp_xri_cmpl =
9889 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
9890 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
9891 nvme_xri_cmpl =
9892 list_empty(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
9893
James Smartf358dd02017-02-12 13:52:34 -08009894 while (!fcp_xri_cmpl || !els_xri_cmpl || !nvme_xri_cmpl ||
9895 !nvmet_xri_cmpl) {
James Smart5af5eee2010-10-22 11:06:38 -04009896 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
James Smart895427b2017-02-12 13:52:30 -08009897 if (!nvme_xri_cmpl)
9898 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9899 "6100 NVME XRI exchange busy "
9900 "wait time: %d seconds.\n",
9901 wait_time/1000);
James Smart5af5eee2010-10-22 11:06:38 -04009902 if (!fcp_xri_cmpl)
9903 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9904 "2877 FCP XRI exchange busy "
9905 "wait time: %d seconds.\n",
9906 wait_time/1000);
9907 if (!els_xri_cmpl)
9908 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9909 "2878 ELS XRI exchange busy "
9910 "wait time: %d seconds.\n",
9911 wait_time/1000);
9912 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
9913 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
9914 } else {
9915 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
9916 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
9917 }
James Smart895427b2017-02-12 13:52:30 -08009918 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
9919 nvme_xri_cmpl = list_empty(
9920 &phba->sli4_hba.lpfc_abts_nvme_buf_list);
9921
9922 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
9923 fcp_xri_cmpl = list_empty(
9924 &phba->sli4_hba.lpfc_abts_scsi_buf_list);
9925
James Smart5af5eee2010-10-22 11:06:38 -04009926 els_xri_cmpl =
9927 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
James Smartf358dd02017-02-12 13:52:34 -08009928
9929 nvmet_xri_cmpl =
9930 list_empty(&phba->sli4_hba.lpfc_abts_nvmet_sgl_list);
James Smart5af5eee2010-10-22 11:06:38 -04009931 }
9932}
9933
9934/**
James Smartda0436e2009-05-22 14:51:39 -04009935 * lpfc_sli4_hba_unset - Unset the fcoe hba
9936 * @phba: Pointer to HBA context object.
9937 *
9938 * This function is called in the SLI4 code path to reset the HBA's FCoE
9939 * function. The caller is not required to hold any lock. This routine
9940 * issues PCI function reset mailbox command to reset the FCoE function.
9941 * At the end of the function, it calls lpfc_hba_down_post function to
9942 * free any pending commands.
9943 **/
9944static void
9945lpfc_sli4_hba_unset(struct lpfc_hba *phba)
9946{
9947 int wait_cnt = 0;
9948 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -04009949 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -04009950
9951 lpfc_stop_hba_timers(phba);
9952 phba->sli4_hba.intr_enable = 0;
9953
9954 /*
9955 * Gracefully wait out the potential current outstanding asynchronous
9956 * mailbox command.
9957 */
9958
9959 /* First, block any pending async mailbox command from posted */
9960 spin_lock_irq(&phba->hbalock);
9961 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
9962 spin_unlock_irq(&phba->hbalock);
9963 /* Now, trying to wait it out if we can */
9964 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9965 msleep(10);
9966 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
9967 break;
9968 }
9969 /* Forcefully release the outstanding mailbox command if timed out */
9970 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9971 spin_lock_irq(&phba->hbalock);
9972 mboxq = phba->sli.mbox_active;
9973 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
9974 __lpfc_mbox_cmpl_put(phba, mboxq);
9975 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9976 phba->sli.mbox_active = NULL;
9977 spin_unlock_irq(&phba->hbalock);
9978 }
9979
James Smart5af5eee2010-10-22 11:06:38 -04009980 /* Abort all iocbs associated with the hba */
9981 lpfc_sli_hba_iocb_abort(phba);
9982
9983 /* Wait for completion of device XRI exchange busy */
9984 lpfc_sli4_xri_exchange_busy_wait(phba);
9985
James Smartda0436e2009-05-22 14:51:39 -04009986 /* Disable PCI subsystem interrupt */
9987 lpfc_sli4_disable_intr(phba);
9988
James Smart912e3ac2011-05-24 11:42:11 -04009989 /* Disable SR-IOV if enabled */
9990 if (phba->cfg_sriov_nr_virtfn)
9991 pci_disable_sriov(pdev);
9992
James Smartda0436e2009-05-22 14:51:39 -04009993 /* Stop kthread signal shall trigger work_done one more time */
9994 kthread_stop(phba->worker_thread);
9995
James Smart3677a3a2010-09-29 11:19:14 -04009996 /* Reset SLI4 HBA FCoE function */
9997 lpfc_pci_function_reset(phba);
James Smart5350d872011-10-10 21:33:49 -04009998 lpfc_sli4_queue_destroy(phba);
James Smart3677a3a2010-09-29 11:19:14 -04009999
James Smartda0436e2009-05-22 14:51:39 -040010000 /* Stop the SLI4 device port */
10001 phba->pport->work_port_events = 0;
10002}
10003
James Smart28baac72010-02-12 14:42:03 -050010004 /**
10005 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
10006 * @phba: Pointer to HBA context object.
10007 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10008 *
10009 * This function is called in the SLI4 code path to read the port's
10010 * sli4 capabilities.
10011 *
10012 * This function may be be called from any context that can block-wait
10013 * for the completion. The expectation is that this routine is called
10014 * typically from probe_one or from the online routine.
10015 **/
10016int
10017lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10018{
10019 int rc;
10020 struct lpfc_mqe *mqe;
10021 struct lpfc_pc_sli4_params *sli4_params;
10022 uint32_t mbox_tmo;
10023
10024 rc = 0;
10025 mqe = &mboxq->u.mqe;
10026
10027 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -050010028 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -050010029 if (!phba->sli4_hba.intr_enable)
10030 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
10031 else {
James Smarta183a152011-10-10 21:32:43 -040010032 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -050010033 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10034 }
10035
10036 if (unlikely(rc))
10037 return 1;
10038
10039 sli4_params = &phba->sli4_hba.pc_sli4_params;
10040 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
10041 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
10042 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
10043 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
10044 &mqe->un.sli4_params);
10045 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
10046 &mqe->un.sli4_params);
10047 sli4_params->proto_types = mqe->un.sli4_params.word3;
10048 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
10049 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
10050 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
10051 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
10052 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
10053 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
10054 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
10055 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
10056 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
10057 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
10058 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
10059 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
10060 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
10061 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
10062 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
10063 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
10064 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
10065 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
10066 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
10067 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -040010068
10069 /* Make sure that sge_supp_len can be handled by the driver */
10070 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10071 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10072
James Smart28baac72010-02-12 14:42:03 -050010073 return rc;
10074}
10075
James Smartda0436e2009-05-22 14:51:39 -040010076/**
James Smartfedd3b72011-02-16 12:39:24 -050010077 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
10078 * @phba: Pointer to HBA context object.
10079 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
10080 *
10081 * This function is called in the SLI4 code path to read the port's
10082 * sli4 capabilities.
10083 *
10084 * This function may be be called from any context that can block-wait
10085 * for the completion. The expectation is that this routine is called
10086 * typically from probe_one or from the online routine.
10087 **/
10088int
10089lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
10090{
10091 int rc;
10092 struct lpfc_mqe *mqe = &mboxq->u.mqe;
10093 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -040010094 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -050010095 int length;
10096 struct lpfc_sli4_parameters *mbx_sli4_parameters;
10097
James Smart6d368e52011-05-24 11:44:12 -040010098 /*
10099 * By default, the driver assumes the SLI4 port requires RPI
10100 * header postings. The SLI4_PARAM response will correct this
10101 * assumption.
10102 */
10103 phba->sli4_hba.rpi_hdrs_in_use = 1;
10104
James Smartfedd3b72011-02-16 12:39:24 -050010105 /* Read the port's SLI4 Config Parameters */
10106 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
10107 sizeof(struct lpfc_sli4_cfg_mhdr));
10108 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
10109 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
10110 length, LPFC_SLI4_MBX_EMBED);
10111 if (!phba->sli4_hba.intr_enable)
10112 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -040010113 else {
10114 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
10115 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
10116 }
James Smartfedd3b72011-02-16 12:39:24 -050010117 if (unlikely(rc))
10118 return rc;
10119 sli4_params = &phba->sli4_hba.pc_sli4_params;
10120 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
10121 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
10122 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
10123 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
10124 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
10125 mbx_sli4_parameters);
10126 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
10127 mbx_sli4_parameters);
10128 if (bf_get(cfg_phwq, mbx_sli4_parameters))
10129 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
10130 else
10131 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
10132 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
10133 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
James Smart1ba981f2014-02-20 09:56:45 -050010134 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010135 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
10136 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
10137 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
10138 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
James Smart0c651872013-07-15 18:33:23 -040010139 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010140 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
10141 mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080010142 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -050010143 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
10144 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -040010145 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
10146 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -080010147 phba->nvme_support = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
10148 bf_get(cfg_xib, mbx_sli4_parameters));
10149
10150 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) ||
10151 !phba->nvme_support) {
10152 phba->nvme_support = 0;
10153 phba->nvmet_support = 0;
James Smart2d7dbc42017-02-12 13:52:35 -080010154 phba->cfg_nvmet_mrq = 0;
James Smart895427b2017-02-12 13:52:30 -080010155 phba->cfg_nvme_io_channel = 0;
10156 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
10157 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
10158 "6101 Disabling NVME support: "
10159 "Not supported by firmware: %d %d\n",
10160 bf_get(cfg_nvme, mbx_sli4_parameters),
10161 bf_get(cfg_xib, mbx_sli4_parameters));
10162
10163 /* If firmware doesn't support NVME, just use SCSI support */
10164 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
10165 return -ENODEV;
10166 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
10167 }
James Smart05580562011-05-24 11:40:48 -040010168
James Smartf358dd02017-02-12 13:52:34 -080010169 if (bf_get(cfg_xib, mbx_sli4_parameters) && phba->cfg_suppress_rsp)
10170 phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP;
10171
James Smart05580562011-05-24 11:40:48 -040010172 /* Make sure that sge_supp_len can be handled by the driver */
10173 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
10174 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
10175
James Smartb5c53952016-03-31 14:12:30 -070010176 /*
10177 * Issue IOs with CDB embedded in WQE to minimized the number
10178 * of DMAs the firmware has to do. Setting this to 1 also forces
10179 * the driver to use 128 bytes WQEs for FCP IOs.
10180 */
10181 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
10182 phba->fcp_embed_io = 1;
10183 else
10184 phba->fcp_embed_io = 0;
James Smart7bdedb32016-07-06 12:36:00 -070010185
10186 /*
10187 * Check if the SLI port supports MDS Diagnostics
10188 */
10189 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
10190 phba->mds_diags_support = 1;
10191 else
10192 phba->mds_diags_support = 0;
James Smartfedd3b72011-02-16 12:39:24 -050010193 return 0;
10194}
10195
10196/**
James Smart3772a992009-05-22 14:50:54 -040010197 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
10198 * @pdev: pointer to PCI device
10199 * @pid: pointer to PCI device identifier
10200 *
10201 * This routine is to be called to attach a device with SLI-3 interface spec
10202 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10203 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10204 * information of the device and driver to see if the driver state that it can
10205 * support this kind of device. If the match is successful, the driver core
10206 * invokes this routine. If this routine determines it can claim the HBA, it
10207 * does all the initialization that it needs to do to handle the HBA properly.
10208 *
10209 * Return code
10210 * 0 - driver can claim the device
10211 * negative value - driver can not claim the device
10212 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010213static int
James Smart3772a992009-05-22 14:50:54 -040010214lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
10215{
10216 struct lpfc_hba *phba;
10217 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040010218 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -040010219 int error;
10220 uint32_t cfg_mode, intr_mode;
10221
10222 /* Allocate memory for HBA structure */
10223 phba = lpfc_hba_alloc(pdev);
10224 if (!phba)
10225 return -ENOMEM;
10226
10227 /* Perform generic PCI device enabling operation */
10228 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040010229 if (error)
James Smart3772a992009-05-22 14:50:54 -040010230 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -040010231
10232 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
10233 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
10234 if (error)
10235 goto out_disable_pci_dev;
10236
10237 /* Set up SLI-3 specific device PCI memory space */
10238 error = lpfc_sli_pci_mem_setup(phba);
10239 if (error) {
10240 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10241 "1402 Failed to set up pci memory space.\n");
10242 goto out_disable_pci_dev;
10243 }
10244
James Smart3772a992009-05-22 14:50:54 -040010245 /* Set up SLI-3 specific device driver resources */
10246 error = lpfc_sli_driver_resource_setup(phba);
10247 if (error) {
10248 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10249 "1404 Failed to set up driver resource.\n");
10250 goto out_unset_pci_mem_s3;
10251 }
10252
10253 /* Initialize and populate the iocb list per host */
10254 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
10255 if (error) {
10256 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10257 "1405 Failed to initialize iocb list.\n");
10258 goto out_unset_driver_resource_s3;
10259 }
10260
10261 /* Set up common device driver resources */
10262 error = lpfc_setup_driver_resource_phase2(phba);
10263 if (error) {
10264 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10265 "1406 Failed to set up driver resource.\n");
10266 goto out_free_iocb_list;
10267 }
10268
James Smart079b5c92011-08-21 21:48:49 -040010269 /* Get the default values for Model Name and Description */
10270 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
10271
James Smart3772a992009-05-22 14:50:54 -040010272 /* Create SCSI host to the physical port */
10273 error = lpfc_create_shost(phba);
10274 if (error) {
10275 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10276 "1407 Failed to create scsi host.\n");
10277 goto out_unset_driver_resource;
10278 }
10279
10280 /* Configure sysfs attributes */
10281 vport = phba->pport;
10282 error = lpfc_alloc_sysfs_attr(vport);
10283 if (error) {
10284 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10285 "1476 Failed to allocate sysfs attr\n");
10286 goto out_destroy_shost;
10287 }
10288
James Smart6669f9b2009-10-02 15:16:45 -040010289 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -040010290 /* Now, trying to enable interrupt and bring up the device */
10291 cfg_mode = phba->cfg_use_msi;
10292 while (true) {
10293 /* Put device to a known state before enabling interrupt */
10294 lpfc_stop_port(phba);
10295 /* Configure and enable interrupt */
10296 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
10297 if (intr_mode == LPFC_INTR_ERROR) {
10298 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10299 "0431 Failed to enable interrupt.\n");
10300 error = -ENODEV;
10301 goto out_free_sysfs_attr;
10302 }
10303 /* SLI-3 HBA setup */
10304 if (lpfc_sli_hba_setup(phba)) {
10305 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10306 "1477 Failed to set up hba\n");
10307 error = -ENODEV;
10308 goto out_remove_device;
10309 }
10310
10311 /* Wait 50ms for the interrupts of previous mailbox commands */
10312 msleep(50);
10313 /* Check active interrupts on message signaled interrupts */
10314 if (intr_mode == 0 ||
10315 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
10316 /* Log the current active interrupt mode */
10317 phba->intr_mode = intr_mode;
10318 lpfc_log_intr_mode(phba, intr_mode);
10319 break;
10320 } else {
10321 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10322 "0447 Configure interrupt mode (%d) "
10323 "failed active interrupt test.\n",
10324 intr_mode);
10325 /* Disable the current interrupt mode */
10326 lpfc_sli_disable_intr(phba);
10327 /* Try next level of interrupt mode */
10328 cfg_mode = --intr_mode;
10329 }
10330 }
10331
10332 /* Perform post initialization setup */
10333 lpfc_post_init_setup(phba);
10334
10335 /* Check if there are static vports to be created. */
10336 lpfc_create_static_vport(phba);
10337
10338 return 0;
10339
10340out_remove_device:
10341 lpfc_unset_hba(phba);
10342out_free_sysfs_attr:
10343 lpfc_free_sysfs_attr(vport);
10344out_destroy_shost:
10345 lpfc_destroy_shost(phba);
10346out_unset_driver_resource:
10347 lpfc_unset_driver_resource_phase2(phba);
10348out_free_iocb_list:
10349 lpfc_free_iocb_list(phba);
10350out_unset_driver_resource_s3:
10351 lpfc_sli_driver_resource_unset(phba);
10352out_unset_pci_mem_s3:
10353 lpfc_sli_pci_mem_unset(phba);
10354out_disable_pci_dev:
10355 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040010356 if (shost)
10357 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -040010358out_free_phba:
10359 lpfc_hba_free(phba);
10360 return error;
10361}
10362
10363/**
10364 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -040010365 * @pdev: pointer to PCI device
10366 *
James Smart3772a992009-05-22 14:50:54 -040010367 * This routine is to be called to disattach a device with SLI-3 interface
10368 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
10369 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10370 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -040010371 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010372static void
James Smart3772a992009-05-22 14:50:54 -040010373lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -050010374{
James Smart2e0fef82007-06-17 19:56:36 -050010375 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10376 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -050010377 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -050010378 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -050010379 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -050010380
James Smart549e55c2007-08-02 11:09:51 -040010381 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -040010382 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -040010383 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -050010384
James Smart858c9f62007-06-17 19:56:39 -050010385 lpfc_free_sysfs_attr(vport);
10386
James Smarteada2722008-12-04 22:39:13 -050010387 /* Release all the vports against this physical port */
10388 vports = lpfc_create_vport_work_array(phba);
10389 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040010390 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10391 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
10392 continue;
James Smarteada2722008-12-04 22:39:13 -050010393 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040010394 }
James Smarteada2722008-12-04 22:39:13 -050010395 lpfc_destroy_vport_work_array(phba, vports);
10396
10397 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -050010398 fc_remove_host(shost);
10399 scsi_remove_host(shost);
James Smartd613b6a2017-02-12 13:52:37 -080010400
10401 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
10402 * localports are destroyed after to cleanup all transport memory.
10403 */
James Smart87af33f2007-10-27 13:37:43 -040010404 lpfc_cleanup(vport);
James Smartd613b6a2017-02-12 13:52:37 -080010405 lpfc_nvmet_destroy_targetport(phba);
10406 lpfc_nvme_destroy_localport(vport);
James Smart87af33f2007-10-27 13:37:43 -040010407
James Smart2e0fef82007-06-17 19:56:36 -050010408 /*
10409 * Bring down the SLI Layer. This step disable all interrupts,
10410 * clears the rings, discards all mailbox commands, and resets
10411 * the HBA.
10412 */
James Smarta257bf92009-04-06 18:48:10 -040010413
Justin P. Mattock48e34d02010-12-30 15:07:58 -080010414 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -050010415 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -040010416 /* Stop kthread signal shall trigger work_done one more time */
10417 kthread_stop(phba->worker_thread);
10418 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -050010419 lpfc_sli_brdrestart(phba);
10420
James Smart72859902012-01-18 16:25:38 -050010421 kfree(phba->vpi_bmask);
10422 kfree(phba->vpi_ids);
10423
James Smart3772a992009-05-22 14:50:54 -040010424 lpfc_stop_hba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -050010425 spin_lock_irq(&phba->hbalock);
10426 list_del_init(&vport->listentry);
10427 spin_unlock_irq(&phba->hbalock);
10428
James Smart858c9f62007-06-17 19:56:39 -050010429 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -050010430
James Smart912e3ac2011-05-24 11:42:11 -040010431 /* Disable SR-IOV if enabled */
10432 if (phba->cfg_sriov_nr_virtfn)
10433 pci_disable_sriov(pdev);
10434
James Smart5b75da22008-12-04 22:39:35 -050010435 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -040010436 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -050010437
James Smart858c9f62007-06-17 19:56:39 -050010438 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -050010439
10440 /*
10441 * Call scsi_free before mem_free since scsi bufs are released to their
10442 * corresponding pools here.
10443 */
10444 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -040010445 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -050010446
James Smart34b02dc2008-08-24 21:49:55 -040010447 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
10448 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -050010449
James Smart2e0fef82007-06-17 19:56:36 -050010450 /* Free resources associated with SLI2 interface */
10451 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -040010452 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -050010453
10454 /* unmap adapter SLIM and Control Registers */
10455 iounmap(phba->ctrl_regs_memmap_p);
10456 iounmap(phba->slim_memmap_p);
10457
James Smart3772a992009-05-22 14:50:54 -040010458 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -050010459
Johannes Thumshirne0c04832016-06-07 09:44:03 +020010460 pci_release_mem_regions(pdev);
James Smart2e0fef82007-06-17 19:56:36 -050010461 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -050010462}
10463
Linas Vepstas8d63f372007-02-14 14:28:36 -060010464/**
James Smart3772a992009-05-22 14:50:54 -040010465 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050010466 * @pdev: pointer to PCI device
10467 * @msg: power management message
10468 *
James Smart3772a992009-05-22 14:50:54 -040010469 * This routine is to be called from the kernel's PCI subsystem to support
10470 * system Power Management (PM) to device with SLI-3 interface spec. When
10471 * PM invokes this method, it quiesces the device by stopping the driver's
10472 * worker thread for the device, turning off device's interrupt and DMA,
10473 * and bring the device offline. Note that as the driver implements the
10474 * minimum PM requirements to a power-aware driver's PM support for the
10475 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10476 * to the suspend() method call will be treated as SUSPEND and the driver will
10477 * fully reinitialize its device during resume() method call, the driver will
10478 * set device to PCI_D3hot state in PCI config space instead of setting it
10479 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -050010480 *
10481 * Return code
James Smart3772a992009-05-22 14:50:54 -040010482 * 0 - driver suspended the device
10483 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050010484 **/
10485static int
James Smart3772a992009-05-22 14:50:54 -040010486lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -050010487{
10488 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10489 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10490
10491 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10492 "0473 PCI device Power Management suspend.\n");
10493
10494 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040010495 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -050010496 lpfc_offline(phba);
10497 kthread_stop(phba->worker_thread);
10498
10499 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -040010500 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -050010501
10502 /* Save device state to PCI config space */
10503 pci_save_state(pdev);
10504 pci_set_power_state(pdev, PCI_D3hot);
10505
10506 return 0;
10507}
10508
10509/**
James Smart3772a992009-05-22 14:50:54 -040010510 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050010511 * @pdev: pointer to PCI device
10512 *
James Smart3772a992009-05-22 14:50:54 -040010513 * This routine is to be called from the kernel's PCI subsystem to support
10514 * system Power Management (PM) to device with SLI-3 interface spec. When PM
10515 * invokes this method, it restores the device's PCI config space state and
10516 * fully reinitializes the device and brings it online. Note that as the
10517 * driver implements the minimum PM requirements to a power-aware driver's
10518 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
10519 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
10520 * driver will fully reinitialize its device during resume() method call,
10521 * the device will be set to PCI_D0 directly in PCI config space before
10522 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -050010523 *
10524 * Return code
James Smart3772a992009-05-22 14:50:54 -040010525 * 0 - driver suspended the device
10526 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050010527 **/
10528static int
James Smart3772a992009-05-22 14:50:54 -040010529lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -050010530{
10531 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10532 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -050010533 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050010534 int error;
10535
10536 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10537 "0452 PCI device Power Management resume.\n");
10538
10539 /* Restore device state from PCI config space */
10540 pci_set_power_state(pdev, PCI_D0);
10541 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -040010542
James Smart1dfb5a42010-02-12 14:40:50 -050010543 /*
10544 * As the new kernel behavior of pci_restore_state() API call clears
10545 * device saved_state flag, need to save the restored state again.
10546 */
10547 pci_save_state(pdev);
10548
James Smart3a55b532008-12-04 22:38:54 -050010549 if (pdev->is_busmaster)
10550 pci_set_master(pdev);
10551
10552 /* Startup the kernel thread for this host adapter. */
10553 phba->worker_thread = kthread_run(lpfc_do_work, phba,
10554 "lpfc_worker_%d", phba->brd_no);
10555 if (IS_ERR(phba->worker_thread)) {
10556 error = PTR_ERR(phba->worker_thread);
10557 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10558 "0434 PM resume failed to start worker "
10559 "thread: error=x%x.\n", error);
10560 return error;
10561 }
10562
James Smart5b75da22008-12-04 22:39:35 -050010563 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040010564 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050010565 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -050010566 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -050010567 "0430 PM resume Failed to enable interrupt\n");
10568 return -EIO;
10569 } else
10570 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050010571
10572 /* Restart HBA and bring it online */
10573 lpfc_sli_brdrestart(phba);
10574 lpfc_online(phba);
10575
James Smart5b75da22008-12-04 22:39:35 -050010576 /* Log the current active interrupt mode */
10577 lpfc_log_intr_mode(phba, phba->intr_mode);
10578
James Smart3a55b532008-12-04 22:38:54 -050010579 return 0;
10580}
10581
10582/**
James Smart891478a2009-11-18 15:40:23 -050010583 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
10584 * @phba: pointer to lpfc hba data structure.
10585 *
10586 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -040010587 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -050010588 **/
10589static void
10590lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
10591{
10592 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10593 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -040010594
10595 /*
10596 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10597 * and let the SCSI mid-layer to retry them to recover.
10598 */
James Smartdb55fba2014-04-04 13:52:02 -040010599 lpfc_sli_abort_fcp_rings(phba);
James Smart891478a2009-11-18 15:40:23 -050010600}
10601
10602/**
James Smart0d878412009-10-02 15:16:56 -040010603 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
10604 * @phba: pointer to lpfc hba data structure.
10605 *
10606 * This routine is called to prepare the SLI3 device for PCI slot reset. It
10607 * disables the device interrupt and pci device, and aborts the internal FCP
10608 * pending I/Os.
10609 **/
10610static void
10611lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
10612{
James Smart0d878412009-10-02 15:16:56 -040010613 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050010614 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -040010615
James Smart75baf692010-06-08 18:31:21 -040010616 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040010617 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010618
James Smarte2af0d22010-03-15 11:25:32 -040010619 /* Block all SCSI devices' I/Os on the host */
10620 lpfc_scsi_dev_block(phba);
10621
James Smartea714f32013-04-17 20:18:47 -040010622 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10623 lpfc_sli_flush_fcp_rings(phba);
10624
James Smarte2af0d22010-03-15 11:25:32 -040010625 /* stop all timers */
10626 lpfc_stop_hba_timers(phba);
10627
James Smart0d878412009-10-02 15:16:56 -040010628 /* Disable interrupt and pci device */
10629 lpfc_sli_disable_intr(phba);
10630 pci_disable_device(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -040010631}
10632
10633/**
10634 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
10635 * @phba: pointer to lpfc hba data structure.
10636 *
10637 * This routine is called to prepare the SLI3 device for PCI slot permanently
10638 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10639 * pending I/Os.
10640 **/
10641static void
James Smart75baf692010-06-08 18:31:21 -040010642lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -040010643{
10644 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050010645 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -040010646 /* Block all SCSI devices' I/Os on the host */
10647 lpfc_scsi_dev_block(phba);
10648
10649 /* stop all timers */
10650 lpfc_stop_hba_timers(phba);
10651
James Smart0d878412009-10-02 15:16:56 -040010652 /* Clean up all driver's outstanding SCSI I/Os */
10653 lpfc_sli_flush_fcp_rings(phba);
10654}
10655
10656/**
James Smart3772a992009-05-22 14:50:54 -040010657 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -040010658 * @pdev: pointer to PCI device.
10659 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010660 *
James Smart3772a992009-05-22 14:50:54 -040010661 * This routine is called from the PCI subsystem for I/O error handling to
10662 * device with SLI-3 interface spec. This function is called by the PCI
10663 * subsystem after a PCI bus error affecting this device has been detected.
10664 * When this function is invoked, it will need to stop all the I/Os and
10665 * interrupt(s) to the device. Once that is done, it will return
10666 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
10667 * as desired.
James Smarte59058c2008-08-24 21:49:00 -040010668 *
10669 * Return codes
James Smart0d878412009-10-02 15:16:56 -040010670 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -040010671 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10672 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -040010673 **/
James Smart3772a992009-05-22 14:50:54 -040010674static pci_ers_result_t
10675lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010676{
James Smart51ef4c22007-08-02 11:10:31 -040010677 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10678 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010679
James Smart0d878412009-10-02 15:16:56 -040010680 switch (state) {
10681 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -050010682 /* Non-fatal error, prepare for recovery */
10683 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -040010684 return PCI_ERS_RESULT_CAN_RECOVER;
10685 case pci_channel_io_frozen:
10686 /* Fatal error, prepare for slot reset */
10687 lpfc_sli_prep_dev_for_reset(phba);
10688 return PCI_ERS_RESULT_NEED_RESET;
10689 case pci_channel_io_perm_failure:
10690 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -040010691 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010692 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -040010693 default:
10694 /* Unknown state, prepare and request slot reset */
10695 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10696 "0472 Unknown PCI error state: x%x\n", state);
10697 lpfc_sli_prep_dev_for_reset(phba);
10698 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -040010699 }
Linas Vepstas8d63f372007-02-14 14:28:36 -060010700}
10701
10702/**
James Smart3772a992009-05-22 14:50:54 -040010703 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -040010704 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010705 *
James Smart3772a992009-05-22 14:50:54 -040010706 * This routine is called from the PCI subsystem for error handling to
10707 * device with SLI-3 interface spec. This is called after PCI bus has been
10708 * reset to restart the PCI card from scratch, as if from a cold-boot.
10709 * During the PCI subsystem error recovery, after driver returns
10710 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10711 * recovery and then call this routine before calling the .resume method
10712 * to recover the device. This function will initialize the HBA device,
10713 * enable the interrupt, but it will just put the HBA to offline state
10714 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -040010715 *
10716 * Return codes
James Smart3772a992009-05-22 14:50:54 -040010717 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10718 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -060010719 */
James Smart3772a992009-05-22 14:50:54 -040010720static pci_ers_result_t
10721lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010722{
James Smart51ef4c22007-08-02 11:10:31 -040010723 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10724 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010725 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -050010726 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010727
10728 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +110010729 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -060010730 printk(KERN_ERR "lpfc: Cannot re-enable "
10731 "PCI device after reset.\n");
10732 return PCI_ERS_RESULT_DISCONNECT;
10733 }
10734
James Smart97207482008-12-04 22:39:19 -050010735 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050010736
10737 /*
10738 * As the new kernel behavior of pci_restore_state() API call clears
10739 * device saved_state flag, need to save the restored state again.
10740 */
10741 pci_save_state(pdev);
10742
James Smart97207482008-12-04 22:39:19 -050010743 if (pdev->is_busmaster)
10744 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010745
James Smart92d7f7b2007-06-17 19:56:38 -050010746 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040010747 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -050010748 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010749
James Smart5b75da22008-12-04 22:39:35 -050010750 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040010751 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050010752 if (intr_mode == LPFC_INTR_ERROR) {
10753 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10754 "0427 Cannot re-enable interrupt after "
10755 "slot reset.\n");
10756 return PCI_ERS_RESULT_DISCONNECT;
10757 } else
10758 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010759
James Smart75baf692010-06-08 18:31:21 -040010760 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -040010761 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010762 lpfc_offline(phba);
10763 lpfc_sli_brdrestart(phba);
10764
James Smart5b75da22008-12-04 22:39:35 -050010765 /* Log the current active interrupt mode */
10766 lpfc_log_intr_mode(phba, phba->intr_mode);
10767
Linas Vepstas8d63f372007-02-14 14:28:36 -060010768 return PCI_ERS_RESULT_RECOVERED;
10769}
10770
10771/**
James Smart3772a992009-05-22 14:50:54 -040010772 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -040010773 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -060010774 *
James Smart3772a992009-05-22 14:50:54 -040010775 * This routine is called from the PCI subsystem for error handling to device
10776 * with SLI-3 interface spec. It is called when kernel error recovery tells
10777 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10778 * error recovery. After this call, traffic can start to flow from this device
10779 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010780 */
James Smart3772a992009-05-22 14:50:54 -040010781static void
10782lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010783{
James Smart51ef4c22007-08-02 11:10:31 -040010784 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10785 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010786
James Smarte2af0d22010-03-15 11:25:32 -040010787 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -040010788 lpfc_online(phba);
James Smart0d878412009-10-02 15:16:56 -040010789
10790 /* Clean up Advanced Error Reporting (AER) if needed */
10791 if (phba->hba_flag & HBA_AER_ENABLED)
10792 pci_cleanup_aer_uncorrect_error_status(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010793}
10794
James Smart3772a992009-05-22 14:50:54 -040010795/**
James Smartda0436e2009-05-22 14:51:39 -040010796 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
10797 * @phba: pointer to lpfc hba data structure.
10798 *
10799 * returns the number of ELS/CT IOCBs to reserve
10800 **/
10801int
10802lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
10803{
10804 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
10805
James Smartf1126682009-06-10 17:22:44 -040010806 if (phba->sli_rev == LPFC_SLI_REV4) {
10807 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -040010808 return 10;
James Smartf1126682009-06-10 17:22:44 -040010809 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -040010810 return 25;
James Smartf1126682009-06-10 17:22:44 -040010811 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -040010812 return 50;
James Smartf1126682009-06-10 17:22:44 -040010813 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -040010814 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -040010815 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -040010816 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -040010817 else if (max_xri <= 2048)
10818 return 200;
10819 else
10820 return 250;
James Smartf1126682009-06-10 17:22:44 -040010821 } else
10822 return 0;
James Smartda0436e2009-05-22 14:51:39 -040010823}
10824
10825/**
James Smart895427b2017-02-12 13:52:30 -080010826 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
10827 * @phba: pointer to lpfc hba data structure.
10828 *
James Smartf358dd02017-02-12 13:52:34 -080010829 * returns the number of ELS/CT + NVMET IOCBs to reserve
James Smart895427b2017-02-12 13:52:30 -080010830 **/
10831int
10832lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
10833{
10834 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
10835
James Smartf358dd02017-02-12 13:52:34 -080010836 if (phba->nvmet_support)
10837 max_xri += LPFC_NVMET_BUF_POST;
James Smart895427b2017-02-12 13:52:30 -080010838 return max_xri;
10839}
10840
10841
10842/**
James Smart52d52442011-05-24 11:42:45 -040010843 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -040010844 * @fw: pointer to firmware image returned from request_firmware.
James Smartce396282012-09-29 11:30:56 -040010845 * @phba: pointer to lpfc hba data structure.
James Smart52d52442011-05-24 11:42:45 -040010846 *
James Smart52d52442011-05-24 11:42:45 -040010847 **/
James Smartce396282012-09-29 11:30:56 -040010848static void
10849lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -040010850{
James Smartce396282012-09-29 11:30:56 -040010851 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -050010852 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -040010853 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -040010854 struct list_head dma_buffer_list;
10855 int i, rc = 0;
10856 struct lpfc_dmabuf *dmabuf, *next;
10857 uint32_t offset = 0, temp_offset = 0;
James Smart6b6ef5d2016-10-13 15:06:17 -070010858 uint32_t magic_number, ftype, fid, fsize;
James Smart52d52442011-05-24 11:42:45 -040010859
James Smartc71ab862012-10-31 14:44:33 -040010860 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -040010861 if (!fw) {
10862 rc = -ENXIO;
10863 goto out;
10864 }
10865 image = (struct lpfc_grp_hdr *)fw->data;
10866
James Smart6b6ef5d2016-10-13 15:06:17 -070010867 magic_number = be32_to_cpu(image->magic_number);
10868 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
10869 fid = bf_get_be32(lpfc_grp_hdr_id, image),
10870 fsize = be32_to_cpu(image->size);
10871
James Smart52d52442011-05-24 11:42:45 -040010872 INIT_LIST_HEAD(&dma_buffer_list);
James Smart6b6ef5d2016-10-13 15:06:17 -070010873 if ((magic_number != LPFC_GROUP_OJECT_MAGIC_G5 &&
10874 magic_number != LPFC_GROUP_OJECT_MAGIC_G6) ||
10875 ftype != LPFC_FILE_TYPE_GROUP || fsize != fw->size) {
James Smart52d52442011-05-24 11:42:45 -040010876 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10877 "3022 Invalid FW image found. "
Arnd Bergmannefe583c2016-10-17 14:35:46 +020010878 "Magic:%x Type:%x ID:%x Size %d %zd\n",
James Smart6b6ef5d2016-10-13 15:06:17 -070010879 magic_number, ftype, fid, fsize, fw->size);
James Smartce396282012-09-29 11:30:56 -040010880 rc = -EINVAL;
10881 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010882 }
10883 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -040010884 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -040010885 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartce396282012-09-29 11:30:56 -040010886 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -040010887 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -040010888 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -040010889 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
10890 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
10891 GFP_KERNEL);
10892 if (!dmabuf) {
10893 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040010894 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010895 }
10896 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
10897 SLI4_PAGE_SIZE,
10898 &dmabuf->phys,
10899 GFP_KERNEL);
10900 if (!dmabuf->virt) {
10901 kfree(dmabuf);
10902 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040010903 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010904 }
10905 list_add_tail(&dmabuf->list, &dma_buffer_list);
10906 }
10907 while (offset < fw->size) {
10908 temp_offset = offset;
10909 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -040010910 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -040010911 memcpy(dmabuf->virt,
10912 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -040010913 fw->size - temp_offset);
10914 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -040010915 break;
10916 }
James Smart52d52442011-05-24 11:42:45 -040010917 memcpy(dmabuf->virt, fw->data + temp_offset,
10918 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -040010919 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -040010920 }
10921 rc = lpfc_wr_object(phba, &dma_buffer_list,
10922 (fw->size - offset), &offset);
James Smartce396282012-09-29 11:30:56 -040010923 if (rc)
10924 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010925 }
10926 rc = offset;
10927 }
James Smartce396282012-09-29 11:30:56 -040010928
10929release_out:
James Smart52d52442011-05-24 11:42:45 -040010930 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
10931 list_del(&dmabuf->list);
10932 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
10933 dmabuf->virt, dmabuf->phys);
10934 kfree(dmabuf);
10935 }
James Smartce396282012-09-29 11:30:56 -040010936 release_firmware(fw);
10937out:
10938 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc71ab862012-10-31 14:44:33 -040010939 "3024 Firmware update done: %d.\n", rc);
James Smartce396282012-09-29 11:30:56 -040010940 return;
James Smart52d52442011-05-24 11:42:45 -040010941}
10942
10943/**
James Smartc71ab862012-10-31 14:44:33 -040010944 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
10945 * @phba: pointer to lpfc hba data structure.
10946 *
10947 * This routine is called to perform Linux generic firmware upgrade on device
10948 * that supports such feature.
10949 **/
10950int
10951lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
10952{
10953 uint8_t file_name[ELX_MODEL_NAME_SIZE];
10954 int ret;
10955 const struct firmware *fw;
10956
10957 /* Only supported on SLI4 interface type 2 for now */
10958 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
10959 LPFC_SLI_INTF_IF_TYPE_2)
10960 return -EPERM;
10961
10962 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
10963
10964 if (fw_upgrade == INT_FW_UPGRADE) {
10965 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
10966 file_name, &phba->pcidev->dev,
10967 GFP_KERNEL, (void *)phba,
10968 lpfc_write_firmware);
10969 } else if (fw_upgrade == RUN_FW_UPGRADE) {
10970 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
10971 if (!ret)
10972 lpfc_write_firmware(fw, (void *)phba);
10973 } else {
10974 ret = -EINVAL;
10975 }
10976
10977 return ret;
10978}
10979
10980/**
James Smartda0436e2009-05-22 14:51:39 -040010981 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
10982 * @pdev: pointer to PCI device
10983 * @pid: pointer to PCI device identifier
10984 *
10985 * This routine is called from the kernel's PCI subsystem to device with
10986 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10987 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10988 * information of the device and driver to see if the driver state that it
10989 * can support this kind of device. If the match is successful, the driver
10990 * core invokes this routine. If this routine determines it can claim the HBA,
10991 * it does all the initialization that it needs to do to handle the HBA
10992 * properly.
10993 *
10994 * Return code
10995 * 0 - driver can claim the device
10996 * negative value - driver can not claim the device
10997 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010998static int
James Smartda0436e2009-05-22 14:51:39 -040010999lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
11000{
11001 struct lpfc_hba *phba;
11002 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040011003 struct Scsi_Host *shost = NULL;
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040011004 int error;
James Smartda0436e2009-05-22 14:51:39 -040011005 uint32_t cfg_mode, intr_mode;
James Smartda0436e2009-05-22 14:51:39 -040011006
11007 /* Allocate memory for HBA structure */
11008 phba = lpfc_hba_alloc(pdev);
11009 if (!phba)
11010 return -ENOMEM;
11011
11012 /* Perform generic PCI device enabling operation */
11013 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040011014 if (error)
James Smartda0436e2009-05-22 14:51:39 -040011015 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -040011016
11017 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
11018 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
11019 if (error)
11020 goto out_disable_pci_dev;
11021
11022 /* Set up SLI-4 specific device PCI memory space */
11023 error = lpfc_sli4_pci_mem_setup(phba);
11024 if (error) {
11025 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11026 "1410 Failed to set up pci memory space.\n");
11027 goto out_disable_pci_dev;
11028 }
11029
James Smartda0436e2009-05-22 14:51:39 -040011030 /* Set up SLI-4 Specific device driver resources */
11031 error = lpfc_sli4_driver_resource_setup(phba);
11032 if (error) {
11033 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11034 "1412 Failed to set up driver resource.\n");
11035 goto out_unset_pci_mem_s4;
11036 }
11037
11038 /* Initialize and populate the iocb list per host */
James Smart2a9bf3d2010-06-07 15:24:45 -040011039
11040 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11041 "2821 initialize iocb list %d.\n",
11042 phba->cfg_iocb_cnt*1024);
11043 error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
11044
James Smartda0436e2009-05-22 14:51:39 -040011045 if (error) {
11046 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11047 "1413 Failed to initialize iocb list.\n");
11048 goto out_unset_driver_resource_s4;
11049 }
11050
James Smart19ca7602010-11-20 23:11:55 -050011051 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -040011052 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -050011053
James Smartda0436e2009-05-22 14:51:39 -040011054 /* Set up common device driver resources */
11055 error = lpfc_setup_driver_resource_phase2(phba);
11056 if (error) {
11057 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11058 "1414 Failed to set up driver resource.\n");
11059 goto out_free_iocb_list;
11060 }
11061
James Smart079b5c92011-08-21 21:48:49 -040011062 /* Get the default values for Model Name and Description */
11063 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
11064
James Smartda0436e2009-05-22 14:51:39 -040011065 /* Create SCSI host to the physical port */
11066 error = lpfc_create_shost(phba);
11067 if (error) {
11068 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11069 "1415 Failed to create scsi host.\n");
11070 goto out_unset_driver_resource;
11071 }
11072
11073 /* Configure sysfs attributes */
11074 vport = phba->pport;
11075 error = lpfc_alloc_sysfs_attr(vport);
11076 if (error) {
11077 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11078 "1416 Failed to allocate sysfs attr\n");
11079 goto out_destroy_shost;
11080 }
11081
James Smart6669f9b2009-10-02 15:16:45 -040011082 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -040011083 /* Now, trying to enable interrupt and bring up the device */
11084 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -040011085
James Smart7b15db32013-01-03 15:43:29 -050011086 /* Put device to a known state before enabling interrupt */
11087 lpfc_stop_port(phba);
James Smart895427b2017-02-12 13:52:30 -080011088
James Smart7b15db32013-01-03 15:43:29 -050011089 /* Configure and enable interrupt */
11090 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
11091 if (intr_mode == LPFC_INTR_ERROR) {
11092 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11093 "0426 Failed to enable interrupt.\n");
11094 error = -ENODEV;
11095 goto out_free_sysfs_attr;
James Smartda0436e2009-05-22 14:51:39 -040011096 }
James Smart7b15db32013-01-03 15:43:29 -050011097 /* Default to single EQ for non-MSI-X */
James Smart895427b2017-02-12 13:52:30 -080011098 if (phba->intr_type != MSIX) {
11099 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
11100 phba->cfg_fcp_io_channel = 1;
James Smart2d7dbc42017-02-12 13:52:35 -080011101 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
James Smart895427b2017-02-12 13:52:30 -080011102 phba->cfg_nvme_io_channel = 1;
James Smart2d7dbc42017-02-12 13:52:35 -080011103 if (phba->nvmet_support)
11104 phba->cfg_nvmet_mrq = 1;
11105 }
James Smart895427b2017-02-12 13:52:30 -080011106 phba->io_channel_irqs = 1;
11107 }
11108
James Smart7b15db32013-01-03 15:43:29 -050011109 /* Set up SLI-4 HBA */
11110 if (lpfc_sli4_hba_setup(phba)) {
11111 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11112 "1421 Failed to set up hba\n");
11113 error = -ENODEV;
11114 goto out_disable_intr;
11115 }
11116
11117 /* Log the current active interrupt mode */
11118 phba->intr_mode = intr_mode;
11119 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -040011120
11121 /* Perform post initialization setup */
11122 lpfc_post_init_setup(phba);
11123
James Smart01649562017-02-12 13:52:32 -080011124 /* NVME support in FW earlier in the driver load corrects the
11125 * FC4 type making a check for nvme_support unnecessary.
11126 */
11127 if ((phba->nvmet_support == 0) &&
11128 (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
11129 /* Create NVME binding with nvme_fc_transport. This
11130 * ensures the vport is initialized.
11131 */
11132 error = lpfc_nvme_create_localport(vport);
11133 if (error) {
11134 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11135 "6004 NVME registration failed, "
11136 "error x%x\n",
11137 error);
11138 goto out_disable_intr;
11139 }
11140 }
James Smart895427b2017-02-12 13:52:30 -080011141
James Smartc71ab862012-10-31 14:44:33 -040011142 /* check for firmware upgrade or downgrade */
11143 if (phba->cfg_request_firmware_upgrade)
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040011144 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -040011145
James Smart1c6834a2009-07-19 10:01:26 -040011146 /* Check if there are static vports to be created. */
11147 lpfc_create_static_vport(phba);
James Smartda0436e2009-05-22 14:51:39 -040011148 return 0;
11149
11150out_disable_intr:
11151 lpfc_sli4_disable_intr(phba);
11152out_free_sysfs_attr:
11153 lpfc_free_sysfs_attr(vport);
11154out_destroy_shost:
11155 lpfc_destroy_shost(phba);
11156out_unset_driver_resource:
11157 lpfc_unset_driver_resource_phase2(phba);
11158out_free_iocb_list:
11159 lpfc_free_iocb_list(phba);
11160out_unset_driver_resource_s4:
11161 lpfc_sli4_driver_resource_unset(phba);
11162out_unset_pci_mem_s4:
11163 lpfc_sli4_pci_mem_unset(phba);
11164out_disable_pci_dev:
11165 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040011166 if (shost)
11167 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -040011168out_free_phba:
11169 lpfc_hba_free(phba);
11170 return error;
11171}
11172
11173/**
11174 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
11175 * @pdev: pointer to PCI device
11176 *
11177 * This routine is called from the kernel's PCI subsystem to device with
11178 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
11179 * removed from PCI bus, it performs all the necessary cleanup for the HBA
11180 * device to be removed from the PCI subsystem properly.
11181 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011182static void
James Smartda0436e2009-05-22 14:51:39 -040011183lpfc_pci_remove_one_s4(struct pci_dev *pdev)
11184{
11185 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11186 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
11187 struct lpfc_vport **vports;
11188 struct lpfc_hba *phba = vport->phba;
11189 int i;
11190
11191 /* Mark the device unloading flag */
11192 spin_lock_irq(&phba->hbalock);
11193 vport->load_flag |= FC_UNLOADING;
11194 spin_unlock_irq(&phba->hbalock);
11195
11196 /* Free the HBA sysfs attributes */
11197 lpfc_free_sysfs_attr(vport);
11198
11199 /* Release all the vports against this physical port */
11200 vports = lpfc_create_vport_work_array(phba);
11201 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040011202 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
11203 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
11204 continue;
James Smartda0436e2009-05-22 14:51:39 -040011205 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040011206 }
James Smartda0436e2009-05-22 14:51:39 -040011207 lpfc_destroy_vport_work_array(phba, vports);
11208
11209 /* Remove FC host and then SCSI host with the physical port */
11210 fc_remove_host(shost);
11211 scsi_remove_host(shost);
11212
James Smartd613b6a2017-02-12 13:52:37 -080011213 /* Perform ndlp cleanup on the physical port. The nvme and nvmet
11214 * localports are destroyed after to cleanup all transport memory.
James Smart895427b2017-02-12 13:52:30 -080011215 */
James Smartda0436e2009-05-22 14:51:39 -040011216 lpfc_cleanup(vport);
James Smartd613b6a2017-02-12 13:52:37 -080011217 lpfc_nvmet_destroy_targetport(phba);
11218 lpfc_nvme_destroy_localport(vport);
James Smartda0436e2009-05-22 14:51:39 -040011219
11220 /*
11221 * Bring down the SLI Layer. This step disables all interrupts,
11222 * clears the rings, discards all mailbox commands, and resets
11223 * the HBA FCoE function.
11224 */
11225 lpfc_debugfs_terminate(vport);
11226 lpfc_sli4_hba_unset(phba);
11227
11228 spin_lock_irq(&phba->hbalock);
11229 list_del_init(&vport->listentry);
11230 spin_unlock_irq(&phba->hbalock);
11231
James Smart3677a3a2010-09-29 11:19:14 -040011232 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -040011233 * buffers are released to their corresponding pools here.
11234 */
11235 lpfc_scsi_free(phba);
James Smart895427b2017-02-12 13:52:30 -080011236 lpfc_nvme_free(phba);
James Smart01649562017-02-12 13:52:32 -080011237 lpfc_free_iocb_list(phba);
James Smart67d12732012-08-03 12:36:13 -040011238
James Smartda0436e2009-05-22 14:51:39 -040011239 lpfc_sli4_driver_resource_unset(phba);
11240
11241 /* Unmap adapter Control and Doorbell registers */
11242 lpfc_sli4_pci_mem_unset(phba);
11243
11244 /* Release PCI resources and disable device's PCI function */
11245 scsi_host_put(shost);
11246 lpfc_disable_pci_dev(phba);
11247
11248 /* Finally, free the driver's device data structure */
11249 lpfc_hba_free(phba);
11250
11251 return;
11252}
11253
11254/**
11255 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
11256 * @pdev: pointer to PCI device
11257 * @msg: power management message
11258 *
11259 * This routine is called from the kernel's PCI subsystem to support system
11260 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
11261 * this method, it quiesces the device by stopping the driver's worker
11262 * thread for the device, turning off device's interrupt and DMA, and bring
11263 * the device offline. Note that as the driver implements the minimum PM
11264 * requirements to a power-aware driver's PM support for suspend/resume -- all
11265 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
11266 * method call will be treated as SUSPEND and the driver will fully
11267 * reinitialize its device during resume() method call, the driver will set
11268 * device to PCI_D3hot state in PCI config space instead of setting it
11269 * according to the @msg provided by the PM.
11270 *
11271 * Return code
11272 * 0 - driver suspended the device
11273 * Error otherwise
11274 **/
11275static int
11276lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
11277{
11278 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11279 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11280
11281 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -040011282 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -040011283
11284 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040011285 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -040011286 lpfc_offline(phba);
11287 kthread_stop(phba->worker_thread);
11288
11289 /* Disable interrupt from device */
11290 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040011291 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040011292
11293 /* Save device state to PCI config space */
11294 pci_save_state(pdev);
11295 pci_set_power_state(pdev, PCI_D3hot);
11296
11297 return 0;
11298}
11299
11300/**
11301 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
11302 * @pdev: pointer to PCI device
11303 *
11304 * This routine is called from the kernel's PCI subsystem to support system
11305 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
11306 * this method, it restores the device's PCI config space state and fully
11307 * reinitializes the device and brings it online. Note that as the driver
11308 * implements the minimum PM requirements to a power-aware driver's PM for
11309 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
11310 * to the suspend() method call will be treated as SUSPEND and the driver
11311 * will fully reinitialize its device during resume() method call, the device
11312 * will be set to PCI_D0 directly in PCI config space before restoring the
11313 * state.
11314 *
11315 * Return code
11316 * 0 - driver suspended the device
11317 * Error otherwise
11318 **/
11319static int
11320lpfc_pci_resume_one_s4(struct pci_dev *pdev)
11321{
11322 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11323 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11324 uint32_t intr_mode;
11325 int error;
11326
11327 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
11328 "0292 PCI device Power Management resume.\n");
11329
11330 /* Restore device state from PCI config space */
11331 pci_set_power_state(pdev, PCI_D0);
11332 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050011333
11334 /*
11335 * As the new kernel behavior of pci_restore_state() API call clears
11336 * device saved_state flag, need to save the restored state again.
11337 */
11338 pci_save_state(pdev);
11339
James Smartda0436e2009-05-22 14:51:39 -040011340 if (pdev->is_busmaster)
11341 pci_set_master(pdev);
11342
11343 /* Startup the kernel thread for this host adapter. */
11344 phba->worker_thread = kthread_run(lpfc_do_work, phba,
11345 "lpfc_worker_%d", phba->brd_no);
11346 if (IS_ERR(phba->worker_thread)) {
11347 error = PTR_ERR(phba->worker_thread);
11348 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11349 "0293 PM resume failed to start worker "
11350 "thread: error=x%x.\n", error);
11351 return error;
11352 }
11353
11354 /* Configure and enable interrupt */
11355 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
11356 if (intr_mode == LPFC_INTR_ERROR) {
11357 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11358 "0294 PM resume Failed to enable interrupt\n");
11359 return -EIO;
11360 } else
11361 phba->intr_mode = intr_mode;
11362
11363 /* Restart HBA and bring it online */
11364 lpfc_sli_brdrestart(phba);
11365 lpfc_online(phba);
11366
11367 /* Log the current active interrupt mode */
11368 lpfc_log_intr_mode(phba, phba->intr_mode);
11369
11370 return 0;
11371}
11372
11373/**
James Smart75baf692010-06-08 18:31:21 -040011374 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
11375 * @phba: pointer to lpfc hba data structure.
11376 *
11377 * This routine is called to prepare the SLI4 device for PCI slot recover. It
11378 * aborts all the outstanding SCSI I/Os to the pci device.
11379 **/
11380static void
11381lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
11382{
James Smart75baf692010-06-08 18:31:21 -040011383 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11384 "2828 PCI channel I/O abort preparing for recovery\n");
11385 /*
11386 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
11387 * and let the SCSI mid-layer to retry them to recover.
11388 */
James Smartdb55fba2014-04-04 13:52:02 -040011389 lpfc_sli_abort_fcp_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040011390}
11391
11392/**
11393 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
11394 * @phba: pointer to lpfc hba data structure.
11395 *
11396 * This routine is called to prepare the SLI4 device for PCI slot reset. It
11397 * disables the device interrupt and pci device, and aborts the internal FCP
11398 * pending I/Os.
11399 **/
11400static void
11401lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
11402{
11403 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11404 "2826 PCI channel disable preparing for reset\n");
11405
11406 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040011407 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -040011408
11409 /* Block all SCSI devices' I/Os on the host */
11410 lpfc_scsi_dev_block(phba);
11411
James Smartea714f32013-04-17 20:18:47 -040011412 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
11413 lpfc_sli_flush_fcp_rings(phba);
11414
James Smart75baf692010-06-08 18:31:21 -040011415 /* stop all timers */
11416 lpfc_stop_hba_timers(phba);
11417
11418 /* Disable interrupt and pci device */
11419 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040011420 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -040011421 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -040011422}
11423
11424/**
11425 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
11426 * @phba: pointer to lpfc hba data structure.
11427 *
11428 * This routine is called to prepare the SLI4 device for PCI slot permanently
11429 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
11430 * pending I/Os.
11431 **/
11432static void
11433lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
11434{
11435 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11436 "2827 PCI channel permanent disable for failure\n");
11437
11438 /* Block all SCSI devices' I/Os on the host */
11439 lpfc_scsi_dev_block(phba);
11440
11441 /* stop all timers */
11442 lpfc_stop_hba_timers(phba);
11443
11444 /* Clean up all driver's outstanding SCSI I/Os */
11445 lpfc_sli_flush_fcp_rings(phba);
11446}
11447
11448/**
James Smartda0436e2009-05-22 14:51:39 -040011449 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
11450 * @pdev: pointer to PCI device.
11451 * @state: the current PCI connection state.
11452 *
11453 * This routine is called from the PCI subsystem for error handling to device
11454 * with SLI-4 interface spec. This function is called by the PCI subsystem
11455 * after a PCI bus error affecting this device has been detected. When this
11456 * function is invoked, it will need to stop all the I/Os and interrupt(s)
11457 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
11458 * for the PCI subsystem to perform proper recovery as desired.
11459 *
11460 * Return codes
11461 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11462 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11463 **/
11464static pci_ers_result_t
11465lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
11466{
James Smart75baf692010-06-08 18:31:21 -040011467 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11468 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11469
11470 switch (state) {
11471 case pci_channel_io_normal:
11472 /* Non-fatal error, prepare for recovery */
11473 lpfc_sli4_prep_dev_for_recover(phba);
11474 return PCI_ERS_RESULT_CAN_RECOVER;
11475 case pci_channel_io_frozen:
11476 /* Fatal error, prepare for slot reset */
11477 lpfc_sli4_prep_dev_for_reset(phba);
11478 return PCI_ERS_RESULT_NEED_RESET;
11479 case pci_channel_io_perm_failure:
11480 /* Permanent failure, prepare for device down */
11481 lpfc_sli4_prep_dev_for_perm_failure(phba);
11482 return PCI_ERS_RESULT_DISCONNECT;
11483 default:
11484 /* Unknown state, prepare and request slot reset */
11485 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11486 "2825 Unknown PCI error state: x%x\n", state);
11487 lpfc_sli4_prep_dev_for_reset(phba);
11488 return PCI_ERS_RESULT_NEED_RESET;
11489 }
James Smartda0436e2009-05-22 14:51:39 -040011490}
11491
11492/**
11493 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
11494 * @pdev: pointer to PCI device.
11495 *
11496 * This routine is called from the PCI subsystem for error handling to device
11497 * with SLI-4 interface spec. It is called after PCI bus has been reset to
11498 * restart the PCI card from scratch, as if from a cold-boot. During the
11499 * PCI subsystem error recovery, after the driver returns
11500 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
11501 * recovery and then call this routine before calling the .resume method to
11502 * recover the device. This function will initialize the HBA device, enable
11503 * the interrupt, but it will just put the HBA to offline state without
11504 * passing any I/O traffic.
11505 *
11506 * Return codes
11507 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11508 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11509 */
11510static pci_ers_result_t
11511lpfc_io_slot_reset_s4(struct pci_dev *pdev)
11512{
James Smart75baf692010-06-08 18:31:21 -040011513 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11514 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11515 struct lpfc_sli *psli = &phba->sli;
11516 uint32_t intr_mode;
11517
11518 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
11519 if (pci_enable_device_mem(pdev)) {
11520 printk(KERN_ERR "lpfc: Cannot re-enable "
11521 "PCI device after reset.\n");
11522 return PCI_ERS_RESULT_DISCONNECT;
11523 }
11524
11525 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040011526
11527 /*
11528 * As the new kernel behavior of pci_restore_state() API call clears
11529 * device saved_state flag, need to save the restored state again.
11530 */
11531 pci_save_state(pdev);
11532
James Smart75baf692010-06-08 18:31:21 -040011533 if (pdev->is_busmaster)
11534 pci_set_master(pdev);
11535
11536 spin_lock_irq(&phba->hbalock);
11537 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
11538 spin_unlock_irq(&phba->hbalock);
11539
11540 /* Configure and enable interrupt */
11541 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
11542 if (intr_mode == LPFC_INTR_ERROR) {
11543 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11544 "2824 Cannot re-enable interrupt after "
11545 "slot reset.\n");
11546 return PCI_ERS_RESULT_DISCONNECT;
11547 } else
11548 phba->intr_mode = intr_mode;
11549
11550 /* Log the current active interrupt mode */
11551 lpfc_log_intr_mode(phba, phba->intr_mode);
11552
James Smartda0436e2009-05-22 14:51:39 -040011553 return PCI_ERS_RESULT_RECOVERED;
11554}
11555
11556/**
11557 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
11558 * @pdev: pointer to PCI device
11559 *
11560 * This routine is called from the PCI subsystem for error handling to device
11561 * with SLI-4 interface spec. It is called when kernel error recovery tells
11562 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
11563 * error recovery. After this call, traffic can start to flow from this device
11564 * again.
11565 **/
11566static void
11567lpfc_io_resume_s4(struct pci_dev *pdev)
11568{
James Smart75baf692010-06-08 18:31:21 -040011569 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11570 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11571
11572 /*
11573 * In case of slot reset, as function reset is performed through
11574 * mailbox command which needs DMA to be enabled, this operation
11575 * has to be moved to the io resume phase. Taking device offline
11576 * will perform the necessary cleanup.
11577 */
11578 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
11579 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040011580 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040011581 lpfc_offline(phba);
11582 lpfc_sli_brdrestart(phba);
11583 /* Bring the device back online */
11584 lpfc_online(phba);
11585 }
11586
11587 /* Clean up Advanced Error Reporting (AER) if needed */
11588 if (phba->hba_flag & HBA_AER_ENABLED)
11589 pci_cleanup_aer_uncorrect_error_status(pdev);
James Smartda0436e2009-05-22 14:51:39 -040011590}
11591
11592/**
James Smart3772a992009-05-22 14:50:54 -040011593 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
11594 * @pdev: pointer to PCI device
11595 * @pid: pointer to PCI device identifier
11596 *
11597 * This routine is to be registered to the kernel's PCI subsystem. When an
11598 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
11599 * at PCI device-specific information of the device and driver to see if the
11600 * driver state that it can support this kind of device. If the match is
11601 * successful, the driver core invokes this routine. This routine dispatches
11602 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
11603 * do all the initialization that it needs to do to handle the HBA device
11604 * properly.
11605 *
11606 * Return code
11607 * 0 - driver can claim the device
11608 * negative value - driver can not claim the device
11609 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011610static int
James Smart3772a992009-05-22 14:50:54 -040011611lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
11612{
11613 int rc;
James Smart8fa38512009-07-19 10:01:03 -040011614 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040011615
James Smart28baac72010-02-12 14:42:03 -050011616 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040011617 return -ENODEV;
11618
James Smart8fa38512009-07-19 10:01:03 -040011619 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050011620 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040011621 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040011622 else
James Smart3772a992009-05-22 14:50:54 -040011623 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040011624
James Smart3772a992009-05-22 14:50:54 -040011625 return rc;
11626}
11627
11628/**
11629 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
11630 * @pdev: pointer to PCI device
11631 *
11632 * This routine is to be registered to the kernel's PCI subsystem. When an
11633 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
11634 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
11635 * remove routine, which will perform all the necessary cleanup for the
11636 * device to be removed from the PCI subsystem properly.
11637 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011638static void
James Smart3772a992009-05-22 14:50:54 -040011639lpfc_pci_remove_one(struct pci_dev *pdev)
11640{
11641 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11642 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11643
11644 switch (phba->pci_dev_grp) {
11645 case LPFC_PCI_DEV_LP:
11646 lpfc_pci_remove_one_s3(pdev);
11647 break;
James Smartda0436e2009-05-22 14:51:39 -040011648 case LPFC_PCI_DEV_OC:
11649 lpfc_pci_remove_one_s4(pdev);
11650 break;
James Smart3772a992009-05-22 14:50:54 -040011651 default:
11652 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11653 "1424 Invalid PCI device group: 0x%x\n",
11654 phba->pci_dev_grp);
11655 break;
11656 }
11657 return;
11658}
11659
11660/**
11661 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
11662 * @pdev: pointer to PCI device
11663 * @msg: power management message
11664 *
11665 * This routine is to be registered to the kernel's PCI subsystem to support
11666 * system Power Management (PM). When PM invokes this method, it dispatches
11667 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
11668 * suspend the device.
11669 *
11670 * Return code
11671 * 0 - driver suspended the device
11672 * Error otherwise
11673 **/
11674static int
11675lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
11676{
11677 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11678 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11679 int rc = -ENODEV;
11680
11681 switch (phba->pci_dev_grp) {
11682 case LPFC_PCI_DEV_LP:
11683 rc = lpfc_pci_suspend_one_s3(pdev, msg);
11684 break;
James Smartda0436e2009-05-22 14:51:39 -040011685 case LPFC_PCI_DEV_OC:
11686 rc = lpfc_pci_suspend_one_s4(pdev, msg);
11687 break;
James Smart3772a992009-05-22 14:50:54 -040011688 default:
11689 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11690 "1425 Invalid PCI device group: 0x%x\n",
11691 phba->pci_dev_grp);
11692 break;
11693 }
11694 return rc;
11695}
11696
11697/**
11698 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
11699 * @pdev: pointer to PCI device
11700 *
11701 * This routine is to be registered to the kernel's PCI subsystem to support
11702 * system Power Management (PM). When PM invokes this method, it dispatches
11703 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
11704 * resume the device.
11705 *
11706 * Return code
11707 * 0 - driver suspended the device
11708 * Error otherwise
11709 **/
11710static int
11711lpfc_pci_resume_one(struct pci_dev *pdev)
11712{
11713 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11714 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11715 int rc = -ENODEV;
11716
11717 switch (phba->pci_dev_grp) {
11718 case LPFC_PCI_DEV_LP:
11719 rc = lpfc_pci_resume_one_s3(pdev);
11720 break;
James Smartda0436e2009-05-22 14:51:39 -040011721 case LPFC_PCI_DEV_OC:
11722 rc = lpfc_pci_resume_one_s4(pdev);
11723 break;
James Smart3772a992009-05-22 14:50:54 -040011724 default:
11725 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11726 "1426 Invalid PCI device group: 0x%x\n",
11727 phba->pci_dev_grp);
11728 break;
11729 }
11730 return rc;
11731}
11732
11733/**
11734 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
11735 * @pdev: pointer to PCI device.
11736 * @state: the current PCI connection state.
11737 *
11738 * This routine is registered to the PCI subsystem for error handling. This
11739 * function is called by the PCI subsystem after a PCI bus error affecting
11740 * this device has been detected. When this routine is invoked, it dispatches
11741 * the action to the proper SLI-3 or SLI-4 device error detected handling
11742 * routine, which will perform the proper error detected operation.
11743 *
11744 * Return codes
11745 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11746 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11747 **/
11748static pci_ers_result_t
11749lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
11750{
11751 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11752 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11753 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11754
11755 switch (phba->pci_dev_grp) {
11756 case LPFC_PCI_DEV_LP:
11757 rc = lpfc_io_error_detected_s3(pdev, state);
11758 break;
James Smartda0436e2009-05-22 14:51:39 -040011759 case LPFC_PCI_DEV_OC:
11760 rc = lpfc_io_error_detected_s4(pdev, state);
11761 break;
James Smart3772a992009-05-22 14:50:54 -040011762 default:
11763 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11764 "1427 Invalid PCI device group: 0x%x\n",
11765 phba->pci_dev_grp);
11766 break;
11767 }
11768 return rc;
11769}
11770
11771/**
11772 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
11773 * @pdev: pointer to PCI device.
11774 *
11775 * This routine is registered to the PCI subsystem for error handling. This
11776 * function is called after PCI bus has been reset to restart the PCI card
11777 * from scratch, as if from a cold-boot. When this routine is invoked, it
11778 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
11779 * routine, which will perform the proper device reset.
11780 *
11781 * Return codes
11782 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11783 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11784 **/
11785static pci_ers_result_t
11786lpfc_io_slot_reset(struct pci_dev *pdev)
11787{
11788 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11789 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11790 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11791
11792 switch (phba->pci_dev_grp) {
11793 case LPFC_PCI_DEV_LP:
11794 rc = lpfc_io_slot_reset_s3(pdev);
11795 break;
James Smartda0436e2009-05-22 14:51:39 -040011796 case LPFC_PCI_DEV_OC:
11797 rc = lpfc_io_slot_reset_s4(pdev);
11798 break;
James Smart3772a992009-05-22 14:50:54 -040011799 default:
11800 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11801 "1428 Invalid PCI device group: 0x%x\n",
11802 phba->pci_dev_grp);
11803 break;
11804 }
11805 return rc;
11806}
11807
11808/**
11809 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
11810 * @pdev: pointer to PCI device
11811 *
11812 * This routine is registered to the PCI subsystem for error handling. It
11813 * is called when kernel error recovery tells the lpfc driver that it is
11814 * OK to resume normal PCI operation after PCI bus error recovery. When
11815 * this routine is invoked, it dispatches the action to the proper SLI-3
11816 * or SLI-4 device io_resume routine, which will resume the device operation.
11817 **/
11818static void
11819lpfc_io_resume(struct pci_dev *pdev)
11820{
11821 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11822 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11823
11824 switch (phba->pci_dev_grp) {
11825 case LPFC_PCI_DEV_LP:
11826 lpfc_io_resume_s3(pdev);
11827 break;
James Smartda0436e2009-05-22 14:51:39 -040011828 case LPFC_PCI_DEV_OC:
11829 lpfc_io_resume_s4(pdev);
11830 break;
James Smart3772a992009-05-22 14:50:54 -040011831 default:
11832 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11833 "1429 Invalid PCI device group: 0x%x\n",
11834 phba->pci_dev_grp);
11835 break;
11836 }
11837 return;
11838}
11839
James Smart1ba981f2014-02-20 09:56:45 -050011840/**
11841 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
11842 * @phba: pointer to lpfc hba data structure.
11843 *
11844 * This routine checks to see if OAS is supported for this adapter. If
11845 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
11846 * the enable oas flag is cleared and the pool created for OAS device data
11847 * is destroyed.
11848 *
11849 **/
11850void
11851lpfc_sli4_oas_verify(struct lpfc_hba *phba)
11852{
11853
11854 if (!phba->cfg_EnableXLane)
11855 return;
11856
11857 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
11858 phba->cfg_fof = 1;
11859 } else {
James Smartf38fa0b2014-04-04 13:52:21 -040011860 phba->cfg_fof = 0;
James Smart1ba981f2014-02-20 09:56:45 -050011861 if (phba->device_data_mem_pool)
11862 mempool_destroy(phba->device_data_mem_pool);
11863 phba->device_data_mem_pool = NULL;
11864 }
11865
11866 return;
11867}
11868
11869/**
11870 * lpfc_fof_queue_setup - Set up all the fof queues
11871 * @phba: pointer to lpfc hba data structure.
11872 *
11873 * This routine is invoked to set up all the fof queues for the FC HBA
11874 * operation.
11875 *
11876 * Return codes
11877 * 0 - successful
11878 * -ENOMEM - No available memory
11879 **/
11880int
11881lpfc_fof_queue_setup(struct lpfc_hba *phba)
11882{
James Smart895427b2017-02-12 13:52:30 -080011883 struct lpfc_sli_ring *pring;
James Smart1ba981f2014-02-20 09:56:45 -050011884 int rc;
11885
11886 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
11887 if (rc)
11888 return -ENOMEM;
11889
James Smartf38fa0b2014-04-04 13:52:21 -040011890 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050011891
11892 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
11893 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
11894 if (rc)
11895 goto out_oas_cq;
11896
11897 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
11898 phba->sli4_hba.oas_cq, LPFC_FCP);
11899 if (rc)
11900 goto out_oas_wq;
11901
James Smart895427b2017-02-12 13:52:30 -080011902 /* Bind this CQ/WQ to the NVME ring */
11903 pring = phba->sli4_hba.oas_wq->pring;
11904 pring->sli.sli4.wqp =
11905 (void *)phba->sli4_hba.oas_wq;
11906 phba->sli4_hba.oas_cq->pring = pring;
James Smart1ba981f2014-02-20 09:56:45 -050011907 }
11908
11909 return 0;
11910
11911out_oas_wq:
James Smartf38fa0b2014-04-04 13:52:21 -040011912 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
James Smart1ba981f2014-02-20 09:56:45 -050011913out_oas_cq:
11914 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
11915 return rc;
11916
11917}
11918
11919/**
11920 * lpfc_fof_queue_create - Create all the fof queues
11921 * @phba: pointer to lpfc hba data structure.
11922 *
11923 * This routine is invoked to allocate all the fof queues for the FC HBA
11924 * operation. For each SLI4 queue type, the parameters such as queue entry
11925 * count (queue depth) shall be taken from the module parameter. For now,
11926 * we just use some constant number as place holder.
11927 *
11928 * Return codes
11929 * 0 - successful
11930 * -ENOMEM - No availble memory
11931 * -EIO - The mailbox failed to complete successfully.
11932 **/
11933int
11934lpfc_fof_queue_create(struct lpfc_hba *phba)
11935{
11936 struct lpfc_queue *qdesc;
11937
11938 /* Create FOF EQ */
11939 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
11940 phba->sli4_hba.eq_ecount);
11941 if (!qdesc)
11942 goto out_error;
11943
11944 phba->sli4_hba.fof_eq = qdesc;
11945
James Smartf38fa0b2014-04-04 13:52:21 -040011946 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050011947
11948 /* Create OAS CQ */
11949 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
11950 phba->sli4_hba.cq_ecount);
11951 if (!qdesc)
11952 goto out_error;
11953
11954 phba->sli4_hba.oas_cq = qdesc;
11955
11956 /* Create OAS WQ */
11957 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
11958 phba->sli4_hba.wq_ecount);
11959 if (!qdesc)
11960 goto out_error;
11961
11962 phba->sli4_hba.oas_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -080011963 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
James Smart1ba981f2014-02-20 09:56:45 -050011964
11965 }
11966 return 0;
11967
11968out_error:
11969 lpfc_fof_queue_destroy(phba);
11970 return -ENOMEM;
11971}
11972
11973/**
11974 * lpfc_fof_queue_destroy - Destroy all the fof queues
11975 * @phba: pointer to lpfc hba data structure.
11976 *
11977 * This routine is invoked to release all the SLI4 queues with the FC HBA
11978 * operation.
11979 *
11980 * Return codes
11981 * 0 - successful
11982 **/
11983int
11984lpfc_fof_queue_destroy(struct lpfc_hba *phba)
11985{
11986 /* Release FOF Event queue */
11987 if (phba->sli4_hba.fof_eq != NULL) {
11988 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
11989 phba->sli4_hba.fof_eq = NULL;
11990 }
11991
11992 /* Release OAS Completion queue */
11993 if (phba->sli4_hba.oas_cq != NULL) {
11994 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
11995 phba->sli4_hba.oas_cq = NULL;
11996 }
11997
11998 /* Release OAS Work queue */
11999 if (phba->sli4_hba.oas_wq != NULL) {
12000 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
12001 phba->sli4_hba.oas_wq = NULL;
12002 }
12003 return 0;
12004}
12005
dea31012005-04-17 16:05:31 -050012006MODULE_DEVICE_TABLE(pci, lpfc_id_table);
12007
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070012008static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060012009 .error_detected = lpfc_io_error_detected,
12010 .slot_reset = lpfc_io_slot_reset,
12011 .resume = lpfc_io_resume,
12012};
12013
dea31012005-04-17 16:05:31 -050012014static struct pci_driver lpfc_driver = {
12015 .name = LPFC_DRIVER_NAME,
12016 .id_table = lpfc_id_table,
12017 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080012018 .remove = lpfc_pci_remove_one,
James Smart3a55b532008-12-04 22:38:54 -050012019 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040012020 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050012021 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050012022};
12023
James Smart3ef6d242012-01-18 16:23:48 -050012024static const struct file_operations lpfc_mgmt_fop = {
Al Viro858feac2013-04-14 22:39:37 -040012025 .owner = THIS_MODULE,
James Smart3ef6d242012-01-18 16:23:48 -050012026};
12027
12028static struct miscdevice lpfc_mgmt_dev = {
12029 .minor = MISC_DYNAMIC_MINOR,
12030 .name = "lpfcmgmt",
12031 .fops = &lpfc_mgmt_fop,
12032};
12033
James Smarte59058c2008-08-24 21:49:00 -040012034/**
James Smart3621a712009-04-06 18:47:14 -040012035 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040012036 *
12037 * This routine is to be invoked when the lpfc module is loaded into the
12038 * kernel. The special kernel macro module_init() is used to indicate the
12039 * role of this routine to the kernel as lpfc module entry point.
12040 *
12041 * Return codes
12042 * 0 - successful
12043 * -ENOMEM - FC attach transport failed
12044 * all others - failed
12045 */
dea31012005-04-17 16:05:31 -050012046static int __init
12047lpfc_init(void)
12048{
12049 int error = 0;
12050
12051 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012052 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050012053
James Smart3ef6d242012-01-18 16:23:48 -050012054 error = misc_register(&lpfc_mgmt_dev);
12055 if (error)
12056 printk(KERN_ERR "Could not register lpfcmgmt device, "
12057 "misc_register returned with status %d", error);
12058
James Smart458c0832016-07-06 12:36:07 -070012059 lpfc_transport_functions.vport_create = lpfc_vport_create;
12060 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
dea31012005-04-17 16:05:31 -050012061 lpfc_transport_template =
12062 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040012063 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050012064 return -ENOMEM;
James Smart458c0832016-07-06 12:36:07 -070012065 lpfc_vport_transport_template =
12066 fc_attach_transport(&lpfc_vport_transport_functions);
12067 if (lpfc_vport_transport_template == NULL) {
12068 fc_release_transport(lpfc_transport_template);
12069 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040012070 }
James Smart7bb03bb2013-04-17 20:19:16 -040012071
12072 /* Initialize in case vector mapping is needed */
James Smartb246de12013-05-31 17:03:07 -040012073 lpfc_used_cpu = NULL;
James Smart2ea259e2017-02-12 13:52:27 -080012074 lpfc_present_cpu = num_present_cpus();
James Smart7bb03bb2013-04-17 20:19:16 -040012075
dea31012005-04-17 16:05:31 -050012076 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050012077 if (error) {
dea31012005-04-17 16:05:31 -050012078 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070012079 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050012080 }
dea31012005-04-17 16:05:31 -050012081
12082 return error;
12083}
12084
James Smarte59058c2008-08-24 21:49:00 -040012085/**
James Smart3621a712009-04-06 18:47:14 -040012086 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040012087 *
12088 * This routine is invoked when the lpfc module is removed from the kernel.
12089 * The special kernel macro module_exit() is used to indicate the role of
12090 * this routine to the kernel as lpfc module exit point.
12091 */
dea31012005-04-17 16:05:31 -050012092static void __exit
12093lpfc_exit(void)
12094{
James Smart3ef6d242012-01-18 16:23:48 -050012095 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050012096 pci_unregister_driver(&lpfc_driver);
12097 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070012098 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050012099 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040012100 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
12101 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050012102 (1L << _dump_buf_data_order), _dump_buf_data);
12103 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
12104 }
12105
12106 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040012107 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
12108 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050012109 (1L << _dump_buf_dif_order), _dump_buf_dif);
12110 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
12111 }
James Smartb246de12013-05-31 17:03:07 -040012112 kfree(lpfc_used_cpu);
Johannes Thumshirn79739672015-08-31 16:48:11 -040012113 idr_destroy(&lpfc_hba_index);
dea31012005-04-17 16:05:31 -050012114}
12115
12116module_init(lpfc_init);
12117module_exit(lpfc_exit);
12118MODULE_LICENSE("GPL");
12119MODULE_DESCRIPTION(LPFC_MODULE_DESC);
12120MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
12121MODULE_VERSION("0:" LPFC_DRIVER_VERSION);