blob: 474bafc63055a12e7ae0dcbb0dad60538ab51b82 [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 *);
76static void lpfc_init_sgl_list(struct lpfc_hba *);
James Smartda0436e2009-05-22 14:51:39 -040077static int lpfc_init_active_sgl_array(struct lpfc_hba *);
78static void lpfc_free_active_sgl(struct lpfc_hba *);
79static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
80static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
81static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
82static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
83static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
James Smart618a5232012-06-12 13:54:36 -040084static void lpfc_sli4_disable_intr(struct lpfc_hba *);
85static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t);
James Smart1ba981f2014-02-20 09:56:45 -050086static void lpfc_sli4_oas_verify(struct lpfc_hba *phba);
dea31012005-04-17 16:05:31 -050087
88static struct scsi_transport_template *lpfc_transport_template = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -050089static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
dea31012005-04-17 16:05:31 -050090static DEFINE_IDR(lpfc_hba_index);
91
James Smarte59058c2008-08-24 21:49:00 -040092/**
James Smart3621a712009-04-06 18:47:14 -040093 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
James Smarte59058c2008-08-24 21:49:00 -040094 * @phba: pointer to lpfc hba data structure.
95 *
96 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
97 * mailbox command. It retrieves the revision information from the HBA and
98 * collects the Vital Product Data (VPD) about the HBA for preparing the
99 * configuration of the HBA.
100 *
101 * Return codes:
102 * 0 - success.
103 * -ERESTART - requests the SLI layer to reset the HBA and try again.
104 * Any other value - indicates an error.
105 **/
dea31012005-04-17 16:05:31 -0500106int
James Smart2e0fef82007-06-17 19:56:36 -0500107lpfc_config_port_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500108{
109 lpfc_vpd_t *vp = &phba->vpd;
110 int i = 0, rc;
111 LPFC_MBOXQ_t *pmb;
112 MAILBOX_t *mb;
113 char *lpfc_vpd_data = NULL;
114 uint16_t offset = 0;
115 static char licensed[56] =
116 "key unlock for use with gnu public licensed code only\0";
James Smart65a29c12006-07-06 15:50:50 -0400117 static int init_key = 1;
dea31012005-04-17 16:05:31 -0500118
119 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
120 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500121 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500122 return -ENOMEM;
123 }
124
James Smart04c68492009-05-22 14:52:52 -0400125 mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -0500126 phba->link_state = LPFC_INIT_MBX_CMDS;
dea31012005-04-17 16:05:31 -0500127
128 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
James Smart65a29c12006-07-06 15:50:50 -0400129 if (init_key) {
130 uint32_t *ptext = (uint32_t *) licensed;
dea31012005-04-17 16:05:31 -0500131
James Smart65a29c12006-07-06 15:50:50 -0400132 for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
133 *ptext = cpu_to_be32(*ptext);
134 init_key = 0;
135 }
dea31012005-04-17 16:05:31 -0500136
137 lpfc_read_nv(phba, pmb);
138 memset((char*)mb->un.varRDnvp.rsvd3, 0,
139 sizeof (mb->un.varRDnvp.rsvd3));
140 memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
141 sizeof (licensed));
142
143 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
144
145 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500146 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400147 "0324 Config Port initialization "
dea31012005-04-17 16:05:31 -0500148 "error, mbxCmd x%x READ_NVPARM, "
149 "mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500150 mb->mbxCommand, mb->mbxStatus);
151 mempool_free(pmb, phba->mbox_mem_pool);
152 return -ERESTART;
153 }
154 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
James Smart2e0fef82007-06-17 19:56:36 -0500155 sizeof(phba->wwnn));
156 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
157 sizeof(phba->wwpn));
dea31012005-04-17 16:05:31 -0500158 }
159
James Smart92d7f7b2007-06-17 19:56:38 -0500160 phba->sli3_options = 0x0;
161
dea31012005-04-17 16:05:31 -0500162 /* Setup and issue mailbox READ REV command */
163 lpfc_read_rev(phba, pmb);
164 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
165 if (rc != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500166 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400167 "0439 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500168 "READ_REV, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500169 mb->mbxCommand, mb->mbxStatus);
170 mempool_free( pmb, phba->mbox_mem_pool);
171 return -ERESTART;
172 }
173
James Smart92d7f7b2007-06-17 19:56:38 -0500174
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500175 /*
176 * The value of rr must be 1 since the driver set the cv field to 1.
177 * This setting requires the FW to set all revision fields.
dea31012005-04-17 16:05:31 -0500178 */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500179 if (mb->un.varRdRev.rr == 0) {
dea31012005-04-17 16:05:31 -0500180 vp->rev.rBit = 0;
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500181 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400182 "0440 Adapter failed to init, READ_REV has "
183 "missing revision information.\n");
dea31012005-04-17 16:05:31 -0500184 mempool_free(pmb, phba->mbox_mem_pool);
185 return -ERESTART;
dea31012005-04-17 16:05:31 -0500186 }
187
James Smart495a7142008-06-14 22:52:59 -0400188 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
189 mempool_free(pmb, phba->mbox_mem_pool);
James Smarted957682007-06-17 19:56:37 -0500190 return -EINVAL;
James Smart495a7142008-06-14 22:52:59 -0400191 }
James Smarted957682007-06-17 19:56:37 -0500192
dea31012005-04-17 16:05:31 -0500193 /* Save information as VPD data */
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500194 vp->rev.rBit = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500195 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
James.Smart@Emulex.Com1de933f2005-11-28 11:41:15 -0500196 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
197 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
198 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
199 memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
dea31012005-04-17 16:05:31 -0500200 vp->rev.biuRev = mb->un.varRdRev.biuRev;
201 vp->rev.smRev = mb->un.varRdRev.smRev;
202 vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
203 vp->rev.endecRev = mb->un.varRdRev.endecRev;
204 vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
205 vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
206 vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
207 vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
208 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
209 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
210
James Smart92d7f7b2007-06-17 19:56:38 -0500211 /* If the sli feature level is less then 9, we must
212 * tear down all RPIs and VPIs on link down if NPIV
213 * is enabled.
214 */
215 if (vp->rev.feaLevelHigh < 9)
216 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
217
dea31012005-04-17 16:05:31 -0500218 if (lpfc_is_LC_HBA(phba->pcidev->device))
219 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
220 sizeof (phba->RandomData));
221
dea31012005-04-17 16:05:31 -0500222 /* Get adapter VPD information */
dea31012005-04-17 16:05:31 -0500223 lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
224 if (!lpfc_vpd_data)
James Smartd7c255b2008-08-24 21:50:00 -0400225 goto out_free_mbox;
dea31012005-04-17 16:05:31 -0500226 do {
James Smarta0c87cb2009-07-19 10:01:10 -0400227 lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
dea31012005-04-17 16:05:31 -0500228 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
229
230 if (rc != MBX_SUCCESS) {
231 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400232 "0441 VPD not present on adapter, "
dea31012005-04-17 16:05:31 -0500233 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500234 mb->mbxCommand, mb->mbxStatus);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500235 mb->un.varDmp.word_cnt = 0;
dea31012005-04-17 16:05:31 -0500236 }
James Smart04c68492009-05-22 14:52:52 -0400237 /* dump mem may return a zero when finished or we got a
238 * mailbox error, either way we are done.
239 */
240 if (mb->un.varDmp.word_cnt == 0)
241 break;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500242 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
243 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
James Smartd7c255b2008-08-24 21:50:00 -0400244 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
245 lpfc_vpd_data + offset,
James Smart92d7f7b2007-06-17 19:56:38 -0500246 mb->un.varDmp.word_cnt);
dea31012005-04-17 16:05:31 -0500247 offset += mb->un.varDmp.word_cnt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500248 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
249 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
dea31012005-04-17 16:05:31 -0500250
251 kfree(lpfc_vpd_data);
dea31012005-04-17 16:05:31 -0500252out_free_mbox:
253 mempool_free(pmb, phba->mbox_mem_pool);
254 return 0;
255}
256
James Smarte59058c2008-08-24 21:49:00 -0400257/**
James Smart3621a712009-04-06 18:47:14 -0400258 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
James Smarte59058c2008-08-24 21:49:00 -0400259 * @phba: pointer to lpfc hba data structure.
260 * @pmboxq: pointer to the driver internal queue element for mailbox command.
261 *
262 * This is the completion handler for driver's configuring asynchronous event
263 * mailbox command to the device. If the mailbox command returns successfully,
264 * it will set internal async event support flag to 1; otherwise, it will
265 * set internal async event support flag to 0.
266 **/
James Smart57127f12007-10-27 13:37:05 -0400267static void
268lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
269{
James Smart04c68492009-05-22 14:52:52 -0400270 if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
James Smart57127f12007-10-27 13:37:05 -0400271 phba->temp_sensor_support = 1;
272 else
273 phba->temp_sensor_support = 0;
274 mempool_free(pmboxq, phba->mbox_mem_pool);
275 return;
276}
277
James Smarte59058c2008-08-24 21:49:00 -0400278/**
James Smart3621a712009-04-06 18:47:14 -0400279 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
James Smart97207482008-12-04 22:39:19 -0500280 * @phba: pointer to lpfc hba data structure.
281 * @pmboxq: pointer to the driver internal queue element for mailbox command.
282 *
283 * This is the completion handler for dump mailbox command for getting
284 * wake up parameters. When this command complete, the response contain
285 * Option rom version of the HBA. This function translate the version number
286 * into a human readable string and store it in OptionROMVersion.
287 **/
288static void
289lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
290{
291 struct prog_id *prg;
292 uint32_t prog_id_word;
293 char dist = ' ';
294 /* character array used for decoding dist type. */
295 char dist_char[] = "nabx";
296
James Smart04c68492009-05-22 14:52:52 -0400297 if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
James Smart9f1e1b52008-12-04 22:39:40 -0500298 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500299 return;
James Smart9f1e1b52008-12-04 22:39:40 -0500300 }
James Smart97207482008-12-04 22:39:19 -0500301
302 prg = (struct prog_id *) &prog_id_word;
303
304 /* word 7 contain option rom version */
James Smart04c68492009-05-22 14:52:52 -0400305 prog_id_word = pmboxq->u.mb.un.varWords[7];
James Smart97207482008-12-04 22:39:19 -0500306
307 /* Decode the Option rom version word to a readable string */
308 if (prg->dist < 4)
309 dist = dist_char[prg->dist];
310
311 if ((prg->dist == 3) && (prg->num == 0))
James Smarta2fc4aef2014-09-03 12:57:55 -0400312 snprintf(phba->OptionROMVersion, 32, "%d.%d%d",
James Smart97207482008-12-04 22:39:19 -0500313 prg->ver, prg->rev, prg->lev);
314 else
James Smarta2fc4aef2014-09-03 12:57:55 -0400315 snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d",
James Smart97207482008-12-04 22:39:19 -0500316 prg->ver, prg->rev, prg->lev,
317 dist, prg->num);
James Smart9f1e1b52008-12-04 22:39:40 -0500318 mempool_free(pmboxq, phba->mbox_mem_pool);
James Smart97207482008-12-04 22:39:19 -0500319 return;
320}
321
322/**
James Smart05580562011-05-24 11:40:48 -0400323 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
324 * cfg_soft_wwnn, cfg_soft_wwpn
325 * @vport: pointer to lpfc vport data structure.
326 *
327 *
328 * Return codes
329 * None.
330 **/
331void
332lpfc_update_vport_wwn(struct lpfc_vport *vport)
333{
334 /* If the soft name exists then update it using the service params */
335 if (vport->phba->cfg_soft_wwnn)
336 u64_to_wwn(vport->phba->cfg_soft_wwnn,
337 vport->fc_sparam.nodeName.u.wwn);
338 if (vport->phba->cfg_soft_wwpn)
339 u64_to_wwn(vport->phba->cfg_soft_wwpn,
340 vport->fc_sparam.portName.u.wwn);
341
342 /*
343 * If the name is empty or there exists a soft name
344 * then copy the service params name, otherwise use the fc name
345 */
346 if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn)
347 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
348 sizeof(struct lpfc_name));
349 else
350 memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename,
351 sizeof(struct lpfc_name));
352
353 if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn)
354 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
355 sizeof(struct lpfc_name));
356 else
357 memcpy(&vport->fc_sparam.portName, &vport->fc_portname,
358 sizeof(struct lpfc_name));
359}
360
361/**
James Smart3621a712009-04-06 18:47:14 -0400362 * lpfc_config_port_post - Perform lpfc initialization after config port
James Smarte59058c2008-08-24 21:49:00 -0400363 * @phba: pointer to lpfc hba data structure.
364 *
365 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
366 * command call. It performs all internal resource and state setups on the
367 * port: post IOCB buffers, enable appropriate host interrupt attentions,
368 * ELS ring timers, etc.
369 *
370 * Return codes
371 * 0 - success.
372 * Any other value - error.
373 **/
dea31012005-04-17 16:05:31 -0500374int
James Smart2e0fef82007-06-17 19:56:36 -0500375lpfc_config_port_post(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500376{
James Smart2e0fef82007-06-17 19:56:36 -0500377 struct lpfc_vport *vport = phba->pport;
James Smarta257bf92009-04-06 18:48:10 -0400378 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500379 LPFC_MBOXQ_t *pmb;
380 MAILBOX_t *mb;
381 struct lpfc_dmabuf *mp;
382 struct lpfc_sli *psli = &phba->sli;
383 uint32_t status, timeout;
James Smart2e0fef82007-06-17 19:56:36 -0500384 int i, j;
385 int rc;
dea31012005-04-17 16:05:31 -0500386
James Smart7af67052007-10-27 13:38:11 -0400387 spin_lock_irq(&phba->hbalock);
388 /*
389 * If the Config port completed correctly the HBA is not
390 * over heated any more.
391 */
392 if (phba->over_temp_state == HBA_OVER_TEMP)
393 phba->over_temp_state = HBA_NORMAL_TEMP;
394 spin_unlock_irq(&phba->hbalock);
395
dea31012005-04-17 16:05:31 -0500396 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
397 if (!pmb) {
James Smart2e0fef82007-06-17 19:56:36 -0500398 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500399 return -ENOMEM;
400 }
James Smart04c68492009-05-22 14:52:52 -0400401 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500402
dea31012005-04-17 16:05:31 -0500403 /* Get login parameters for NID. */
James Smart9f1177a2010-02-26 14:12:57 -0500404 rc = lpfc_read_sparam(phba, pmb, 0);
405 if (rc) {
406 mempool_free(pmb, phba->mbox_mem_pool);
407 return -ENOMEM;
408 }
409
James Smarted957682007-06-17 19:56:37 -0500410 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500411 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500412 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400413 "0448 Adapter failed init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500414 "READ_SPARM mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500415 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500416 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500417 mp = (struct lpfc_dmabuf *) pmb->context1;
James Smart9f1177a2010-02-26 14:12:57 -0500418 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500419 lpfc_mbuf_free(phba, mp->virt, mp->phys);
420 kfree(mp);
421 return -EIO;
422 }
423
424 mp = (struct lpfc_dmabuf *) pmb->context1;
425
James Smart2e0fef82007-06-17 19:56:36 -0500426 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500427 lpfc_mbuf_free(phba, mp->virt, mp->phys);
428 kfree(mp);
429 pmb->context1 = NULL;
James Smart05580562011-05-24 11:40:48 -0400430 lpfc_update_vport_wwn(vport);
James Smarta257bf92009-04-06 18:48:10 -0400431
432 /* Update the fc_host data structures with new wwn. */
433 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
434 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart21e9a0a2009-05-22 14:53:21 -0400435 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smarta257bf92009-04-06 18:48:10 -0400436
dea31012005-04-17 16:05:31 -0500437 /* If no serial number in VPD data, use low 6 bytes of WWNN */
438 /* This should be consolidated into parse_vpd ? - mr */
439 if (phba->SerialNumber[0] == 0) {
440 uint8_t *outptr;
441
James Smart2e0fef82007-06-17 19:56:36 -0500442 outptr = &vport->fc_nodename.u.s.IEEE[0];
dea31012005-04-17 16:05:31 -0500443 for (i = 0; i < 12; i++) {
444 status = *outptr++;
445 j = ((status & 0xf0) >> 4);
446 if (j <= 9)
447 phba->SerialNumber[i] =
448 (char)((uint8_t) 0x30 + (uint8_t) j);
449 else
450 phba->SerialNumber[i] =
451 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
452 i++;
453 j = (status & 0xf);
454 if (j <= 9)
455 phba->SerialNumber[i] =
456 (char)((uint8_t) 0x30 + (uint8_t) j);
457 else
458 phba->SerialNumber[i] =
459 (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
460 }
461 }
462
dea31012005-04-17 16:05:31 -0500463 lpfc_read_config(phba, pmb);
James Smarted957682007-06-17 19:56:37 -0500464 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500465 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
James Smarted957682007-06-17 19:56:37 -0500466 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400467 "0453 Adapter failed to init, mbxCmd x%x "
dea31012005-04-17 16:05:31 -0500468 "READ_CONFIG, mbxStatus x%x\n",
dea31012005-04-17 16:05:31 -0500469 mb->mbxCommand, mb->mbxStatus);
James Smart2e0fef82007-06-17 19:56:36 -0500470 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500471 mempool_free( pmb, phba->mbox_mem_pool);
472 return -EIO;
473 }
474
James Smarta0c87cb2009-07-19 10:01:10 -0400475 /* Check if the port is disabled */
476 lpfc_sli_read_link_ste(phba);
477
dea31012005-04-17 16:05:31 -0500478 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -0400479 i = (mb->un.varRdConfig.max_xri + 1);
480 if (phba->cfg_hba_queue_depth > i) {
481 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
482 "3359 HBA queue depth changed from %d to %d\n",
483 phba->cfg_hba_queue_depth, i);
484 phba->cfg_hba_queue_depth = i;
485 }
486
487 /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */
488 i = (mb->un.varRdConfig.max_xri >> 3);
489 if (phba->pport->cfg_lun_queue_depth > i) {
490 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
491 "3360 LUN queue depth changed from %d to %d\n",
492 phba->pport->cfg_lun_queue_depth, i);
493 phba->pport->cfg_lun_queue_depth = i;
494 }
dea31012005-04-17 16:05:31 -0500495
496 phba->lmt = mb->un.varRdConfig.lmt;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -0500497
498 /* Get the default values for Model Name and Description */
499 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
500
James Smart2e0fef82007-06-17 19:56:36 -0500501 phba->link_state = LPFC_LINK_DOWN;
dea31012005-04-17 16:05:31 -0500502
James Smart0b727fe2007-10-27 13:37:25 -0400503 /* Only process IOCBs on ELS ring till hba_state is READY */
James Smart895427b2017-02-12 13:52:30 -0800504 if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr)
505 psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT;
506 if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr)
507 psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500508
509 /* Post receive buffers for desired rings */
James Smarted957682007-06-17 19:56:37 -0500510 if (phba->sli_rev != 3)
511 lpfc_post_rcv_buf(phba);
dea31012005-04-17 16:05:31 -0500512
James Smart93996272008-08-24 21:50:30 -0400513 /*
514 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
515 */
516 if (phba->intr_type == MSIX) {
517 rc = lpfc_config_msi(phba, pmb);
518 if (rc) {
519 mempool_free(pmb, phba->mbox_mem_pool);
520 return -EIO;
521 }
522 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
523 if (rc != MBX_SUCCESS) {
524 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
525 "0352 Config MSI mailbox command "
526 "failed, mbxCmd x%x, mbxStatus x%x\n",
James Smart04c68492009-05-22 14:52:52 -0400527 pmb->u.mb.mbxCommand,
528 pmb->u.mb.mbxStatus);
James Smart93996272008-08-24 21:50:30 -0400529 mempool_free(pmb, phba->mbox_mem_pool);
530 return -EIO;
531 }
532 }
533
James Smart04c68492009-05-22 14:52:52 -0400534 spin_lock_irq(&phba->hbalock);
James Smart93996272008-08-24 21:50:30 -0400535 /* Initialize ERATT handling flag */
536 phba->hba_flag &= ~HBA_ERATT_HANDLED;
537
dea31012005-04-17 16:05:31 -0500538 /* Enable appropriate host interrupts */
James Smart9940b972011-03-11 16:06:12 -0500539 if (lpfc_readl(phba->HCregaddr, &status)) {
540 spin_unlock_irq(&phba->hbalock);
541 return -EIO;
542 }
dea31012005-04-17 16:05:31 -0500543 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
544 if (psli->num_rings > 0)
545 status |= HC_R0INT_ENA;
546 if (psli->num_rings > 1)
547 status |= HC_R1INT_ENA;
548 if (psli->num_rings > 2)
549 status |= HC_R2INT_ENA;
550 if (psli->num_rings > 3)
551 status |= HC_R3INT_ENA;
552
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500553 if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
554 (phba->cfg_poll & DISABLE_FCP_RING_INT))
James Smart93996272008-08-24 21:50:30 -0400555 status &= ~(HC_R0INT_ENA);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500556
dea31012005-04-17 16:05:31 -0500557 writel(status, phba->HCregaddr);
558 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500559 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500560
James Smart93996272008-08-24 21:50:30 -0400561 /* Set up ring-0 (ELS) timer */
562 timeout = phba->fc_ratov * 2;
James Smart256ec0d2013-04-17 20:14:58 -0400563 mod_timer(&vport->els_tmofunc,
564 jiffies + msecs_to_jiffies(1000 * timeout));
James Smart93996272008-08-24 21:50:30 -0400565 /* Set up heart beat (HB) timer */
James Smart256ec0d2013-04-17 20:14:58 -0400566 mod_timer(&phba->hb_tmofunc,
567 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -0500568 phba->hb_outstanding = 0;
569 phba->last_completion_time = jiffies;
James Smart93996272008-08-24 21:50:30 -0400570 /* Set up error attention (ERATT) polling timer */
James Smart256ec0d2013-04-17 20:14:58 -0400571 mod_timer(&phba->eratt_poll,
James Smart65791f12016-07-06 12:35:56 -0700572 jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
dea31012005-04-17 16:05:31 -0500573
James Smarta0c87cb2009-07-19 10:01:10 -0400574 if (phba->hba_flag & LINK_DISABLED) {
575 lpfc_printf_log(phba,
576 KERN_ERR, LOG_INIT,
577 "2598 Adapter Link is disabled.\n");
578 lpfc_down_link(phba, pmb);
579 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
580 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
581 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
582 lpfc_printf_log(phba,
583 KERN_ERR, LOG_INIT,
584 "2599 Adapter failed to issue DOWN_LINK"
585 " mbox command rc 0x%x\n", rc);
586
587 mempool_free(pmb, phba->mbox_mem_pool);
588 return -EIO;
589 }
James Smarte40a02c2010-02-26 14:13:54 -0500590 } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
James Smart026abb82011-12-13 13:20:45 -0500591 mempool_free(pmb, phba->mbox_mem_pool);
592 rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
593 if (rc)
594 return rc;
dea31012005-04-17 16:05:31 -0500595 }
596 /* MBOX buffer will be freed in mbox compl */
James Smart57127f12007-10-27 13:37:05 -0400597 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500598 if (!pmb) {
599 phba->link_state = LPFC_HBA_ERROR;
600 return -ENOMEM;
601 }
602
James Smart57127f12007-10-27 13:37:05 -0400603 lpfc_config_async(phba, pmb, LPFC_ELS_RING);
604 pmb->mbox_cmpl = lpfc_config_async_cmpl;
605 pmb->vport = phba->pport;
606 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500607
James Smart57127f12007-10-27 13:37:05 -0400608 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
609 lpfc_printf_log(phba,
610 KERN_ERR,
611 LOG_INIT,
612 "0456 Adapter failed to issue "
James Smarte4e74272009-07-19 10:01:38 -0400613 "ASYNCEVT_ENABLE mbox status x%x\n",
James Smart57127f12007-10-27 13:37:05 -0400614 rc);
615 mempool_free(pmb, phba->mbox_mem_pool);
616 }
James Smart97207482008-12-04 22:39:19 -0500617
618 /* Get Option rom version */
619 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart9f1177a2010-02-26 14:12:57 -0500620 if (!pmb) {
621 phba->link_state = LPFC_HBA_ERROR;
622 return -ENOMEM;
623 }
624
James Smart97207482008-12-04 22:39:19 -0500625 lpfc_dump_wakeup_param(phba, pmb);
626 pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
627 pmb->vport = phba->pport;
628 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
629
630 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
631 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
James Smarte4e74272009-07-19 10:01:38 -0400632 "to get Option ROM version status x%x\n", rc);
James Smart97207482008-12-04 22:39:19 -0500633 mempool_free(pmb, phba->mbox_mem_pool);
634 }
635
James Smartd7c255b2008-08-24 21:50:00 -0400636 return 0;
James Smartce8b3ce2006-07-06 15:50:36 -0400637}
638
James Smarte59058c2008-08-24 21:49:00 -0400639/**
James Smart84d1b002010-02-12 14:42:33 -0500640 * lpfc_hba_init_link - Initialize the FC link
641 * @phba: pointer to lpfc hba data structure.
James Smart6e7288d2010-06-07 15:23:35 -0400642 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500643 *
644 * This routine will issue the INIT_LINK mailbox command call.
645 * It is available to other drivers through the lpfc_hba data
646 * structure for use as a delayed link up mechanism with the
647 * module parameter lpfc_suppress_link_up.
648 *
649 * Return code
650 * 0 - success
651 * Any other value - error
652 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400653static int
James Smart6e7288d2010-06-07 15:23:35 -0400654lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500655{
James Smart1b511972011-12-13 13:23:09 -0500656 return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag);
657}
658
659/**
660 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
661 * @phba: pointer to lpfc hba data structure.
662 * @fc_topology: desired fc topology.
663 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
664 *
665 * This routine will issue the INIT_LINK mailbox command call.
666 * It is available to other drivers through the lpfc_hba data
667 * structure for use as a delayed link up mechanism with the
668 * module parameter lpfc_suppress_link_up.
669 *
670 * Return code
671 * 0 - success
672 * Any other value - error
673 **/
674int
675lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology,
676 uint32_t flag)
677{
James Smart84d1b002010-02-12 14:42:33 -0500678 struct lpfc_vport *vport = phba->pport;
679 LPFC_MBOXQ_t *pmb;
680 MAILBOX_t *mb;
681 int rc;
682
683 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
684 if (!pmb) {
685 phba->link_state = LPFC_HBA_ERROR;
686 return -ENOMEM;
687 }
688 mb = &pmb->u.mb;
689 pmb->vport = vport;
690
James Smart026abb82011-12-13 13:20:45 -0500691 if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) ||
692 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) &&
693 !(phba->lmt & LMT_1Gb)) ||
694 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) &&
695 !(phba->lmt & LMT_2Gb)) ||
696 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) &&
697 !(phba->lmt & LMT_4Gb)) ||
698 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) &&
699 !(phba->lmt & LMT_8Gb)) ||
700 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) &&
701 !(phba->lmt & LMT_10Gb)) ||
702 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) &&
James Smartd38dd522015-08-31 16:48:17 -0400703 !(phba->lmt & LMT_16Gb)) ||
704 ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) &&
705 !(phba->lmt & LMT_32Gb))) {
James Smart026abb82011-12-13 13:20:45 -0500706 /* Reset link speed to auto */
707 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
708 "1302 Invalid speed for this board:%d "
709 "Reset link speed to auto.\n",
710 phba->cfg_link_speed);
711 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
712 }
James Smart1b511972011-12-13 13:23:09 -0500713 lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed);
James Smart84d1b002010-02-12 14:42:33 -0500714 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart1b511972011-12-13 13:23:09 -0500715 if (phba->sli_rev < LPFC_SLI_REV4)
716 lpfc_set_loopback_flag(phba);
James Smart6e7288d2010-06-07 15:23:35 -0400717 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart76a95d72010-11-20 23:11:48 -0500718 if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
James Smart84d1b002010-02-12 14:42:33 -0500719 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
720 "0498 Adapter failed to init, mbxCmd x%x "
721 "INIT_LINK, mbxStatus x%x\n",
722 mb->mbxCommand, mb->mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -0500723 if (phba->sli_rev <= LPFC_SLI_REV3) {
724 /* Clear all interrupt enable conditions */
725 writel(0, phba->HCregaddr);
726 readl(phba->HCregaddr); /* flush */
727 /* Clear all pending interrupts */
728 writel(0xffffffff, phba->HAregaddr);
729 readl(phba->HAregaddr); /* flush */
730 }
James Smart84d1b002010-02-12 14:42:33 -0500731 phba->link_state = LPFC_HBA_ERROR;
James Smart6e7288d2010-06-07 15:23:35 -0400732 if (rc != MBX_BUSY || flag == MBX_POLL)
James Smart84d1b002010-02-12 14:42:33 -0500733 mempool_free(pmb, phba->mbox_mem_pool);
734 return -EIO;
735 }
James Smarte40a02c2010-02-26 14:13:54 -0500736 phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK;
James Smart6e7288d2010-06-07 15:23:35 -0400737 if (flag == MBX_POLL)
738 mempool_free(pmb, phba->mbox_mem_pool);
James Smart84d1b002010-02-12 14:42:33 -0500739
740 return 0;
741}
742
743/**
744 * lpfc_hba_down_link - this routine downs the FC link
James Smart6e7288d2010-06-07 15:23:35 -0400745 * @phba: pointer to lpfc hba data structure.
746 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
James Smart84d1b002010-02-12 14:42:33 -0500747 *
748 * This routine will issue the DOWN_LINK mailbox command call.
749 * It is available to other drivers through the lpfc_hba data
750 * structure for use to stop the link.
751 *
752 * Return code
753 * 0 - success
754 * Any other value - error
755 **/
Rashika Kheriae399b222014-09-03 12:55:28 -0400756static int
James Smart6e7288d2010-06-07 15:23:35 -0400757lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag)
James Smart84d1b002010-02-12 14:42:33 -0500758{
759 LPFC_MBOXQ_t *pmb;
760 int rc;
761
762 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
763 if (!pmb) {
764 phba->link_state = LPFC_HBA_ERROR;
765 return -ENOMEM;
766 }
767
768 lpfc_printf_log(phba,
769 KERN_ERR, LOG_INIT,
770 "0491 Adapter Link is disabled.\n");
771 lpfc_down_link(phba, pmb);
772 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart6e7288d2010-06-07 15:23:35 -0400773 rc = lpfc_sli_issue_mbox(phba, pmb, flag);
James Smart84d1b002010-02-12 14:42:33 -0500774 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
775 lpfc_printf_log(phba,
776 KERN_ERR, LOG_INIT,
777 "2522 Adapter failed to issue DOWN_LINK"
778 " mbox command rc 0x%x\n", rc);
779
780 mempool_free(pmb, phba->mbox_mem_pool);
781 return -EIO;
782 }
James Smart6e7288d2010-06-07 15:23:35 -0400783 if (flag == MBX_POLL)
784 mempool_free(pmb, phba->mbox_mem_pool);
785
James Smart84d1b002010-02-12 14:42:33 -0500786 return 0;
787}
788
789/**
James Smart3621a712009-04-06 18:47:14 -0400790 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
James Smarte59058c2008-08-24 21:49:00 -0400791 * @phba: pointer to lpfc HBA data structure.
792 *
793 * This routine will do LPFC uninitialization before the HBA is reset when
794 * bringing down the SLI Layer.
795 *
796 * Return codes
797 * 0 - success.
798 * Any other value - error.
799 **/
dea31012005-04-17 16:05:31 -0500800int
James Smart2e0fef82007-06-17 19:56:36 -0500801lpfc_hba_down_prep(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500802{
James Smart1b32f6a2008-02-08 18:49:39 -0500803 struct lpfc_vport **vports;
804 int i;
James Smart3772a992009-05-22 14:50:54 -0400805
806 if (phba->sli_rev <= LPFC_SLI_REV3) {
807 /* Disable interrupts */
808 writel(0, phba->HCregaddr);
809 readl(phba->HCregaddr); /* flush */
810 }
dea31012005-04-17 16:05:31 -0500811
James Smart1b32f6a2008-02-08 18:49:39 -0500812 if (phba->pport->load_flag & FC_UNLOADING)
813 lpfc_cleanup_discovery_resources(phba->pport);
814 else {
815 vports = lpfc_create_vport_work_array(phba);
816 if (vports != NULL)
James Smart3772a992009-05-22 14:50:54 -0400817 for (i = 0; i <= phba->max_vports &&
818 vports[i] != NULL; i++)
James Smart1b32f6a2008-02-08 18:49:39 -0500819 lpfc_cleanup_discovery_resources(vports[i]);
820 lpfc_destroy_vport_work_array(phba, vports);
James Smart7f5f3d02008-02-08 18:50:14 -0500821 }
822 return 0;
dea31012005-04-17 16:05:31 -0500823}
824
James Smarte59058c2008-08-24 21:49:00 -0400825/**
James Smart68e814f2014-05-21 08:04:59 -0400826 * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free
827 * rspiocb which got deferred
828 *
829 * @phba: pointer to lpfc HBA data structure.
830 *
831 * This routine will cleanup completed slow path events after HBA is reset
832 * when bringing down the SLI Layer.
833 *
834 *
835 * Return codes
836 * void.
837 **/
838static void
839lpfc_sli4_free_sp_events(struct lpfc_hba *phba)
840{
841 struct lpfc_iocbq *rspiocbq;
842 struct hbq_dmabuf *dmabuf;
843 struct lpfc_cq_event *cq_event;
844
845 spin_lock_irq(&phba->hbalock);
846 phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
847 spin_unlock_irq(&phba->hbalock);
848
849 while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
850 /* Get the response iocb from the head of work queue */
851 spin_lock_irq(&phba->hbalock);
852 list_remove_head(&phba->sli4_hba.sp_queue_event,
853 cq_event, struct lpfc_cq_event, list);
854 spin_unlock_irq(&phba->hbalock);
855
856 switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
857 case CQE_CODE_COMPL_WQE:
858 rspiocbq = container_of(cq_event, struct lpfc_iocbq,
859 cq_event);
860 lpfc_sli_release_iocbq(phba, rspiocbq);
861 break;
862 case CQE_CODE_RECEIVE:
863 case CQE_CODE_RECEIVE_V1:
864 dmabuf = container_of(cq_event, struct hbq_dmabuf,
865 cq_event);
866 lpfc_in_buf_free(phba, &dmabuf->dbuf);
867 }
868 }
869}
870
871/**
James Smartbcece5f2014-04-04 13:51:34 -0400872 * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset
873 * @phba: pointer to lpfc HBA data structure.
874 *
875 * This routine will cleanup posted ELS buffers after the HBA is reset
876 * when bringing down the SLI Layer.
877 *
878 *
879 * Return codes
880 * void.
881 **/
882static void
883lpfc_hba_free_post_buf(struct lpfc_hba *phba)
884{
885 struct lpfc_sli *psli = &phba->sli;
886 struct lpfc_sli_ring *pring;
887 struct lpfc_dmabuf *mp, *next_mp;
James Smart07eab622014-04-04 13:51:44 -0400888 LIST_HEAD(buflist);
889 int count;
James Smartbcece5f2014-04-04 13:51:34 -0400890
891 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
892 lpfc_sli_hbqbuf_free_all(phba);
893 else {
894 /* Cleanup preposted buffers on the ELS ring */
James Smart895427b2017-02-12 13:52:30 -0800895 pring = &psli->sli3_ring[LPFC_ELS_RING];
James Smart07eab622014-04-04 13:51:44 -0400896 spin_lock_irq(&phba->hbalock);
897 list_splice_init(&pring->postbufq, &buflist);
898 spin_unlock_irq(&phba->hbalock);
899
900 count = 0;
901 list_for_each_entry_safe(mp, next_mp, &buflist, list) {
James Smartbcece5f2014-04-04 13:51:34 -0400902 list_del(&mp->list);
James Smart07eab622014-04-04 13:51:44 -0400903 count++;
James Smartbcece5f2014-04-04 13:51:34 -0400904 lpfc_mbuf_free(phba, mp->virt, mp->phys);
905 kfree(mp);
906 }
James Smart07eab622014-04-04 13:51:44 -0400907
908 spin_lock_irq(&phba->hbalock);
909 pring->postbufq_cnt -= count;
James Smartbcece5f2014-04-04 13:51:34 -0400910 spin_unlock_irq(&phba->hbalock);
911 }
912}
913
914/**
915 * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset
916 * @phba: pointer to lpfc HBA data structure.
917 *
918 * This routine will cleanup the txcmplq after the HBA is reset when bringing
919 * down the SLI Layer.
920 *
921 * Return codes
922 * void
923 **/
924static void
925lpfc_hba_clean_txcmplq(struct lpfc_hba *phba)
926{
927 struct lpfc_sli *psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -0800928 struct lpfc_queue *qp = NULL;
James Smartbcece5f2014-04-04 13:51:34 -0400929 struct lpfc_sli_ring *pring;
930 LIST_HEAD(completions);
931 int i;
932
James Smart895427b2017-02-12 13:52:30 -0800933 if (phba->sli_rev != LPFC_SLI_REV4) {
934 for (i = 0; i < psli->num_rings; i++) {
935 pring = &psli->sli3_ring[i];
James Smartbcece5f2014-04-04 13:51:34 -0400936 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -0800937 /* At this point in time the HBA is either reset or DOA
938 * Nothing should be on txcmplq as it will
939 * NEVER complete.
940 */
941 list_splice_init(&pring->txcmplq, &completions);
942 pring->txcmplq_cnt = 0;
James Smartbcece5f2014-04-04 13:51:34 -0400943 spin_unlock_irq(&phba->hbalock);
944
James Smart895427b2017-02-12 13:52:30 -0800945 lpfc_sli_abort_iocb_ring(phba, pring);
946 }
James Smartbcece5f2014-04-04 13:51:34 -0400947 /* Cancel all the IOCBs from the completions list */
James Smart895427b2017-02-12 13:52:30 -0800948 lpfc_sli_cancel_iocbs(phba, &completions,
949 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
950 return;
951 }
952 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
953 pring = qp->pring;
954 if (!pring)
955 continue;
956 spin_lock_irq(&pring->ring_lock);
957 list_splice_init(&pring->txcmplq, &completions);
958 pring->txcmplq_cnt = 0;
959 spin_unlock_irq(&pring->ring_lock);
James Smartbcece5f2014-04-04 13:51:34 -0400960 lpfc_sli_abort_iocb_ring(phba, pring);
961 }
James Smart895427b2017-02-12 13:52:30 -0800962 /* Cancel all the IOCBs from the completions list */
963 lpfc_sli_cancel_iocbs(phba, &completions,
964 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smartbcece5f2014-04-04 13:51:34 -0400965}
966
967/**
James Smart3772a992009-05-22 14:50:54 -0400968 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
James Smartbcece5f2014-04-04 13:51:34 -0400969 int i;
James Smarte59058c2008-08-24 21:49:00 -0400970 * @phba: pointer to lpfc HBA data structure.
971 *
972 * This routine will do uninitialization after the HBA is reset when bring
973 * down the SLI Layer.
974 *
975 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200976 * 0 - success.
James Smarte59058c2008-08-24 21:49:00 -0400977 * Any other value - error.
978 **/
James Smart3772a992009-05-22 14:50:54 -0400979static int
980lpfc_hba_down_post_s3(struct lpfc_hba *phba)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500981{
James Smartbcece5f2014-04-04 13:51:34 -0400982 lpfc_hba_free_post_buf(phba);
983 lpfc_hba_clean_txcmplq(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500984 return 0;
985}
James Smart5af5eee2010-10-22 11:06:38 -0400986
James Smartda0436e2009-05-22 14:51:39 -0400987/**
988 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
989 * @phba: pointer to lpfc HBA data structure.
990 *
991 * This routine will do uninitialization after the HBA is reset when bring
992 * down the SLI Layer.
993 *
994 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200995 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -0400996 * Any other value - error.
997 **/
998static int
999lpfc_hba_down_post_s4(struct lpfc_hba *phba)
1000{
1001 struct lpfc_scsi_buf *psb, *psb_next;
1002 LIST_HEAD(aborts);
James Smart895427b2017-02-12 13:52:30 -08001003 LIST_HEAD(nvme_aborts);
James Smartda0436e2009-05-22 14:51:39 -04001004 unsigned long iflag = 0;
James Smart0f65ff62010-02-26 14:14:23 -05001005 struct lpfc_sglq *sglq_entry = NULL;
1006
James Smart895427b2017-02-12 13:52:30 -08001007
1008 lpfc_sli_hbqbuf_free_all(phba);
James Smartbcece5f2014-04-04 13:51:34 -04001009 lpfc_hba_clean_txcmplq(phba);
1010
James Smartda0436e2009-05-22 14:51:39 -04001011 /* At this point in time the HBA is either reset or DOA. Either
1012 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
James Smart895427b2017-02-12 13:52:30 -08001013 * on the lpfc_els_sgl_list so that it can either be freed if the
James Smartda0436e2009-05-22 14:51:39 -04001014 * driver is unloading or reposted if the driver is restarting
1015 * the port.
1016 */
James Smart895427b2017-02-12 13:52:30 -08001017 spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */
James Smartda0436e2009-05-22 14:51:39 -04001018 /* scsl_buf_list */
James Smart895427b2017-02-12 13:52:30 -08001019 /* sgl_list_lock required because worker thread uses this
James Smartda0436e2009-05-22 14:51:39 -04001020 * list.
1021 */
James Smart895427b2017-02-12 13:52:30 -08001022 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05001023 list_for_each_entry(sglq_entry,
1024 &phba->sli4_hba.lpfc_abts_els_sgl_list, list)
1025 sglq_entry->state = SGL_FREED;
1026
James Smartda0436e2009-05-22 14:51:39 -04001027 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
James Smart895427b2017-02-12 13:52:30 -08001028 &phba->sli4_hba.lpfc_els_sgl_list);
1029
1030 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04001031 /* abts_scsi_buf_list_lock required because worker thread uses this
1032 * list.
1033 */
James Smart895427b2017-02-12 13:52:30 -08001034 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
1035 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1036 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
1037 &aborts);
1038 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
1039 }
1040
1041 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
1042 spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1043 list_splice_init(&phba->sli4_hba.lpfc_abts_nvme_buf_list,
1044 &nvme_aborts);
1045 spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock);
1046 }
1047
James Smartda0436e2009-05-22 14:51:39 -04001048 spin_unlock_irq(&phba->hbalock);
1049
1050 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
1051 psb->pCmd = NULL;
1052 psb->status = IOSTAT_SUCCESS;
1053 }
James Smarta40fc5f2013-04-17 20:17:40 -04001054 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
1055 list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
1056 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
James Smart68e814f2014-05-21 08:04:59 -04001057
James Smart895427b2017-02-12 13:52:30 -08001058 list_for_each_entry_safe(psb, psb_next, &nvme_aborts, list) {
1059 psb->pCmd = NULL;
1060 psb->status = IOSTAT_SUCCESS;
1061 }
1062 spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag);
1063 list_splice(&nvme_aborts, &phba->lpfc_nvme_buf_list_put);
1064 spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag);
1065
James Smart68e814f2014-05-21 08:04:59 -04001066 lpfc_sli4_free_sp_events(phba);
James Smartda0436e2009-05-22 14:51:39 -04001067 return 0;
1068}
1069
1070/**
1071 * lpfc_hba_down_post - Wrapper func for hba down post routine
1072 * @phba: pointer to lpfc HBA data structure.
1073 *
1074 * This routine wraps the actual SLI3 or SLI4 routine for performing
1075 * uninitialization after the HBA is reset when bring down the SLI Layer.
1076 *
1077 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001078 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001079 * Any other value - error.
1080 **/
1081int
1082lpfc_hba_down_post(struct lpfc_hba *phba)
1083{
1084 return (*phba->lpfc_hba_down_post)(phba);
1085}
Jamie Wellnitz41415862006-02-28 19:25:27 -05001086
James Smarte59058c2008-08-24 21:49:00 -04001087/**
James Smart3621a712009-04-06 18:47:14 -04001088 * lpfc_hb_timeout - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001089 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1090 *
1091 * This is the HBA-timer timeout handler registered to the lpfc driver. When
1092 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
1093 * work-port-events bitmap and the worker thread is notified. This timeout
1094 * event will be used by the worker thread to invoke the actual timeout
1095 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
1096 * be performed in the timeout handler and the HBA timeout event bit shall
1097 * be cleared by the worker thread after it has taken the event bitmap out.
1098 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01001099static void
James Smart858c9f62007-06-17 19:56:39 -05001100lpfc_hb_timeout(unsigned long ptr)
1101{
1102 struct lpfc_hba *phba;
James Smart5e9d9b82008-06-14 22:52:53 -04001103 uint32_t tmo_posted;
James Smart858c9f62007-06-17 19:56:39 -05001104 unsigned long iflag;
1105
1106 phba = (struct lpfc_hba *)ptr;
James Smart93996272008-08-24 21:50:30 -04001107
1108 /* Check for heart beat timeout conditions */
James Smart858c9f62007-06-17 19:56:39 -05001109 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04001110 tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
1111 if (!tmo_posted)
James Smart858c9f62007-06-17 19:56:39 -05001112 phba->pport->work_port_events |= WORKER_HB_TMO;
1113 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
1114
James Smart93996272008-08-24 21:50:30 -04001115 /* Tell the worker thread there is work to do */
James Smart5e9d9b82008-06-14 22:52:53 -04001116 if (!tmo_posted)
1117 lpfc_worker_wake_up(phba);
James Smart858c9f62007-06-17 19:56:39 -05001118 return;
1119}
1120
James Smarte59058c2008-08-24 21:49:00 -04001121/**
James Smart19ca7602010-11-20 23:11:55 -05001122 * lpfc_rrq_timeout - The RRQ-timer timeout handler
1123 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
1124 *
1125 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
1126 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
1127 * work-port-events bitmap and the worker thread is notified. This timeout
1128 * event will be used by the worker thread to invoke the actual timeout
1129 * handler routine, lpfc_rrq_handler. Any periodical operations will
1130 * be performed in the timeout handler and the RRQ timeout event bit shall
1131 * be cleared by the worker thread after it has taken the event bitmap out.
1132 **/
1133static void
1134lpfc_rrq_timeout(unsigned long ptr)
1135{
1136 struct lpfc_hba *phba;
James Smart19ca7602010-11-20 23:11:55 -05001137 unsigned long iflag;
1138
1139 phba = (struct lpfc_hba *)ptr;
1140 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001141 if (!(phba->pport->load_flag & FC_UNLOADING))
1142 phba->hba_flag |= HBA_RRQ_ACTIVE;
1143 else
1144 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
James Smart19ca7602010-11-20 23:11:55 -05001145 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
James Smart06918ac2014-02-20 09:57:57 -05001146
1147 if (!(phba->pport->load_flag & FC_UNLOADING))
1148 lpfc_worker_wake_up(phba);
James Smart19ca7602010-11-20 23:11:55 -05001149}
1150
1151/**
James Smart3621a712009-04-06 18:47:14 -04001152 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
James Smarte59058c2008-08-24 21:49:00 -04001153 * @phba: pointer to lpfc hba data structure.
1154 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1155 *
1156 * This is the callback function to the lpfc heart-beat mailbox command.
1157 * If configured, the lpfc driver issues the heart-beat mailbox command to
1158 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1159 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1160 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1161 * heart-beat outstanding state. Once the mailbox command comes back and
1162 * no error conditions detected, the heart-beat mailbox command timer is
1163 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1164 * state is cleared for the next heart-beat. If the timer expired with the
1165 * heart-beat outstanding state set, the driver will put the HBA offline.
1166 **/
James Smart858c9f62007-06-17 19:56:39 -05001167static void
1168lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1169{
1170 unsigned long drvr_flag;
1171
1172 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1173 phba->hb_outstanding = 0;
1174 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1175
James Smart93996272008-08-24 21:50:30 -04001176 /* Check and reset heart-beat timer is necessary */
James Smart858c9f62007-06-17 19:56:39 -05001177 mempool_free(pmboxq, phba->mbox_mem_pool);
1178 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
1179 !(phba->link_state == LPFC_HBA_ERROR) &&
James Smart51ef4c22007-08-02 11:10:31 -04001180 !(phba->pport->load_flag & FC_UNLOADING))
James Smart858c9f62007-06-17 19:56:39 -05001181 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001182 jiffies +
1183 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001184 return;
1185}
1186
James Smarte59058c2008-08-24 21:49:00 -04001187/**
James Smart3621a712009-04-06 18:47:14 -04001188 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
James Smarte59058c2008-08-24 21:49:00 -04001189 * @phba: pointer to lpfc hba data structure.
1190 *
1191 * This is the actual HBA-timer timeout handler to be invoked by the worker
1192 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1193 * handler performs any periodic operations needed for the device. If such
1194 * periodic event has already been attended to either in the interrupt handler
1195 * or by processing slow-ring or fast-ring events within the HBA-timer
1196 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1197 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1198 * is configured and there is no heart-beat mailbox command outstanding, a
1199 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1200 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1201 * to offline.
1202 **/
James Smart858c9f62007-06-17 19:56:39 -05001203void
1204lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1205{
James Smart45ed1192009-10-02 15:17:02 -04001206 struct lpfc_vport **vports;
James Smart858c9f62007-06-17 19:56:39 -05001207 LPFC_MBOXQ_t *pmboxq;
James Smart0ff10d42008-01-11 01:52:36 -05001208 struct lpfc_dmabuf *buf_ptr;
James Smart45ed1192009-10-02 15:17:02 -04001209 int retval, i;
James Smart858c9f62007-06-17 19:56:39 -05001210 struct lpfc_sli *psli = &phba->sli;
James Smart0ff10d42008-01-11 01:52:36 -05001211 LIST_HEAD(completions);
James Smart858c9f62007-06-17 19:56:39 -05001212
James Smart45ed1192009-10-02 15:17:02 -04001213 vports = lpfc_create_vport_work_array(phba);
1214 if (vports != NULL)
James Smart4258e982015-12-16 18:11:58 -05001215 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart45ed1192009-10-02 15:17:02 -04001216 lpfc_rcv_seq_check_edtov(vports[i]);
James Smart4258e982015-12-16 18:11:58 -05001217 lpfc_fdmi_num_disc_check(vports[i]);
1218 }
James Smart45ed1192009-10-02 15:17:02 -04001219 lpfc_destroy_vport_work_array(phba, vports);
1220
James Smart858c9f62007-06-17 19:56:39 -05001221 if ((phba->link_state == LPFC_HBA_ERROR) ||
James Smart51ef4c22007-08-02 11:10:31 -04001222 (phba->pport->load_flag & FC_UNLOADING) ||
James Smart858c9f62007-06-17 19:56:39 -05001223 (phba->pport->fc_flag & FC_OFFLINE_MODE))
1224 return;
1225
1226 spin_lock_irq(&phba->pport->work_port_lock);
James Smart858c9f62007-06-17 19:56:39 -05001227
James Smart256ec0d2013-04-17 20:14:58 -04001228 if (time_after(phba->last_completion_time +
1229 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1230 jiffies)) {
James Smart858c9f62007-06-17 19:56:39 -05001231 spin_unlock_irq(&phba->pport->work_port_lock);
1232 if (!phba->hb_outstanding)
1233 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001234 jiffies +
1235 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001236 else
1237 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001238 jiffies +
1239 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001240 return;
1241 }
1242 spin_unlock_irq(&phba->pport->work_port_lock);
1243
James Smart0ff10d42008-01-11 01:52:36 -05001244 if (phba->elsbuf_cnt &&
1245 (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
1246 spin_lock_irq(&phba->hbalock);
1247 list_splice_init(&phba->elsbuf, &completions);
1248 phba->elsbuf_cnt = 0;
1249 phba->elsbuf_prev_cnt = 0;
1250 spin_unlock_irq(&phba->hbalock);
1251
1252 while (!list_empty(&completions)) {
1253 list_remove_head(&completions, buf_ptr,
1254 struct lpfc_dmabuf, list);
1255 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1256 kfree(buf_ptr);
1257 }
1258 }
1259 phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
1260
James Smart858c9f62007-06-17 19:56:39 -05001261 /* If there is no heart beat outstanding, issue a heartbeat command */
James Smart13815c82008-01-11 01:52:48 -05001262 if (phba->cfg_enable_hba_heartbeat) {
1263 if (!phba->hb_outstanding) {
James Smartbc739052010-08-04 16:11:18 -04001264 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1265 (list_empty(&psli->mboxq))) {
1266 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1267 GFP_KERNEL);
1268 if (!pmboxq) {
1269 mod_timer(&phba->hb_tmofunc,
1270 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001271 msecs_to_jiffies(1000 *
1272 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001273 return;
1274 }
James Smart13815c82008-01-11 01:52:48 -05001275
James Smartbc739052010-08-04 16:11:18 -04001276 lpfc_heart_beat(phba, pmboxq);
1277 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1278 pmboxq->vport = phba->pport;
1279 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1280 MBX_NOWAIT);
James Smart13815c82008-01-11 01:52:48 -05001281
James Smartbc739052010-08-04 16:11:18 -04001282 if (retval != MBX_BUSY &&
1283 retval != MBX_SUCCESS) {
1284 mempool_free(pmboxq,
1285 phba->mbox_mem_pool);
1286 mod_timer(&phba->hb_tmofunc,
1287 jiffies +
James Smart256ec0d2013-04-17 20:14:58 -04001288 msecs_to_jiffies(1000 *
1289 LPFC_HB_MBOX_INTERVAL));
James Smartbc739052010-08-04 16:11:18 -04001290 return;
1291 }
1292 phba->skipped_hb = 0;
1293 phba->hb_outstanding = 1;
1294 } else if (time_before_eq(phba->last_completion_time,
1295 phba->skipped_hb)) {
1296 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1297 "2857 Last completion time not "
1298 " updated in %d ms\n",
1299 jiffies_to_msecs(jiffies
1300 - phba->last_completion_time));
1301 } else
1302 phba->skipped_hb = jiffies;
1303
James Smart858c9f62007-06-17 19:56:39 -05001304 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001305 jiffies +
1306 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001307 return;
James Smart13815c82008-01-11 01:52:48 -05001308 } else {
1309 /*
1310 * If heart beat timeout called with hb_outstanding set
James Smartdcf2a4e2010-09-29 11:18:53 -04001311 * we need to give the hb mailbox cmd a chance to
1312 * complete or TMO.
James Smart13815c82008-01-11 01:52:48 -05001313 */
James Smartdcf2a4e2010-09-29 11:18:53 -04001314 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1315 "0459 Adapter heartbeat still out"
1316 "standing:last compl time was %d ms.\n",
1317 jiffies_to_msecs(jiffies
1318 - phba->last_completion_time));
1319 mod_timer(&phba->hb_tmofunc,
James Smart256ec0d2013-04-17 20:14:58 -04001320 jiffies +
1321 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
James Smart858c9f62007-06-17 19:56:39 -05001322 }
James Smart4258e982015-12-16 18:11:58 -05001323 } else {
1324 mod_timer(&phba->hb_tmofunc,
1325 jiffies +
1326 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
James Smart858c9f62007-06-17 19:56:39 -05001327 }
1328}
1329
James Smarte59058c2008-08-24 21:49:00 -04001330/**
James Smart3621a712009-04-06 18:47:14 -04001331 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
James Smarte59058c2008-08-24 21:49:00 -04001332 * @phba: pointer to lpfc hba data structure.
1333 *
1334 * This routine is called to bring the HBA offline when HBA hardware error
1335 * other than Port Error 6 has been detected.
1336 **/
James Smart09372822008-01-11 01:52:54 -05001337static void
1338lpfc_offline_eratt(struct lpfc_hba *phba)
1339{
1340 struct lpfc_sli *psli = &phba->sli;
1341
1342 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001343 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart09372822008-01-11 01:52:54 -05001344 spin_unlock_irq(&phba->hbalock);
James Smart618a5232012-06-12 13:54:36 -04001345 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart09372822008-01-11 01:52:54 -05001346
1347 lpfc_offline(phba);
1348 lpfc_reset_barrier(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001349 spin_lock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001350 lpfc_sli_brdreset(phba);
James Smartf4b4c682009-05-22 14:53:12 -04001351 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001352 lpfc_hba_down_post(phba);
1353 lpfc_sli_brdready(phba, HS_MBRDY);
1354 lpfc_unblock_mgmt_io(phba);
1355 phba->link_state = LPFC_HBA_ERROR;
1356 return;
1357}
1358
James Smarte59058c2008-08-24 21:49:00 -04001359/**
James Smartda0436e2009-05-22 14:51:39 -04001360 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1361 * @phba: pointer to lpfc hba data structure.
1362 *
1363 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1364 * other than Port Error 6 has been detected.
1365 **/
James Smarta88dbb62013-04-17 20:18:39 -04001366void
James Smartda0436e2009-05-22 14:51:39 -04001367lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1368{
James Smart946727d2015-04-07 15:07:09 -04001369 spin_lock_irq(&phba->hbalock);
1370 phba->link_state = LPFC_HBA_ERROR;
1371 spin_unlock_irq(&phba->hbalock);
1372
James Smart618a5232012-06-12 13:54:36 -04001373 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smartda0436e2009-05-22 14:51:39 -04001374 lpfc_offline(phba);
James Smartda0436e2009-05-22 14:51:39 -04001375 lpfc_hba_down_post(phba);
James Smartda0436e2009-05-22 14:51:39 -04001376 lpfc_unblock_mgmt_io(phba);
James Smartda0436e2009-05-22 14:51:39 -04001377}
1378
1379/**
James Smarta257bf92009-04-06 18:48:10 -04001380 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1381 * @phba: pointer to lpfc hba data structure.
1382 *
1383 * This routine is invoked to handle the deferred HBA hardware error
1384 * conditions. This type of error is indicated by HBA by setting ER1
1385 * and another ER bit in the host status register. The driver will
1386 * wait until the ER1 bit clears before handling the error condition.
1387 **/
1388static void
1389lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
1390{
1391 uint32_t old_host_status = phba->work_hs;
James Smarta257bf92009-04-06 18:48:10 -04001392 struct lpfc_sli *psli = &phba->sli;
1393
James Smartf4b4c682009-05-22 14:53:12 -04001394 /* If the pci channel is offline, ignore possible errors,
1395 * since we cannot communicate with the pci card anyway.
1396 */
1397 if (pci_channel_offline(phba->pcidev)) {
1398 spin_lock_irq(&phba->hbalock);
1399 phba->hba_flag &= ~DEFER_ERATT;
1400 spin_unlock_irq(&phba->hbalock);
1401 return;
1402 }
1403
James Smarta257bf92009-04-06 18:48:10 -04001404 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1405 "0479 Deferred Adapter Hardware Error "
1406 "Data: x%x x%x x%x\n",
1407 phba->work_hs,
1408 phba->work_status[0], phba->work_status[1]);
1409
1410 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001411 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smarta257bf92009-04-06 18:48:10 -04001412 spin_unlock_irq(&phba->hbalock);
1413
1414
1415 /*
1416 * Firmware stops when it triggred erratt. That could cause the I/Os
1417 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1418 * SCSI layer retry it after re-establishing link.
1419 */
James Smartdb55fba2014-04-04 13:52:02 -04001420 lpfc_sli_abort_fcp_rings(phba);
James Smarta257bf92009-04-06 18:48:10 -04001421
1422 /*
1423 * There was a firmware error. Take the hba offline and then
1424 * attempt to restart it.
1425 */
James Smart618a5232012-06-12 13:54:36 -04001426 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smarta257bf92009-04-06 18:48:10 -04001427 lpfc_offline(phba);
1428
1429 /* Wait for the ER1 bit to clear.*/
1430 while (phba->work_hs & HS_FFER1) {
1431 msleep(100);
James Smart9940b972011-03-11 16:06:12 -05001432 if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) {
1433 phba->work_hs = UNPLUG_ERR ;
1434 break;
1435 }
James Smarta257bf92009-04-06 18:48:10 -04001436 /* If driver is unloading let the worker thread continue */
1437 if (phba->pport->load_flag & FC_UNLOADING) {
1438 phba->work_hs = 0;
1439 break;
1440 }
1441 }
1442
1443 /*
1444 * This is to ptrotect against a race condition in which
1445 * first write to the host attention register clear the
1446 * host status register.
1447 */
1448 if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
1449 phba->work_hs = old_host_status & ~HS_FFER1;
1450
James Smart3772a992009-05-22 14:50:54 -04001451 spin_lock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001452 phba->hba_flag &= ~DEFER_ERATT;
James Smart3772a992009-05-22 14:50:54 -04001453 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04001454 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
1455 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
1456}
1457
James Smart3772a992009-05-22 14:50:54 -04001458static void
1459lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
1460{
1461 struct lpfc_board_event_header board_event;
1462 struct Scsi_Host *shost;
1463
1464 board_event.event_type = FC_REG_BOARD_EVENT;
1465 board_event.subcategory = LPFC_EVENT_PORTINTERR;
1466 shost = lpfc_shost_from_vport(phba->pport);
1467 fc_host_post_vendor_event(shost, fc_get_event_number(),
1468 sizeof(board_event),
1469 (char *) &board_event,
1470 LPFC_NL_VENDOR_ID);
1471}
1472
James Smarta257bf92009-04-06 18:48:10 -04001473/**
James Smart3772a992009-05-22 14:50:54 -04001474 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
James Smarte59058c2008-08-24 21:49:00 -04001475 * @phba: pointer to lpfc hba data structure.
1476 *
1477 * This routine is invoked to handle the following HBA hardware error
1478 * conditions:
1479 * 1 - HBA error attention interrupt
1480 * 2 - DMA ring index out of range
1481 * 3 - Mailbox command came back as unknown
1482 **/
James Smart3772a992009-05-22 14:50:54 -04001483static void
1484lpfc_handle_eratt_s3(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001485{
James Smart2e0fef82007-06-17 19:56:36 -05001486 struct lpfc_vport *vport = phba->pport;
James Smart2e0fef82007-06-17 19:56:36 -05001487 struct lpfc_sli *psli = &phba->sli;
James Smartd2873e42006-08-18 17:46:43 -04001488 uint32_t event_data;
James Smart57127f12007-10-27 13:37:05 -04001489 unsigned long temperature;
1490 struct temp_event temp_event_data;
James Smart92d7f7b2007-06-17 19:56:38 -05001491 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05001492
Linas Vepstas8d63f372007-02-14 14:28:36 -06001493 /* If the pci channel is offline, ignore possible errors,
James Smart3772a992009-05-22 14:50:54 -04001494 * since we cannot communicate with the pci card anyway.
1495 */
1496 if (pci_channel_offline(phba->pcidev)) {
1497 spin_lock_irq(&phba->hbalock);
1498 phba->hba_flag &= ~DEFER_ERATT;
1499 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -06001500 return;
James Smart3772a992009-05-22 14:50:54 -04001501 }
1502
James Smart13815c82008-01-11 01:52:48 -05001503 /* If resets are disabled then leave the HBA alone and return */
1504 if (!phba->cfg_enable_hba_reset)
1505 return;
dea31012005-04-17 16:05:31 -05001506
James Smartea2151b2008-09-07 11:52:10 -04001507 /* Send an internal error event to mgmt application */
James Smart3772a992009-05-22 14:50:54 -04001508 lpfc_board_errevt_to_mgmt(phba);
James Smartea2151b2008-09-07 11:52:10 -04001509
James Smarta257bf92009-04-06 18:48:10 -04001510 if (phba->hba_flag & DEFER_ERATT)
1511 lpfc_handle_deferred_eratt(phba);
1512
James Smartdcf2a4e2010-09-29 11:18:53 -04001513 if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) {
1514 if (phba->work_hs & HS_FFER6)
1515 /* Re-establishing Link */
1516 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1517 "1301 Re-establishing Link "
1518 "Data: x%x x%x x%x\n",
1519 phba->work_hs, phba->work_status[0],
1520 phba->work_status[1]);
1521 if (phba->work_hs & HS_FFER8)
1522 /* Device Zeroization */
1523 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1524 "2861 Host Authentication device "
1525 "zeroization Data:x%x x%x x%x\n",
1526 phba->work_hs, phba->work_status[0],
1527 phba->work_status[1]);
James Smart58da1ff2008-04-07 10:15:56 -04001528
James Smart92d7f7b2007-06-17 19:56:38 -05001529 spin_lock_irq(&phba->hbalock);
James Smartf4b4c682009-05-22 14:53:12 -04001530 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -05001531 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001532
1533 /*
1534 * Firmware stops when it triggled erratt with HS_FFER6.
1535 * That could cause the I/Os dropped by the firmware.
1536 * Error iocb (I/O) on txcmplq and let the SCSI layer
1537 * retry it after re-establishing link.
1538 */
James Smartdb55fba2014-04-04 13:52:02 -04001539 lpfc_sli_abort_fcp_rings(phba);
dea31012005-04-17 16:05:31 -05001540
dea31012005-04-17 16:05:31 -05001541 /*
1542 * There was a firmware error. Take the hba offline and then
1543 * attempt to restart it.
1544 */
James Smart618a5232012-06-12 13:54:36 -04001545 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
dea31012005-04-17 16:05:31 -05001546 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001547 lpfc_sli_brdrestart(phba);
dea31012005-04-17 16:05:31 -05001548 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
James Smart46fa3112007-04-25 09:51:45 -04001549 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05001550 return;
1551 }
James Smart46fa3112007-04-25 09:51:45 -04001552 lpfc_unblock_mgmt_io(phba);
James Smart57127f12007-10-27 13:37:05 -04001553 } else if (phba->work_hs & HS_CRIT_TEMP) {
1554 temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
1555 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1556 temp_event_data.event_code = LPFC_CRIT_TEMP;
1557 temp_event_data.data = (uint32_t)temperature;
1558
1559 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04001560 "0406 Adapter maximum temperature exceeded "
James Smart57127f12007-10-27 13:37:05 -04001561 "(%ld), taking this port offline "
1562 "Data: x%x x%x x%x\n",
1563 temperature, phba->work_hs,
1564 phba->work_status[0], phba->work_status[1]);
1565
1566 shost = lpfc_shost_from_vport(phba->pport);
1567 fc_host_post_vendor_event(shost, fc_get_event_number(),
1568 sizeof(temp_event_data),
1569 (char *) &temp_event_data,
1570 SCSI_NL_VID_TYPE_PCI
1571 | PCI_VENDOR_ID_EMULEX);
1572
James Smart7af67052007-10-27 13:38:11 -04001573 spin_lock_irq(&phba->hbalock);
James Smart7af67052007-10-27 13:38:11 -04001574 phba->over_temp_state = HBA_OVER_TEMP;
1575 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001576 lpfc_offline_eratt(phba);
James Smart57127f12007-10-27 13:37:05 -04001577
dea31012005-04-17 16:05:31 -05001578 } else {
1579 /* The if clause above forces this code path when the status
James Smart93996272008-08-24 21:50:30 -04001580 * failure is a value other than FFER6. Do not call the offline
1581 * twice. This is the adapter hardware error path.
dea31012005-04-17 16:05:31 -05001582 */
1583 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001584 "0457 Adapter Hardware Error "
dea31012005-04-17 16:05:31 -05001585 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001586 phba->work_hs,
dea31012005-04-17 16:05:31 -05001587 phba->work_status[0], phba->work_status[1]);
1588
James Smartd2873e42006-08-18 17:46:43 -04001589 event_data = FC_REG_DUMP_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05001590 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001591 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04001592 sizeof(event_data), (char *) &event_data,
1593 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1594
James Smart09372822008-01-11 01:52:54 -05001595 lpfc_offline_eratt(phba);
dea31012005-04-17 16:05:31 -05001596 }
James Smart93996272008-08-24 21:50:30 -04001597 return;
dea31012005-04-17 16:05:31 -05001598}
1599
James Smarte59058c2008-08-24 21:49:00 -04001600/**
James Smart618a5232012-06-12 13:54:36 -04001601 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1602 * @phba: pointer to lpfc hba data structure.
1603 * @mbx_action: flag for mailbox shutdown action.
1604 *
1605 * This routine is invoked to perform an SLI4 port PCI function reset in
1606 * response to port status register polling attention. It waits for port
1607 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1608 * During this process, interrupt vectors are freed and later requested
1609 * for handling possible port resource change.
1610 **/
1611static int
James Smarte10b2022014-02-20 09:57:43 -05001612lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action,
1613 bool en_rn_msg)
James Smart618a5232012-06-12 13:54:36 -04001614{
1615 int rc;
1616 uint32_t intr_mode;
1617
James Smart65791f12016-07-06 12:35:56 -07001618 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1619 LPFC_SLI_INTF_IF_TYPE_2) {
1620 /*
1621 * On error status condition, driver need to wait for port
1622 * ready before performing reset.
1623 */
1624 rc = lpfc_sli4_pdev_status_reg_wait(phba);
James Smart0e916ee2016-07-06 12:36:06 -07001625 if (rc)
James Smart65791f12016-07-06 12:35:56 -07001626 return rc;
James Smart618a5232012-06-12 13:54:36 -04001627 }
James Smart0e916ee2016-07-06 12:36:06 -07001628
James Smart65791f12016-07-06 12:35:56 -07001629 /* need reset: attempt for port recovery */
1630 if (en_rn_msg)
1631 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1632 "2887 Reset Needed: Attempting Port "
1633 "Recovery...\n");
1634 lpfc_offline_prep(phba, mbx_action);
1635 lpfc_offline(phba);
1636 /* release interrupt for possible resource change */
1637 lpfc_sli4_disable_intr(phba);
1638 lpfc_sli_brdrestart(phba);
1639 /* request and enable interrupt */
1640 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
1641 if (intr_mode == LPFC_INTR_ERROR) {
1642 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1643 "3175 Failed to enable interrupt\n");
1644 return -EIO;
1645 }
1646 phba->intr_mode = intr_mode;
1647 rc = lpfc_online(phba);
1648 if (rc == 0)
1649 lpfc_unblock_mgmt_io(phba);
1650
James Smart618a5232012-06-12 13:54:36 -04001651 return rc;
1652}
1653
1654/**
James Smartda0436e2009-05-22 14:51:39 -04001655 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1656 * @phba: pointer to lpfc hba data structure.
1657 *
1658 * This routine is invoked to handle the SLI4 HBA hardware error attention
1659 * conditions.
1660 **/
1661static void
1662lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1663{
1664 struct lpfc_vport *vport = phba->pport;
1665 uint32_t event_data;
1666 struct Scsi_Host *shost;
James Smart2fcee4b2010-12-15 17:57:46 -05001667 uint32_t if_type;
James Smart2e90f4b2011-12-13 13:22:37 -05001668 struct lpfc_register portstat_reg = {0};
1669 uint32_t reg_err1, reg_err2;
1670 uint32_t uerrlo_reg, uemasklo_reg;
James Smart65791f12016-07-06 12:35:56 -07001671 uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2;
James Smarte10b2022014-02-20 09:57:43 -05001672 bool en_rn_msg = true;
James Smart946727d2015-04-07 15:07:09 -04001673 struct temp_event temp_event_data;
James Smart65791f12016-07-06 12:35:56 -07001674 struct lpfc_register portsmphr_reg;
1675 int rc, i;
James Smartda0436e2009-05-22 14:51:39 -04001676
1677 /* If the pci channel is offline, ignore possible errors, since
1678 * we cannot communicate with the pci card anyway.
1679 */
1680 if (pci_channel_offline(phba->pcidev))
1681 return;
James Smartda0436e2009-05-22 14:51:39 -04001682
James Smart65791f12016-07-06 12:35:56 -07001683 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
James Smart2fcee4b2010-12-15 17:57:46 -05001684 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1685 switch (if_type) {
1686 case LPFC_SLI_INTF_IF_TYPE_0:
James Smart2e90f4b2011-12-13 13:22:37 -05001687 pci_rd_rc1 = lpfc_readl(
1688 phba->sli4_hba.u.if_type0.UERRLOregaddr,
1689 &uerrlo_reg);
1690 pci_rd_rc2 = lpfc_readl(
1691 phba->sli4_hba.u.if_type0.UEMASKLOregaddr,
1692 &uemasklo_reg);
1693 /* consider PCI bus read error as pci_channel_offline */
1694 if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO)
1695 return;
James Smart65791f12016-07-06 12:35:56 -07001696 if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) {
1697 lpfc_sli4_offline_eratt(phba);
1698 return;
1699 }
1700 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1701 "7623 Checking UE recoverable");
1702
1703 for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) {
1704 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1705 &portsmphr_reg.word0))
1706 continue;
1707
1708 smphr_port_status = bf_get(lpfc_port_smphr_port_status,
1709 &portsmphr_reg);
1710 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1711 LPFC_PORT_SEM_UE_RECOVERABLE)
1712 break;
1713 /*Sleep for 1Sec, before checking SEMAPHORE */
1714 msleep(1000);
1715 }
1716
1717 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1718 "4827 smphr_port_status x%x : Waited %dSec",
1719 smphr_port_status, i);
1720
1721 /* Recoverable UE, reset the HBA device */
1722 if ((smphr_port_status & LPFC_PORT_SEM_MASK) ==
1723 LPFC_PORT_SEM_UE_RECOVERABLE) {
1724 for (i = 0; i < 20; i++) {
1725 msleep(1000);
1726 if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
1727 &portsmphr_reg.word0) &&
1728 (LPFC_POST_STAGE_PORT_READY ==
1729 bf_get(lpfc_port_smphr_port_status,
1730 &portsmphr_reg))) {
1731 rc = lpfc_sli4_port_sta_fn_reset(phba,
1732 LPFC_MBX_NO_WAIT, en_rn_msg);
1733 if (rc == 0)
1734 return;
1735 lpfc_printf_log(phba,
1736 KERN_ERR, LOG_INIT,
1737 "4215 Failed to recover UE");
1738 break;
1739 }
1740 }
1741 }
1742 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1743 "7624 Firmware not ready: Failing UE recovery,"
1744 " waited %dSec", i);
James Smart2fcee4b2010-12-15 17:57:46 -05001745 lpfc_sli4_offline_eratt(phba);
1746 break;
James Smart946727d2015-04-07 15:07:09 -04001747
James Smart2fcee4b2010-12-15 17:57:46 -05001748 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2e90f4b2011-12-13 13:22:37 -05001749 pci_rd_rc1 = lpfc_readl(
1750 phba->sli4_hba.u.if_type2.STATUSregaddr,
1751 &portstat_reg.word0);
1752 /* consider PCI bus read error as pci_channel_offline */
James Smart6b5151f2012-01-18 16:24:06 -05001753 if (pci_rd_rc1 == -EIO) {
1754 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1755 "3151 PCI bus read access failure: x%x\n",
1756 readl(phba->sli4_hba.u.if_type2.STATUSregaddr));
James Smart2e90f4b2011-12-13 13:22:37 -05001757 return;
James Smart6b5151f2012-01-18 16:24:06 -05001758 }
James Smart2e90f4b2011-12-13 13:22:37 -05001759 reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
1760 reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
James Smart2fcee4b2010-12-15 17:57:46 -05001761 if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) {
James Smart2fcee4b2010-12-15 17:57:46 -05001762 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1763 "2889 Port Overtemperature event, "
James Smart946727d2015-04-07 15:07:09 -04001764 "taking port offline Data: x%x x%x\n",
1765 reg_err1, reg_err2);
1766
James Smart310429e2016-07-06 12:35:54 -07001767 phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04001768 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
1769 temp_event_data.event_code = LPFC_CRIT_TEMP;
1770 temp_event_data.data = 0xFFFFFFFF;
1771
1772 shost = lpfc_shost_from_vport(phba->pport);
1773 fc_host_post_vendor_event(shost, fc_get_event_number(),
1774 sizeof(temp_event_data),
1775 (char *)&temp_event_data,
1776 SCSI_NL_VID_TYPE_PCI
1777 | PCI_VENDOR_ID_EMULEX);
1778
James Smart2fcee4b2010-12-15 17:57:46 -05001779 spin_lock_irq(&phba->hbalock);
1780 phba->over_temp_state = HBA_OVER_TEMP;
1781 spin_unlock_irq(&phba->hbalock);
1782 lpfc_sli4_offline_eratt(phba);
James Smart946727d2015-04-07 15:07:09 -04001783 return;
James Smart2fcee4b2010-12-15 17:57:46 -05001784 }
James Smart2e90f4b2011-12-13 13:22:37 -05001785 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smarte10b2022014-02-20 09:57:43 -05001786 reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) {
James Smart2e90f4b2011-12-13 13:22:37 -05001787 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte10b2022014-02-20 09:57:43 -05001788 "3143 Port Down: Firmware Update "
1789 "Detected\n");
1790 en_rn_msg = false;
1791 } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
James Smart2e90f4b2011-12-13 13:22:37 -05001792 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1793 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1794 "3144 Port Down: Debug Dump\n");
1795 else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1796 reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON)
1797 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1798 "3145 Port Down: Provisioning\n");
James Smart618a5232012-06-12 13:54:36 -04001799
James Smart946727d2015-04-07 15:07:09 -04001800 /* If resets are disabled then leave the HBA alone and return */
1801 if (!phba->cfg_enable_hba_reset)
1802 return;
1803
James Smart618a5232012-06-12 13:54:36 -04001804 /* Check port status register for function reset */
James Smarte10b2022014-02-20 09:57:43 -05001805 rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT,
1806 en_rn_msg);
James Smart618a5232012-06-12 13:54:36 -04001807 if (rc == 0) {
1808 /* don't report event on forced debug dump */
1809 if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 &&
1810 reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP)
1811 return;
1812 else
1813 break;
James Smart2fcee4b2010-12-15 17:57:46 -05001814 }
James Smart618a5232012-06-12 13:54:36 -04001815 /* fall through for not able to recover */
James Smart6b5151f2012-01-18 16:24:06 -05001816 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1817 "3152 Unrecoverable error, bring the port "
1818 "offline\n");
James Smart2fcee4b2010-12-15 17:57:46 -05001819 lpfc_sli4_offline_eratt(phba);
1820 break;
1821 case LPFC_SLI_INTF_IF_TYPE_1:
1822 default:
1823 break;
1824 }
James Smart2e90f4b2011-12-13 13:22:37 -05001825 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1826 "3123 Report dump event to upper layer\n");
1827 /* Send an internal error event to mgmt application */
1828 lpfc_board_errevt_to_mgmt(phba);
1829
1830 event_data = FC_REG_DUMP_EVENT;
1831 shost = lpfc_shost_from_vport(vport);
1832 fc_host_post_vendor_event(shost, fc_get_event_number(),
1833 sizeof(event_data), (char *) &event_data,
1834 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
James Smartda0436e2009-05-22 14:51:39 -04001835}
1836
1837/**
1838 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1839 * @phba: pointer to lpfc HBA data structure.
1840 *
1841 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1842 * routine from the API jump table function pointer from the lpfc_hba struct.
1843 *
1844 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001845 * 0 - success.
James Smartda0436e2009-05-22 14:51:39 -04001846 * Any other value - error.
1847 **/
1848void
1849lpfc_handle_eratt(struct lpfc_hba *phba)
1850{
1851 (*phba->lpfc_handle_eratt)(phba);
1852}
1853
1854/**
James Smart3621a712009-04-06 18:47:14 -04001855 * lpfc_handle_latt - The HBA link event handler
James Smarte59058c2008-08-24 21:49:00 -04001856 * @phba: pointer to lpfc hba data structure.
1857 *
1858 * This routine is invoked from the worker thread to handle a HBA host
James Smart895427b2017-02-12 13:52:30 -08001859 * attention link event. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04001860 **/
dea31012005-04-17 16:05:31 -05001861void
James Smart2e0fef82007-06-17 19:56:36 -05001862lpfc_handle_latt(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001863{
James Smart2e0fef82007-06-17 19:56:36 -05001864 struct lpfc_vport *vport = phba->pport;
1865 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001866 LPFC_MBOXQ_t *pmb;
1867 volatile uint32_t control;
1868 struct lpfc_dmabuf *mp;
James Smart09372822008-01-11 01:52:54 -05001869 int rc = 0;
dea31012005-04-17 16:05:31 -05001870
1871 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001872 if (!pmb) {
1873 rc = 1;
dea31012005-04-17 16:05:31 -05001874 goto lpfc_handle_latt_err_exit;
James Smart09372822008-01-11 01:52:54 -05001875 }
dea31012005-04-17 16:05:31 -05001876
1877 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
James Smart09372822008-01-11 01:52:54 -05001878 if (!mp) {
1879 rc = 2;
dea31012005-04-17 16:05:31 -05001880 goto lpfc_handle_latt_free_pmb;
James Smart09372822008-01-11 01:52:54 -05001881 }
dea31012005-04-17 16:05:31 -05001882
1883 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
James Smart09372822008-01-11 01:52:54 -05001884 if (!mp->virt) {
1885 rc = 3;
dea31012005-04-17 16:05:31 -05001886 goto lpfc_handle_latt_free_mp;
James Smart09372822008-01-11 01:52:54 -05001887 }
dea31012005-04-17 16:05:31 -05001888
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001889 /* Cleanup any outstanding ELS commands */
James Smart549e55c2007-08-02 11:09:51 -04001890 lpfc_els_flush_all_cmd(phba);
dea31012005-04-17 16:05:31 -05001891
1892 psli->slistat.link_event++;
James Smart76a95d72010-11-20 23:11:48 -05001893 lpfc_read_topology(phba, pmb, mp);
1894 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smart2e0fef82007-06-17 19:56:36 -05001895 pmb->vport = vport;
James Smart0d2b6b82008-06-14 22:52:47 -04001896 /* Block ELS IOCBs until we have processed this mbox command */
James Smart895427b2017-02-12 13:52:30 -08001897 phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
James Smart0b727fe2007-10-27 13:37:25 -04001898 rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
James Smart09372822008-01-11 01:52:54 -05001899 if (rc == MBX_NOT_FINISHED) {
1900 rc = 4;
James Smart14691152006-12-02 13:34:28 -05001901 goto lpfc_handle_latt_free_mbuf;
James Smart09372822008-01-11 01:52:54 -05001902 }
dea31012005-04-17 16:05:31 -05001903
1904 /* Clear Link Attention in HA REG */
James Smart2e0fef82007-06-17 19:56:36 -05001905 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001906 writel(HA_LATT, phba->HAregaddr);
1907 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001908 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001909
1910 return;
1911
James Smart14691152006-12-02 13:34:28 -05001912lpfc_handle_latt_free_mbuf:
James Smart895427b2017-02-12 13:52:30 -08001913 phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart14691152006-12-02 13:34:28 -05001914 lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05001915lpfc_handle_latt_free_mp:
1916 kfree(mp);
1917lpfc_handle_latt_free_pmb:
James Smart1dcb58e2007-04-25 09:51:30 -04001918 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001919lpfc_handle_latt_err_exit:
1920 /* Enable Link attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001921 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001922 psli->sli_flag |= LPFC_PROCESS_LA;
1923 control = readl(phba->HCregaddr);
1924 control |= HC_LAINT_ENA;
1925 writel(control, phba->HCregaddr);
1926 readl(phba->HCregaddr); /* flush */
1927
1928 /* Clear Link Attention in HA REG */
1929 writel(HA_LATT, phba->HAregaddr);
1930 readl(phba->HAregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001931 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001932 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001933 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001934
James Smart09372822008-01-11 01:52:54 -05001935 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1936 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
dea31012005-04-17 16:05:31 -05001937
1938 return;
1939}
1940
James Smarte59058c2008-08-24 21:49:00 -04001941/**
James Smart3621a712009-04-06 18:47:14 -04001942 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
James Smarte59058c2008-08-24 21:49:00 -04001943 * @phba: pointer to lpfc hba data structure.
1944 * @vpd: pointer to the vital product data.
1945 * @len: length of the vital product data in bytes.
1946 *
1947 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1948 * an array of characters. In this routine, the ModelName, ProgramType, and
1949 * ModelDesc, etc. fields of the phba data structure will be populated.
1950 *
1951 * Return codes
1952 * 0 - pointer to the VPD passed in is NULL
1953 * 1 - success
1954 **/
James Smart3772a992009-05-22 14:50:54 -04001955int
James Smart2e0fef82007-06-17 19:56:36 -05001956lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
dea31012005-04-17 16:05:31 -05001957{
1958 uint8_t lenlo, lenhi;
Anton Blanchard07da60c2007-03-21 08:41:47 -05001959 int Length;
dea31012005-04-17 16:05:31 -05001960 int i, j;
1961 int finished = 0;
1962 int index = 0;
1963
1964 if (!vpd)
1965 return 0;
1966
1967 /* Vital Product */
James Smarted957682007-06-17 19:56:37 -05001968 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001969 "0455 Vital Product Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001970 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
1971 (uint32_t) vpd[3]);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001972 while (!finished && (index < (len - 4))) {
dea31012005-04-17 16:05:31 -05001973 switch (vpd[index]) {
1974 case 0x82:
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001975 case 0x91:
dea31012005-04-17 16:05:31 -05001976 index += 1;
1977 lenlo = vpd[index];
1978 index += 1;
1979 lenhi = vpd[index];
1980 index += 1;
1981 i = ((((unsigned short)lenhi) << 8) + lenlo);
1982 index += i;
1983 break;
1984 case 0x90:
1985 index += 1;
1986 lenlo = vpd[index];
1987 index += 1;
1988 lenhi = vpd[index];
1989 index += 1;
1990 Length = ((((unsigned short)lenhi) << 8) + lenlo);
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05001991 if (Length > len - index)
1992 Length = len - index;
dea31012005-04-17 16:05:31 -05001993 while (Length > 0) {
1994 /* Look for Serial Number */
1995 if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
1996 index += 2;
1997 i = vpd[index];
1998 index += 1;
1999 j = 0;
2000 Length -= (3+i);
2001 while(i--) {
2002 phba->SerialNumber[j++] = vpd[index++];
2003 if (j == 31)
2004 break;
2005 }
2006 phba->SerialNumber[j] = 0;
2007 continue;
2008 }
2009 else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
2010 phba->vpd_flag |= VPD_MODEL_DESC;
2011 index += 2;
2012 i = vpd[index];
2013 index += 1;
2014 j = 0;
2015 Length -= (3+i);
2016 while(i--) {
2017 phba->ModelDesc[j++] = vpd[index++];
2018 if (j == 255)
2019 break;
2020 }
2021 phba->ModelDesc[j] = 0;
2022 continue;
2023 }
2024 else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
2025 phba->vpd_flag |= VPD_MODEL_NAME;
2026 index += 2;
2027 i = vpd[index];
2028 index += 1;
2029 j = 0;
2030 Length -= (3+i);
2031 while(i--) {
2032 phba->ModelName[j++] = vpd[index++];
2033 if (j == 79)
2034 break;
2035 }
2036 phba->ModelName[j] = 0;
2037 continue;
2038 }
2039 else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
2040 phba->vpd_flag |= VPD_PROGRAM_TYPE;
2041 index += 2;
2042 i = vpd[index];
2043 index += 1;
2044 j = 0;
2045 Length -= (3+i);
2046 while(i--) {
2047 phba->ProgramType[j++] = vpd[index++];
2048 if (j == 255)
2049 break;
2050 }
2051 phba->ProgramType[j] = 0;
2052 continue;
2053 }
2054 else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
2055 phba->vpd_flag |= VPD_PORT;
2056 index += 2;
2057 i = vpd[index];
2058 index += 1;
2059 j = 0;
2060 Length -= (3+i);
2061 while(i--) {
James Smartcd1c8302011-10-10 21:33:25 -04002062 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2063 (phba->sli4_hba.pport_name_sta ==
2064 LPFC_SLI4_PPNAME_GET)) {
2065 j++;
2066 index++;
2067 } else
2068 phba->Port[j++] = vpd[index++];
2069 if (j == 19)
2070 break;
dea31012005-04-17 16:05:31 -05002071 }
James Smartcd1c8302011-10-10 21:33:25 -04002072 if ((phba->sli_rev != LPFC_SLI_REV4) ||
2073 (phba->sli4_hba.pport_name_sta ==
2074 LPFC_SLI4_PPNAME_NON))
2075 phba->Port[j] = 0;
dea31012005-04-17 16:05:31 -05002076 continue;
2077 }
2078 else {
2079 index += 2;
2080 i = vpd[index];
2081 index += 1;
2082 index += i;
2083 Length -= (3 + i);
2084 }
2085 }
2086 finished = 0;
2087 break;
2088 case 0x78:
2089 finished = 1;
2090 break;
2091 default:
2092 index ++;
2093 break;
2094 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002095 }
dea31012005-04-17 16:05:31 -05002096
2097 return(1);
2098}
2099
James Smarte59058c2008-08-24 21:49:00 -04002100/**
James Smart3621a712009-04-06 18:47:14 -04002101 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
James Smarte59058c2008-08-24 21:49:00 -04002102 * @phba: pointer to lpfc hba data structure.
2103 * @mdp: pointer to the data structure to hold the derived model name.
2104 * @descp: pointer to the data structure to hold the derived description.
2105 *
2106 * This routine retrieves HBA's description based on its registered PCI device
2107 * ID. The @descp passed into this function points to an array of 256 chars. It
2108 * shall be returned with the model name, maximum speed, and the host bus type.
2109 * The @mdp passed into this function points to an array of 80 chars. When the
2110 * function returns, the @mdp will be filled with the model name.
2111 **/
dea31012005-04-17 16:05:31 -05002112static void
James Smart2e0fef82007-06-17 19:56:36 -05002113lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
dea31012005-04-17 16:05:31 -05002114{
2115 lpfc_vpd_t *vp;
James.Smart@Emulex.Comfefcb2b2005-11-28 15:08:56 -05002116 uint16_t dev_id = phba->pcidev->device;
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002117 int max_speed;
James Smart84774a42008-08-24 21:50:06 -04002118 int GE = 0;
James Smartda0436e2009-05-22 14:51:39 -04002119 int oneConnect = 0; /* default is not a oneConnect */
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002120 struct {
James Smarta747c9c2009-11-18 15:41:10 -05002121 char *name;
2122 char *bus;
2123 char *function;
2124 } m = {"<Unknown>", "", ""};
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002125
2126 if (mdp && mdp[0] != '\0'
2127 && descp && descp[0] != '\0')
2128 return;
2129
James Smartd38dd522015-08-31 16:48:17 -04002130 if (phba->lmt & LMT_32Gb)
2131 max_speed = 32;
2132 else if (phba->lmt & LMT_16Gb)
James Smartc0c11512011-05-24 11:41:34 -04002133 max_speed = 16;
2134 else if (phba->lmt & LMT_10Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002135 max_speed = 10;
2136 else if (phba->lmt & LMT_8Gb)
2137 max_speed = 8;
2138 else if (phba->lmt & LMT_4Gb)
2139 max_speed = 4;
2140 else if (phba->lmt & LMT_2Gb)
2141 max_speed = 2;
James Smart4169d862012-09-29 11:32:09 -04002142 else if (phba->lmt & LMT_1Gb)
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002143 max_speed = 1;
James Smart4169d862012-09-29 11:32:09 -04002144 else
2145 max_speed = 0;
dea31012005-04-17 16:05:31 -05002146
2147 vp = &phba->vpd;
dea31012005-04-17 16:05:31 -05002148
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002149 switch (dev_id) {
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002150 case PCI_DEVICE_ID_FIREFLY:
James Smart12222f42014-05-21 08:05:19 -04002151 m = (typeof(m)){"LP6000", "PCI",
2152 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002153 break;
dea31012005-04-17 16:05:31 -05002154 case PCI_DEVICE_ID_SUPERFLY:
2155 if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
James Smart12222f42014-05-21 08:05:19 -04002156 m = (typeof(m)){"LP7000", "PCI", ""};
dea31012005-04-17 16:05:31 -05002157 else
James Smart12222f42014-05-21 08:05:19 -04002158 m = (typeof(m)){"LP7000E", "PCI", ""};
2159 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002160 break;
2161 case PCI_DEVICE_ID_DRAGONFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002162 m = (typeof(m)){"LP8000", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002163 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002164 break;
2165 case PCI_DEVICE_ID_CENTAUR:
2166 if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
James Smart12222f42014-05-21 08:05:19 -04002167 m = (typeof(m)){"LP9002", "PCI", ""};
dea31012005-04-17 16:05:31 -05002168 else
James Smart12222f42014-05-21 08:05:19 -04002169 m = (typeof(m)){"LP9000", "PCI", ""};
2170 m.function = "Obsolete, Unsupported Fibre Channel Adapter";
dea31012005-04-17 16:05:31 -05002171 break;
2172 case PCI_DEVICE_ID_RFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002173 m = (typeof(m)){"LP952", "PCI",
James Smart12222f42014-05-21 08:05:19 -04002174 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002175 break;
2176 case PCI_DEVICE_ID_PEGASUS:
James Smarta747c9c2009-11-18 15:41:10 -05002177 m = (typeof(m)){"LP9802", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002178 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002179 break;
2180 case PCI_DEVICE_ID_THOR:
James Smarta747c9c2009-11-18 15:41:10 -05002181 m = (typeof(m)){"LP10000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002182 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002183 break;
2184 case PCI_DEVICE_ID_VIPER:
James Smarta747c9c2009-11-18 15:41:10 -05002185 m = (typeof(m)){"LPX1000", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002186 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002187 break;
2188 case PCI_DEVICE_ID_PFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002189 m = (typeof(m)){"LP982", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002190 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002191 break;
2192 case PCI_DEVICE_ID_TFLY:
James Smarta747c9c2009-11-18 15:41:10 -05002193 m = (typeof(m)){"LP1050", "PCI-X",
James Smart12222f42014-05-21 08:05:19 -04002194 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002195 break;
2196 case PCI_DEVICE_ID_HELIOS:
James Smarta747c9c2009-11-18 15:41:10 -05002197 m = (typeof(m)){"LP11000", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002198 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002199 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002200 case PCI_DEVICE_ID_HELIOS_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002201 m = (typeof(m)){"LP11000-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002202 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002203 break;
2204 case PCI_DEVICE_ID_HELIOS_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002205 m = (typeof(m)){"LP11002-SP", "PCI-X2",
James Smart12222f42014-05-21 08:05:19 -04002206 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002207 break;
2208 case PCI_DEVICE_ID_NEPTUNE:
James Smart12222f42014-05-21 08:05:19 -04002209 m = (typeof(m)){"LPe1000", "PCIe",
2210 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002211 break;
2212 case PCI_DEVICE_ID_NEPTUNE_SCSP:
James Smart12222f42014-05-21 08:05:19 -04002213 m = (typeof(m)){"LPe1000-SP", "PCIe",
2214 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002215 break;
2216 case PCI_DEVICE_ID_NEPTUNE_DCSP:
James Smart12222f42014-05-21 08:05:19 -04002217 m = (typeof(m)){"LPe1002-SP", "PCIe",
2218 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002219 break;
dea31012005-04-17 16:05:31 -05002220 case PCI_DEVICE_ID_BMID:
James Smarta747c9c2009-11-18 15:41:10 -05002221 m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002222 break;
2223 case PCI_DEVICE_ID_BSMB:
James Smart12222f42014-05-21 08:05:19 -04002224 m = (typeof(m)){"LP111", "PCI-X2",
2225 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002226 break;
2227 case PCI_DEVICE_ID_ZEPHYR:
James Smarta747c9c2009-11-18 15:41:10 -05002228 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002229 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002230 case PCI_DEVICE_ID_ZEPHYR_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002231 m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002232 break;
2233 case PCI_DEVICE_ID_ZEPHYR_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002234 m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
James Smarta257bf92009-04-06 18:48:10 -04002235 GE = 1;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002236 break;
dea31012005-04-17 16:05:31 -05002237 case PCI_DEVICE_ID_ZMID:
James Smarta747c9c2009-11-18 15:41:10 -05002238 m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002239 break;
2240 case PCI_DEVICE_ID_ZSMB:
James Smarta747c9c2009-11-18 15:41:10 -05002241 m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002242 break;
2243 case PCI_DEVICE_ID_LP101:
James Smart12222f42014-05-21 08:05:19 -04002244 m = (typeof(m)){"LP101", "PCI-X",
2245 "Obsolete, Unsupported Fibre Channel Adapter"};
dea31012005-04-17 16:05:31 -05002246 break;
2247 case PCI_DEVICE_ID_LP10000S:
James Smart12222f42014-05-21 08:05:19 -04002248 m = (typeof(m)){"LP10000-S", "PCI",
2249 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com06325e72005-06-25 10:34:22 -04002250 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002251 case PCI_DEVICE_ID_LP11000S:
James Smart12222f42014-05-21 08:05:19 -04002252 m = (typeof(m)){"LP11000-S", "PCI-X2",
2253 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart18a3b592006-12-02 13:35:08 -05002254 break;
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002255 case PCI_DEVICE_ID_LPE11000S:
James Smart12222f42014-05-21 08:05:19 -04002256 m = (typeof(m)){"LPe11000-S", "PCIe",
2257 "Obsolete, Unsupported Fibre Channel Adapter"};
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002258 break;
James Smartb87eab32007-04-25 09:53:28 -04002259 case PCI_DEVICE_ID_SAT:
James Smarta747c9c2009-11-18 15:41:10 -05002260 m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002261 break;
2262 case PCI_DEVICE_ID_SAT_MID:
James Smarta747c9c2009-11-18 15:41:10 -05002263 m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002264 break;
2265 case PCI_DEVICE_ID_SAT_SMB:
James Smarta747c9c2009-11-18 15:41:10 -05002266 m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002267 break;
2268 case PCI_DEVICE_ID_SAT_DCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002269 m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002270 break;
2271 case PCI_DEVICE_ID_SAT_SCSP:
James Smarta747c9c2009-11-18 15:41:10 -05002272 m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002273 break;
2274 case PCI_DEVICE_ID_SAT_S:
James Smarta747c9c2009-11-18 15:41:10 -05002275 m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
James Smartb87eab32007-04-25 09:53:28 -04002276 break;
James Smart84774a42008-08-24 21:50:06 -04002277 case PCI_DEVICE_ID_HORNET:
James Smart12222f42014-05-21 08:05:19 -04002278 m = (typeof(m)){"LP21000", "PCIe",
2279 "Obsolete, Unsupported FCoE Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002280 GE = 1;
2281 break;
2282 case PCI_DEVICE_ID_PROTEUS_VF:
James Smarta747c9c2009-11-18 15:41:10 -05002283 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002284 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002285 break;
2286 case PCI_DEVICE_ID_PROTEUS_PF:
James Smarta747c9c2009-11-18 15:41:10 -05002287 m = (typeof(m)){"LPev12000", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002288 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002289 break;
2290 case PCI_DEVICE_ID_PROTEUS_S:
James Smarta747c9c2009-11-18 15:41:10 -05002291 m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
James Smart12222f42014-05-21 08:05:19 -04002292 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart84774a42008-08-24 21:50:06 -04002293 break;
James Smartda0436e2009-05-22 14:51:39 -04002294 case PCI_DEVICE_ID_TIGERSHARK:
2295 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002296 m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
James Smartda0436e2009-05-22 14:51:39 -04002297 break;
James Smarta747c9c2009-11-18 15:41:10 -05002298 case PCI_DEVICE_ID_TOMCAT:
James Smart6669f9b2009-10-02 15:16:45 -04002299 oneConnect = 1;
James Smarta747c9c2009-11-18 15:41:10 -05002300 m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
2301 break;
2302 case PCI_DEVICE_ID_FALCON:
2303 m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
2304 "EmulexSecure Fibre"};
James Smart6669f9b2009-10-02 15:16:45 -04002305 break;
James Smart98fc5dd2010-06-07 15:24:29 -04002306 case PCI_DEVICE_ID_BALIUS:
2307 m = (typeof(m)){"LPVe12002", "PCIe Shared I/O",
James Smart12222f42014-05-21 08:05:19 -04002308 "Obsolete, Unsupported Fibre Channel Adapter"};
James Smart98fc5dd2010-06-07 15:24:29 -04002309 break;
James Smart085c6472010-11-20 23:11:37 -05002310 case PCI_DEVICE_ID_LANCER_FC:
James Smartc0c11512011-05-24 11:41:34 -04002311 m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
James Smart085c6472010-11-20 23:11:37 -05002312 break;
James Smart12222f42014-05-21 08:05:19 -04002313 case PCI_DEVICE_ID_LANCER_FC_VF:
2314 m = (typeof(m)){"LPe16000", "PCIe",
2315 "Obsolete, Unsupported Fibre Channel Adapter"};
2316 break;
James Smart085c6472010-11-20 23:11:37 -05002317 case PCI_DEVICE_ID_LANCER_FCOE:
2318 oneConnect = 1;
James Smart079b5c92011-08-21 21:48:49 -04002319 m = (typeof(m)){"OCe15100", "PCIe", "FCoE"};
James Smart085c6472010-11-20 23:11:37 -05002320 break;
James Smart12222f42014-05-21 08:05:19 -04002321 case PCI_DEVICE_ID_LANCER_FCOE_VF:
2322 oneConnect = 1;
2323 m = (typeof(m)){"OCe15100", "PCIe",
2324 "Obsolete, Unsupported FCoE"};
2325 break;
James Smartd38dd522015-08-31 16:48:17 -04002326 case PCI_DEVICE_ID_LANCER_G6_FC:
2327 m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"};
2328 break;
James Smartf8cafd32012-08-03 12:42:51 -04002329 case PCI_DEVICE_ID_SKYHAWK:
2330 case PCI_DEVICE_ID_SKYHAWK_VF:
2331 oneConnect = 1;
2332 m = (typeof(m)){"OCe14000", "PCIe", "FCoE"};
2333 break;
James.Smart@Emulex.Com5cc36b32005-11-28 11:42:19 -05002334 default:
James Smarta747c9c2009-11-18 15:41:10 -05002335 m = (typeof(m)){"Unknown", "", ""};
James.Smart@Emulex.Come4adb202005-11-28 11:42:12 -05002336 break;
dea31012005-04-17 16:05:31 -05002337 }
Jamie Wellnitz74b72a52006-02-28 22:33:04 -05002338
2339 if (mdp && mdp[0] == '\0')
2340 snprintf(mdp, 79,"%s", m.name);
James Smartc0c11512011-05-24 11:41:34 -04002341 /*
2342 * oneConnect hba requires special processing, they are all initiators
James Smartda0436e2009-05-22 14:51:39 -04002343 * and we put the port number on the end
2344 */
2345 if (descp && descp[0] == '\0') {
2346 if (oneConnect)
2347 snprintf(descp, 255,
James Smart4169d862012-09-29 11:32:09 -04002348 "Emulex OneConnect %s, %s Initiator %s",
James Smarta747c9c2009-11-18 15:41:10 -05002349 m.name, m.function,
James Smartda0436e2009-05-22 14:51:39 -04002350 phba->Port);
James Smart4169d862012-09-29 11:32:09 -04002351 else if (max_speed == 0)
2352 snprintf(descp, 255,
Sebastian Herbszt290237d2015-08-31 16:48:08 -04002353 "Emulex %s %s %s",
James Smart4169d862012-09-29 11:32:09 -04002354 m.name, m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002355 else
2356 snprintf(descp, 255,
2357 "Emulex %s %d%s %s %s",
James Smarta747c9c2009-11-18 15:41:10 -05002358 m.name, max_speed, (GE) ? "GE" : "Gb",
2359 m.bus, m.function);
James Smartda0436e2009-05-22 14:51:39 -04002360 }
dea31012005-04-17 16:05:31 -05002361}
2362
James Smarte59058c2008-08-24 21:49:00 -04002363/**
James Smart3621a712009-04-06 18:47:14 -04002364 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04002365 * @phba: pointer to lpfc hba data structure.
2366 * @pring: pointer to a IOCB ring.
2367 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2368 *
2369 * This routine posts a given number of IOCBs with the associated DMA buffer
2370 * descriptors specified by the cnt argument to the given IOCB ring.
2371 *
2372 * Return codes
2373 * The number of IOCBs NOT able to be posted to the IOCB ring.
2374 **/
dea31012005-04-17 16:05:31 -05002375int
James Smart495a7142008-06-14 22:52:59 -04002376lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
dea31012005-04-17 16:05:31 -05002377{
2378 IOCB_t *icmd;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002379 struct lpfc_iocbq *iocb;
dea31012005-04-17 16:05:31 -05002380 struct lpfc_dmabuf *mp1, *mp2;
2381
2382 cnt += pring->missbufcnt;
2383
2384 /* While there are buffers to post */
2385 while (cnt > 0) {
2386 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -04002387 iocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -05002388 if (iocb == NULL) {
2389 pring->missbufcnt = cnt;
2390 return cnt;
2391 }
dea31012005-04-17 16:05:31 -05002392 icmd = &iocb->iocb;
2393
2394 /* 2 buffers can be posted per command */
2395 /* Allocate buffer to post */
2396 mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2397 if (mp1)
James Smart98c9ea52007-10-27 13:37:33 -04002398 mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
2399 if (!mp1 || !mp1->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002400 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002401 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002402 pring->missbufcnt = cnt;
2403 return cnt;
2404 }
2405
2406 INIT_LIST_HEAD(&mp1->list);
2407 /* Allocate buffer to post */
2408 if (cnt > 1) {
2409 mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
2410 if (mp2)
2411 mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
2412 &mp2->phys);
James Smart98c9ea52007-10-27 13:37:33 -04002413 if (!mp2 || !mp2->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002414 kfree(mp2);
dea31012005-04-17 16:05:31 -05002415 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2416 kfree(mp1);
James Bottomley604a3e32005-10-29 10:28:33 -05002417 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002418 pring->missbufcnt = cnt;
2419 return cnt;
2420 }
2421
2422 INIT_LIST_HEAD(&mp2->list);
2423 } else {
2424 mp2 = NULL;
2425 }
2426
2427 icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
2428 icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
2429 icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
2430 icmd->ulpBdeCount = 1;
2431 cnt--;
2432 if (mp2) {
2433 icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
2434 icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
2435 icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
2436 cnt--;
2437 icmd->ulpBdeCount = 2;
2438 }
2439
2440 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
2441 icmd->ulpLe = 1;
2442
James Smart3772a992009-05-22 14:50:54 -04002443 if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
2444 IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002445 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
2446 kfree(mp1);
2447 cnt++;
2448 if (mp2) {
2449 lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
2450 kfree(mp2);
2451 cnt++;
2452 }
James Bottomley604a3e32005-10-29 10:28:33 -05002453 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -05002454 pring->missbufcnt = cnt;
dea31012005-04-17 16:05:31 -05002455 return cnt;
2456 }
dea31012005-04-17 16:05:31 -05002457 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
James Smart92d7f7b2007-06-17 19:56:38 -05002458 if (mp2)
dea31012005-04-17 16:05:31 -05002459 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
dea31012005-04-17 16:05:31 -05002460 }
2461 pring->missbufcnt = 0;
2462 return 0;
2463}
2464
James Smarte59058c2008-08-24 21:49:00 -04002465/**
James Smart3621a712009-04-06 18:47:14 -04002466 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
James Smarte59058c2008-08-24 21:49:00 -04002467 * @phba: pointer to lpfc hba data structure.
2468 *
2469 * This routine posts initial receive IOCB buffers to the ELS ring. The
2470 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
James Smart895427b2017-02-12 13:52:30 -08002471 * set to 64 IOCBs. SLI3 only.
James Smarte59058c2008-08-24 21:49:00 -04002472 *
2473 * Return codes
2474 * 0 - success (currently always success)
2475 **/
dea31012005-04-17 16:05:31 -05002476static int
James Smart2e0fef82007-06-17 19:56:36 -05002477lpfc_post_rcv_buf(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002478{
2479 struct lpfc_sli *psli = &phba->sli;
2480
2481 /* Ring 0, ELS / CT buffers */
James Smart895427b2017-02-12 13:52:30 -08002482 lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0);
dea31012005-04-17 16:05:31 -05002483 /* Ring 2 - FCP no buffers needed */
2484
2485 return 0;
2486}
2487
2488#define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2489
James Smarte59058c2008-08-24 21:49:00 -04002490/**
James Smart3621a712009-04-06 18:47:14 -04002491 * lpfc_sha_init - Set up initial array of hash table entries
James Smarte59058c2008-08-24 21:49:00 -04002492 * @HashResultPointer: pointer to an array as hash table.
2493 *
2494 * This routine sets up the initial values to the array of hash table entries
2495 * for the LC HBAs.
2496 **/
dea31012005-04-17 16:05:31 -05002497static void
2498lpfc_sha_init(uint32_t * HashResultPointer)
2499{
2500 HashResultPointer[0] = 0x67452301;
2501 HashResultPointer[1] = 0xEFCDAB89;
2502 HashResultPointer[2] = 0x98BADCFE;
2503 HashResultPointer[3] = 0x10325476;
2504 HashResultPointer[4] = 0xC3D2E1F0;
2505}
2506
James Smarte59058c2008-08-24 21:49:00 -04002507/**
James Smart3621a712009-04-06 18:47:14 -04002508 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
James Smarte59058c2008-08-24 21:49:00 -04002509 * @HashResultPointer: pointer to an initial/result hash table.
2510 * @HashWorkingPointer: pointer to an working hash table.
2511 *
2512 * This routine iterates an initial hash table pointed by @HashResultPointer
2513 * with the values from the working hash table pointeed by @HashWorkingPointer.
2514 * The results are putting back to the initial hash table, returned through
2515 * the @HashResultPointer as the result hash table.
2516 **/
dea31012005-04-17 16:05:31 -05002517static void
2518lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
2519{
2520 int t;
2521 uint32_t TEMP;
2522 uint32_t A, B, C, D, E;
2523 t = 16;
2524 do {
2525 HashWorkingPointer[t] =
2526 S(1,
2527 HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
2528 8] ^
2529 HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
2530 } while (++t <= 79);
2531 t = 0;
2532 A = HashResultPointer[0];
2533 B = HashResultPointer[1];
2534 C = HashResultPointer[2];
2535 D = HashResultPointer[3];
2536 E = HashResultPointer[4];
2537
2538 do {
2539 if (t < 20) {
2540 TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
2541 } else if (t < 40) {
2542 TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
2543 } else if (t < 60) {
2544 TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
2545 } else {
2546 TEMP = (B ^ C ^ D) + 0xCA62C1D6;
2547 }
2548 TEMP += S(5, A) + E + HashWorkingPointer[t];
2549 E = D;
2550 D = C;
2551 C = S(30, B);
2552 B = A;
2553 A = TEMP;
2554 } while (++t <= 79);
2555
2556 HashResultPointer[0] += A;
2557 HashResultPointer[1] += B;
2558 HashResultPointer[2] += C;
2559 HashResultPointer[3] += D;
2560 HashResultPointer[4] += E;
2561
2562}
2563
James Smarte59058c2008-08-24 21:49:00 -04002564/**
James Smart3621a712009-04-06 18:47:14 -04002565 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
James Smarte59058c2008-08-24 21:49:00 -04002566 * @RandomChallenge: pointer to the entry of host challenge random number array.
2567 * @HashWorking: pointer to the entry of the working hash array.
2568 *
2569 * This routine calculates the working hash array referred by @HashWorking
2570 * from the challenge random numbers associated with the host, referred by
2571 * @RandomChallenge. The result is put into the entry of the working hash
2572 * array and returned by reference through @HashWorking.
2573 **/
dea31012005-04-17 16:05:31 -05002574static void
2575lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
2576{
2577 *HashWorking = (*RandomChallenge ^ *HashWorking);
2578}
2579
James Smarte59058c2008-08-24 21:49:00 -04002580/**
James Smart3621a712009-04-06 18:47:14 -04002581 * lpfc_hba_init - Perform special handling for LC HBA initialization
James Smarte59058c2008-08-24 21:49:00 -04002582 * @phba: pointer to lpfc hba data structure.
2583 * @hbainit: pointer to an array of unsigned 32-bit integers.
2584 *
2585 * This routine performs the special handling for LC HBA initialization.
2586 **/
dea31012005-04-17 16:05:31 -05002587void
2588lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
2589{
2590 int t;
2591 uint32_t *HashWorking;
James Smart2e0fef82007-06-17 19:56:36 -05002592 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
dea31012005-04-17 16:05:31 -05002593
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002594 HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002595 if (!HashWorking)
2596 return;
2597
dea31012005-04-17 16:05:31 -05002598 HashWorking[0] = HashWorking[78] = *pwwnn++;
2599 HashWorking[1] = HashWorking[79] = *pwwnn;
2600
2601 for (t = 0; t < 7; t++)
2602 lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
2603
2604 lpfc_sha_init(hbainit);
2605 lpfc_sha_iterate(hbainit, HashWorking);
2606 kfree(HashWorking);
2607}
2608
James Smarte59058c2008-08-24 21:49:00 -04002609/**
James Smart3621a712009-04-06 18:47:14 -04002610 * lpfc_cleanup - Performs vport cleanups before deleting a vport
James Smarte59058c2008-08-24 21:49:00 -04002611 * @vport: pointer to a virtual N_Port data structure.
2612 *
2613 * This routine performs the necessary cleanups before deleting the @vport.
2614 * It invokes the discovery state machine to perform necessary state
2615 * transitions and to release the ndlps associated with the @vport. Note,
2616 * the physical port is treated as @vport 0.
2617 **/
James Smart87af33f2007-10-27 13:37:43 -04002618void
James Smart2e0fef82007-06-17 19:56:36 -05002619lpfc_cleanup(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002620{
James Smart87af33f2007-10-27 13:37:43 -04002621 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002622 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smarta8adb832007-10-27 13:37:53 -04002623 int i = 0;
dea31012005-04-17 16:05:31 -05002624
James Smart87af33f2007-10-27 13:37:43 -04002625 if (phba->link_state > LPFC_LINK_DOWN)
2626 lpfc_port_link_failure(vport);
2627
2628 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002629 if (!NLP_CHK_NODE_ACT(ndlp)) {
2630 ndlp = lpfc_enable_node(vport, ndlp,
2631 NLP_STE_UNUSED_NODE);
2632 if (!ndlp)
2633 continue;
2634 spin_lock_irq(&phba->ndlp_lock);
2635 NLP_SET_FREE_REQ(ndlp);
2636 spin_unlock_irq(&phba->ndlp_lock);
2637 /* Trigger the release of the ndlp memory */
2638 lpfc_nlp_put(ndlp);
2639 continue;
2640 }
2641 spin_lock_irq(&phba->ndlp_lock);
2642 if (NLP_CHK_FREE_REQ(ndlp)) {
2643 /* The ndlp should not be in memory free mode already */
2644 spin_unlock_irq(&phba->ndlp_lock);
2645 continue;
2646 } else
2647 /* Indicate request for freeing ndlp memory */
2648 NLP_SET_FREE_REQ(ndlp);
2649 spin_unlock_irq(&phba->ndlp_lock);
2650
James Smart58da1ff2008-04-07 10:15:56 -04002651 if (vport->port_type != LPFC_PHYSICAL_PORT &&
2652 ndlp->nlp_DID == Fabric_DID) {
2653 /* Just free up ndlp with Fabric_DID for vports */
2654 lpfc_nlp_put(ndlp);
2655 continue;
2656 }
2657
James Smarteff4a012012-01-18 16:25:25 -05002658 /* take care of nodes in unused state before the state
2659 * machine taking action.
2660 */
2661 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
2662 lpfc_nlp_put(ndlp);
2663 continue;
2664 }
2665
James Smart87af33f2007-10-27 13:37:43 -04002666 if (ndlp->nlp_type & NLP_FABRIC)
2667 lpfc_disc_state_machine(vport, ndlp, NULL,
2668 NLP_EVT_DEVICE_RECOVERY);
James Smarte47c9092008-02-08 18:49:26 -05002669
James Smarta0f2d3e2017-02-12 13:52:31 -08002670 if (ndlp->nlp_fc4_type & NLP_FC4_NVME) {
2671 /* Remove the NVME transport reference now and
2672 * continue to remove the node.
2673 */
2674 lpfc_nlp_put(ndlp);
2675 }
2676
James Smart87af33f2007-10-27 13:37:43 -04002677 lpfc_disc_state_machine(vport, ndlp, NULL,
2678 NLP_EVT_DEVICE_RM);
2679 }
2680
James Smarta8adb832007-10-27 13:37:53 -04002681 /* At this point, ALL ndlp's should be gone
2682 * because of the previous NLP_EVT_DEVICE_RM.
2683 * Lets wait for this to happen, if needed.
2684 */
James Smart87af33f2007-10-27 13:37:43 -04002685 while (!list_empty(&vport->fc_nodes)) {
James Smarta8adb832007-10-27 13:37:53 -04002686 if (i++ > 3000) {
James Smart87af33f2007-10-27 13:37:43 -04002687 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smarta8adb832007-10-27 13:37:53 -04002688 "0233 Nodelist not empty\n");
James Smarte47c9092008-02-08 18:49:26 -05002689 list_for_each_entry_safe(ndlp, next_ndlp,
2690 &vport->fc_nodes, nlp_listp) {
2691 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
2692 LOG_NODE,
James Smartd7c255b2008-08-24 21:50:00 -04002693 "0282 did:x%x ndlp:x%p "
James Smarte47c9092008-02-08 18:49:26 -05002694 "usgmap:x%x refcnt:%d\n",
2695 ndlp->nlp_DID, (void *)ndlp,
2696 ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01002697 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05002698 }
James Smarta8adb832007-10-27 13:37:53 -04002699 break;
James Smart87af33f2007-10-27 13:37:43 -04002700 }
James Smarta8adb832007-10-27 13:37:53 -04002701
2702 /* Wait for any activity on ndlps to settle */
2703 msleep(10);
James Smart87af33f2007-10-27 13:37:43 -04002704 }
James Smart1151e3e2011-02-16 12:39:35 -05002705 lpfc_cleanup_vports_rrqs(vport, NULL);
dea31012005-04-17 16:05:31 -05002706}
2707
James Smarte59058c2008-08-24 21:49:00 -04002708/**
James Smart3621a712009-04-06 18:47:14 -04002709 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
James Smarte59058c2008-08-24 21:49:00 -04002710 * @vport: pointer to a virtual N_Port data structure.
2711 *
2712 * This routine stops all the timers associated with a @vport. This function
2713 * is invoked before disabling or deleting a @vport. Note that the physical
2714 * port is treated as @vport 0.
2715 **/
James Smart92d7f7b2007-06-17 19:56:38 -05002716void
2717lpfc_stop_vport_timers(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002718{
James Smart92d7f7b2007-06-17 19:56:38 -05002719 del_timer_sync(&vport->els_tmofunc);
James Smart92494142011-02-16 12:39:44 -05002720 del_timer_sync(&vport->delayed_disc_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002721 lpfc_can_disctmo(vport);
2722 return;
dea31012005-04-17 16:05:31 -05002723}
2724
James Smarte59058c2008-08-24 21:49:00 -04002725/**
James Smartecfd03c2010-02-12 14:41:27 -05002726 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2727 * @phba: pointer to lpfc hba data structure.
2728 *
2729 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2730 * caller of this routine should already hold the host lock.
2731 **/
2732void
2733__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2734{
James Smart5ac6b302010-10-22 11:05:36 -04002735 /* Clear pending FCF rediscovery wait flag */
2736 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2737
James Smartecfd03c2010-02-12 14:41:27 -05002738 /* Now, try to stop the timer */
2739 del_timer(&phba->fcf.redisc_wait);
2740}
2741
2742/**
2743 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2744 * @phba: pointer to lpfc hba data structure.
2745 *
2746 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2747 * checks whether the FCF rediscovery wait timer is pending with the host
2748 * lock held before proceeding with disabling the timer and clearing the
2749 * wait timer pendig flag.
2750 **/
2751void
2752lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2753{
2754 spin_lock_irq(&phba->hbalock);
2755 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2756 /* FCF rediscovery timer already fired or stopped */
2757 spin_unlock_irq(&phba->hbalock);
2758 return;
2759 }
2760 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart5ac6b302010-10-22 11:05:36 -04002761 /* Clear failover in progress flags */
2762 phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC);
James Smartecfd03c2010-02-12 14:41:27 -05002763 spin_unlock_irq(&phba->hbalock);
2764}
2765
2766/**
James Smart3772a992009-05-22 14:50:54 -04002767 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
James Smarte59058c2008-08-24 21:49:00 -04002768 * @phba: pointer to lpfc hba data structure.
2769 *
2770 * This routine stops all the timers associated with a HBA. This function is
2771 * invoked before either putting a HBA offline or unloading the driver.
2772 **/
James Smart3772a992009-05-22 14:50:54 -04002773void
2774lpfc_stop_hba_timers(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002775{
James Smart51ef4c22007-08-02 11:10:31 -04002776 lpfc_stop_vport_timers(phba->pport);
James Smart2e0fef82007-06-17 19:56:36 -05002777 del_timer_sync(&phba->sli.mbox_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002778 del_timer_sync(&phba->fabric_block_timer);
James Smart93996272008-08-24 21:50:30 -04002779 del_timer_sync(&phba->eratt_poll);
James Smart3772a992009-05-22 14:50:54 -04002780 del_timer_sync(&phba->hb_tmofunc);
James Smart1151e3e2011-02-16 12:39:35 -05002781 if (phba->sli_rev == LPFC_SLI_REV4) {
2782 del_timer_sync(&phba->rrq_tmr);
2783 phba->hba_flag &= ~HBA_RRQ_ACTIVE;
2784 }
James Smart3772a992009-05-22 14:50:54 -04002785 phba->hb_outstanding = 0;
2786
2787 switch (phba->pci_dev_grp) {
2788 case LPFC_PCI_DEV_LP:
2789 /* Stop any LightPulse device specific driver timers */
2790 del_timer_sync(&phba->fcp_poll_timer);
2791 break;
2792 case LPFC_PCI_DEV_OC:
2793 /* Stop any OneConnect device sepcific driver timers */
James Smartecfd03c2010-02-12 14:41:27 -05002794 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
James Smart3772a992009-05-22 14:50:54 -04002795 break;
2796 default:
2797 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2798 "0297 Invalid device group (x%x)\n",
2799 phba->pci_dev_grp);
2800 break;
2801 }
James Smart2e0fef82007-06-17 19:56:36 -05002802 return;
dea31012005-04-17 16:05:31 -05002803}
2804
James Smarte59058c2008-08-24 21:49:00 -04002805/**
James Smart3621a712009-04-06 18:47:14 -04002806 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
James Smarte59058c2008-08-24 21:49:00 -04002807 * @phba: pointer to lpfc hba data structure.
2808 *
2809 * This routine marks a HBA's management interface as blocked. Once the HBA's
2810 * management interface is marked as blocked, all the user space access to
2811 * the HBA, whether they are from sysfs interface or libdfc interface will
2812 * all be blocked. The HBA is set to block the management interface when the
2813 * driver prepares the HBA interface for online or offline.
2814 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01002815static void
James Smart618a5232012-06-12 13:54:36 -04002816lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action)
Adrian Bunka6ababd2007-11-05 18:07:33 +01002817{
2818 unsigned long iflag;
James Smart6e7288d2010-06-07 15:23:35 -04002819 uint8_t actcmd = MBX_HEARTBEAT;
2820 unsigned long timeout;
2821
Adrian Bunka6ababd2007-11-05 18:07:33 +01002822 spin_lock_irqsave(&phba->hbalock, iflag);
2823 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
James Smart618a5232012-06-12 13:54:36 -04002824 spin_unlock_irqrestore(&phba->hbalock, iflag);
2825 if (mbx_action == LPFC_MBX_NO_WAIT)
2826 return;
2827 timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
2828 spin_lock_irqsave(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002829 if (phba->sli.mbox_active) {
James Smart6e7288d2010-06-07 15:23:35 -04002830 actcmd = phba->sli.mbox_active->u.mb.mbxCommand;
James Smarta183a152011-10-10 21:32:43 -04002831 /* Determine how long we might wait for the active mailbox
2832 * command to be gracefully completed by firmware.
2833 */
2834 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
2835 phba->sli.mbox_active) * 1000) + jiffies;
2836 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002837 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smarta183a152011-10-10 21:32:43 -04002838
James Smart6e7288d2010-06-07 15:23:35 -04002839 /* Wait for the outstnading mailbox command to complete */
2840 while (phba->sli.mbox_active) {
2841 /* Check active mailbox complete status every 2ms */
2842 msleep(2);
2843 if (time_after(jiffies, timeout)) {
2844 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2845 "2813 Mgmt IO is Blocked %x "
2846 "- mbox cmd %x still active\n",
2847 phba->sli.sli_flag, actcmd);
2848 break;
2849 }
2850 }
Adrian Bunka6ababd2007-11-05 18:07:33 +01002851}
2852
James Smarte59058c2008-08-24 21:49:00 -04002853/**
James Smart6b5151f2012-01-18 16:24:06 -05002854 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
2855 * @phba: pointer to lpfc hba data structure.
2856 *
2857 * Allocate RPIs for all active remote nodes. This is needed whenever
2858 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
2859 * is to fixup the temporary rpi assignments.
2860 **/
2861void
2862lpfc_sli4_node_prep(struct lpfc_hba *phba)
2863{
2864 struct lpfc_nodelist *ndlp, *next_ndlp;
2865 struct lpfc_vport **vports;
2866 int i;
2867
2868 if (phba->sli_rev != LPFC_SLI_REV4)
2869 return;
2870
2871 vports = lpfc_create_vport_work_array(phba);
2872 if (vports != NULL) {
2873 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2874 if (vports[i]->load_flag & FC_UNLOADING)
2875 continue;
2876
2877 list_for_each_entry_safe(ndlp, next_ndlp,
2878 &vports[i]->fc_nodes,
2879 nlp_listp) {
James Smartbe6bb942015-04-07 15:07:22 -04002880 if (NLP_CHK_NODE_ACT(ndlp)) {
James Smart6b5151f2012-01-18 16:24:06 -05002881 ndlp->nlp_rpi =
2882 lpfc_sli4_alloc_rpi(phba);
James Smartbe6bb942015-04-07 15:07:22 -04002883 lpfc_printf_vlog(ndlp->vport, KERN_INFO,
2884 LOG_NODE,
2885 "0009 rpi:%x DID:%x "
2886 "flg:%x map:%x %p\n",
2887 ndlp->nlp_rpi,
2888 ndlp->nlp_DID,
2889 ndlp->nlp_flag,
2890 ndlp->nlp_usg_map,
2891 ndlp);
2892 }
James Smart6b5151f2012-01-18 16:24:06 -05002893 }
2894 }
2895 }
2896 lpfc_destroy_vport_work_array(phba, vports);
2897}
2898
2899/**
James Smart3621a712009-04-06 18:47:14 -04002900 * lpfc_online - Initialize and bring a HBA online
James Smarte59058c2008-08-24 21:49:00 -04002901 * @phba: pointer to lpfc hba data structure.
2902 *
2903 * This routine initializes the HBA and brings a HBA online. During this
2904 * process, the management interface is blocked to prevent user space access
2905 * to the HBA interfering with the driver initialization.
2906 *
2907 * Return codes
2908 * 0 - successful
2909 * 1 - failed
2910 **/
dea31012005-04-17 16:05:31 -05002911int
James Smart2e0fef82007-06-17 19:56:36 -05002912lpfc_online(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002913{
Julia Lawall372bd282008-12-16 16:15:08 +01002914 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04002915 struct lpfc_vport **vports;
2916 int i;
James Smart16a3a202013-04-17 20:14:38 -04002917 bool vpis_cleared = false;
James Smart2e0fef82007-06-17 19:56:36 -05002918
dea31012005-04-17 16:05:31 -05002919 if (!phba)
2920 return 0;
Julia Lawall372bd282008-12-16 16:15:08 +01002921 vport = phba->pport;
dea31012005-04-17 16:05:31 -05002922
James Smart2e0fef82007-06-17 19:56:36 -05002923 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05002924 return 0;
2925
James Smarted957682007-06-17 19:56:37 -05002926 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04002927 "0458 Bring Adapter online\n");
dea31012005-04-17 16:05:31 -05002928
James Smart618a5232012-06-12 13:54:36 -04002929 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
dea31012005-04-17 16:05:31 -05002930
James Smartda0436e2009-05-22 14:51:39 -04002931 if (phba->sli_rev == LPFC_SLI_REV4) {
2932 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
2933 lpfc_unblock_mgmt_io(phba);
2934 return 1;
2935 }
James Smart16a3a202013-04-17 20:14:38 -04002936 spin_lock_irq(&phba->hbalock);
2937 if (!phba->sli4_hba.max_cfg_param.vpi_used)
2938 vpis_cleared = true;
2939 spin_unlock_irq(&phba->hbalock);
James Smartda0436e2009-05-22 14:51:39 -04002940 } else {
James Smart895427b2017-02-12 13:52:30 -08002941 lpfc_sli_queue_init(phba);
James Smartda0436e2009-05-22 14:51:39 -04002942 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
2943 lpfc_unblock_mgmt_io(phba);
2944 return 1;
2945 }
James Smart46fa3112007-04-25 09:51:45 -04002946 }
dea31012005-04-17 16:05:31 -05002947
James Smart549e55c2007-08-02 11:09:51 -04002948 vports = lpfc_create_vport_work_array(phba);
Arnd Bergmannaeb66412016-03-14 15:29:44 +01002949 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04002950 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04002951 struct Scsi_Host *shost;
2952 shost = lpfc_shost_from_vport(vports[i]);
2953 spin_lock_irq(shost->host_lock);
2954 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
2955 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2956 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart16a3a202013-04-17 20:14:38 -04002957 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart1c6834a2009-07-19 10:01:26 -04002958 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart16a3a202013-04-17 20:14:38 -04002959 if ((vpis_cleared) &&
2960 (vports[i]->port_type !=
2961 LPFC_PHYSICAL_PORT))
2962 vports[i]->vpi = 0;
2963 }
James Smart549e55c2007-08-02 11:09:51 -04002964 spin_unlock_irq(shost->host_lock);
2965 }
Arnd Bergmannaeb66412016-03-14 15:29:44 +01002966 }
2967 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05002968
James Smart46fa3112007-04-25 09:51:45 -04002969 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -05002970 return 0;
2971}
2972
James Smarte59058c2008-08-24 21:49:00 -04002973/**
James Smart3621a712009-04-06 18:47:14 -04002974 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
James Smarte59058c2008-08-24 21:49:00 -04002975 * @phba: pointer to lpfc hba data structure.
2976 *
2977 * This routine marks a HBA's management interface as not blocked. Once the
2978 * HBA's management interface is marked as not blocked, all the user space
2979 * access to the HBA, whether they are from sysfs interface or libdfc
2980 * interface will be allowed. The HBA is set to block the management interface
2981 * when the driver prepares the HBA interface for online or offline and then
2982 * set to unblock the management interface afterwards.
2983 **/
James Smart46fa3112007-04-25 09:51:45 -04002984void
James Smart46fa3112007-04-25 09:51:45 -04002985lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
2986{
2987 unsigned long iflag;
2988
James Smart2e0fef82007-06-17 19:56:36 -05002989 spin_lock_irqsave(&phba->hbalock, iflag);
2990 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
2991 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart46fa3112007-04-25 09:51:45 -04002992}
2993
James Smarte59058c2008-08-24 21:49:00 -04002994/**
James Smart3621a712009-04-06 18:47:14 -04002995 * lpfc_offline_prep - Prepare a HBA to be brought offline
James Smarte59058c2008-08-24 21:49:00 -04002996 * @phba: pointer to lpfc hba data structure.
2997 *
2998 * This routine is invoked to prepare a HBA to be brought offline. It performs
2999 * unregistration login to all the nodes on all vports and flushes the mailbox
3000 * queue to make it ready to be brought offline.
3001 **/
James Smart46fa3112007-04-25 09:51:45 -04003002void
James Smart618a5232012-06-12 13:54:36 -04003003lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action)
James Smart46fa3112007-04-25 09:51:45 -04003004{
James Smart2e0fef82007-06-17 19:56:36 -05003005 struct lpfc_vport *vport = phba->pport;
James Smart46fa3112007-04-25 09:51:45 -04003006 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart87af33f2007-10-27 13:37:43 -04003007 struct lpfc_vport **vports;
James Smart72100cc2010-02-12 14:43:01 -05003008 struct Scsi_Host *shost;
James Smart87af33f2007-10-27 13:37:43 -04003009 int i;
dea31012005-04-17 16:05:31 -05003010
James Smart2e0fef82007-06-17 19:56:36 -05003011 if (vport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003012 return;
dea31012005-04-17 16:05:31 -05003013
James Smart618a5232012-06-12 13:54:36 -04003014 lpfc_block_mgmt_io(phba, mbx_action);
dea31012005-04-17 16:05:31 -05003015
3016 lpfc_linkdown(phba);
3017
James Smart87af33f2007-10-27 13:37:43 -04003018 /* Issue an unreg_login to all nodes on all vports */
3019 vports = lpfc_create_vport_work_array(phba);
3020 if (vports != NULL) {
James Smartda0436e2009-05-22 14:51:39 -04003021 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smarta8adb832007-10-27 13:37:53 -04003022 if (vports[i]->load_flag & FC_UNLOADING)
3023 continue;
James Smart72100cc2010-02-12 14:43:01 -05003024 shost = lpfc_shost_from_vport(vports[i]);
3025 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003026 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003027 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3028 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05003029 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05003030
James Smart87af33f2007-10-27 13:37:43 -04003031 shost = lpfc_shost_from_vport(vports[i]);
3032 list_for_each_entry_safe(ndlp, next_ndlp,
3033 &vports[i]->fc_nodes,
3034 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003035 if (!NLP_CHK_NODE_ACT(ndlp))
3036 continue;
James Smart87af33f2007-10-27 13:37:43 -04003037 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3038 continue;
3039 if (ndlp->nlp_type & NLP_FABRIC) {
3040 lpfc_disc_state_machine(vports[i], ndlp,
3041 NULL, NLP_EVT_DEVICE_RECOVERY);
3042 lpfc_disc_state_machine(vports[i], ndlp,
3043 NULL, NLP_EVT_DEVICE_RM);
3044 }
3045 spin_lock_irq(shost->host_lock);
3046 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart401ee0c2012-03-01 22:35:34 -05003047 spin_unlock_irq(shost->host_lock);
James Smart6b5151f2012-01-18 16:24:06 -05003048 /*
3049 * Whenever an SLI4 port goes offline, free the
James Smart401ee0c2012-03-01 22:35:34 -05003050 * RPI. Get a new RPI when the adapter port
3051 * comes back online.
James Smart6b5151f2012-01-18 16:24:06 -05003052 */
James Smartbe6bb942015-04-07 15:07:22 -04003053 if (phba->sli_rev == LPFC_SLI_REV4) {
3054 lpfc_printf_vlog(ndlp->vport,
3055 KERN_INFO, LOG_NODE,
3056 "0011 lpfc_offline: "
3057 "ndlp:x%p did %x "
3058 "usgmap:x%x rpi:%x\n",
3059 ndlp, ndlp->nlp_DID,
3060 ndlp->nlp_usg_map,
3061 ndlp->nlp_rpi);
3062
James Smart6b5151f2012-01-18 16:24:06 -05003063 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smartbe6bb942015-04-07 15:07:22 -04003064 }
James Smart87af33f2007-10-27 13:37:43 -04003065 lpfc_unreg_rpi(vports[i], ndlp);
3066 }
3067 }
3068 }
James Smart09372822008-01-11 01:52:54 -05003069 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003070
James Smart618a5232012-06-12 13:54:36 -04003071 lpfc_sli_mbox_sys_shutdown(phba, mbx_action);
James Smart46fa3112007-04-25 09:51:45 -04003072}
3073
James Smarte59058c2008-08-24 21:49:00 -04003074/**
James Smart3621a712009-04-06 18:47:14 -04003075 * lpfc_offline - Bring a HBA offline
James Smarte59058c2008-08-24 21:49:00 -04003076 * @phba: pointer to lpfc hba data structure.
3077 *
3078 * This routine actually brings a HBA offline. It stops all the timers
3079 * associated with the HBA, brings down the SLI layer, and eventually
3080 * marks the HBA as in offline state for the upper layer protocol.
3081 **/
James Smart46fa3112007-04-25 09:51:45 -04003082void
James Smart2e0fef82007-06-17 19:56:36 -05003083lpfc_offline(struct lpfc_hba *phba)
James Smart46fa3112007-04-25 09:51:45 -04003084{
James Smart549e55c2007-08-02 11:09:51 -04003085 struct Scsi_Host *shost;
3086 struct lpfc_vport **vports;
3087 int i;
James Smart46fa3112007-04-25 09:51:45 -04003088
James Smart549e55c2007-08-02 11:09:51 -04003089 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart46fa3112007-04-25 09:51:45 -04003090 return;
James Smart688a8862006-07-06 15:49:56 -04003091
James Smartda0436e2009-05-22 14:51:39 -04003092 /* stop port and all timers associated with this hba */
3093 lpfc_stop_port(phba);
James Smart51ef4c22007-08-02 11:10:31 -04003094 vports = lpfc_create_vport_work_array(phba);
3095 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003096 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart51ef4c22007-08-02 11:10:31 -04003097 lpfc_stop_vport_timers(vports[i]);
James Smart09372822008-01-11 01:52:54 -05003098 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05003099 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003100 "0460 Bring Adapter offline\n");
dea31012005-04-17 16:05:31 -05003101 /* Bring down the SLI Layer and cleanup. The HBA is offline
3102 now. */
3103 lpfc_sli_hba_down(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003104 spin_lock_irq(&phba->hbalock);
James Smart7054a602007-04-25 09:52:34 -04003105 phba->work_ha = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003106 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -04003107 vports = lpfc_create_vport_work_array(phba);
3108 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -04003109 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04003110 shost = lpfc_shost_from_vport(vports[i]);
James Smart549e55c2007-08-02 11:09:51 -04003111 spin_lock_irq(shost->host_lock);
3112 vports[i]->work_port_events = 0;
3113 vports[i]->fc_flag |= FC_OFFLINE_MODE;
3114 spin_unlock_irq(shost->host_lock);
3115 }
James Smart09372822008-01-11 01:52:54 -05003116 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05003117}
3118
James Smarte59058c2008-08-24 21:49:00 -04003119/**
James Smart3621a712009-04-06 18:47:14 -04003120 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
James Smarte59058c2008-08-24 21:49:00 -04003121 * @phba: pointer to lpfc hba data structure.
3122 *
3123 * This routine is to free all the SCSI buffers and IOCBs from the driver
3124 * list back to kernel. It is called from lpfc_pci_remove_one to free
3125 * the internal resources before the device is removed from the system.
James Smarte59058c2008-08-24 21:49:00 -04003126 **/
James Smart8a9d2e82012-05-09 21:16:12 -04003127static void
James Smart2e0fef82007-06-17 19:56:36 -05003128lpfc_scsi_free(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003129{
3130 struct lpfc_scsi_buf *sb, *sb_next;
dea31012005-04-17 16:05:31 -05003131
James Smart895427b2017-02-12 13:52:30 -08003132 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3133 return;
3134
James Smart2e0fef82007-06-17 19:56:36 -05003135 spin_lock_irq(&phba->hbalock);
James Smarta40fc5f2013-04-17 20:17:40 -04003136
dea31012005-04-17 16:05:31 -05003137 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smarta40fc5f2013-04-17 20:17:40 -04003138
3139 spin_lock(&phba->scsi_buf_list_put_lock);
3140 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3141 list) {
dea31012005-04-17 16:05:31 -05003142 list_del(&sb->list);
James Smart895427b2017-02-12 13:52:30 -08003143 pci_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05003144 sb->dma_handle);
dea31012005-04-17 16:05:31 -05003145 kfree(sb);
3146 phba->total_scsi_bufs--;
3147 }
James Smarta40fc5f2013-04-17 20:17:40 -04003148 spin_unlock(&phba->scsi_buf_list_put_lock);
3149
3150 spin_lock(&phba->scsi_buf_list_get_lock);
3151 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3152 list) {
3153 list_del(&sb->list);
James Smart895427b2017-02-12 13:52:30 -08003154 pci_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smarta40fc5f2013-04-17 20:17:40 -04003155 sb->dma_handle);
3156 kfree(sb);
3157 phba->total_scsi_bufs--;
3158 }
3159 spin_unlock(&phba->scsi_buf_list_get_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003160 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003161}
James Smart8a9d2e82012-05-09 21:16:12 -04003162/**
James Smart895427b2017-02-12 13:52:30 -08003163 * lpfc_nvme_free - Free all the NVME buffers and IOCBs from driver lists
3164 * @phba: pointer to lpfc hba data structure.
3165 *
3166 * This routine is to free all the NVME buffers and IOCBs from the driver
3167 * list back to kernel. It is called from lpfc_pci_remove_one to free
3168 * the internal resources before the device is removed from the system.
3169 **/
3170static void
3171lpfc_nvme_free(struct lpfc_hba *phba)
3172{
3173 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
James Smart895427b2017-02-12 13:52:30 -08003174
3175 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3176 return;
3177
3178 spin_lock_irq(&phba->hbalock);
3179
3180 /* Release all the lpfc_nvme_bufs maintained by this host. */
3181 spin_lock(&phba->nvme_buf_list_put_lock);
3182 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3183 &phba->lpfc_nvme_buf_list_put, list) {
3184 list_del(&lpfc_ncmd->list);
3185 pci_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
3186 lpfc_ncmd->dma_handle);
3187 kfree(lpfc_ncmd);
3188 phba->total_nvme_bufs--;
3189 }
3190 spin_unlock(&phba->nvme_buf_list_put_lock);
3191
3192 spin_lock(&phba->nvme_buf_list_get_lock);
3193 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3194 &phba->lpfc_nvme_buf_list_get, list) {
3195 list_del(&lpfc_ncmd->list);
3196 pci_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
3197 lpfc_ncmd->dma_handle);
3198 kfree(lpfc_ncmd);
3199 phba->total_nvme_bufs--;
3200 }
3201 spin_unlock(&phba->nvme_buf_list_get_lock);
James Smart895427b2017-02-12 13:52:30 -08003202 spin_unlock_irq(&phba->hbalock);
3203}
3204/**
3205 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
James Smart8a9d2e82012-05-09 21:16:12 -04003206 * @phba: pointer to lpfc hba data structure.
3207 *
3208 * This routine first calculates the sizes of the current els and allocated
3209 * scsi sgl lists, and then goes through all sgls to updates the physical
3210 * XRIs assigned due to port function reset. During port initialization, the
3211 * current els and allocated scsi sgl lists are 0s.
3212 *
3213 * Return codes
3214 * 0 - successful (for now, it always returns 0)
3215 **/
3216int
James Smart895427b2017-02-12 13:52:30 -08003217lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
James Smart8a9d2e82012-05-09 21:16:12 -04003218{
3219 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
James Smart895427b2017-02-12 13:52:30 -08003220 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart8a9d2e82012-05-09 21:16:12 -04003221 LIST_HEAD(els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003222 int rc;
3223
3224 /*
3225 * update on pci function's els xri-sgl list
3226 */
3227 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart895427b2017-02-12 13:52:30 -08003228
James Smart8a9d2e82012-05-09 21:16:12 -04003229 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3230 /* els xri-sgl expanded */
3231 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3232 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3233 "3157 ELS xri-sgl count increased from "
3234 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3235 els_xri_cnt);
3236 /* allocate the additional els sgls */
3237 for (i = 0; i < xri_cnt; i++) {
3238 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3239 GFP_KERNEL);
3240 if (sglq_entry == NULL) {
3241 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3242 "2562 Failure to allocate an "
3243 "ELS sgl entry:%d\n", i);
3244 rc = -ENOMEM;
3245 goto out_free_mem;
3246 }
3247 sglq_entry->buff_type = GEN_BUFF_TYPE;
3248 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3249 &sglq_entry->phys);
3250 if (sglq_entry->virt == NULL) {
3251 kfree(sglq_entry);
3252 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3253 "2563 Failure to allocate an "
3254 "ELS mbuf:%d\n", i);
3255 rc = -ENOMEM;
3256 goto out_free_mem;
3257 }
3258 sglq_entry->sgl = sglq_entry->virt;
3259 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3260 sglq_entry->state = SGL_FREED;
3261 list_add_tail(&sglq_entry->list, &els_sgl_list);
3262 }
James Smart38c20672013-03-01 16:37:44 -05003263 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003264 spin_lock(&phba->sli4_hba.sgl_list_lock);
3265 list_splice_init(&els_sgl_list,
3266 &phba->sli4_hba.lpfc_els_sgl_list);
3267 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart38c20672013-03-01 16:37:44 -05003268 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003269 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3270 /* els xri-sgl shrinked */
3271 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3272 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3273 "3158 ELS xri-sgl count decreased from "
3274 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3275 els_xri_cnt);
3276 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003277 spin_lock(&phba->sli4_hba.sgl_list_lock);
3278 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
3279 &els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003280 /* release extra els sgls from list */
3281 for (i = 0; i < xri_cnt; i++) {
3282 list_remove_head(&els_sgl_list,
3283 sglq_entry, struct lpfc_sglq, list);
3284 if (sglq_entry) {
James Smart895427b2017-02-12 13:52:30 -08003285 __lpfc_mbuf_free(phba, sglq_entry->virt,
3286 sglq_entry->phys);
James Smart8a9d2e82012-05-09 21:16:12 -04003287 kfree(sglq_entry);
3288 }
3289 }
James Smart895427b2017-02-12 13:52:30 -08003290 list_splice_init(&els_sgl_list,
3291 &phba->sli4_hba.lpfc_els_sgl_list);
3292 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003293 spin_unlock_irq(&phba->hbalock);
3294 } else
3295 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3296 "3163 ELS xri-sgl count unchanged: %d\n",
3297 els_xri_cnt);
3298 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3299
3300 /* update xris to els sgls on the list */
3301 sglq_entry = NULL;
3302 sglq_entry_next = NULL;
3303 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
James Smart895427b2017-02-12 13:52:30 -08003304 &phba->sli4_hba.lpfc_els_sgl_list, list) {
James Smart8a9d2e82012-05-09 21:16:12 -04003305 lxri = lpfc_sli4_next_xritag(phba);
3306 if (lxri == NO_XRI) {
3307 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3308 "2400 Failed to allocate xri for "
3309 "ELS sgl\n");
3310 rc = -ENOMEM;
3311 goto out_free_mem;
3312 }
3313 sglq_entry->sli4_lxritag = lxri;
3314 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3315 }
James Smart895427b2017-02-12 13:52:30 -08003316 return 0;
3317
3318out_free_mem:
3319 lpfc_free_els_sgl_list(phba);
3320 return rc;
3321}
3322
3323/**
3324 * lpfc_sli4_scsi_sgl_update - update xri-sgl sizing and mapping
3325 * @phba: pointer to lpfc hba data structure.
3326 *
3327 * This routine first calculates the sizes of the current els and allocated
3328 * scsi sgl lists, and then goes through all sgls to updates the physical
3329 * XRIs assigned due to port function reset. During port initialization, the
3330 * current els and allocated scsi sgl lists are 0s.
3331 *
3332 * Return codes
3333 * 0 - successful (for now, it always returns 0)
3334 **/
3335int
3336lpfc_sli4_scsi_sgl_update(struct lpfc_hba *phba)
3337{
3338 struct lpfc_scsi_buf *psb, *psb_next;
3339 uint16_t i, lxri, els_xri_cnt, scsi_xri_cnt;
3340 LIST_HEAD(scsi_sgl_list);
3341 int rc;
3342
3343 /*
3344 * update on pci function's els xri-sgl list
3345 */
3346 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3347 phba->total_scsi_bufs = 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003348
3349 /*
3350 * update on pci function's allocated scsi xri-sgl list
3351 */
James Smart8a9d2e82012-05-09 21:16:12 -04003352 /* maximum number of xris available for scsi buffers */
3353 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3354 els_xri_cnt;
3355
James Smart895427b2017-02-12 13:52:30 -08003356 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3357 return 0;
3358
3359 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3360 phba->sli4_hba.scsi_xri_max = /* Split them up */
3361 (phba->sli4_hba.scsi_xri_max *
3362 phba->cfg_xri_split) / 100;
James Smart8a9d2e82012-05-09 21:16:12 -04003363
James Smarta40fc5f2013-04-17 20:17:40 -04003364 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003365 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003366 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3367 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
James Smart164cecd2013-09-06 12:22:38 -04003368 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003369 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003370
3371 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3372 /* max scsi xri shrinked below the allocated scsi buffers */
3373 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3374 phba->sli4_hba.scsi_xri_max;
3375 /* release the extra allocated scsi buffers */
3376 for (i = 0; i < scsi_xri_cnt; i++) {
3377 list_remove_head(&scsi_sgl_list, psb,
3378 struct lpfc_scsi_buf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04003379 if (psb) {
James Smart895427b2017-02-12 13:52:30 -08003380 pci_pool_free(phba->lpfc_sg_dma_buf_pool,
James Smarta2fc4aef2014-09-03 12:57:55 -04003381 psb->data, psb->dma_handle);
3382 kfree(psb);
3383 }
James Smart8a9d2e82012-05-09 21:16:12 -04003384 }
James Smarta40fc5f2013-04-17 20:17:40 -04003385 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003386 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
James Smarta40fc5f2013-04-17 20:17:40 -04003387 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003388 }
3389
3390 /* update xris associated to remaining allocated scsi buffers */
3391 psb = NULL;
3392 psb_next = NULL;
3393 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3394 lxri = lpfc_sli4_next_xritag(phba);
3395 if (lxri == NO_XRI) {
3396 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3397 "2560 Failed to allocate xri for "
3398 "scsi buffer\n");
3399 rc = -ENOMEM;
3400 goto out_free_mem;
3401 }
3402 psb->cur_iocbq.sli4_lxritag = lxri;
3403 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3404 }
James Smarta40fc5f2013-04-17 20:17:40 -04003405 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003406 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003407 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3408 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
James Smart164cecd2013-09-06 12:22:38 -04003409 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003410 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
dea31012005-04-17 16:05:31 -05003411 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003412
3413out_free_mem:
James Smart8a9d2e82012-05-09 21:16:12 -04003414 lpfc_scsi_free(phba);
3415 return rc;
dea31012005-04-17 16:05:31 -05003416}
3417
James Smarte59058c2008-08-24 21:49:00 -04003418/**
James Smart895427b2017-02-12 13:52:30 -08003419 * lpfc_sli4_nvme_sgl_update - update xri-sgl sizing and mapping
3420 * @phba: pointer to lpfc hba data structure.
3421 *
3422 * This routine first calculates the sizes of the current els and allocated
3423 * scsi sgl lists, and then goes through all sgls to updates the physical
3424 * XRIs assigned due to port function reset. During port initialization, the
3425 * current els and allocated scsi sgl lists are 0s.
3426 *
3427 * Return codes
3428 * 0 - successful (for now, it always returns 0)
3429 **/
3430int
3431lpfc_sli4_nvme_sgl_update(struct lpfc_hba *phba)
3432{
3433 struct lpfc_nvme_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
3434 uint16_t i, lxri, els_xri_cnt;
3435 uint16_t nvme_xri_cnt, nvme_xri_max;
3436 LIST_HEAD(nvme_sgl_list);
3437 int rc;
3438
3439 phba->total_nvme_bufs = 0;
3440
3441 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3442 return 0;
3443 /*
3444 * update on pci function's allocated nvme xri-sgl list
3445 */
3446
3447 /* maximum number of xris available for nvme buffers */
3448 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3449 nvme_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3450 phba->sli4_hba.nvme_xri_max = nvme_xri_max;
3451 phba->sli4_hba.nvme_xri_max -= phba->sli4_hba.scsi_xri_max;
3452
3453 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3454 "6074 Current allocated NVME xri-sgl count:%d, "
3455 "maximum NVME xri count:%d\n",
3456 phba->sli4_hba.nvme_xri_cnt,
3457 phba->sli4_hba.nvme_xri_max);
3458
3459 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3460 spin_lock(&phba->nvme_buf_list_put_lock);
3461 list_splice_init(&phba->lpfc_nvme_buf_list_get, &nvme_sgl_list);
3462 list_splice(&phba->lpfc_nvme_buf_list_put, &nvme_sgl_list);
3463 spin_unlock(&phba->nvme_buf_list_put_lock);
3464 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3465
3466 if (phba->sli4_hba.nvme_xri_cnt > phba->sli4_hba.nvme_xri_max) {
3467 /* max nvme xri shrunk below the allocated nvme buffers */
3468 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3469 nvme_xri_cnt = phba->sli4_hba.nvme_xri_cnt -
3470 phba->sli4_hba.nvme_xri_max;
3471 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3472 /* release the extra allocated nvme buffers */
3473 for (i = 0; i < nvme_xri_cnt; i++) {
3474 list_remove_head(&nvme_sgl_list, lpfc_ncmd,
3475 struct lpfc_nvme_buf, list);
3476 if (lpfc_ncmd) {
3477 pci_pool_free(phba->lpfc_sg_dma_buf_pool,
3478 lpfc_ncmd->data,
3479 lpfc_ncmd->dma_handle);
3480 kfree(lpfc_ncmd);
3481 }
3482 }
3483 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3484 phba->sli4_hba.nvme_xri_cnt -= nvme_xri_cnt;
3485 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3486 }
3487
3488 /* update xris associated to remaining allocated nvme buffers */
3489 lpfc_ncmd = NULL;
3490 lpfc_ncmd_next = NULL;
3491 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3492 &nvme_sgl_list, list) {
3493 lxri = lpfc_sli4_next_xritag(phba);
3494 if (lxri == NO_XRI) {
3495 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3496 "6075 Failed to allocate xri for "
3497 "nvme buffer\n");
3498 rc = -ENOMEM;
3499 goto out_free_mem;
3500 }
3501 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
3502 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3503 }
3504 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3505 spin_lock(&phba->nvme_buf_list_put_lock);
3506 list_splice_init(&nvme_sgl_list, &phba->lpfc_nvme_buf_list_get);
3507 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
3508 spin_unlock(&phba->nvme_buf_list_put_lock);
3509 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3510 return 0;
3511
3512out_free_mem:
3513 lpfc_nvme_free(phba);
3514 return rc;
3515}
3516
3517/**
James Smart3621a712009-04-06 18:47:14 -04003518 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04003519 * @phba: pointer to lpfc hba data structure.
3520 * @instance: a unique integer ID to this FC port.
3521 * @dev: pointer to the device data structure.
3522 *
3523 * This routine creates a FC port for the upper layer protocol. The FC port
3524 * can be created on top of either a physical port or a virtual port provided
3525 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3526 * and associates the FC port created before adding the shost into the SCSI
3527 * layer.
3528 *
3529 * Return codes
3530 * @vport - pointer to the virtual N_Port data structure.
3531 * NULL - port create failed.
3532 **/
James Smart2e0fef82007-06-17 19:56:36 -05003533struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04003534lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04003535{
James Smart2e0fef82007-06-17 19:56:36 -05003536 struct lpfc_vport *vport;
James Smart895427b2017-02-12 13:52:30 -08003537 struct Scsi_Host *shost = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003538 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04003539
James Smart895427b2017-02-12 13:52:30 -08003540 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
3541 if (dev != &phba->pcidev->dev) {
3542 shost = scsi_host_alloc(&lpfc_vport_template,
3543 sizeof(struct lpfc_vport));
3544 } else {
3545 if (phba->sli_rev == LPFC_SLI_REV4)
3546 shost = scsi_host_alloc(&lpfc_template,
3547 sizeof(struct lpfc_vport));
3548 else
3549 shost = scsi_host_alloc(&lpfc_template_s3,
3550 sizeof(struct lpfc_vport));
3551 }
3552 } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
3553 shost = scsi_host_alloc(&lpfc_template_nvme,
James Smartea4142f2015-04-07 15:07:13 -04003554 sizeof(struct lpfc_vport));
3555 }
James Smart2e0fef82007-06-17 19:56:36 -05003556 if (!shost)
3557 goto out;
James Smart47a86172007-04-25 09:53:22 -04003558
James Smart2e0fef82007-06-17 19:56:36 -05003559 vport = (struct lpfc_vport *) shost->hostdata;
3560 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05003561 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05003562 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05003563 vport->fc_rscn_flush = 0;
James Smart3de2a652007-08-02 11:09:59 -04003564 lpfc_get_vport_cfgparam(vport);
James Smart895427b2017-02-12 13:52:30 -08003565
James Smart2e0fef82007-06-17 19:56:36 -05003566 shost->unique_id = instance;
3567 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04003568 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05003569 shost->this_id = -1;
3570 shost->max_cmd_len = 16;
James Smart8b0dff12015-05-22 10:42:38 -04003571 shost->nr_hw_queues = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04003572 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05003573 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04003574 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smartda0436e2009-05-22 14:51:39 -04003575 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
3576 }
James Smart81301a92008-12-04 22:39:46 -05003577
James Smart47a86172007-04-25 09:53:22 -04003578 /*
James Smart2e0fef82007-06-17 19:56:36 -05003579 * Set initial can_queue value since 0 is no longer supported and
3580 * scsi_add_host will fail. This will be adjusted later based on the
3581 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04003582 */
James Smart2e0fef82007-06-17 19:56:36 -05003583 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04003584 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05003585 shost->transportt = lpfc_vport_transport_template;
3586 vport->port_type = LPFC_NPIV_PORT;
3587 } else {
3588 shost->transportt = lpfc_transport_template;
3589 vport->port_type = LPFC_PHYSICAL_PORT;
3590 }
James Smart47a86172007-04-25 09:53:22 -04003591
James Smart2e0fef82007-06-17 19:56:36 -05003592 /* Initialize all internally managed lists. */
3593 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04003594 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05003595 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04003596
James Smart2e0fef82007-06-17 19:56:36 -05003597 init_timer(&vport->fc_disctmo);
3598 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003599 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04003600
James Smart2e0fef82007-06-17 19:56:36 -05003601 init_timer(&vport->els_tmofunc);
3602 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003603 vport->els_tmofunc.data = (unsigned long)vport;
James Smart92494142011-02-16 12:39:44 -05003604
3605 init_timer(&vport->delayed_disc_tmo);
3606 vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
3607 vport->delayed_disc_tmo.data = (unsigned long)vport;
3608
James Bottomleyd139b9b2009-11-05 13:33:12 -06003609 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05003610 if (error)
3611 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04003612
James Smart549e55c2007-08-02 11:09:51 -04003613 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003614 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04003615 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003616 return vport;
James Smart47a86172007-04-25 09:53:22 -04003617
James Smart2e0fef82007-06-17 19:56:36 -05003618out_put_shost:
3619 scsi_host_put(shost);
3620out:
3621 return NULL;
James Smart47a86172007-04-25 09:53:22 -04003622}
3623
James Smarte59058c2008-08-24 21:49:00 -04003624/**
James Smart3621a712009-04-06 18:47:14 -04003625 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04003626 * @vport: pointer to an lpfc virtual N_Port data structure.
3627 *
3628 * This routine destroys a FC port from the upper layer protocol. All the
3629 * resources associated with the port are released.
3630 **/
James Smart2e0fef82007-06-17 19:56:36 -05003631void
3632destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04003633{
James Smart92d7f7b2007-06-17 19:56:38 -05003634 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3635 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003636
James Smart858c9f62007-06-17 19:56:39 -05003637 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05003638 fc_remove_host(shost);
3639 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04003640
James Smart92d7f7b2007-06-17 19:56:38 -05003641 spin_lock_irq(&phba->hbalock);
3642 list_del_init(&vport->listentry);
3643 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04003644
James Smart92d7f7b2007-06-17 19:56:38 -05003645 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04003646 return;
James Smart47a86172007-04-25 09:53:22 -04003647}
3648
James Smarte59058c2008-08-24 21:49:00 -04003649/**
James Smart3621a712009-04-06 18:47:14 -04003650 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04003651 *
3652 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3653 * uses the kernel idr facility to perform the task.
3654 *
3655 * Return codes:
3656 * instance - a unique integer ID allocated as the new instance.
3657 * -1 - lpfc get instance failed.
3658 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003659int
3660lpfc_get_instance(void)
3661{
Tejun Heoab516032013-02-27 17:04:44 -08003662 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003663
Tejun Heoab516032013-02-27 17:04:44 -08003664 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
3665 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003666}
3667
James Smarte59058c2008-08-24 21:49:00 -04003668/**
James Smart3621a712009-04-06 18:47:14 -04003669 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04003670 * @shost: pointer to SCSI host data structure.
3671 * @time: elapsed time of the scan in jiffies.
3672 *
3673 * This routine is called by the SCSI layer with a SCSI host to determine
3674 * whether the scan host is finished.
3675 *
3676 * Note: there is no scan_start function as adapter initialization will have
3677 * asynchronously kicked off the link initialization.
3678 *
3679 * Return codes
3680 * 0 - SCSI host scan is not over yet.
3681 * 1 - SCSI host scan is over.
3682 **/
James Smart47a86172007-04-25 09:53:22 -04003683int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
3684{
James Smart2e0fef82007-06-17 19:56:36 -05003685 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3686 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05003687 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04003688
James Smart858c9f62007-06-17 19:56:39 -05003689 spin_lock_irq(shost->host_lock);
3690
James Smart51ef4c22007-08-02 11:10:31 -04003691 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05003692 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003693 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05003694 }
James Smart256ec0d2013-04-17 20:14:58 -04003695 if (time >= msecs_to_jiffies(30 * 1000)) {
James Smart2e0fef82007-06-17 19:56:36 -05003696 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003697 "0461 Scanning longer than 30 "
3698 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003699 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003700 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003701 }
James Smart256ec0d2013-04-17 20:14:58 -04003702 if (time >= msecs_to_jiffies(15 * 1000) &&
3703 phba->link_state <= LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05003704 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003705 "0465 Link down longer than 15 "
3706 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003707 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05003708 goto finished;
James Smart47a86172007-04-25 09:53:22 -04003709 }
3710
James Smart2e0fef82007-06-17 19:56:36 -05003711 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05003712 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003713 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05003714 goto finished;
James Smart256ec0d2013-04-17 20:14:58 -04003715 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
James Smart858c9f62007-06-17 19:56:39 -05003716 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003717 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05003718 goto finished;
3719
3720 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003721
3722finished:
James Smart858c9f62007-06-17 19:56:39 -05003723 spin_unlock_irq(shost->host_lock);
3724 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003725}
3726
James Smarte59058c2008-08-24 21:49:00 -04003727/**
James Smart3621a712009-04-06 18:47:14 -04003728 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04003729 * @shost: pointer to SCSI host data structure.
3730 *
3731 * This routine initializes a given SCSI host attributes on a FC port. The
3732 * SCSI host can be either on top of a physical port or a virtual port.
3733 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003734void lpfc_host_attrib_init(struct Scsi_Host *shost)
3735{
3736 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3737 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003738 /*
James Smart2e0fef82007-06-17 19:56:36 -05003739 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04003740 */
3741
James Smart2e0fef82007-06-17 19:56:36 -05003742 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
3743 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04003744 fc_host_supported_classes(shost) = FC_COS_CLASS3;
3745
3746 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003747 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003748 fc_host_supported_fc4s(shost)[2] = 1;
3749 fc_host_supported_fc4s(shost)[7] = 1;
3750
James Smart92d7f7b2007-06-17 19:56:38 -05003751 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
3752 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04003753
3754 fc_host_supported_speeds(shost) = 0;
James Smartd38dd522015-08-31 16:48:17 -04003755 if (phba->lmt & LMT_32Gb)
3756 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
James Smart88a2cfb2011-07-22 18:36:33 -04003757 if (phba->lmt & LMT_16Gb)
3758 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
James Smart47a86172007-04-25 09:53:22 -04003759 if (phba->lmt & LMT_10Gb)
3760 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04003761 if (phba->lmt & LMT_8Gb)
3762 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04003763 if (phba->lmt & LMT_4Gb)
3764 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
3765 if (phba->lmt & LMT_2Gb)
3766 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
3767 if (phba->lmt & LMT_1Gb)
3768 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
3769
3770 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05003771 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
3772 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04003773
Mike Christie0af5d702010-09-15 16:52:31 -05003774 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
3775
James Smart47a86172007-04-25 09:53:22 -04003776 /* This value is also unchanging */
3777 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003778 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003779 fc_host_active_fc4s(shost)[2] = 1;
3780 fc_host_active_fc4s(shost)[7] = 1;
3781
James Smart92d7f7b2007-06-17 19:56:38 -05003782 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04003783 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04003784 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04003785 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04003786}
dea31012005-04-17 16:05:31 -05003787
James Smarte59058c2008-08-24 21:49:00 -04003788/**
James Smartda0436e2009-05-22 14:51:39 -04003789 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04003790 * @phba: pointer to lpfc hba data structure.
3791 *
James Smartda0436e2009-05-22 14:51:39 -04003792 * This routine is invoked to stop an SLI3 device port, it stops the device
3793 * from generating interrupts and stops the device driver's timers for the
3794 * device.
James Smarte59058c2008-08-24 21:49:00 -04003795 **/
James Smartdb2378e2008-02-08 18:49:51 -05003796static void
James Smartda0436e2009-05-22 14:51:39 -04003797lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05003798{
James Smartda0436e2009-05-22 14:51:39 -04003799 /* Clear all interrupt enable conditions */
3800 writel(0, phba->HCregaddr);
3801 readl(phba->HCregaddr); /* flush */
3802 /* Clear all pending interrupts */
3803 writel(0xffffffff, phba->HAregaddr);
3804 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04003805
James Smartda0436e2009-05-22 14:51:39 -04003806 /* Reset some HBA SLI setup states */
3807 lpfc_stop_hba_timers(phba);
3808 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05003809}
3810
James Smarte59058c2008-08-24 21:49:00 -04003811/**
James Smartda0436e2009-05-22 14:51:39 -04003812 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05003813 * @phba: pointer to lpfc hba data structure.
3814 *
James Smartda0436e2009-05-22 14:51:39 -04003815 * This routine is invoked to stop an SLI4 device port, it stops the device
3816 * from generating interrupts and stops the device driver's timers for the
3817 * device.
3818 **/
3819static void
3820lpfc_stop_port_s4(struct lpfc_hba *phba)
3821{
3822 /* Reset some HBA SLI4 setup states */
3823 lpfc_stop_hba_timers(phba);
3824 phba->pport->work_port_events = 0;
3825 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04003826}
3827
3828/**
3829 * lpfc_stop_port - Wrapper function for stopping hba port
3830 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05003831 *
James Smartda0436e2009-05-22 14:51:39 -04003832 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3833 * the API jump table function pointer from the lpfc_hba struct.
3834 **/
3835void
3836lpfc_stop_port(struct lpfc_hba *phba)
3837{
3838 phba->lpfc_stop_port(phba);
3839}
3840
3841/**
James Smartecfd03c2010-02-12 14:41:27 -05003842 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3843 * @phba: Pointer to hba for which this call is being executed.
3844 *
3845 * This routine starts the timer waiting for the FCF rediscovery to complete.
3846 **/
3847void
3848lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
3849{
3850 unsigned long fcf_redisc_wait_tmo =
3851 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
3852 /* Start fcf rediscovery wait period timer */
3853 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
3854 spin_lock_irq(&phba->hbalock);
3855 /* Allow action to new fcf asynchronous event */
3856 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
3857 /* Mark the FCF rediscovery pending state */
3858 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
3859 spin_unlock_irq(&phba->hbalock);
3860}
3861
3862/**
3863 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
3864 * @ptr: Map to lpfc_hba data structure pointer.
3865 *
3866 * This routine is invoked when waiting for FCF table rediscover has been
3867 * timed out. If new FCF record(s) has (have) been discovered during the
3868 * wait period, a new FCF event shall be added to the FCOE async event
3869 * list, and then worker thread shall be waked up for processing from the
3870 * worker thread context.
3871 **/
Rashika Kheriae399b222014-09-03 12:55:28 -04003872static void
James Smartecfd03c2010-02-12 14:41:27 -05003873lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
3874{
3875 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
3876
3877 /* Don't send FCF rediscovery event if timer cancelled */
3878 spin_lock_irq(&phba->hbalock);
3879 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
3880 spin_unlock_irq(&phba->hbalock);
3881 return;
3882 }
3883 /* Clear FCF rediscovery timer pending flag */
3884 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
3885 /* FCF rediscovery event to worker thread */
3886 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
3887 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003888 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04003889 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05003890 /* wake up worker thread */
3891 lpfc_worker_wake_up(phba);
3892}
3893
3894/**
James Smartda0436e2009-05-22 14:51:39 -04003895 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
3896 * @phba: pointer to lpfc hba data structure.
3897 * @acqe_link: pointer to the async link completion queue entry.
3898 *
3899 * This routine is to parse the SLI4 link-attention link fault code and
3900 * translate it into the base driver's read link attention mailbox command
3901 * status.
3902 *
3903 * Return: Link-attention status in terms of base driver's coding.
3904 **/
3905static uint16_t
3906lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
3907 struct lpfc_acqe_link *acqe_link)
3908{
3909 uint16_t latt_fault;
3910
3911 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
3912 case LPFC_ASYNC_LINK_FAULT_NONE:
3913 case LPFC_ASYNC_LINK_FAULT_LOCAL:
3914 case LPFC_ASYNC_LINK_FAULT_REMOTE:
3915 latt_fault = 0;
3916 break;
3917 default:
3918 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3919 "0398 Invalid link fault code: x%x\n",
3920 bf_get(lpfc_acqe_link_fault, acqe_link));
3921 latt_fault = MBXERR_ERROR;
3922 break;
3923 }
3924 return latt_fault;
3925}
3926
3927/**
3928 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
3929 * @phba: pointer to lpfc hba data structure.
3930 * @acqe_link: pointer to the async link completion queue entry.
3931 *
3932 * This routine is to parse the SLI4 link attention type and translate it
3933 * into the base driver's link attention type coding.
3934 *
3935 * Return: Link attention type in terms of base driver's coding.
3936 **/
3937static uint8_t
3938lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
3939 struct lpfc_acqe_link *acqe_link)
3940{
3941 uint8_t att_type;
3942
3943 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
3944 case LPFC_ASYNC_LINK_STATUS_DOWN:
3945 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05003946 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04003947 break;
3948 case LPFC_ASYNC_LINK_STATUS_UP:
3949 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05003950 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003951 break;
3952 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05003953 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04003954 break;
3955 default:
3956 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3957 "0399 Invalid link attention type: x%x\n",
3958 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003959 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003960 break;
3961 }
3962 return att_type;
3963}
3964
3965/**
James Smart8b68cd52012-09-29 11:32:37 -04003966 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
3967 * @phba: pointer to lpfc hba data structure.
3968 *
3969 * This routine is to get an SLI3 FC port's link speed in Mbps.
3970 *
3971 * Return: link speed in terms of Mbps.
3972 **/
3973uint32_t
3974lpfc_sli_port_speed_get(struct lpfc_hba *phba)
3975{
3976 uint32_t link_speed;
3977
3978 if (!lpfc_is_link_up(phba))
3979 return 0;
3980
James Smarta085e872015-12-16 18:12:02 -05003981 if (phba->sli_rev <= LPFC_SLI_REV3) {
3982 switch (phba->fc_linkspeed) {
3983 case LPFC_LINK_SPEED_1GHZ:
3984 link_speed = 1000;
3985 break;
3986 case LPFC_LINK_SPEED_2GHZ:
3987 link_speed = 2000;
3988 break;
3989 case LPFC_LINK_SPEED_4GHZ:
3990 link_speed = 4000;
3991 break;
3992 case LPFC_LINK_SPEED_8GHZ:
3993 link_speed = 8000;
3994 break;
3995 case LPFC_LINK_SPEED_10GHZ:
3996 link_speed = 10000;
3997 break;
3998 case LPFC_LINK_SPEED_16GHZ:
3999 link_speed = 16000;
4000 break;
4001 default:
4002 link_speed = 0;
4003 }
4004 } else {
4005 if (phba->sli4_hba.link_state.logical_speed)
4006 link_speed =
4007 phba->sli4_hba.link_state.logical_speed;
4008 else
4009 link_speed = phba->sli4_hba.link_state.speed;
James Smart8b68cd52012-09-29 11:32:37 -04004010 }
4011 return link_speed;
4012}
4013
4014/**
4015 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
4016 * @phba: pointer to lpfc hba data structure.
4017 * @evt_code: asynchronous event code.
4018 * @speed_code: asynchronous event link speed code.
4019 *
4020 * This routine is to parse the giving SLI4 async event link speed code into
4021 * value of Mbps for the link speed.
4022 *
4023 * Return: link speed in terms of Mbps.
4024 **/
4025static uint32_t
4026lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
4027 uint8_t speed_code)
4028{
4029 uint32_t port_speed;
4030
4031 switch (evt_code) {
4032 case LPFC_TRAILER_CODE_LINK:
4033 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004034 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smart8b68cd52012-09-29 11:32:37 -04004035 port_speed = 0;
4036 break;
James Smart26d830e2015-04-07 15:07:17 -04004037 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004038 port_speed = 10;
4039 break;
James Smart26d830e2015-04-07 15:07:17 -04004040 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004041 port_speed = 100;
4042 break;
James Smart26d830e2015-04-07 15:07:17 -04004043 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004044 port_speed = 1000;
4045 break;
James Smart26d830e2015-04-07 15:07:17 -04004046 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004047 port_speed = 10000;
4048 break;
James Smart26d830e2015-04-07 15:07:17 -04004049 case LPFC_ASYNC_LINK_SPEED_20GBPS:
4050 port_speed = 20000;
4051 break;
4052 case LPFC_ASYNC_LINK_SPEED_25GBPS:
4053 port_speed = 25000;
4054 break;
4055 case LPFC_ASYNC_LINK_SPEED_40GBPS:
4056 port_speed = 40000;
4057 break;
James Smart8b68cd52012-09-29 11:32:37 -04004058 default:
4059 port_speed = 0;
4060 }
4061 break;
4062 case LPFC_TRAILER_CODE_FC:
4063 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004064 case LPFC_FC_LA_SPEED_UNKNOWN:
James Smart8b68cd52012-09-29 11:32:37 -04004065 port_speed = 0;
4066 break;
James Smart26d830e2015-04-07 15:07:17 -04004067 case LPFC_FC_LA_SPEED_1G:
James Smart8b68cd52012-09-29 11:32:37 -04004068 port_speed = 1000;
4069 break;
James Smart26d830e2015-04-07 15:07:17 -04004070 case LPFC_FC_LA_SPEED_2G:
James Smart8b68cd52012-09-29 11:32:37 -04004071 port_speed = 2000;
4072 break;
James Smart26d830e2015-04-07 15:07:17 -04004073 case LPFC_FC_LA_SPEED_4G:
James Smart8b68cd52012-09-29 11:32:37 -04004074 port_speed = 4000;
4075 break;
James Smart26d830e2015-04-07 15:07:17 -04004076 case LPFC_FC_LA_SPEED_8G:
James Smart8b68cd52012-09-29 11:32:37 -04004077 port_speed = 8000;
4078 break;
James Smart26d830e2015-04-07 15:07:17 -04004079 case LPFC_FC_LA_SPEED_10G:
James Smart8b68cd52012-09-29 11:32:37 -04004080 port_speed = 10000;
4081 break;
James Smart26d830e2015-04-07 15:07:17 -04004082 case LPFC_FC_LA_SPEED_16G:
James Smart8b68cd52012-09-29 11:32:37 -04004083 port_speed = 16000;
4084 break;
James Smartd38dd522015-08-31 16:48:17 -04004085 case LPFC_FC_LA_SPEED_32G:
4086 port_speed = 32000;
4087 break;
James Smart8b68cd52012-09-29 11:32:37 -04004088 default:
4089 port_speed = 0;
4090 }
4091 break;
4092 default:
4093 port_speed = 0;
4094 }
4095 return port_speed;
4096}
4097
4098/**
James Smart70f3c072010-12-15 17:57:33 -05004099 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04004100 * @phba: pointer to lpfc hba data structure.
4101 * @acqe_link: pointer to the async link completion queue entry.
4102 *
James Smart70f3c072010-12-15 17:57:33 -05004103 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04004104 **/
4105static void
4106lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
4107 struct lpfc_acqe_link *acqe_link)
4108{
4109 struct lpfc_dmabuf *mp;
4110 LPFC_MBOXQ_t *pmb;
4111 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05004112 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04004113 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05004114 int rc;
James Smartda0436e2009-05-22 14:51:39 -04004115
4116 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05004117 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04004118 return;
James Smart32b97932009-07-19 10:01:21 -04004119 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004120 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4121 if (!pmb) {
4122 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4123 "0395 The mboxq allocation failed\n");
4124 return;
4125 }
4126 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4127 if (!mp) {
4128 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4129 "0396 The lpfc_dmabuf allocation failed\n");
4130 goto out_free_pmb;
4131 }
4132 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4133 if (!mp->virt) {
4134 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4135 "0397 The mbuf allocation failed\n");
4136 goto out_free_dmabuf;
4137 }
4138
4139 /* Cleanup any outstanding ELS commands */
4140 lpfc_els_flush_all_cmd(phba);
4141
4142 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004143 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smartda0436e2009-05-22 14:51:39 -04004144
4145 /* Update link event statistics */
4146 phba->sli.slistat.link_event++;
4147
James Smart76a95d72010-11-20 23:11:48 -05004148 /* Create lpfc_handle_latt mailbox command from link ACQE */
4149 lpfc_read_topology(phba, pmb, mp);
4150 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04004151 pmb->vport = phba->pport;
4152
James Smartda0436e2009-05-22 14:51:39 -04004153 /* Keep the link status for extra SLI4 state machine reference */
4154 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004155 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
4156 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04004157 phba->sli4_hba.link_state.duplex =
4158 bf_get(lpfc_acqe_link_duplex, acqe_link);
4159 phba->sli4_hba.link_state.status =
4160 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05004161 phba->sli4_hba.link_state.type =
4162 bf_get(lpfc_acqe_link_type, acqe_link);
4163 phba->sli4_hba.link_state.number =
4164 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04004165 phba->sli4_hba.link_state.fault =
4166 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05004167 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004168 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
4169
James Smart70f3c072010-12-15 17:57:33 -05004170 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04004171 "2900 Async FC/FCoE Link event - Speed:%dGBit "
4172 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
4173 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05004174 phba->sli4_hba.link_state.speed,
4175 phba->sli4_hba.link_state.topology,
4176 phba->sli4_hba.link_state.status,
4177 phba->sli4_hba.link_state.type,
4178 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004179 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004180 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05004181 /*
4182 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
4183 * topology info. Note: Optional for non FC-AL ports.
4184 */
4185 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
4186 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4187 if (rc == MBX_NOT_FINISHED)
4188 goto out_free_dmabuf;
4189 return;
4190 }
4191 /*
4192 * For FCoE Mode: fill in all the topology information we need and call
4193 * the READ_TOPOLOGY completion routine to continue without actually
4194 * sending the READ_TOPOLOGY mailbox command to the port.
4195 */
4196 /* Parse and translate status field */
4197 mb = &pmb->u.mb;
4198 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
4199
4200 /* Parse and translate link attention fields */
4201 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
4202 la->eventTag = acqe_link->event_tag;
4203 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
4204 bf_set(lpfc_mbx_read_top_link_spd, la,
James Smarta085e872015-12-16 18:12:02 -05004205 (bf_get(lpfc_acqe_link_speed, acqe_link)));
James Smart76a95d72010-11-20 23:11:48 -05004206
4207 /* Fake the the following irrelvant fields */
4208 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
4209 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
4210 bf_set(lpfc_mbx_read_top_il, la, 0);
4211 bf_set(lpfc_mbx_read_top_pb, la, 0);
4212 bf_set(lpfc_mbx_read_top_fa, la, 0);
4213 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04004214
4215 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05004216 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04004217
4218 return;
4219
4220out_free_dmabuf:
4221 kfree(mp);
4222out_free_pmb:
4223 mempool_free(pmb, phba->mbox_mem_pool);
4224}
4225
4226/**
James Smart70f3c072010-12-15 17:57:33 -05004227 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
4228 * @phba: pointer to lpfc hba data structure.
4229 * @acqe_fc: pointer to the async fc completion queue entry.
4230 *
4231 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
4232 * that the event was received and then issue a read_topology mailbox command so
4233 * that the rest of the driver will treat it the same as SLI3.
4234 **/
4235static void
4236lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
4237{
4238 struct lpfc_dmabuf *mp;
4239 LPFC_MBOXQ_t *pmb;
James Smart7bdedb32016-07-06 12:36:00 -07004240 MAILBOX_t *mb;
4241 struct lpfc_mbx_read_top *la;
James Smart70f3c072010-12-15 17:57:33 -05004242 int rc;
4243
4244 if (bf_get(lpfc_trailer_type, acqe_fc) !=
4245 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
4246 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4247 "2895 Non FC link Event detected.(%d)\n",
4248 bf_get(lpfc_trailer_type, acqe_fc));
4249 return;
4250 }
4251 /* Keep the link status for extra SLI4 state machine reference */
4252 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004253 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
4254 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05004255 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
4256 phba->sli4_hba.link_state.topology =
4257 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
4258 phba->sli4_hba.link_state.status =
4259 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
4260 phba->sli4_hba.link_state.type =
4261 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
4262 phba->sli4_hba.link_state.number =
4263 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
4264 phba->sli4_hba.link_state.fault =
4265 bf_get(lpfc_acqe_link_fault, acqe_fc);
4266 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004267 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart70f3c072010-12-15 17:57:33 -05004268 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4269 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4270 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4271 "%dMbps Fault:%d\n",
4272 phba->sli4_hba.link_state.speed,
4273 phba->sli4_hba.link_state.topology,
4274 phba->sli4_hba.link_state.status,
4275 phba->sli4_hba.link_state.type,
4276 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004277 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004278 phba->sli4_hba.link_state.fault);
4279 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4280 if (!pmb) {
4281 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4282 "2897 The mboxq allocation failed\n");
4283 return;
4284 }
4285 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4286 if (!mp) {
4287 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4288 "2898 The lpfc_dmabuf allocation failed\n");
4289 goto out_free_pmb;
4290 }
4291 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4292 if (!mp->virt) {
4293 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4294 "2899 The mbuf allocation failed\n");
4295 goto out_free_dmabuf;
4296 }
4297
4298 /* Cleanup any outstanding ELS commands */
4299 lpfc_els_flush_all_cmd(phba);
4300
4301 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004302 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smart70f3c072010-12-15 17:57:33 -05004303
4304 /* Update link event statistics */
4305 phba->sli.slistat.link_event++;
4306
4307 /* Create lpfc_handle_latt mailbox command from link ACQE */
4308 lpfc_read_topology(phba, pmb, mp);
4309 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4310 pmb->vport = phba->pport;
4311
James Smart7bdedb32016-07-06 12:36:00 -07004312 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
4313 /* Parse and translate status field */
4314 mb = &pmb->u.mb;
4315 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba,
4316 (void *)acqe_fc);
4317
4318 /* Parse and translate link attention fields */
4319 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
4320 la->eventTag = acqe_fc->event_tag;
4321 bf_set(lpfc_mbx_read_top_att_type, la,
4322 LPFC_FC_LA_TYPE_LINK_DOWN);
4323
4324 /* Invoke the mailbox command callback function */
4325 lpfc_mbx_cmpl_read_topology(phba, pmb);
4326
4327 return;
4328 }
4329
James Smart70f3c072010-12-15 17:57:33 -05004330 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4331 if (rc == MBX_NOT_FINISHED)
4332 goto out_free_dmabuf;
4333 return;
4334
4335out_free_dmabuf:
4336 kfree(mp);
4337out_free_pmb:
4338 mempool_free(pmb, phba->mbox_mem_pool);
4339}
4340
4341/**
4342 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4343 * @phba: pointer to lpfc hba data structure.
4344 * @acqe_fc: pointer to the async SLI completion queue entry.
4345 *
4346 * This routine is to handle the SLI4 asynchronous SLI events.
4347 **/
4348static void
4349lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
4350{
James Smart4b8bae02012-06-12 13:55:07 -04004351 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04004352 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04004353 uint8_t status;
James Smart946727d2015-04-07 15:07:09 -04004354 uint8_t evt_type;
James Smart448193b2015-12-16 18:12:05 -05004355 uint8_t operational = 0;
James Smart946727d2015-04-07 15:07:09 -04004356 struct temp_event temp_event_data;
James Smart4b8bae02012-06-12 13:55:07 -04004357 struct lpfc_acqe_misconfigured_event *misconfigured;
James Smart946727d2015-04-07 15:07:09 -04004358 struct Scsi_Host *shost;
James Smart4b8bae02012-06-12 13:55:07 -04004359
James Smart946727d2015-04-07 15:07:09 -04004360 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
4361
James Smart448193b2015-12-16 18:12:05 -05004362 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4363 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4364 "x%08x SLI Event Type:%d\n",
4365 acqe_sli->event_data1, acqe_sli->event_data2,
4366 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004367
4368 port_name = phba->Port[0];
4369 if (port_name == 0x00)
4370 port_name = '?'; /* get port name is empty */
4371
James Smart946727d2015-04-07 15:07:09 -04004372 switch (evt_type) {
4373 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
4374 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4375 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
4376 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4377
4378 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4379 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4380 acqe_sli->event_data1, port_name);
4381
James Smart310429e2016-07-06 12:35:54 -07004382 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04004383 shost = lpfc_shost_from_vport(phba->pport);
4384 fc_host_post_vendor_event(shost, fc_get_event_number(),
4385 sizeof(temp_event_data),
4386 (char *)&temp_event_data,
4387 SCSI_NL_VID_TYPE_PCI
4388 | PCI_VENDOR_ID_EMULEX);
4389 break;
4390 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
4391 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4392 temp_event_data.event_code = LPFC_NORMAL_TEMP;
4393 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4394
4395 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4396 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4397 acqe_sli->event_data1, port_name);
4398
4399 shost = lpfc_shost_from_vport(phba->pport);
4400 fc_host_post_vendor_event(shost, fc_get_event_number(),
4401 sizeof(temp_event_data),
4402 (char *)&temp_event_data,
4403 SCSI_NL_VID_TYPE_PCI
4404 | PCI_VENDOR_ID_EMULEX);
4405 break;
4406 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
4407 misconfigured = (struct lpfc_acqe_misconfigured_event *)
James Smart4b8bae02012-06-12 13:55:07 -04004408 &acqe_sli->event_data1;
4409
James Smart946727d2015-04-07 15:07:09 -04004410 /* fetch the status for this port */
4411 switch (phba->sli4_hba.lnk_info.lnk_no) {
4412 case LPFC_LINK_NUMBER_0:
James Smart448193b2015-12-16 18:12:05 -05004413 status = bf_get(lpfc_sli_misconfigured_port0_state,
4414 &misconfigured->theEvent);
4415 operational = bf_get(lpfc_sli_misconfigured_port0_op,
James Smart4b8bae02012-06-12 13:55:07 -04004416 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004417 break;
4418 case LPFC_LINK_NUMBER_1:
James Smart448193b2015-12-16 18:12:05 -05004419 status = bf_get(lpfc_sli_misconfigured_port1_state,
4420 &misconfigured->theEvent);
4421 operational = bf_get(lpfc_sli_misconfigured_port1_op,
James Smart4b8bae02012-06-12 13:55:07 -04004422 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004423 break;
4424 case LPFC_LINK_NUMBER_2:
James Smart448193b2015-12-16 18:12:05 -05004425 status = bf_get(lpfc_sli_misconfigured_port2_state,
4426 &misconfigured->theEvent);
4427 operational = bf_get(lpfc_sli_misconfigured_port2_op,
James Smart4b8bae02012-06-12 13:55:07 -04004428 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004429 break;
4430 case LPFC_LINK_NUMBER_3:
James Smart448193b2015-12-16 18:12:05 -05004431 status = bf_get(lpfc_sli_misconfigured_port3_state,
4432 &misconfigured->theEvent);
4433 operational = bf_get(lpfc_sli_misconfigured_port3_op,
James Smart4b8bae02012-06-12 13:55:07 -04004434 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004435 break;
4436 default:
James Smart448193b2015-12-16 18:12:05 -05004437 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4438 "3296 "
4439 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
4440 "event: Invalid link %d",
4441 phba->sli4_hba.lnk_info.lnk_no);
4442 return;
James Smart946727d2015-04-07 15:07:09 -04004443 }
James Smart4b8bae02012-06-12 13:55:07 -04004444
James Smart448193b2015-12-16 18:12:05 -05004445 /* Skip if optic state unchanged */
4446 if (phba->sli4_hba.lnk_info.optic_state == status)
4447 return;
4448
James Smart946727d2015-04-07 15:07:09 -04004449 switch (status) {
4450 case LPFC_SLI_EVENT_STATUS_VALID:
James Smart448193b2015-12-16 18:12:05 -05004451 sprintf(message, "Physical Link is functional");
4452 break;
James Smart946727d2015-04-07 15:07:09 -04004453 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
4454 sprintf(message, "Optics faulted/incorrectly "
4455 "installed/not installed - Reseat optics, "
4456 "if issue not resolved, replace.");
4457 break;
4458 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
4459 sprintf(message,
4460 "Optics of two types installed - Remove one "
4461 "optic or install matching pair of optics.");
4462 break;
4463 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
4464 sprintf(message, "Incompatible optics - Replace with "
James Smart292098b2012-09-29 11:31:41 -04004465 "compatible optics for card to function.");
James Smart946727d2015-04-07 15:07:09 -04004466 break;
James Smart448193b2015-12-16 18:12:05 -05004467 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
4468 sprintf(message, "Unqualified optics - Replace with "
4469 "Avago optics for Warranty and Technical "
4470 "Support - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08004471 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05004472 break;
4473 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
4474 sprintf(message, "Uncertified optics - Replace with "
4475 "Avago-certified optics to enable link "
4476 "operation - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08004477 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05004478 break;
James Smart946727d2015-04-07 15:07:09 -04004479 default:
4480 /* firmware is reporting a status we don't know about */
4481 sprintf(message, "Unknown event status x%02x", status);
4482 break;
4483 }
James Smart448193b2015-12-16 18:12:05 -05004484 phba->sli4_hba.lnk_info.optic_state = status;
James Smart946727d2015-04-07 15:07:09 -04004485 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart448193b2015-12-16 18:12:05 -05004486 "3176 Port Name %c %s\n", port_name, message);
James Smart946727d2015-04-07 15:07:09 -04004487 break;
4488 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
4489 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4490 "3192 Remote DPort Test Initiated - "
4491 "Event Data1:x%08x Event Data2: x%08x\n",
4492 acqe_sli->event_data1, acqe_sli->event_data2);
James Smart4b8bae02012-06-12 13:55:07 -04004493 break;
4494 default:
James Smart946727d2015-04-07 15:07:09 -04004495 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4496 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
4497 "x%08x SLI Event Type:%d\n",
4498 acqe_sli->event_data1, acqe_sli->event_data2,
4499 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004500 break;
4501 }
James Smart70f3c072010-12-15 17:57:33 -05004502}
4503
4504/**
James Smartfc2b9892010-02-26 14:15:29 -05004505 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
4506 * @vport: pointer to vport data structure.
4507 *
4508 * This routine is to perform Clear Virtual Link (CVL) on a vport in
4509 * response to a CVL event.
4510 *
4511 * Return the pointer to the ndlp with the vport if successful, otherwise
4512 * return NULL.
4513 **/
4514static struct lpfc_nodelist *
4515lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
4516{
4517 struct lpfc_nodelist *ndlp;
4518 struct Scsi_Host *shost;
4519 struct lpfc_hba *phba;
4520
4521 if (!vport)
4522 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05004523 phba = vport->phba;
4524 if (!phba)
4525 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04004526 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4527 if (!ndlp) {
4528 /* Cannot find existing Fabric ndlp, so allocate a new one */
4529 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4530 if (!ndlp)
4531 return 0;
4532 lpfc_nlp_init(vport, ndlp, Fabric_DID);
4533 /* Set the node type */
4534 ndlp->nlp_type |= NLP_FABRIC;
4535 /* Put ndlp onto node list */
4536 lpfc_enqueue_node(vport, ndlp);
4537 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4538 /* re-setup ndlp without removing from node list */
4539 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4540 if (!ndlp)
4541 return 0;
4542 }
James Smart63e801c2010-11-20 23:14:19 -05004543 if ((phba->pport->port_state < LPFC_FLOGI) &&
4544 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004545 return NULL;
4546 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05004547 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
4548 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004549 return NULL;
4550 shost = lpfc_shost_from_vport(vport);
4551 if (!shost)
4552 return NULL;
4553 lpfc_linkdown_port(vport);
4554 lpfc_cleanup_pending_mbox(vport);
4555 spin_lock_irq(shost->host_lock);
4556 vport->fc_flag |= FC_VPORT_CVL_RCVD;
4557 spin_unlock_irq(shost->host_lock);
4558
4559 return ndlp;
4560}
4561
4562/**
4563 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4564 * @vport: pointer to lpfc hba data structure.
4565 *
4566 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4567 * response to a FCF dead event.
4568 **/
4569static void
4570lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
4571{
4572 struct lpfc_vport **vports;
4573 int i;
4574
4575 vports = lpfc_create_vport_work_array(phba);
4576 if (vports)
4577 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4578 lpfc_sli4_perform_vport_cvl(vports[i]);
4579 lpfc_destroy_vport_work_array(phba, vports);
4580}
4581
4582/**
James Smart76a95d72010-11-20 23:11:48 -05004583 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04004584 * @phba: pointer to lpfc hba data structure.
4585 * @acqe_link: pointer to the async fcoe completion queue entry.
4586 *
4587 * This routine is to handle the SLI4 asynchronous fcoe event.
4588 **/
4589static void
James Smart76a95d72010-11-20 23:11:48 -05004590lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05004591 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04004592{
James Smart70f3c072010-12-15 17:57:33 -05004593 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004594 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04004595 struct lpfc_vport *vport;
4596 struct lpfc_nodelist *ndlp;
4597 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05004598 int active_vlink_present;
4599 struct lpfc_vport **vports;
4600 int i;
James Smartda0436e2009-05-22 14:51:39 -04004601
James Smart70f3c072010-12-15 17:57:33 -05004602 phba->fc_eventTag = acqe_fip->event_tag;
4603 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004604 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05004605 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
4606 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
4607 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04004608 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4609 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004610 "2546 New FCF event, evt_tag:x%x, "
4611 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004612 acqe_fip->event_tag,
4613 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04004614 else
4615 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
4616 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004617 "2788 FCF param modified event, "
4618 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004619 acqe_fip->event_tag,
4620 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04004621 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004622 /*
4623 * During period of FCF discovery, read the FCF
4624 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04004625 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05004626 */
4627 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4628 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004629 "2779 Read FCF (x%x) for updating "
4630 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05004631 acqe_fip->index);
4632 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004633 }
James Smart38b92ef2010-08-04 16:11:39 -04004634
4635 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04004636 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04004637 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04004638 spin_unlock_irq(&phba->hbalock);
4639 break;
4640 }
4641 /* If fast FCF failover rescan event is pending, do nothing */
4642 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
4643 spin_unlock_irq(&phba->hbalock);
4644 break;
4645 }
4646
James Smartc2b97122013-05-31 17:05:36 -04004647 /* If the FCF has been in discovered state, do nothing. */
4648 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
James Smart3804dc82010-07-14 15:31:37 -04004649 spin_unlock_irq(&phba->hbalock);
4650 break;
4651 }
4652 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04004653
James Smart0c9ab6f2010-02-26 14:15:57 -05004654 /* Otherwise, scan the entire FCF table and re-discover SAN */
4655 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004656 "2770 Start FCF table scan per async FCF "
4657 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004658 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004659 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
4660 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04004661 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004662 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4663 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04004664 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04004665 break;
4666
James Smart70f3c072010-12-15 17:57:33 -05004667 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04004668 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04004669 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004670 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
4671 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004672 break;
4673
James Smart70f3c072010-12-15 17:57:33 -05004674 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05004675 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004676 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004677 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05004678 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04004679 /*
4680 * If we are in the middle of FCF failover process, clear
4681 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04004682 */
James Smartfc2b9892010-02-26 14:15:29 -05004683 spin_lock_irq(&phba->hbalock);
James Smarta1cadfe2016-07-06 12:36:02 -07004684 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
4685 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
James Smartfc2b9892010-02-26 14:15:29 -05004686 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004687 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05004688 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004689 break;
4690 }
James Smart38b92ef2010-08-04 16:11:39 -04004691 spin_unlock_irq(&phba->hbalock);
4692
4693 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05004694 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04004695 break;
4696
4697 /*
4698 * Otherwise, request the port to rediscover the entire FCF
4699 * table for a fast recovery from case that the current FCF
4700 * is no longer valid as we are not in the middle of FCF
4701 * failover process already.
4702 */
James Smartc2b97122013-05-31 17:05:36 -04004703 spin_lock_irq(&phba->hbalock);
4704 /* Mark the fast failover process in progress */
4705 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
4706 spin_unlock_irq(&phba->hbalock);
4707
4708 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
4709 "2771 Start FCF fast failover process due to "
4710 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
4711 "\n", acqe_fip->event_tag, acqe_fip->index);
4712 rc = lpfc_sli4_redisc_fcf_table(phba);
4713 if (rc) {
4714 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4715 LOG_DISCOVERY,
4716 "2772 Issue FCF rediscover mabilbox "
4717 "command failed, fail through to FCF "
4718 "dead event\n");
4719 spin_lock_irq(&phba->hbalock);
4720 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
4721 spin_unlock_irq(&phba->hbalock);
4722 /*
4723 * Last resort will fail over by treating this
4724 * as a link down to FCF registration.
4725 */
4726 lpfc_sli4_fcf_dead_failthrough(phba);
4727 } else {
4728 /* Reset FCF roundrobin bmask for new discovery */
4729 lpfc_sli4_clear_fcf_rr_bmask(phba);
4730 /*
4731 * Handling fast FCF failover to a DEAD FCF event is
4732 * considered equalivant to receiving CVL to all vports.
4733 */
4734 lpfc_sli4_perform_all_vport_cvl(phba);
4735 }
James Smartda0436e2009-05-22 14:51:39 -04004736 break;
James Smart70f3c072010-12-15 17:57:33 -05004737 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05004738 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004739 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04004740 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05004741 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04004742
James Smart6669f9b2009-10-02 15:16:45 -04004743 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04004744 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004745 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004746 if (!ndlp)
4747 break;
James Smart695a8142010-01-26 23:08:03 -05004748 active_vlink_present = 0;
4749
4750 vports = lpfc_create_vport_work_array(phba);
4751 if (vports) {
4752 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
4753 i++) {
4754 if ((!(vports[i]->fc_flag &
4755 FC_VPORT_CVL_RCVD)) &&
4756 (vports[i]->port_state > LPFC_FDISC)) {
4757 active_vlink_present = 1;
4758 break;
4759 }
4760 }
4761 lpfc_destroy_vport_work_array(phba, vports);
4762 }
4763
James Smartcc823552015-05-21 13:55:26 -04004764 /*
4765 * Don't re-instantiate if vport is marked for deletion.
4766 * If we are here first then vport_delete is going to wait
4767 * for discovery to complete.
4768 */
4769 if (!(vport->load_flag & FC_UNLOADING) &&
4770 active_vlink_present) {
James Smart695a8142010-01-26 23:08:03 -05004771 /*
4772 * If there are other active VLinks present,
4773 * re-instantiate the Vlink using FDISC.
4774 */
James Smart256ec0d2013-04-17 20:14:58 -04004775 mod_timer(&ndlp->nlp_delayfunc,
4776 jiffies + msecs_to_jiffies(1000));
James Smartfc2b9892010-02-26 14:15:29 -05004777 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004778 spin_lock_irq(shost->host_lock);
4779 ndlp->nlp_flag |= NLP_DELAY_TMO;
4780 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05004781 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
4782 vport->port_state = LPFC_FDISC;
4783 } else {
James Smartecfd03c2010-02-12 14:41:27 -05004784 /*
4785 * Otherwise, we request port to rediscover
4786 * the entire FCF table for a fast recovery
4787 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05004788 * is no longer valid if we are not already
4789 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05004790 */
James Smartfc2b9892010-02-26 14:15:29 -05004791 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004792 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05004793 spin_unlock_irq(&phba->hbalock);
4794 break;
4795 }
4796 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05004797 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004798 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004799 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4800 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004801 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05004802 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05004803 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05004804 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004805 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4806 LOG_DISCOVERY,
4807 "2774 Issue FCF rediscover "
4808 "mabilbox command failed, "
4809 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05004810 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004811 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004812 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05004813 /*
4814 * Last resort will be re-try on the
4815 * the current registered FCF entry.
4816 */
4817 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04004818 } else
4819 /*
4820 * Reset FCF roundrobin bmask for new
4821 * discovery.
4822 */
James Smart7d791df2011-07-22 18:37:52 -04004823 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04004824 }
4825 break;
James Smartda0436e2009-05-22 14:51:39 -04004826 default:
4827 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4828 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05004829 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004830 break;
4831 }
4832}
4833
4834/**
4835 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
4836 * @phba: pointer to lpfc hba data structure.
4837 * @acqe_link: pointer to the async dcbx completion queue entry.
4838 *
4839 * This routine is to handle the SLI4 asynchronous dcbx event.
4840 **/
4841static void
4842lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
4843 struct lpfc_acqe_dcbx *acqe_dcbx)
4844{
James Smart4d9ab992009-10-02 15:16:39 -04004845 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004846 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4847 "0290 The SLI4 DCBX asynchronous event is not "
4848 "handled yet\n");
4849}
4850
4851/**
James Smartb19a0612010-04-06 14:48:51 -04004852 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
4853 * @phba: pointer to lpfc hba data structure.
4854 * @acqe_link: pointer to the async grp5 completion queue entry.
4855 *
4856 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
4857 * is an asynchronous notified of a logical link speed change. The Port
4858 * reports the logical link speed in units of 10Mbps.
4859 **/
4860static void
4861lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
4862 struct lpfc_acqe_grp5 *acqe_grp5)
4863{
4864 uint16_t prev_ll_spd;
4865
4866 phba->fc_eventTag = acqe_grp5->event_tag;
4867 phba->fcoe_eventtag = acqe_grp5->event_tag;
4868 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
4869 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004870 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04004871 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4872 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04004873 "from %dMbps to %dMbps\n", prev_ll_spd,
4874 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04004875}
4876
4877/**
James Smartda0436e2009-05-22 14:51:39 -04004878 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
4879 * @phba: pointer to lpfc hba data structure.
4880 *
4881 * This routine is invoked by the worker thread to process all the pending
4882 * SLI4 asynchronous events.
4883 **/
4884void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
4885{
4886 struct lpfc_cq_event *cq_event;
4887
4888 /* First, declare the async event has been handled */
4889 spin_lock_irq(&phba->hbalock);
4890 phba->hba_flag &= ~ASYNC_EVENT;
4891 spin_unlock_irq(&phba->hbalock);
4892 /* Now, handle all the async events */
4893 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
4894 /* Get the first event from the head of the event queue */
4895 spin_lock_irq(&phba->hbalock);
4896 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
4897 cq_event, struct lpfc_cq_event, list);
4898 spin_unlock_irq(&phba->hbalock);
4899 /* Process the asynchronous event */
4900 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
4901 case LPFC_TRAILER_CODE_LINK:
4902 lpfc_sli4_async_link_evt(phba,
4903 &cq_event->cqe.acqe_link);
4904 break;
4905 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05004906 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004907 break;
4908 case LPFC_TRAILER_CODE_DCBX:
4909 lpfc_sli4_async_dcbx_evt(phba,
4910 &cq_event->cqe.acqe_dcbx);
4911 break;
James Smartb19a0612010-04-06 14:48:51 -04004912 case LPFC_TRAILER_CODE_GRP5:
4913 lpfc_sli4_async_grp5_evt(phba,
4914 &cq_event->cqe.acqe_grp5);
4915 break;
James Smart70f3c072010-12-15 17:57:33 -05004916 case LPFC_TRAILER_CODE_FC:
4917 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
4918 break;
4919 case LPFC_TRAILER_CODE_SLI:
4920 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
4921 break;
James Smartda0436e2009-05-22 14:51:39 -04004922 default:
4923 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4924 "1804 Invalid asynchrous event code: "
4925 "x%x\n", bf_get(lpfc_trailer_code,
4926 &cq_event->cqe.mcqe_cmpl));
4927 break;
4928 }
4929 /* Free the completion event processed to the free pool */
4930 lpfc_sli4_cq_event_release(phba, cq_event);
4931 }
4932}
4933
4934/**
James Smartecfd03c2010-02-12 14:41:27 -05004935 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
4936 * @phba: pointer to lpfc hba data structure.
4937 *
4938 * This routine is invoked by the worker thread to process FCF table
4939 * rediscovery pending completion event.
4940 **/
4941void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
4942{
4943 int rc;
4944
4945 spin_lock_irq(&phba->hbalock);
4946 /* Clear FCF rediscovery timeout event */
4947 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
4948 /* Clear driver fast failover FCF record flag */
4949 phba->fcf.failover_rec.flag = 0;
4950 /* Set state for FCF fast failover */
4951 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
4952 spin_unlock_irq(&phba->hbalock);
4953
4954 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05004955 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004956 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05004957 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05004958 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004959 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4960 "2747 Issue FCF scan read FCF mailbox "
4961 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05004962}
4963
4964/**
James Smartda0436e2009-05-22 14:51:39 -04004965 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
4966 * @phba: pointer to lpfc hba data structure.
4967 * @dev_grp: The HBA PCI-Device group number.
4968 *
4969 * This routine is invoked to set up the per HBA PCI-Device group function
4970 * API jump table entries.
4971 *
4972 * Return: 0 if success, otherwise -ENODEV
4973 **/
4974int
4975lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05004976{
4977 int rc;
4978
James Smartda0436e2009-05-22 14:51:39 -04004979 /* Set up lpfc PCI-device group */
4980 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05004981
James Smartda0436e2009-05-22 14:51:39 -04004982 /* The LPFC_PCI_DEV_OC uses SLI4 */
4983 if (dev_grp == LPFC_PCI_DEV_OC)
4984 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05004985
James Smartda0436e2009-05-22 14:51:39 -04004986 /* Set up device INIT API function jump table */
4987 rc = lpfc_init_api_table_setup(phba, dev_grp);
4988 if (rc)
4989 return -ENODEV;
4990 /* Set up SCSI API function jump table */
4991 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
4992 if (rc)
4993 return -ENODEV;
4994 /* Set up SLI API function jump table */
4995 rc = lpfc_sli_api_table_setup(phba, dev_grp);
4996 if (rc)
4997 return -ENODEV;
4998 /* Set up MBOX API function jump table */
4999 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
5000 if (rc)
5001 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05005002
James Smartda0436e2009-05-22 14:51:39 -04005003 return 0;
James Smart5b75da22008-12-04 22:39:35 -05005004}
5005
5006/**
James Smart3621a712009-04-06 18:47:14 -04005007 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05005008 * @phba: pointer to lpfc hba data structure.
5009 * @intr_mode: active interrupt mode adopted.
5010 *
5011 * This routine it invoked to log the currently used active interrupt mode
5012 * to the device.
James Smart3772a992009-05-22 14:50:54 -04005013 **/
5014static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05005015{
5016 switch (intr_mode) {
5017 case 0:
5018 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5019 "0470 Enable INTx interrupt mode.\n");
5020 break;
5021 case 1:
5022 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5023 "0481 Enabled MSI interrupt mode.\n");
5024 break;
5025 case 2:
5026 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5027 "0480 Enabled MSI-X interrupt mode.\n");
5028 break;
5029 default:
5030 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5031 "0482 Illegal interrupt mode.\n");
5032 break;
5033 }
5034 return;
5035}
5036
James Smart5b75da22008-12-04 22:39:35 -05005037/**
James Smart3772a992009-05-22 14:50:54 -04005038 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05005039 * @phba: pointer to lpfc hba data structure.
5040 *
James Smart3772a992009-05-22 14:50:54 -04005041 * This routine is invoked to enable the PCI device that is common to all
5042 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05005043 *
5044 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005045 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005046 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05005047 **/
James Smart3772a992009-05-22 14:50:54 -04005048static int
5049lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05005050{
James Smart3772a992009-05-22 14:50:54 -04005051 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05005052
James Smart3772a992009-05-22 14:50:54 -04005053 /* Obtain PCI device reference */
5054 if (!phba->pcidev)
5055 goto out_error;
5056 else
5057 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04005058 /* Enable PCI device */
5059 if (pci_enable_device_mem(pdev))
5060 goto out_error;
5061 /* Request PCI resource for the device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005062 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
James Smart3772a992009-05-22 14:50:54 -04005063 goto out_disable_device;
5064 /* Set up device as PCI master and save state for EEH */
5065 pci_set_master(pdev);
5066 pci_try_set_mwi(pdev);
5067 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05005068
James Smart05580562011-05-24 11:40:48 -04005069 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
Jon Mason453193e2013-09-11 15:38:13 -07005070 if (pci_is_pcie(pdev))
James Smart05580562011-05-24 11:40:48 -04005071 pdev->needs_freset = 1;
5072
James Smart3772a992009-05-22 14:50:54 -04005073 return 0;
James Smart5b75da22008-12-04 22:39:35 -05005074
James Smart3772a992009-05-22 14:50:54 -04005075out_disable_device:
5076 pci_disable_device(pdev);
5077out_error:
James Smart079b5c92011-08-21 21:48:49 -04005078 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005079 "1401 Failed to enable pci device\n");
James Smart3772a992009-05-22 14:50:54 -04005080 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05005081}
5082
5083/**
James Smart3772a992009-05-22 14:50:54 -04005084 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05005085 * @phba: pointer to lpfc hba data structure.
5086 *
James Smart3772a992009-05-22 14:50:54 -04005087 * This routine is invoked to disable the PCI device that is common to all
5088 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05005089 **/
5090static void
James Smart3772a992009-05-22 14:50:54 -04005091lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05005092{
James Smart3772a992009-05-22 14:50:54 -04005093 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05005094
James Smart3772a992009-05-22 14:50:54 -04005095 /* Obtain PCI device reference */
5096 if (!phba->pcidev)
5097 return;
5098 else
5099 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04005100 /* Release PCI resource and disable PCI device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005101 pci_release_mem_regions(pdev);
James Smart3772a992009-05-22 14:50:54 -04005102 pci_disable_device(pdev);
James Smart5b75da22008-12-04 22:39:35 -05005103
5104 return;
5105}
5106
5107/**
James Smart3772a992009-05-22 14:50:54 -04005108 * lpfc_reset_hba - Reset a hba
5109 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04005110 *
James Smart3772a992009-05-22 14:50:54 -04005111 * This routine is invoked to reset a hba device. It brings the HBA
5112 * offline, performs a board restart, and then brings the board back
5113 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
5114 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04005115 **/
James Smart3772a992009-05-22 14:50:54 -04005116void
5117lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05005118{
James Smart3772a992009-05-22 14:50:54 -04005119 /* If resets are disabled then set error state and return. */
5120 if (!phba->cfg_enable_hba_reset) {
5121 phba->link_state = LPFC_HBA_ERROR;
5122 return;
5123 }
James Smartee620212014-04-04 13:51:53 -04005124 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
5125 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
5126 else
5127 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart3772a992009-05-22 14:50:54 -04005128 lpfc_offline(phba);
5129 lpfc_sli_brdrestart(phba);
5130 lpfc_online(phba);
5131 lpfc_unblock_mgmt_io(phba);
5132}
dea31012005-04-17 16:05:31 -05005133
James Smart3772a992009-05-22 14:50:54 -04005134/**
James Smart0a96e972011-07-22 18:37:28 -04005135 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
5136 * @phba: pointer to lpfc hba data structure.
5137 *
5138 * This function enables the PCI SR-IOV virtual functions to a physical
5139 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5140 * enable the number of virtual functions to the physical function. As
5141 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5142 * API call does not considered as an error condition for most of the device.
5143 **/
5144uint16_t
5145lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
5146{
5147 struct pci_dev *pdev = phba->pcidev;
5148 uint16_t nr_virtfn;
5149 int pos;
5150
James Smart0a96e972011-07-22 18:37:28 -04005151 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
5152 if (pos == 0)
5153 return 0;
5154
5155 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
5156 return nr_virtfn;
5157}
5158
5159/**
James Smart912e3ac2011-05-24 11:42:11 -04005160 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
5161 * @phba: pointer to lpfc hba data structure.
5162 * @nr_vfn: number of virtual functions to be enabled.
5163 *
5164 * This function enables the PCI SR-IOV virtual functions to a physical
5165 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5166 * enable the number of virtual functions to the physical function. As
5167 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5168 * API call does not considered as an error condition for most of the device.
5169 **/
5170int
5171lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
5172{
5173 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04005174 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04005175 int rc;
5176
James Smart0a96e972011-07-22 18:37:28 -04005177 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
5178 if (nr_vfn > max_nr_vfn) {
5179 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5180 "3057 Requested vfs (%d) greater than "
5181 "supported vfs (%d)", nr_vfn, max_nr_vfn);
5182 return -EINVAL;
5183 }
5184
James Smart912e3ac2011-05-24 11:42:11 -04005185 rc = pci_enable_sriov(pdev, nr_vfn);
5186 if (rc) {
5187 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5188 "2806 Failed to enable sriov on this device "
5189 "with vfn number nr_vf:%d, rc:%d\n",
5190 nr_vfn, rc);
5191 } else
5192 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5193 "2807 Successful enable sriov on this device "
5194 "with vfn number nr_vf:%d\n", nr_vfn);
5195 return rc;
5196}
5197
5198/**
James Smart895427b2017-02-12 13:52:30 -08005199 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
James Smart3772a992009-05-22 14:50:54 -04005200 * @phba: pointer to lpfc hba data structure.
5201 *
James Smart895427b2017-02-12 13:52:30 -08005202 * This routine is invoked to set up the driver internal resources before the
5203 * device specific resource setup to support the HBA device it attached to.
James Smart3772a992009-05-22 14:50:54 -04005204 *
5205 * Return codes
James Smart895427b2017-02-12 13:52:30 -08005206 * 0 - successful
5207 * other values - error
James Smart3772a992009-05-22 14:50:54 -04005208 **/
5209static int
James Smart895427b2017-02-12 13:52:30 -08005210lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
James Smart3772a992009-05-22 14:50:54 -04005211{
James Smart895427b2017-02-12 13:52:30 -08005212 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05005213
James Smart3772a992009-05-22 14:50:54 -04005214 /*
James Smart895427b2017-02-12 13:52:30 -08005215 * Driver resources common to all SLI revisions
James Smart3772a992009-05-22 14:50:54 -04005216 */
James Smart895427b2017-02-12 13:52:30 -08005217 atomic_set(&phba->fast_event_count, 0);
5218 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005219
James Smart895427b2017-02-12 13:52:30 -08005220 /* Initialize ndlp management spinlock */
5221 spin_lock_init(&phba->ndlp_lock);
James Smart3772a992009-05-22 14:50:54 -04005222
James Smart895427b2017-02-12 13:52:30 -08005223 INIT_LIST_HEAD(&phba->port_list);
5224 INIT_LIST_HEAD(&phba->work_list);
5225 init_waitqueue_head(&phba->wait_4_mlo_m_q);
5226
5227 /* Initialize the wait queue head for the kernel thread */
5228 init_waitqueue_head(&phba->work_waitq);
5229
5230 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5231 "1403 Protocols supported %s %s\n",
5232 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
5233 "SCSI" : " "),
5234 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
5235 "NVME" : " "));
5236
5237 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5238 /* Initialize the scsi buffer list used by driver for scsi IO */
5239 spin_lock_init(&phba->scsi_buf_list_get_lock);
5240 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5241 spin_lock_init(&phba->scsi_buf_list_put_lock);
5242 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
5243 }
5244
5245 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
5246 (phba->nvmet_support == 0)) {
5247 /* Initialize the NVME buffer list used by driver for NVME IO */
5248 spin_lock_init(&phba->nvme_buf_list_get_lock);
5249 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_get);
5250 spin_lock_init(&phba->nvme_buf_list_put_lock);
5251 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
5252 }
5253
5254 /* Initialize the fabric iocb list */
5255 INIT_LIST_HEAD(&phba->fabric_iocb_list);
5256
5257 /* Initialize list to save ELS buffers */
5258 INIT_LIST_HEAD(&phba->elsbuf);
5259
5260 /* Initialize FCF connection rec list */
5261 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
5262
5263 /* Initialize OAS configuration list */
5264 spin_lock_init(&phba->devicelock);
5265 INIT_LIST_HEAD(&phba->luns);
5266
James Smart3772a992009-05-22 14:50:54 -04005267 /* MBOX heartbeat timer */
5268 init_timer(&psli->mbox_tmo);
5269 psli->mbox_tmo.function = lpfc_mbox_timeout;
5270 psli->mbox_tmo.data = (unsigned long) phba;
James Smart3772a992009-05-22 14:50:54 -04005271 /* Fabric block timer */
5272 init_timer(&phba->fabric_block_timer);
5273 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
5274 phba->fabric_block_timer.data = (unsigned long) phba;
5275 /* EA polling mode timer */
5276 init_timer(&phba->eratt_poll);
5277 phba->eratt_poll.function = lpfc_poll_eratt;
5278 phba->eratt_poll.data = (unsigned long) phba;
James Smart895427b2017-02-12 13:52:30 -08005279 /* Heartbeat timer */
5280 init_timer(&phba->hb_tmofunc);
5281 phba->hb_tmofunc.function = lpfc_hb_timeout;
5282 phba->hb_tmofunc.data = (unsigned long)phba;
5283
5284 return 0;
5285}
5286
5287/**
5288 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
5289 * @phba: pointer to lpfc hba data structure.
5290 *
5291 * This routine is invoked to set up the driver internal resources specific to
5292 * support the SLI-3 HBA device it attached to.
5293 *
5294 * Return codes
5295 * 0 - successful
5296 * other values - error
5297 **/
5298static int
5299lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
5300{
5301 int rc;
5302
5303 /*
5304 * Initialize timers used by driver
5305 */
5306
5307 /* FCP polling mode timer */
5308 init_timer(&phba->fcp_poll_timer);
5309 phba->fcp_poll_timer.function = lpfc_poll_timeout;
5310 phba->fcp_poll_timer.data = (unsigned long) phba;
James Smart3772a992009-05-22 14:50:54 -04005311
5312 /* Host attention work mask setup */
5313 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
5314 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
5315
5316 /* Get all the module params for configuring this host */
5317 lpfc_get_cfgparam(phba);
James Smart895427b2017-02-12 13:52:30 -08005318 /* Set up phase-1 common device driver resources */
5319
5320 rc = lpfc_setup_driver_resource_phase1(phba);
5321 if (rc)
5322 return -ENODEV;
5323
James Smart49198b32010-04-06 15:04:33 -04005324 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
5325 phba->menlo_flag |= HBA_MENLO_SUPPORT;
5326 /* check for menlo minimum sg count */
5327 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
5328 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
5329 }
5330
James Smart895427b2017-02-12 13:52:30 -08005331 if (!phba->sli.sli3_ring)
5332 phba->sli.sli3_ring = kzalloc(LPFC_SLI3_MAX_RING *
James Smart2a76a282012-08-03 12:35:54 -04005333 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
James Smart895427b2017-02-12 13:52:30 -08005334 if (!phba->sli.sli3_ring)
James Smart2a76a282012-08-03 12:35:54 -04005335 return -ENOMEM;
5336
James Smart3772a992009-05-22 14:50:54 -04005337 /*
James Smart96f70772013-04-17 20:16:15 -04005338 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smart3772a992009-05-22 14:50:54 -04005339 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart3772a992009-05-22 14:50:54 -04005340 */
James Smart3772a992009-05-22 14:50:54 -04005341
James Smart96f70772013-04-17 20:16:15 -04005342 /* Initialize the host templates the configured values. */
James Smart3772a992009-05-22 14:50:54 -04005343 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
Bodo Stroesser5f406fa2015-08-31 16:48:10 -04005344 lpfc_template_s3.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart3772a992009-05-22 14:50:54 -04005345
James Smart96f70772013-04-17 20:16:15 -04005346 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
5347 if (phba->cfg_enable_bg) {
5348 /*
5349 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5350 * the FCP rsp, and a BDE for each. Sice we have no control
5351 * over how many protection data segments the SCSI Layer
5352 * will hand us (ie: there could be one for every block
5353 * in the IO), we just allocate enough BDEs to accomidate
5354 * our max amount and we need to limit lpfc_sg_seg_cnt to
5355 * minimize the risk of running out.
5356 */
5357 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5358 sizeof(struct fcp_rsp) +
5359 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
5360
5361 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
5362 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
5363
5364 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
5365 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
5366 } else {
5367 /*
5368 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5369 * the FCP rsp, a BDE for each, and a BDE for up to
5370 * cfg_sg_seg_cnt data segments.
5371 */
5372 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5373 sizeof(struct fcp_rsp) +
5374 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
5375
5376 /* Total BDEs in BPL for scsi_sg_list */
5377 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5378 }
5379
5380 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5381 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
5382 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5383 phba->cfg_total_seg_cnt);
5384
James Smart3772a992009-05-22 14:50:54 -04005385 phba->max_vpi = LPFC_MAX_VPI;
5386 /* This will be set to correct value after config_port mbox */
5387 phba->max_vports = 0;
5388
5389 /*
5390 * Initialize the SLI Layer to run with lpfc HBAs.
5391 */
5392 lpfc_sli_setup(phba);
James Smart895427b2017-02-12 13:52:30 -08005393 lpfc_sli_queue_init(phba);
James Smart3772a992009-05-22 14:50:54 -04005394
5395 /* Allocate device driver memory */
5396 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
5397 return -ENOMEM;
5398
James Smart912e3ac2011-05-24 11:42:11 -04005399 /*
5400 * Enable sr-iov virtual functions if supported and configured
5401 * through the module parameter.
5402 */
5403 if (phba->cfg_sriov_nr_virtfn > 0) {
5404 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5405 phba->cfg_sriov_nr_virtfn);
5406 if (rc) {
5407 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5408 "2808 Requested number of SR-IOV "
5409 "virtual functions (%d) is not "
5410 "supported\n",
5411 phba->cfg_sriov_nr_virtfn);
5412 phba->cfg_sriov_nr_virtfn = 0;
5413 }
5414 }
5415
James Smart3772a992009-05-22 14:50:54 -04005416 return 0;
5417}
5418
5419/**
5420 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
5421 * @phba: pointer to lpfc hba data structure.
5422 *
5423 * This routine is invoked to unset the driver internal resources set up
5424 * specific for supporting the SLI-3 HBA device it attached to.
5425 **/
5426static void
5427lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
5428{
5429 /* Free device driver memory allocated */
5430 lpfc_mem_free_all(phba);
5431
5432 return;
5433}
5434
5435/**
James Smartda0436e2009-05-22 14:51:39 -04005436 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
5437 * @phba: pointer to lpfc hba data structure.
5438 *
5439 * This routine is invoked to set up the driver internal resources specific to
5440 * support the SLI-4 HBA device it attached to.
5441 *
5442 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005443 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04005444 * other values - error
5445 **/
5446static int
5447lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5448{
James Smart28baac72010-02-12 14:42:03 -05005449 LPFC_MBOXQ_t *mboxq;
James Smart895427b2017-02-12 13:52:30 -08005450 int rc, i, max_buf_size;
James Smart28baac72010-02-12 14:42:03 -05005451 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
5452 struct lpfc_mqe *mqe;
James Smart09294d42013-04-17 20:16:05 -04005453 int longs;
James Smart1ba981f2014-02-20 09:56:45 -05005454 int fof_vectors = 0;
James Smartda0436e2009-05-22 14:51:39 -04005455
James Smart895427b2017-02-12 13:52:30 -08005456 phba->sli4_hba.num_online_cpu = num_online_cpus();
5457 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
5458 phba->sli4_hba.curr_disp_cpu = 0;
5459
James Smart716d3bc2013-09-06 12:18:28 -04005460 /* Get all the module params for configuring this host */
5461 lpfc_get_cfgparam(phba);
5462
James Smart895427b2017-02-12 13:52:30 -08005463 /* Set up phase-1 common device driver resources */
5464 rc = lpfc_setup_driver_resource_phase1(phba);
5465 if (rc)
5466 return -ENODEV;
5467
James Smartda0436e2009-05-22 14:51:39 -04005468 /* Before proceed, wait for POST done and device ready */
5469 rc = lpfc_sli4_post_status_check(phba);
5470 if (rc)
5471 return -ENODEV;
5472
5473 /*
5474 * Initialize timers used by driver
5475 */
5476
James Smart19ca7602010-11-20 23:11:55 -05005477 init_timer(&phba->rrq_tmr);
5478 phba->rrq_tmr.function = lpfc_rrq_timeout;
5479 phba->rrq_tmr.data = (unsigned long)phba;
James Smartda0436e2009-05-22 14:51:39 -04005480
James Smartecfd03c2010-02-12 14:41:27 -05005481 /* FCF rediscover timer */
5482 init_timer(&phba->fcf.redisc_wait);
5483 phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
5484 phba->fcf.redisc_wait.data = (unsigned long)phba;
5485
James Smartda0436e2009-05-22 14:51:39 -04005486 /*
James Smart7ad20aa2011-05-24 11:44:28 -04005487 * Control structure for handling external multi-buffer mailbox
5488 * command pass-through.
5489 */
5490 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
5491 sizeof(struct lpfc_mbox_ext_buf_ctx));
5492 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
5493
James Smartda0436e2009-05-22 14:51:39 -04005494 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04005495
James Smartda0436e2009-05-22 14:51:39 -04005496 /* This will be set to correct value after the read_config mbox */
5497 phba->max_vports = 0;
5498
5499 /* Program the default value of vlan_id and fc_map */
5500 phba->valid_vlan = 0;
5501 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5502 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5503 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5504
5505 /*
James Smart2a76a282012-08-03 12:35:54 -04005506 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
James Smart895427b2017-02-12 13:52:30 -08005507 * we will associate a new ring, for each EQ/CQ/WQ tuple.
5508 * The WQ create will allocate the ring.
James Smart2a76a282012-08-03 12:35:54 -04005509 */
James Smart085c6472010-11-20 23:11:37 -05005510
James Smart09294d42013-04-17 20:16:05 -04005511 /*
5512 * It doesn't matter what family our adapter is in, we are
5513 * limited to 2 Pages, 512 SGEs, for our SGL.
5514 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
5515 */
5516 max_buf_size = (2 * SLI4_PAGE_SIZE);
5517 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2)
5518 phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2;
James Smart09294d42013-04-17 20:16:05 -04005519
James Smartda0436e2009-05-22 14:51:39 -04005520 /*
James Smart895427b2017-02-12 13:52:30 -08005521 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
5522 * used to create the sg_dma_buf_pool must be calculated.
James Smart28baac72010-02-12 14:42:03 -05005523 */
James Smart96f70772013-04-17 20:16:15 -04005524 if (phba->cfg_enable_bg) {
5525 /*
James Smart895427b2017-02-12 13:52:30 -08005526 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
5527 * the FCP rsp, and a SGE. Sice we have no control
5528 * over how many protection segments the SCSI Layer
James Smart96f70772013-04-17 20:16:15 -04005529 * will hand us (ie: there could be one for every block
James Smart895427b2017-02-12 13:52:30 -08005530 * in the IO), just allocate enough SGEs to accomidate
5531 * our max amount and we need to limit lpfc_sg_seg_cnt
5532 * to minimize the risk of running out.
James Smart96f70772013-04-17 20:16:15 -04005533 */
5534 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08005535 sizeof(struct fcp_rsp) + max_buf_size;
James Smart96f70772013-04-17 20:16:15 -04005536
5537 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
5538 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
5539
5540 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
James Smart895427b2017-02-12 13:52:30 -08005541 phba->cfg_sg_seg_cnt =
5542 LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
James Smart96f70772013-04-17 20:16:15 -04005543 } else {
5544 /*
James Smart895427b2017-02-12 13:52:30 -08005545 * The scsi_buf for a regular I/O holds the FCP cmnd,
James Smart96f70772013-04-17 20:16:15 -04005546 * the FCP rsp, a SGE for each, and a SGE for up to
5547 * cfg_sg_seg_cnt data segments.
5548 */
5549 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08005550 sizeof(struct fcp_rsp) +
5551 ((phba->cfg_sg_seg_cnt + 2) *
5552 sizeof(struct sli4_sge));
James Smart96f70772013-04-17 20:16:15 -04005553
5554 /* Total SGEs for scsi_sg_list */
5555 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
James Smart895427b2017-02-12 13:52:30 -08005556
James Smart96f70772013-04-17 20:16:15 -04005557 /*
James Smart895427b2017-02-12 13:52:30 -08005558 * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only
5559 * need to post 1 page for the SGL.
James Smart96f70772013-04-17 20:16:15 -04005560 */
James Smart085c6472010-11-20 23:11:37 -05005561 }
James Smartacd68592012-01-18 16:25:09 -05005562
James Smart96f70772013-04-17 20:16:15 -04005563 /* Initialize the host templates with the updated values. */
5564 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5565 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5566
5567 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
5568 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
5569 else
5570 phba->cfg_sg_dma_buf_size =
5571 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
5572
5573 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5574 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
5575 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5576 phba->cfg_total_seg_cnt);
James Smartda0436e2009-05-22 14:51:39 -04005577
5578 /* Initialize buffer queue management fields */
James Smart895427b2017-02-12 13:52:30 -08005579 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
James Smartda0436e2009-05-22 14:51:39 -04005580 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
5581 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
5582
5583 /*
5584 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
5585 */
James Smart895427b2017-02-12 13:52:30 -08005586 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5587 /* Initialize the Abort scsi buffer list used by driver */
5588 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
5589 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
5590 }
5591
5592 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
5593 /* Initialize the Abort nvme buffer list used by driver */
5594 spin_lock_init(&phba->sli4_hba.abts_nvme_buf_list_lock);
5595 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
5596 }
5597
James Smartda0436e2009-05-22 14:51:39 -04005598 /* This abort list used by worker thread */
James Smart895427b2017-02-12 13:52:30 -08005599 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04005600
5601 /*
James Smart6d368e52011-05-24 11:44:12 -04005602 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04005603 */
5604
5605 /* Driver internel slow-path CQ Event pool */
5606 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
5607 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04005608 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04005609 /* Asynchronous event CQ Event work queue list */
5610 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
5611 /* Fast-path XRI aborted CQ Event work queue list */
5612 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
5613 /* Slow-path XRI aborted CQ Event work queue list */
5614 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
5615 /* Receive queue CQ Event work queue list */
5616 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
5617
James Smart6d368e52011-05-24 11:44:12 -04005618 /* Initialize extent block lists. */
5619 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
5620 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
5621 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
5622 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
5623
James Smart448193b2015-12-16 18:12:05 -05005624 /* initialize optic_state to 0xFF */
5625 phba->sli4_hba.lnk_info.optic_state = 0xff;
5626
James Smartda0436e2009-05-22 14:51:39 -04005627 /* Allocate device driver memory */
5628 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
5629 if (rc)
5630 return -ENOMEM;
5631
James Smart2fcee4b2010-12-15 17:57:46 -05005632 /* IF Type 2 ports get initialized now. */
5633 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5634 LPFC_SLI_INTF_IF_TYPE_2) {
5635 rc = lpfc_pci_function_reset(phba);
James Smart895427b2017-02-12 13:52:30 -08005636 if (unlikely(rc)) {
5637 rc = -ENODEV;
5638 goto out_free_mem;
5639 }
James Smart946727d2015-04-07 15:07:09 -04005640 phba->temp_sensor_support = 1;
James Smart2fcee4b2010-12-15 17:57:46 -05005641 }
5642
James Smartda0436e2009-05-22 14:51:39 -04005643 /* Create the bootstrap mailbox command */
5644 rc = lpfc_create_bootstrap_mbox(phba);
5645 if (unlikely(rc))
5646 goto out_free_mem;
5647
5648 /* Set up the host's endian order with the device. */
5649 rc = lpfc_setup_endian_order(phba);
5650 if (unlikely(rc))
5651 goto out_free_bsmbx;
5652
5653 /* Set up the hba's configuration parameters. */
5654 rc = lpfc_sli4_read_config(phba);
5655 if (unlikely(rc))
5656 goto out_free_bsmbx;
James Smartcff261f2013-12-17 20:29:47 -05005657 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
5658 if (unlikely(rc))
5659 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005660
James Smart2fcee4b2010-12-15 17:57:46 -05005661 /* IF Type 0 ports get initialized now. */
5662 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5663 LPFC_SLI_INTF_IF_TYPE_0) {
5664 rc = lpfc_pci_function_reset(phba);
5665 if (unlikely(rc))
5666 goto out_free_bsmbx;
5667 }
James Smartda0436e2009-05-22 14:51:39 -04005668
James Smartcb5172e2010-03-15 11:25:07 -04005669 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
5670 GFP_KERNEL);
5671 if (!mboxq) {
5672 rc = -ENOMEM;
5673 goto out_free_bsmbx;
5674 }
5675
James Smart895427b2017-02-12 13:52:30 -08005676 phba->nvmet_support = 0;
5677
5678 lpfc_nvme_mod_param_dep(phba);
5679
James Smartfedd3b72011-02-16 12:39:24 -05005680 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04005681 lpfc_supported_pages(mboxq);
5682 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05005683 if (!rc) {
5684 mqe = &mboxq->u.mqe;
5685 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
5686 LPFC_MAX_SUPPORTED_PAGES);
5687 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
5688 switch (pn_page[i]) {
5689 case LPFC_SLI4_PARAMETERS:
5690 phba->sli4_hba.pc_sli4_params.supported = 1;
5691 break;
5692 default:
5693 break;
5694 }
5695 }
5696 /* Read the port's SLI4 Parameters capabilities if supported. */
5697 if (phba->sli4_hba.pc_sli4_params.supported)
5698 rc = lpfc_pc_sli4_params_get(phba, mboxq);
5699 if (rc) {
5700 mempool_free(mboxq, phba->mbox_mem_pool);
5701 rc = -EIO;
5702 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04005703 }
5704 }
James Smart65791f12016-07-06 12:35:56 -07005705
James Smartfedd3b72011-02-16 12:39:24 -05005706 /*
5707 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04005708 * If this call fails, it isn't critical unless the SLI4 parameters come
5709 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05005710 */
James Smart6d368e52011-05-24 11:44:12 -04005711 rc = lpfc_get_sli4_parameters(phba, mboxq);
5712 if (rc) {
5713 if (phba->sli4_hba.extents_in_use &&
5714 phba->sli4_hba.rpi_hdrs_in_use) {
5715 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5716 "2999 Unsupported SLI4 Parameters "
5717 "Extents and RPI headers enabled.\n");
James Smart6d368e52011-05-24 11:44:12 -04005718 }
James Smart895427b2017-02-12 13:52:30 -08005719 mempool_free(mboxq, phba->mbox_mem_pool);
5720 goto out_free_bsmbx;
James Smart6d368e52011-05-24 11:44:12 -04005721 }
James Smart895427b2017-02-12 13:52:30 -08005722
James Smartcb5172e2010-03-15 11:25:07 -04005723 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -05005724
5725 /* Verify OAS is supported */
5726 lpfc_sli4_oas_verify(phba);
5727 if (phba->cfg_fof)
5728 fof_vectors = 1;
5729
James Smart5350d872011-10-10 21:33:49 -04005730 /* Verify all the SLI4 queues */
5731 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04005732 if (rc)
5733 goto out_free_bsmbx;
5734
5735 /* Create driver internal CQE event pool */
5736 rc = lpfc_sli4_cq_event_pool_create(phba);
5737 if (rc)
James Smart5350d872011-10-10 21:33:49 -04005738 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005739
James Smart8a9d2e82012-05-09 21:16:12 -04005740 /* Initialize sgl lists per host */
5741 lpfc_init_sgl_list(phba);
5742
5743 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04005744 rc = lpfc_init_active_sgl_array(phba);
5745 if (rc) {
5746 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5747 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04005748 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04005749 }
James Smartda0436e2009-05-22 14:51:39 -04005750 rc = lpfc_sli4_init_rpi_hdrs(phba);
5751 if (rc) {
5752 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5753 "1432 Failed to initialize rpi headers.\n");
5754 goto out_free_active_sgl;
5755 }
5756
James Smarta93ff372010-10-22 11:06:08 -04005757 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05005758 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
5759 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
5760 GFP_KERNEL);
5761 if (!phba->fcf.fcf_rr_bmask) {
5762 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5763 "2759 Failed allocate memory for FCF round "
5764 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04005765 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05005766 goto out_remove_rpi_hdrs;
5767 }
5768
James Smart895427b2017-02-12 13:52:30 -08005769 phba->sli4_hba.hba_eq_hdl = kcalloc(fof_vectors + phba->io_channel_irqs,
5770 sizeof(struct lpfc_hba_eq_hdl),
5771 GFP_KERNEL);
5772 if (!phba->sli4_hba.hba_eq_hdl) {
James Smart67d12732012-08-03 12:36:13 -04005773 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5774 "2572 Failed allocate memory for "
5775 "fast-path per-EQ handle array\n");
5776 rc = -ENOMEM;
5777 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04005778 }
5779
James Smart895427b2017-02-12 13:52:30 -08005780 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_present_cpu,
5781 sizeof(struct lpfc_vector_map_info),
5782 GFP_KERNEL);
James Smart7bb03bb2013-04-17 20:19:16 -04005783 if (!phba->sli4_hba.cpu_map) {
5784 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5785 "3327 Failed allocate memory for msi-x "
5786 "interrupt vector mapping\n");
5787 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08005788 goto out_free_hba_eq_hdl;
James Smart7bb03bb2013-04-17 20:19:16 -04005789 }
James Smartb246de12013-05-31 17:03:07 -04005790 if (lpfc_used_cpu == NULL) {
James Smart895427b2017-02-12 13:52:30 -08005791 lpfc_used_cpu = kcalloc(lpfc_present_cpu, sizeof(uint16_t),
5792 GFP_KERNEL);
James Smartb246de12013-05-31 17:03:07 -04005793 if (!lpfc_used_cpu) {
5794 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5795 "3335 Failed allocate memory for msi-x "
5796 "interrupt vector mapping\n");
5797 kfree(phba->sli4_hba.cpu_map);
5798 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08005799 goto out_free_hba_eq_hdl;
James Smartb246de12013-05-31 17:03:07 -04005800 }
5801 for (i = 0; i < lpfc_present_cpu; i++)
5802 lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
5803 }
5804
James Smart912e3ac2011-05-24 11:42:11 -04005805 /*
5806 * Enable sr-iov virtual functions if supported and configured
5807 * through the module parameter.
5808 */
5809 if (phba->cfg_sriov_nr_virtfn > 0) {
5810 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5811 phba->cfg_sriov_nr_virtfn);
5812 if (rc) {
5813 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5814 "3020 Requested number of SR-IOV "
5815 "virtual functions (%d) is not "
5816 "supported\n",
5817 phba->cfg_sriov_nr_virtfn);
5818 phba->cfg_sriov_nr_virtfn = 0;
5819 }
5820 }
5821
James Smart5248a742011-07-22 18:37:06 -04005822 return 0;
James Smartda0436e2009-05-22 14:51:39 -04005823
James Smart895427b2017-02-12 13:52:30 -08005824out_free_hba_eq_hdl:
5825 kfree(phba->sli4_hba.hba_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05005826out_free_fcf_rr_bmask:
5827 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04005828out_remove_rpi_hdrs:
5829 lpfc_sli4_remove_rpi_hdrs(phba);
5830out_free_active_sgl:
5831 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04005832out_destroy_cq_event_pool:
5833 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04005834out_free_bsmbx:
5835 lpfc_destroy_bootstrap_mbox(phba);
5836out_free_mem:
5837 lpfc_mem_free(phba);
5838 return rc;
5839}
5840
5841/**
5842 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
5843 * @phba: pointer to lpfc hba data structure.
5844 *
5845 * This routine is invoked to unset the driver internal resources set up
5846 * specific for supporting the SLI-4 HBA device it attached to.
5847 **/
5848static void
5849lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
5850{
5851 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
5852
James Smart7bb03bb2013-04-17 20:19:16 -04005853 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
5854 kfree(phba->sli4_hba.cpu_map);
5855 phba->sli4_hba.num_present_cpu = 0;
5856 phba->sli4_hba.num_online_cpu = 0;
James Smart76fd07a2014-02-20 09:57:18 -05005857 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04005858
James Smartda0436e2009-05-22 14:51:39 -04005859 /* Free memory allocated for fast-path work queue handles */
James Smart895427b2017-02-12 13:52:30 -08005860 kfree(phba->sli4_hba.hba_eq_hdl);
James Smartda0436e2009-05-22 14:51:39 -04005861
5862 /* Free the allocated rpi headers. */
5863 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04005864 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04005865
James Smart0c9ab6f2010-02-26 14:15:57 -05005866 /* Free eligible FCF index bmask */
5867 kfree(phba->fcf.fcf_rr_bmask);
5868
James Smartda0436e2009-05-22 14:51:39 -04005869 /* Free the ELS sgl list */
5870 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04005871 lpfc_free_els_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04005872
James Smartda0436e2009-05-22 14:51:39 -04005873 /* Free the completion queue EQ event pool */
5874 lpfc_sli4_cq_event_release_all(phba);
5875 lpfc_sli4_cq_event_pool_destroy(phba);
5876
James Smart6d368e52011-05-24 11:44:12 -04005877 /* Release resource identifiers. */
5878 lpfc_sli4_dealloc_resource_identifiers(phba);
5879
James Smartda0436e2009-05-22 14:51:39 -04005880 /* Free the bsmbx region. */
5881 lpfc_destroy_bootstrap_mbox(phba);
5882
5883 /* Free the SLI Layer memory with SLI4 HBAs */
5884 lpfc_mem_free_all(phba);
5885
5886 /* Free the current connect table */
5887 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04005888 &phba->fcf_conn_rec_list, list) {
5889 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04005890 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04005891 }
James Smartda0436e2009-05-22 14:51:39 -04005892
5893 return;
5894}
5895
5896/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005897 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04005898 * @phba: The hba struct for which this call is being executed.
5899 * @dev_grp: The HBA PCI-Device group number.
5900 *
5901 * This routine sets up the device INIT interface API function jump table
5902 * in @phba struct.
5903 *
5904 * Returns: 0 - success, -ENODEV - failure.
5905 **/
5906int
5907lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5908{
James Smart84d1b002010-02-12 14:42:33 -05005909 phba->lpfc_hba_init_link = lpfc_hba_init_link;
5910 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05005911 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04005912 switch (dev_grp) {
5913 case LPFC_PCI_DEV_LP:
5914 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
5915 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
5916 phba->lpfc_stop_port = lpfc_stop_port_s3;
5917 break;
James Smartda0436e2009-05-22 14:51:39 -04005918 case LPFC_PCI_DEV_OC:
5919 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
5920 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
5921 phba->lpfc_stop_port = lpfc_stop_port_s4;
5922 break;
James Smart3772a992009-05-22 14:50:54 -04005923 default:
5924 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5925 "1431 Invalid HBA PCI-device group: 0x%x\n",
5926 dev_grp);
5927 return -ENODEV;
5928 break;
5929 }
5930 return 0;
5931}
5932
5933/**
James Smart3772a992009-05-22 14:50:54 -04005934 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
5935 * @phba: pointer to lpfc hba data structure.
5936 *
5937 * This routine is invoked to set up the driver internal resources after the
5938 * device specific resource setup to support the HBA device it attached to.
5939 *
5940 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005941 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005942 * other values - error
5943 **/
5944static int
5945lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
5946{
5947 int error;
5948
5949 /* Startup the kernel thread for this host adapter. */
5950 phba->worker_thread = kthread_run(lpfc_do_work, phba,
5951 "lpfc_worker_%d", phba->brd_no);
5952 if (IS_ERR(phba->worker_thread)) {
5953 error = PTR_ERR(phba->worker_thread);
5954 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005955 }
5956
James Smart3772a992009-05-22 14:50:54 -04005957 return 0;
5958}
5959
5960/**
5961 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
5962 * @phba: pointer to lpfc hba data structure.
5963 *
5964 * This routine is invoked to unset the driver internal resources set up after
5965 * the device specific resource setup for supporting the HBA device it
5966 * attached to.
5967 **/
5968static void
5969lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
5970{
5971 /* Stop kernel worker thread */
5972 kthread_stop(phba->worker_thread);
5973}
5974
5975/**
5976 * lpfc_free_iocb_list - Free iocb list.
5977 * @phba: pointer to lpfc hba data structure.
5978 *
5979 * This routine is invoked to free the driver's IOCB list and memory.
5980 **/
5981static void
5982lpfc_free_iocb_list(struct lpfc_hba *phba)
5983{
5984 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
5985
5986 spin_lock_irq(&phba->hbalock);
5987 list_for_each_entry_safe(iocbq_entry, iocbq_next,
5988 &phba->lpfc_iocb_list, list) {
5989 list_del(&iocbq_entry->list);
5990 kfree(iocbq_entry);
5991 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005992 }
James Smart3772a992009-05-22 14:50:54 -04005993 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005994
James Smart3772a992009-05-22 14:50:54 -04005995 return;
5996}
dea31012005-04-17 16:05:31 -05005997
James Smart3772a992009-05-22 14:50:54 -04005998/**
5999 * lpfc_init_iocb_list - Allocate and initialize iocb list.
6000 * @phba: pointer to lpfc hba data structure.
6001 *
6002 * This routine is invoked to allocate and initizlize the driver's IOCB
6003 * list and set up the IOCB tag array accordingly.
6004 *
6005 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006006 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006007 * other values - error
6008 **/
6009static int
6010lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
6011{
6012 struct lpfc_iocbq *iocbq_entry = NULL;
6013 uint16_t iotag;
6014 int i;
dea31012005-04-17 16:05:31 -05006015
6016 /* Initialize and populate the iocb list per host. */
6017 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04006018 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07006019 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05006020 if (iocbq_entry == NULL) {
6021 printk(KERN_ERR "%s: only allocated %d iocbs of "
6022 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07006023 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05006024 goto out_free_iocbq;
6025 }
6026
James Bottomley604a3e32005-10-29 10:28:33 -05006027 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
6028 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04006029 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05006030 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04006031 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05006032 goto out_free_iocbq;
6033 }
James Smart6d368e52011-05-24 11:44:12 -04006034 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04006035 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05006036
6037 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006038 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
6039 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05006040 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006041 }
6042
James Smart3772a992009-05-22 14:50:54 -04006043 return 0;
6044
6045out_free_iocbq:
6046 lpfc_free_iocb_list(phba);
6047
6048 return -ENOMEM;
6049}
6050
6051/**
James Smart8a9d2e82012-05-09 21:16:12 -04006052 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04006053 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04006054 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04006055 *
James Smart8a9d2e82012-05-09 21:16:12 -04006056 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04006057 **/
James Smart8a9d2e82012-05-09 21:16:12 -04006058void
6059lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04006060{
6061 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04006062
6063 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
6064 list_del(&sglq_entry->list);
6065 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
6066 kfree(sglq_entry);
6067 }
6068}
6069
6070/**
6071 * lpfc_free_els_sgl_list - Free els sgl list.
6072 * @phba: pointer to lpfc hba data structure.
6073 *
6074 * This routine is invoked to free the driver's els sgl list and memory.
6075 **/
6076static void
6077lpfc_free_els_sgl_list(struct lpfc_hba *phba)
6078{
James Smartda0436e2009-05-22 14:51:39 -04006079 LIST_HEAD(sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04006080
James Smart8a9d2e82012-05-09 21:16:12 -04006081 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04006082 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08006083 spin_lock(&phba->sli4_hba.sgl_list_lock);
6084 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
6085 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04006086 spin_unlock_irq(&phba->hbalock);
6087
James Smart8a9d2e82012-05-09 21:16:12 -04006088 /* Now free the sgl list */
6089 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04006090}
6091
6092/**
6093 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
6094 * @phba: pointer to lpfc hba data structure.
6095 *
6096 * This routine is invoked to allocate the driver's active sgl memory.
6097 * This array will hold the sglq_entry's for active IOs.
6098 **/
6099static int
6100lpfc_init_active_sgl_array(struct lpfc_hba *phba)
6101{
6102 int size;
6103 size = sizeof(struct lpfc_sglq *);
6104 size *= phba->sli4_hba.max_cfg_param.max_xri;
6105
6106 phba->sli4_hba.lpfc_sglq_active_list =
6107 kzalloc(size, GFP_KERNEL);
6108 if (!phba->sli4_hba.lpfc_sglq_active_list)
6109 return -ENOMEM;
6110 return 0;
6111}
6112
6113/**
6114 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
6115 * @phba: pointer to lpfc hba data structure.
6116 *
6117 * This routine is invoked to walk through the array of active sglq entries
6118 * and free all of the resources.
6119 * This is just a place holder for now.
6120 **/
6121static void
6122lpfc_free_active_sgl(struct lpfc_hba *phba)
6123{
6124 kfree(phba->sli4_hba.lpfc_sglq_active_list);
6125}
6126
6127/**
6128 * lpfc_init_sgl_list - Allocate and initialize sgl list.
6129 * @phba: pointer to lpfc hba data structure.
6130 *
6131 * This routine is invoked to allocate and initizlize the driver's sgl
6132 * list and set up the sgl xritag tag array accordingly.
6133 *
James Smartda0436e2009-05-22 14:51:39 -04006134 **/
James Smart8a9d2e82012-05-09 21:16:12 -04006135static void
James Smartda0436e2009-05-22 14:51:39 -04006136lpfc_init_sgl_list(struct lpfc_hba *phba)
6137{
James Smartda0436e2009-05-22 14:51:39 -04006138 /* Initialize and populate the sglq list per host/VF. */
James Smart895427b2017-02-12 13:52:30 -08006139 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
James Smartda0436e2009-05-22 14:51:39 -04006140 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
6141
James Smart8a9d2e82012-05-09 21:16:12 -04006142 /* els xri-sgl book keeping */
6143 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04006144
James Smart8a9d2e82012-05-09 21:16:12 -04006145 /* scsi xri-buffer book keeping */
James Smartda0436e2009-05-22 14:51:39 -04006146 phba->sli4_hba.scsi_xri_cnt = 0;
James Smart895427b2017-02-12 13:52:30 -08006147
6148 /* nvme xri-buffer book keeping */
6149 phba->sli4_hba.nvme_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04006150}
6151
6152/**
6153 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
6154 * @phba: pointer to lpfc hba data structure.
6155 *
6156 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04006157 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04006158 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04006159 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
6160 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04006161 *
6162 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006163 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04006164 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04006165 **/
6166int
6167lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
6168{
6169 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04006170 struct lpfc_rpi_hdr *rpi_hdr;
6171
6172 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05006173 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04006174 return rc;
James Smart6d368e52011-05-24 11:44:12 -04006175 if (phba->sli4_hba.extents_in_use)
6176 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04006177
6178 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
6179 if (!rpi_hdr) {
6180 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6181 "0391 Error during rpi post operation\n");
6182 lpfc_sli4_remove_rpis(phba);
6183 rc = -ENODEV;
6184 }
6185
6186 return rc;
6187}
6188
6189/**
6190 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
6191 * @phba: pointer to lpfc hba data structure.
6192 *
6193 * This routine is invoked to allocate a single 4KB memory region to
6194 * support rpis and stores them in the phba. This single region
6195 * provides support for up to 64 rpis. The region is used globally
6196 * by the device.
6197 *
6198 * Returns:
6199 * A valid rpi hdr on success.
6200 * A NULL pointer on any failure.
6201 **/
6202struct lpfc_rpi_hdr *
6203lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
6204{
6205 uint16_t rpi_limit, curr_rpi_range;
6206 struct lpfc_dmabuf *dmabuf;
6207 struct lpfc_rpi_hdr *rpi_hdr;
James Smart9589b0622011-04-16 11:03:17 -04006208 uint32_t rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04006209
James Smart6d368e52011-05-24 11:44:12 -04006210 /*
6211 * If the SLI4 port supports extents, posting the rpi header isn't
6212 * required. Set the expected maximum count and let the actual value
6213 * get set when extents are fully allocated.
6214 */
6215 if (!phba->sli4_hba.rpi_hdrs_in_use)
6216 return NULL;
6217 if (phba->sli4_hba.extents_in_use)
6218 return NULL;
6219
6220 /* The limit on the logical index is just the max_rpi count. */
James Smartda0436e2009-05-22 14:51:39 -04006221 rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
James Smart6d368e52011-05-24 11:44:12 -04006222 phba->sli4_hba.max_cfg_param.max_rpi - 1;
James Smartda0436e2009-05-22 14:51:39 -04006223
6224 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006225 /*
6226 * Establish the starting RPI in this header block. The starting
6227 * rpi is normalized to a zero base because the physical rpi is
6228 * port based.
6229 */
James Smart97f2ecf2012-03-01 22:35:23 -05006230 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04006231 spin_unlock_irq(&phba->hbalock);
6232
6233 /*
6234 * The port has a limited number of rpis. The increment here
6235 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
6236 * and to allow the full max_rpi range per port.
6237 */
6238 if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
James Smart9589b0622011-04-16 11:03:17 -04006239 rpi_count = rpi_limit - curr_rpi_range;
6240 else
6241 rpi_count = LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04006242
James Smart6d368e52011-05-24 11:44:12 -04006243 if (!rpi_count)
6244 return NULL;
James Smartda0436e2009-05-22 14:51:39 -04006245 /*
6246 * First allocate the protocol header region for the port. The
6247 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
6248 */
6249 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6250 if (!dmabuf)
6251 return NULL;
6252
Joe Perches1aee3832014-09-03 12:56:12 -04006253 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
6254 LPFC_HDR_TEMPLATE_SIZE,
6255 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04006256 if (!dmabuf->virt) {
6257 rpi_hdr = NULL;
6258 goto err_free_dmabuf;
6259 }
6260
James Smartda0436e2009-05-22 14:51:39 -04006261 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
6262 rpi_hdr = NULL;
6263 goto err_free_coherent;
6264 }
6265
6266 /* Save the rpi header data for cleanup later. */
6267 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
6268 if (!rpi_hdr)
6269 goto err_free_coherent;
6270
6271 rpi_hdr->dmabuf = dmabuf;
6272 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
6273 rpi_hdr->page_count = 1;
6274 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006275
6276 /* The rpi_hdr stores the logical index only. */
6277 rpi_hdr->start_rpi = curr_rpi_range;
James Smartda0436e2009-05-22 14:51:39 -04006278 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
6279
6280 /*
James Smart6d368e52011-05-24 11:44:12 -04006281 * The next_rpi stores the next logical module-64 rpi value used
6282 * to post physical rpis in subsequent rpi postings.
James Smartda0436e2009-05-22 14:51:39 -04006283 */
James Smart9589b0622011-04-16 11:03:17 -04006284 phba->sli4_hba.next_rpi += rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04006285 spin_unlock_irq(&phba->hbalock);
6286 return rpi_hdr;
6287
6288 err_free_coherent:
6289 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
6290 dmabuf->virt, dmabuf->phys);
6291 err_free_dmabuf:
6292 kfree(dmabuf);
6293 return NULL;
6294}
6295
6296/**
6297 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
6298 * @phba: pointer to lpfc hba data structure.
6299 *
6300 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04006301 * to support rpis for SLI4 ports not supporting extents. This routine
6302 * presumes the caller has released all rpis consumed by fabric or port
6303 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04006304 **/
6305void
6306lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
6307{
6308 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
6309
James Smart6d368e52011-05-24 11:44:12 -04006310 if (!phba->sli4_hba.rpi_hdrs_in_use)
6311 goto exit;
6312
James Smartda0436e2009-05-22 14:51:39 -04006313 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
6314 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
6315 list_del(&rpi_hdr->list);
6316 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
6317 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
6318 kfree(rpi_hdr->dmabuf);
6319 kfree(rpi_hdr);
6320 }
James Smart6d368e52011-05-24 11:44:12 -04006321 exit:
6322 /* There are no rpis available to the port now. */
6323 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04006324}
6325
6326/**
James Smart3772a992009-05-22 14:50:54 -04006327 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
6328 * @pdev: pointer to pci device data structure.
6329 *
6330 * This routine is invoked to allocate the driver hba data structure for an
6331 * HBA device. If the allocation is successful, the phba reference to the
6332 * PCI device data structure is set.
6333 *
6334 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006335 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04006336 * NULL - error
6337 **/
6338static struct lpfc_hba *
6339lpfc_hba_alloc(struct pci_dev *pdev)
6340{
6341 struct lpfc_hba *phba;
6342
6343 /* Allocate memory for HBA structure */
6344 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
6345 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02006346 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04006347 return NULL;
6348 }
6349
6350 /* Set reference to PCI device in HBA structure */
6351 phba->pcidev = pdev;
6352
6353 /* Assign an unused board number */
6354 phba->brd_no = lpfc_get_instance();
6355 if (phba->brd_no < 0) {
6356 kfree(phba);
6357 return NULL;
6358 }
James Smart65791f12016-07-06 12:35:56 -07006359 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
James Smart3772a992009-05-22 14:50:54 -04006360
James Smart4fede782010-01-26 23:08:55 -05006361 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04006362 INIT_LIST_HEAD(&phba->ct_ev_waiters);
6363
James Smart3772a992009-05-22 14:50:54 -04006364 return phba;
6365}
6366
6367/**
6368 * lpfc_hba_free - Free driver hba data structure with a device.
6369 * @phba: pointer to lpfc hba data structure.
6370 *
6371 * This routine is invoked to free the driver hba data structure with an
6372 * HBA device.
6373 **/
6374static void
6375lpfc_hba_free(struct lpfc_hba *phba)
6376{
6377 /* Release the driver assigned board number */
6378 idr_remove(&lpfc_hba_index, phba->brd_no);
6379
James Smart895427b2017-02-12 13:52:30 -08006380 /* Free memory allocated with sli3 rings */
6381 kfree(phba->sli.sli3_ring);
6382 phba->sli.sli3_ring = NULL;
James Smart2a76a282012-08-03 12:35:54 -04006383
James Smart3772a992009-05-22 14:50:54 -04006384 kfree(phba);
6385 return;
6386}
6387
6388/**
6389 * lpfc_create_shost - Create hba physical port with associated scsi host.
6390 * @phba: pointer to lpfc hba data structure.
6391 *
6392 * This routine is invoked to create HBA physical port and associate a SCSI
6393 * host with it.
6394 *
6395 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006396 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006397 * other values - error
6398 **/
6399static int
6400lpfc_create_shost(struct lpfc_hba *phba)
6401{
6402 struct lpfc_vport *vport;
6403 struct Scsi_Host *shost;
6404
6405 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05006406 phba->fc_edtov = FF_DEF_EDTOV;
6407 phba->fc_ratov = FF_DEF_RATOV;
6408 phba->fc_altov = FF_DEF_ALTOV;
6409 phba->fc_arbtov = FF_DEF_ARBTOV;
6410
James Smartd7c47992010-06-08 18:31:54 -04006411 atomic_set(&phba->sdev_cnt, 0);
James Smart3de2a652007-08-02 11:09:59 -04006412 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05006413 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04006414 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05006415
6416 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05006417 phba->pport = vport;
James Smart2ea259e2017-02-12 13:52:27 -08006418
James Smart858c9f62007-06-17 19:56:39 -05006419 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04006420 /* Put reference to SCSI host to driver's device private data */
6421 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05006422
James Smart4258e982015-12-16 18:11:58 -05006423 /*
6424 * At this point we are fully registered with PSA. In addition,
6425 * any initial discovery should be completed.
6426 */
6427 vport->load_flag |= FC_ALLOW_FDMI;
James Smart8663cbb2016-03-31 14:12:33 -07006428 if (phba->cfg_enable_SmartSAN ||
6429 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -05006430
6431 /* Setup appropriate attribute masks */
6432 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -07006433 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -05006434 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
6435 else
6436 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
6437 }
James Smart3772a992009-05-22 14:50:54 -04006438 return 0;
6439}
dea31012005-04-17 16:05:31 -05006440
James Smart3772a992009-05-22 14:50:54 -04006441/**
6442 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
6443 * @phba: pointer to lpfc hba data structure.
6444 *
6445 * This routine is invoked to destroy HBA physical port and the associated
6446 * SCSI host.
6447 **/
6448static void
6449lpfc_destroy_shost(struct lpfc_hba *phba)
6450{
6451 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04006452
James Smart3772a992009-05-22 14:50:54 -04006453 /* Destroy physical port that associated with the SCSI host */
6454 destroy_port(vport);
6455
6456 return;
6457}
6458
6459/**
6460 * lpfc_setup_bg - Setup Block guard structures and debug areas.
6461 * @phba: pointer to lpfc hba data structure.
6462 * @shost: the shost to be used to detect Block guard settings.
6463 *
6464 * This routine sets up the local Block guard protocol settings for @shost.
6465 * This routine also allocates memory for debugging bg buffers.
6466 **/
6467static void
6468lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
6469{
James Smartbbeb79b2012-06-12 13:54:27 -04006470 uint32_t old_mask;
6471 uint32_t old_guard;
6472
James Smart3772a992009-05-22 14:50:54 -04006473 int pagecnt = 10;
James Smartb3b98b72016-10-13 15:06:06 -07006474 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
James Smart3772a992009-05-22 14:50:54 -04006475 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6476 "1478 Registering BlockGuard with the "
6477 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04006478
James Smartb3b98b72016-10-13 15:06:06 -07006479 old_mask = phba->cfg_prot_mask;
6480 old_guard = phba->cfg_prot_guard;
James Smartbbeb79b2012-06-12 13:54:27 -04006481
6482 /* Only allow supported values */
James Smartb3b98b72016-10-13 15:06:06 -07006483 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
James Smartbbeb79b2012-06-12 13:54:27 -04006484 SHOST_DIX_TYPE0_PROTECTION |
6485 SHOST_DIX_TYPE1_PROTECTION);
James Smartb3b98b72016-10-13 15:06:06 -07006486 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
6487 SHOST_DIX_GUARD_CRC);
James Smartbbeb79b2012-06-12 13:54:27 -04006488
6489 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
James Smartb3b98b72016-10-13 15:06:06 -07006490 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
6491 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
James Smartbbeb79b2012-06-12 13:54:27 -04006492
James Smartb3b98b72016-10-13 15:06:06 -07006493 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
6494 if ((old_mask != phba->cfg_prot_mask) ||
6495 (old_guard != phba->cfg_prot_guard))
James Smartbbeb79b2012-06-12 13:54:27 -04006496 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6497 "1475 Registering BlockGuard with the "
6498 "SCSI layer: mask %d guard %d\n",
James Smartb3b98b72016-10-13 15:06:06 -07006499 phba->cfg_prot_mask,
6500 phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04006501
James Smartb3b98b72016-10-13 15:06:06 -07006502 scsi_host_set_prot(shost, phba->cfg_prot_mask);
6503 scsi_host_set_guard(shost, phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04006504 } else
6505 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6506 "1479 Not Registering BlockGuard with the SCSI "
6507 "layer, Bad protection parameters: %d %d\n",
6508 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04006509 }
James Smartbbeb79b2012-06-12 13:54:27 -04006510
James Smart81301a92008-12-04 22:39:46 -05006511 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05006512 while (pagecnt) {
6513 spin_lock_init(&_dump_buf_lock);
6514 _dump_buf_data =
6515 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6516 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04006517 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6518 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04006519 "_dump_buf_data at 0x%p\n",
6520 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05006521 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04006522 memset(_dump_buf_data, 0,
6523 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05006524 break;
James Smart3772a992009-05-22 14:50:54 -04006525 } else
James Smart81301a92008-12-04 22:39:46 -05006526 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05006527 }
James Smart81301a92008-12-04 22:39:46 -05006528 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04006529 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6530 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04006531 "memory for hexdump\n");
6532 } else
James Smart6a9c52c2009-10-02 15:16:51 -04006533 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6534 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05006535 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05006536 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05006537 while (pagecnt) {
6538 _dump_buf_dif =
6539 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6540 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04006541 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6542 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04006543 "_dump_buf_dif at 0x%p\n",
6544 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05006545 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04006546 memset(_dump_buf_dif, 0,
6547 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05006548 break;
James Smart3772a992009-05-22 14:50:54 -04006549 } else
James Smart81301a92008-12-04 22:39:46 -05006550 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05006551 }
James Smart81301a92008-12-04 22:39:46 -05006552 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04006553 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6554 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04006555 "memory for hexdump\n");
6556 } else
James Smart6a9c52c2009-10-02 15:16:51 -04006557 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6558 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04006559 _dump_buf_dif);
6560}
6561
6562/**
6563 * lpfc_post_init_setup - Perform necessary device post initialization setup.
6564 * @phba: pointer to lpfc hba data structure.
6565 *
6566 * This routine is invoked to perform all the necessary post initialization
6567 * setup for the device.
6568 **/
6569static void
6570lpfc_post_init_setup(struct lpfc_hba *phba)
6571{
6572 struct Scsi_Host *shost;
6573 struct lpfc_adapter_event_header adapter_event;
6574
6575 /* Get the default values for Model Name and Description */
6576 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
6577
6578 /*
6579 * hba setup may have changed the hba_queue_depth so we need to
6580 * adjust the value of can_queue.
6581 */
6582 shost = pci_get_drvdata(phba->pcidev);
6583 shost->can_queue = phba->cfg_hba_queue_depth - 10;
6584 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
6585 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05006586
6587 lpfc_host_attrib_init(shost);
6588
James Smart2e0fef82007-06-17 19:56:36 -05006589 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
6590 spin_lock_irq(shost->host_lock);
6591 lpfc_poll_start_timer(phba);
6592 spin_unlock_irq(shost->host_lock);
6593 }
James Smart8f6d98d2006-08-01 07:34:00 -04006594
James Smart93996272008-08-24 21:50:30 -04006595 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6596 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04006597 /* Send board arrival event to upper layer */
6598 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
6599 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
6600 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04006601 sizeof(adapter_event),
6602 (char *) &adapter_event,
6603 LPFC_NL_VENDOR_ID);
6604 return;
6605}
6606
6607/**
6608 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
6609 * @phba: pointer to lpfc hba data structure.
6610 *
6611 * This routine is invoked to set up the PCI device memory space for device
6612 * with SLI-3 interface spec.
6613 *
6614 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006615 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006616 * other values - error
6617 **/
6618static int
6619lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
6620{
6621 struct pci_dev *pdev;
6622 unsigned long bar0map_len, bar2map_len;
6623 int i, hbq_count;
6624 void *ptr;
6625 int error = -ENODEV;
6626
6627 /* Obtain PCI device reference */
6628 if (!phba->pcidev)
6629 return error;
6630 else
6631 pdev = phba->pcidev;
6632
6633 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05006634 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
6635 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
6636 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
6637 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smart3772a992009-05-22 14:50:54 -04006638 return error;
Michael Reed8e685972009-09-18 12:02:05 -05006639 }
6640 }
James Smart3772a992009-05-22 14:50:54 -04006641
6642 /* Get the bus address of Bar0 and Bar2 and the number of bytes
6643 * required by each mapping.
6644 */
6645 phba->pci_bar0_map = pci_resource_start(pdev, 0);
6646 bar0map_len = pci_resource_len(pdev, 0);
6647
6648 phba->pci_bar2_map = pci_resource_start(pdev, 2);
6649 bar2map_len = pci_resource_len(pdev, 2);
6650
6651 /* Map HBA SLIM to a kernel virtual address. */
6652 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
6653 if (!phba->slim_memmap_p) {
6654 dev_printk(KERN_ERR, &pdev->dev,
6655 "ioremap failed for SLIM memory.\n");
6656 goto out;
6657 }
6658
6659 /* Map HBA Control Registers to a kernel virtual address. */
6660 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
6661 if (!phba->ctrl_regs_memmap_p) {
6662 dev_printk(KERN_ERR, &pdev->dev,
6663 "ioremap failed for HBA control registers.\n");
6664 goto out_iounmap_slim;
6665 }
6666
6667 /* Allocate memory for SLI-2 structures */
Joe Perches1aee3832014-09-03 12:56:12 -04006668 phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6669 &phba->slim2p.phys, GFP_KERNEL);
James Smart3772a992009-05-22 14:50:54 -04006670 if (!phba->slim2p.virt)
6671 goto out_iounmap;
6672
James Smart3772a992009-05-22 14:50:54 -04006673 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04006674 phba->mbox_ext = (phba->slim2p.virt +
6675 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04006676 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
6677 phba->IOCBs = (phba->slim2p.virt +
6678 offsetof(struct lpfc_sli2_slim, IOCBs));
6679
6680 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
6681 lpfc_sli_hbq_size(),
6682 &phba->hbqslimp.phys,
6683 GFP_KERNEL);
6684 if (!phba->hbqslimp.virt)
6685 goto out_free_slim;
6686
6687 hbq_count = lpfc_sli_hbq_count();
6688 ptr = phba->hbqslimp.virt;
6689 for (i = 0; i < hbq_count; ++i) {
6690 phba->hbqs[i].hbq_virt = ptr;
6691 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
6692 ptr += (lpfc_hbq_defs[i]->entry_count *
6693 sizeof(struct lpfc_hbq_entry));
6694 }
6695 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
6696 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
6697
6698 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
6699
James Smart3772a992009-05-22 14:50:54 -04006700 phba->MBslimaddr = phba->slim_memmap_p;
6701 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
6702 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
6703 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
6704 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04006705
dea31012005-04-17 16:05:31 -05006706 return 0;
6707
dea31012005-04-17 16:05:31 -05006708out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04006709 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6710 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05006711out_iounmap:
6712 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006713out_iounmap_slim:
dea31012005-04-17 16:05:31 -05006714 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05006715out:
6716 return error;
6717}
6718
James Smarte59058c2008-08-24 21:49:00 -04006719/**
James Smart3772a992009-05-22 14:50:54 -04006720 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
6721 * @phba: pointer to lpfc hba data structure.
6722 *
6723 * This routine is invoked to unset the PCI device memory space for device
6724 * with SLI-3 interface spec.
6725 **/
6726static void
6727lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
6728{
6729 struct pci_dev *pdev;
6730
6731 /* Obtain PCI device reference */
6732 if (!phba->pcidev)
6733 return;
6734 else
6735 pdev = phba->pcidev;
6736
6737 /* Free coherent DMA memory allocated */
6738 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
6739 phba->hbqslimp.virt, phba->hbqslimp.phys);
6740 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6741 phba->slim2p.virt, phba->slim2p.phys);
6742
6743 /* I/O memory unmap */
6744 iounmap(phba->ctrl_regs_memmap_p);
6745 iounmap(phba->slim_memmap_p);
6746
6747 return;
6748}
6749
6750/**
James Smartda0436e2009-05-22 14:51:39 -04006751 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
6752 * @phba: pointer to lpfc hba data structure.
6753 *
6754 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
6755 * done and check status.
6756 *
6757 * Return 0 if successful, otherwise -ENODEV.
6758 **/
6759int
6760lpfc_sli4_post_status_check(struct lpfc_hba *phba)
6761{
James Smart2fcee4b2010-12-15 17:57:46 -05006762 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
6763 struct lpfc_register reg_data;
6764 int i, port_error = 0;
6765 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04006766
James Smart9940b972011-03-11 16:06:12 -05006767 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
6768 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05006769 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04006770 return -ENODEV;
6771
James Smartda0436e2009-05-22 14:51:39 -04006772 /* Wait up to 30 seconds for the SLI Port POST done and ready */
6773 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05006774 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
6775 &portsmphr_reg.word0) ||
6776 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006777 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04006778 port_error = -ENODEV;
6779 break;
6780 }
James Smart2fcee4b2010-12-15 17:57:46 -05006781 if (LPFC_POST_STAGE_PORT_READY ==
6782 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04006783 break;
James Smartda0436e2009-05-22 14:51:39 -04006784 msleep(10);
6785 }
6786
James Smart2fcee4b2010-12-15 17:57:46 -05006787 /*
6788 * If there was a port error during POST, then don't proceed with
6789 * other register reads as the data may not be valid. Just exit.
6790 */
6791 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04006792 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006793 "1408 Port Failed POST - portsmphr=0x%x, "
6794 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
6795 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
6796 portsmphr_reg.word0,
6797 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
6798 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
6799 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
6800 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
6801 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
6802 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
6803 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
6804 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
6805 } else {
James Smart28baac72010-02-12 14:42:03 -05006806 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006807 "2534 Device Info: SLIFamily=0x%x, "
6808 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
6809 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05006810 bf_get(lpfc_sli_intf_sli_family,
6811 &phba->sli4_hba.sli_intf),
6812 bf_get(lpfc_sli_intf_slirev,
6813 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006814 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05006815 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006816 bf_get(lpfc_sli_intf_sli_hint1,
6817 &phba->sli4_hba.sli_intf),
6818 bf_get(lpfc_sli_intf_sli_hint2,
6819 &phba->sli4_hba.sli_intf),
6820 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05006821 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05006822 /*
6823 * Check for other Port errors during the initialization
6824 * process. Fail the load if the port did not come up
6825 * correctly.
6826 */
6827 if_type = bf_get(lpfc_sli_intf_if_type,
6828 &phba->sli4_hba.sli_intf);
6829 switch (if_type) {
6830 case LPFC_SLI_INTF_IF_TYPE_0:
6831 phba->sli4_hba.ue_mask_lo =
6832 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
6833 phba->sli4_hba.ue_mask_hi =
6834 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
6835 uerrlo_reg.word0 =
6836 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
6837 uerrhi_reg.word0 =
6838 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
6839 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
6840 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
6841 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6842 "1422 Unrecoverable Error "
6843 "Detected during POST "
6844 "uerr_lo_reg=0x%x, "
6845 "uerr_hi_reg=0x%x, "
6846 "ue_mask_lo_reg=0x%x, "
6847 "ue_mask_hi_reg=0x%x\n",
6848 uerrlo_reg.word0,
6849 uerrhi_reg.word0,
6850 phba->sli4_hba.ue_mask_lo,
6851 phba->sli4_hba.ue_mask_hi);
6852 port_error = -ENODEV;
6853 }
6854 break;
6855 case LPFC_SLI_INTF_IF_TYPE_2:
6856 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05006857 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
6858 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04006859 (bf_get(lpfc_sliport_status_err, &reg_data) &&
6860 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006861 phba->work_status[0] =
6862 readl(phba->sli4_hba.u.if_type2.
6863 ERR1regaddr);
6864 phba->work_status[1] =
6865 readl(phba->sli4_hba.u.if_type2.
6866 ERR2regaddr);
6867 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05006868 "2888 Unrecoverable port error "
6869 "following POST: port status reg "
6870 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05006871 "error 1=0x%x, error 2=0x%x\n",
6872 reg_data.word0,
6873 portsmphr_reg.word0,
6874 phba->work_status[0],
6875 phba->work_status[1]);
6876 port_error = -ENODEV;
6877 }
6878 break;
6879 case LPFC_SLI_INTF_IF_TYPE_1:
6880 default:
6881 break;
6882 }
James Smart28baac72010-02-12 14:42:03 -05006883 }
James Smartda0436e2009-05-22 14:51:39 -04006884 return port_error;
6885}
6886
6887/**
6888 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
6889 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05006890 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04006891 *
6892 * This routine is invoked to set up SLI4 BAR0 PCI config space register
6893 * memory map.
6894 **/
6895static void
James Smart2fcee4b2010-12-15 17:57:46 -05006896lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04006897{
James Smart2fcee4b2010-12-15 17:57:46 -05006898 switch (if_type) {
6899 case LPFC_SLI_INTF_IF_TYPE_0:
6900 phba->sli4_hba.u.if_type0.UERRLOregaddr =
6901 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
6902 phba->sli4_hba.u.if_type0.UERRHIregaddr =
6903 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
6904 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
6905 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
6906 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
6907 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
6908 phba->sli4_hba.SLIINTFregaddr =
6909 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6910 break;
6911 case LPFC_SLI_INTF_IF_TYPE_2:
6912 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006913 phba->sli4_hba.conf_regs_memmap_p +
6914 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006915 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006916 phba->sli4_hba.conf_regs_memmap_p +
6917 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006918 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006919 phba->sli4_hba.conf_regs_memmap_p +
6920 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006921 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006922 phba->sli4_hba.conf_regs_memmap_p +
6923 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006924 phba->sli4_hba.SLIINTFregaddr =
6925 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6926 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006927 phba->sli4_hba.conf_regs_memmap_p +
6928 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006929 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006930 phba->sli4_hba.conf_regs_memmap_p +
6931 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006932 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006933 phba->sli4_hba.conf_regs_memmap_p +
6934 LPFC_ULP0_WQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006935 phba->sli4_hba.EQCQDBregaddr =
6936 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
6937 phba->sli4_hba.MQDBregaddr =
6938 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
6939 phba->sli4_hba.BMBXregaddr =
6940 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
6941 break;
6942 case LPFC_SLI_INTF_IF_TYPE_1:
6943 default:
6944 dev_printk(KERN_ERR, &phba->pcidev->dev,
6945 "FATAL - unsupported SLI4 interface type - %d\n",
6946 if_type);
6947 break;
6948 }
James Smartda0436e2009-05-22 14:51:39 -04006949}
6950
6951/**
6952 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
6953 * @phba: pointer to lpfc hba data structure.
6954 *
6955 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
6956 * memory map.
6957 **/
6958static void
6959lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
6960{
James Smart2fcee4b2010-12-15 17:57:46 -05006961 phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
6962 LPFC_SLIPORT_IF0_SMPHR;
James Smartda0436e2009-05-22 14:51:39 -04006963 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006964 LPFC_HST_ISR0;
James Smartda0436e2009-05-22 14:51:39 -04006965 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006966 LPFC_HST_IMR0;
James Smartda0436e2009-05-22 14:51:39 -04006967 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006968 LPFC_HST_ISCR0;
James Smartda0436e2009-05-22 14:51:39 -04006969}
6970
6971/**
6972 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
6973 * @phba: pointer to lpfc hba data structure.
6974 * @vf: virtual function number
6975 *
6976 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
6977 * based on the given viftual function number, @vf.
6978 *
6979 * Return 0 if successful, otherwise -ENODEV.
6980 **/
6981static int
6982lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
6983{
6984 if (vf > LPFC_VIR_FUNC_MAX)
6985 return -ENODEV;
6986
6987 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05006988 vf * LPFC_VFR_PAGE_SIZE +
6989 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04006990 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05006991 vf * LPFC_VFR_PAGE_SIZE +
6992 LPFC_ULP0_WQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04006993 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6994 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
6995 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6996 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
6997 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
6998 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
6999 return 0;
7000}
7001
7002/**
7003 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
7004 * @phba: pointer to lpfc hba data structure.
7005 *
7006 * This routine is invoked to create the bootstrap mailbox
7007 * region consistent with the SLI-4 interface spec. This
7008 * routine allocates all memory necessary to communicate
7009 * mailbox commands to the port and sets up all alignment
7010 * needs. No locks are expected to be held when calling
7011 * this routine.
7012 *
7013 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007014 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04007015 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04007016 **/
7017static int
7018lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
7019{
7020 uint32_t bmbx_size;
7021 struct lpfc_dmabuf *dmabuf;
7022 struct dma_address *dma_address;
7023 uint32_t pa_addr;
7024 uint64_t phys_addr;
7025
7026 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
7027 if (!dmabuf)
7028 return -ENOMEM;
7029
7030 /*
7031 * The bootstrap mailbox region is comprised of 2 parts
7032 * plus an alignment restriction of 16 bytes.
7033 */
7034 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
Joe Perches1aee3832014-09-03 12:56:12 -04007035 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
7036 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04007037 if (!dmabuf->virt) {
7038 kfree(dmabuf);
7039 return -ENOMEM;
7040 }
James Smartda0436e2009-05-22 14:51:39 -04007041
7042 /*
7043 * Initialize the bootstrap mailbox pointers now so that the register
7044 * operations are simple later. The mailbox dma address is required
7045 * to be 16-byte aligned. Also align the virtual memory as each
7046 * maibox is copied into the bmbx mailbox region before issuing the
7047 * command to the port.
7048 */
7049 phba->sli4_hba.bmbx.dmabuf = dmabuf;
7050 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
7051
7052 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
7053 LPFC_ALIGN_16_BYTE);
7054 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
7055 LPFC_ALIGN_16_BYTE);
7056
7057 /*
7058 * Set the high and low physical addresses now. The SLI4 alignment
7059 * requirement is 16 bytes and the mailbox is posted to the port
7060 * as two 30-bit addresses. The other data is a bit marking whether
7061 * the 30-bit address is the high or low address.
7062 * Upcast bmbx aphys to 64bits so shift instruction compiles
7063 * clean on 32 bit machines.
7064 */
7065 dma_address = &phba->sli4_hba.bmbx.dma_address;
7066 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
7067 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
7068 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
7069 LPFC_BMBX_BIT1_ADDR_HI);
7070
7071 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
7072 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
7073 LPFC_BMBX_BIT1_ADDR_LO);
7074 return 0;
7075}
7076
7077/**
7078 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
7079 * @phba: pointer to lpfc hba data structure.
7080 *
7081 * This routine is invoked to teardown the bootstrap mailbox
7082 * region and release all host resources. This routine requires
7083 * the caller to ensure all mailbox commands recovered, no
7084 * additional mailbox comands are sent, and interrupts are disabled
7085 * before calling this routine.
7086 *
7087 **/
7088static void
7089lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
7090{
7091 dma_free_coherent(&phba->pcidev->dev,
7092 phba->sli4_hba.bmbx.bmbx_size,
7093 phba->sli4_hba.bmbx.dmabuf->virt,
7094 phba->sli4_hba.bmbx.dmabuf->phys);
7095
7096 kfree(phba->sli4_hba.bmbx.dmabuf);
7097 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
7098}
7099
7100/**
7101 * lpfc_sli4_read_config - Get the config parameters.
7102 * @phba: pointer to lpfc hba data structure.
7103 *
7104 * This routine is invoked to read the configuration parameters from the HBA.
7105 * The configuration parameters are used to set the base and maximum values
7106 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
7107 * allocation for the port.
7108 *
7109 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007110 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007111 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007112 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007113 **/
James Smartff78d8f2011-12-13 13:21:35 -05007114int
James Smartda0436e2009-05-22 14:51:39 -04007115lpfc_sli4_read_config(struct lpfc_hba *phba)
7116{
7117 LPFC_MBOXQ_t *pmb;
7118 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04007119 union lpfc_sli4_cfg_shdr *shdr;
7120 uint32_t shdr_status, shdr_add_status;
7121 struct lpfc_mbx_get_func_cfg *get_func_cfg;
7122 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04007123 char *pdesc_0;
James Smartc6918162016-10-13 15:06:16 -07007124 uint16_t forced_link_speed;
7125 uint32_t if_type;
James Smart8aa134a2012-08-14 14:25:29 -04007126 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04007127
7128 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7129 if (!pmb) {
7130 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7131 "2011 Unable to allocate memory for issuing "
7132 "SLI_CONFIG_SPECIAL mailbox command\n");
7133 return -ENOMEM;
7134 }
7135
7136 lpfc_read_config(phba, pmb);
7137
7138 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
7139 if (rc != MBX_SUCCESS) {
7140 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7141 "2012 Mailbox failed , mbxCmd x%x "
7142 "READ_CONFIG, mbxStatus x%x\n",
7143 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7144 bf_get(lpfc_mqe_status, &pmb->u.mqe));
7145 rc = -EIO;
7146 } else {
7147 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05007148 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
7149 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
7150 phba->sli4_hba.lnk_info.lnk_tp =
7151 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
7152 phba->sli4_hba.lnk_info.lnk_no =
7153 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
7154 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7155 "3081 lnk_type:%d, lnk_numb:%d\n",
7156 phba->sli4_hba.lnk_info.lnk_tp,
7157 phba->sli4_hba.lnk_info.lnk_no);
7158 } else
7159 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
7160 "3082 Mailbox (x%x) returned ldv:x0\n",
7161 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart6d368e52011-05-24 11:44:12 -04007162 phba->sli4_hba.extents_in_use =
7163 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04007164 phba->sli4_hba.max_cfg_param.max_xri =
7165 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
7166 phba->sli4_hba.max_cfg_param.xri_base =
7167 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
7168 phba->sli4_hba.max_cfg_param.max_vpi =
7169 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
7170 phba->sli4_hba.max_cfg_param.vpi_base =
7171 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
7172 phba->sli4_hba.max_cfg_param.max_rpi =
7173 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
7174 phba->sli4_hba.max_cfg_param.rpi_base =
7175 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
7176 phba->sli4_hba.max_cfg_param.max_vfi =
7177 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
7178 phba->sli4_hba.max_cfg_param.vfi_base =
7179 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
7180 phba->sli4_hba.max_cfg_param.max_fcfi =
7181 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04007182 phba->sli4_hba.max_cfg_param.max_eq =
7183 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
7184 phba->sli4_hba.max_cfg_param.max_rq =
7185 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
7186 phba->sli4_hba.max_cfg_param.max_wq =
7187 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
7188 phba->sli4_hba.max_cfg_param.max_cq =
7189 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
7190 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
7191 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
7192 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
7193 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05007194 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
7195 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04007196 phba->max_vports = phba->max_vpi;
7197 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04007198 "2003 cfg params Extents? %d "
7199 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04007200 "VPI(B:%d M:%d) "
7201 "VFI(B:%d M:%d) "
7202 "RPI(B:%d M:%d) "
James Smart2ea259e2017-02-12 13:52:27 -08007203 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n",
James Smart6d368e52011-05-24 11:44:12 -04007204 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04007205 phba->sli4_hba.max_cfg_param.xri_base,
7206 phba->sli4_hba.max_cfg_param.max_xri,
7207 phba->sli4_hba.max_cfg_param.vpi_base,
7208 phba->sli4_hba.max_cfg_param.max_vpi,
7209 phba->sli4_hba.max_cfg_param.vfi_base,
7210 phba->sli4_hba.max_cfg_param.max_vfi,
7211 phba->sli4_hba.max_cfg_param.rpi_base,
7212 phba->sli4_hba.max_cfg_param.max_rpi,
James Smart2ea259e2017-02-12 13:52:27 -08007213 phba->sli4_hba.max_cfg_param.max_fcfi,
7214 phba->sli4_hba.max_cfg_param.max_eq,
7215 phba->sli4_hba.max_cfg_param.max_cq,
7216 phba->sli4_hba.max_cfg_param.max_wq,
7217 phba->sli4_hba.max_cfg_param.max_rq);
7218
James Smartda0436e2009-05-22 14:51:39 -04007219 }
James Smart912e3ac2011-05-24 11:42:11 -04007220
7221 if (rc)
7222 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04007223
James Smartc6918162016-10-13 15:06:16 -07007224 /* Update link speed if forced link speed is supported */
7225 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7226 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
7227 forced_link_speed =
7228 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
7229 if (forced_link_speed) {
7230 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
7231
7232 switch (forced_link_speed) {
7233 case LINK_SPEED_1G:
7234 phba->cfg_link_speed =
7235 LPFC_USER_LINK_SPEED_1G;
7236 break;
7237 case LINK_SPEED_2G:
7238 phba->cfg_link_speed =
7239 LPFC_USER_LINK_SPEED_2G;
7240 break;
7241 case LINK_SPEED_4G:
7242 phba->cfg_link_speed =
7243 LPFC_USER_LINK_SPEED_4G;
7244 break;
7245 case LINK_SPEED_8G:
7246 phba->cfg_link_speed =
7247 LPFC_USER_LINK_SPEED_8G;
7248 break;
7249 case LINK_SPEED_10G:
7250 phba->cfg_link_speed =
7251 LPFC_USER_LINK_SPEED_10G;
7252 break;
7253 case LINK_SPEED_16G:
7254 phba->cfg_link_speed =
7255 LPFC_USER_LINK_SPEED_16G;
7256 break;
7257 case LINK_SPEED_32G:
7258 phba->cfg_link_speed =
7259 LPFC_USER_LINK_SPEED_32G;
7260 break;
7261 case 0xffff:
7262 phba->cfg_link_speed =
7263 LPFC_USER_LINK_SPEED_AUTO;
7264 break;
7265 default:
7266 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7267 "0047 Unrecognized link "
7268 "speed : %d\n",
7269 forced_link_speed);
7270 phba->cfg_link_speed =
7271 LPFC_USER_LINK_SPEED_AUTO;
7272 }
7273 }
7274 }
7275
James Smartda0436e2009-05-22 14:51:39 -04007276 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -04007277 length = phba->sli4_hba.max_cfg_param.max_xri -
7278 lpfc_sli4_get_els_iocb_cnt(phba);
7279 if (phba->cfg_hba_queue_depth > length) {
7280 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7281 "3361 HBA queue depth changed from %d to %d\n",
7282 phba->cfg_hba_queue_depth, length);
7283 phba->cfg_hba_queue_depth = length;
7284 }
James Smart912e3ac2011-05-24 11:42:11 -04007285
7286 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
7287 LPFC_SLI_INTF_IF_TYPE_2)
7288 goto read_cfg_out;
7289
7290 /* get the pf# and vf# for SLI4 if_type 2 port */
7291 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
7292 sizeof(struct lpfc_sli4_cfg_mhdr));
7293 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
7294 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
7295 length, LPFC_SLI4_MBX_EMBED);
7296
James Smart8aa134a2012-08-14 14:25:29 -04007297 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04007298 shdr = (union lpfc_sli4_cfg_shdr *)
7299 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
7300 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7301 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04007302 if (rc2 || shdr_status || shdr_add_status) {
James Smart912e3ac2011-05-24 11:42:11 -04007303 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7304 "3026 Mailbox failed , mbxCmd x%x "
7305 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
7306 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7307 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04007308 goto read_cfg_out;
7309 }
7310
7311 /* search for fc_fcoe resrouce descriptor */
7312 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
James Smart912e3ac2011-05-24 11:42:11 -04007313
James Smart8aa134a2012-08-14 14:25:29 -04007314 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
7315 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
7316 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
7317 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
7318 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
7319 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
7320 goto read_cfg_out;
7321
James Smart912e3ac2011-05-24 11:42:11 -04007322 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04007323 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04007324 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04007325 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04007326 phba->sli4_hba.iov.pf_number =
7327 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
7328 phba->sli4_hba.iov.vf_number =
7329 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
7330 break;
7331 }
7332 }
7333
7334 if (i < LPFC_RSRC_DESC_MAX_NUM)
7335 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7336 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
7337 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
7338 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04007339 else
James Smart912e3ac2011-05-24 11:42:11 -04007340 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7341 "3028 GET_FUNCTION_CONFIG: failed to find "
7342 "Resrouce Descriptor:x%x\n",
7343 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04007344
7345read_cfg_out:
7346 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04007347 return rc;
7348}
7349
7350/**
James Smart2fcee4b2010-12-15 17:57:46 -05007351 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04007352 * @phba: pointer to lpfc hba data structure.
7353 *
James Smart2fcee4b2010-12-15 17:57:46 -05007354 * This routine is invoked to setup the port-side endian order when
7355 * the port if_type is 0. This routine has no function for other
7356 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04007357 *
7358 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007359 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007360 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007361 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007362 **/
7363static int
7364lpfc_setup_endian_order(struct lpfc_hba *phba)
7365{
7366 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05007367 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04007368 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
7369 HOST_ENDIAN_HIGH_WORD1};
7370
James Smart2fcee4b2010-12-15 17:57:46 -05007371 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7372 switch (if_type) {
7373 case LPFC_SLI_INTF_IF_TYPE_0:
7374 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7375 GFP_KERNEL);
7376 if (!mboxq) {
7377 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7378 "0492 Unable to allocate memory for "
7379 "issuing SLI_CONFIG_SPECIAL mailbox "
7380 "command\n");
7381 return -ENOMEM;
7382 }
James Smartda0436e2009-05-22 14:51:39 -04007383
James Smart2fcee4b2010-12-15 17:57:46 -05007384 /*
7385 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
7386 * two words to contain special data values and no other data.
7387 */
7388 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
7389 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
7390 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7391 if (rc != MBX_SUCCESS) {
7392 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7393 "0493 SLI_CONFIG_SPECIAL mailbox "
7394 "failed with status x%x\n",
7395 rc);
7396 rc = -EIO;
7397 }
7398 mempool_free(mboxq, phba->mbox_mem_pool);
7399 break;
7400 case LPFC_SLI_INTF_IF_TYPE_2:
7401 case LPFC_SLI_INTF_IF_TYPE_1:
7402 default:
7403 break;
James Smartda0436e2009-05-22 14:51:39 -04007404 }
James Smartda0436e2009-05-22 14:51:39 -04007405 return rc;
7406}
7407
7408/**
James Smart895427b2017-02-12 13:52:30 -08007409 * lpfc_sli4_queue_verify - Verify and update EQ counts
James Smartda0436e2009-05-22 14:51:39 -04007410 * @phba: pointer to lpfc hba data structure.
7411 *
James Smart895427b2017-02-12 13:52:30 -08007412 * This routine is invoked to check the user settable queue counts for EQs.
7413 * After this routine is called the counts will be set to valid values that
James Smart5350d872011-10-10 21:33:49 -04007414 * adhere to the constraints of the system's interrupt vectors and the port's
7415 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04007416 *
7417 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007418 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007419 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007420 **/
7421static int
James Smart5350d872011-10-10 21:33:49 -04007422lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04007423{
James Smart895427b2017-02-12 13:52:30 -08007424 int io_channel;
James Smart1ba981f2014-02-20 09:56:45 -05007425 int fof_vectors = phba->cfg_fof ? 1 : 0;
James Smartda0436e2009-05-22 14:51:39 -04007426
7427 /*
James Smart67d12732012-08-03 12:36:13 -04007428 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04007429 * device parameters
7430 */
7431
James Smart67d12732012-08-03 12:36:13 -04007432 /* Sanity check on HBA EQ parameters */
James Smart895427b2017-02-12 13:52:30 -08007433 io_channel = phba->io_channel_irqs;
James Smartda0436e2009-05-22 14:51:39 -04007434
James Smart895427b2017-02-12 13:52:30 -08007435 if (phba->sli4_hba.num_online_cpu < io_channel) {
James Smart82c3e9b2012-09-29 11:29:50 -04007436 lpfc_printf_log(phba,
7437 KERN_ERR, LOG_INIT,
James Smart90695ee2012-08-14 14:25:36 -04007438 "3188 Reducing IO channels to match number of "
James Smart7bb03bb2013-04-17 20:19:16 -04007439 "online CPUs: from %d to %d\n",
James Smart895427b2017-02-12 13:52:30 -08007440 io_channel, phba->sli4_hba.num_online_cpu);
7441 io_channel = phba->sli4_hba.num_online_cpu;
James Smart90695ee2012-08-14 14:25:36 -04007442 }
7443
James Smart895427b2017-02-12 13:52:30 -08007444 if (io_channel + fof_vectors > phba->sli4_hba.max_cfg_param.max_eq) {
James Smart82c3e9b2012-09-29 11:29:50 -04007445 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7446 "2575 Reducing IO channels to match number of "
7447 "available EQs: from %d to %d\n",
James Smart895427b2017-02-12 13:52:30 -08007448 io_channel,
James Smart82c3e9b2012-09-29 11:29:50 -04007449 phba->sli4_hba.max_cfg_param.max_eq);
James Smart895427b2017-02-12 13:52:30 -08007450 io_channel = phba->sli4_hba.max_cfg_param.max_eq - fof_vectors;
James Smartda0436e2009-05-22 14:51:39 -04007451 }
James Smart67d12732012-08-03 12:36:13 -04007452
James Smart895427b2017-02-12 13:52:30 -08007453 /* The actual number of FCP / NVME event queues adopted */
7454 if (io_channel != phba->io_channel_irqs)
7455 phba->io_channel_irqs = io_channel;
7456 if (phba->cfg_fcp_io_channel > io_channel)
7457 phba->cfg_fcp_io_channel = io_channel;
7458 if (phba->cfg_nvme_io_channel > io_channel)
7459 phba->cfg_nvme_io_channel = io_channel;
7460
7461 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7462 "2574 IRQs: %d, IO Channels: fcp %d nvme %d\n",
7463 phba->io_channel_irqs, phba->cfg_fcp_io_channel,
7464 phba->cfg_nvme_io_channel);
James Smartda0436e2009-05-22 14:51:39 -04007465
James Smartda0436e2009-05-22 14:51:39 -04007466 /* Get EQ depth from module parameter, fake the default for now */
7467 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
7468 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
7469
James Smart5350d872011-10-10 21:33:49 -04007470 /* Get CQ depth from module parameter, fake the default for now */
7471 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
7472 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart5350d872011-10-10 21:33:49 -04007473 return 0;
James Smart895427b2017-02-12 13:52:30 -08007474}
7475
7476static int
7477lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx)
7478{
7479 struct lpfc_queue *qdesc;
7480 int cnt;
7481
7482 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7483 phba->sli4_hba.cq_ecount);
7484 if (!qdesc) {
7485 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7486 "0508 Failed allocate fast-path NVME CQ (%d)\n",
7487 wqidx);
7488 return 1;
7489 }
7490 phba->sli4_hba.nvme_cq[wqidx] = qdesc;
7491
7492 cnt = LPFC_NVME_WQSIZE;
7493 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_WQE128_SIZE, cnt);
7494 if (!qdesc) {
7495 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7496 "0509 Failed allocate fast-path NVME WQ (%d)\n",
7497 wqidx);
7498 return 1;
7499 }
7500 phba->sli4_hba.nvme_wq[wqidx] = qdesc;
7501 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
7502 return 0;
7503}
7504
7505static int
7506lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx)
7507{
7508 struct lpfc_queue *qdesc;
7509 uint32_t wqesize;
7510
7511 /* Create Fast Path FCP CQs */
7512 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7513 phba->sli4_hba.cq_ecount);
7514 if (!qdesc) {
7515 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7516 "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx);
7517 return 1;
7518 }
7519 phba->sli4_hba.fcp_cq[wqidx] = qdesc;
7520
7521 /* Create Fast Path FCP WQs */
7522 wqesize = (phba->fcp_embed_io) ?
7523 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
7524 qdesc = lpfc_sli4_queue_alloc(phba, wqesize, phba->sli4_hba.wq_ecount);
7525 if (!qdesc) {
7526 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7527 "0503 Failed allocate fast-path FCP WQ (%d)\n",
7528 wqidx);
7529 return 1;
7530 }
7531 phba->sli4_hba.fcp_wq[wqidx] = qdesc;
7532 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
7533 return 0;
James Smart5350d872011-10-10 21:33:49 -04007534}
7535
7536/**
7537 * lpfc_sli4_queue_create - Create all the SLI4 queues
7538 * @phba: pointer to lpfc hba data structure.
7539 *
7540 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
7541 * operation. For each SLI4 queue type, the parameters such as queue entry
7542 * count (queue depth) shall be taken from the module parameter. For now,
7543 * we just use some constant number as place holder.
7544 *
7545 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07007546 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04007547 * -ENOMEM - No availble memory
7548 * -EIO - The mailbox failed to complete successfully.
7549 **/
7550int
7551lpfc_sli4_queue_create(struct lpfc_hba *phba)
7552{
7553 struct lpfc_queue *qdesc;
James Smart895427b2017-02-12 13:52:30 -08007554 int idx, io_channel;
James Smart5350d872011-10-10 21:33:49 -04007555
7556 /*
James Smart67d12732012-08-03 12:36:13 -04007557 * Create HBA Record arrays.
James Smart895427b2017-02-12 13:52:30 -08007558 * Both NVME and FCP will share that same vectors / EQs
James Smart5350d872011-10-10 21:33:49 -04007559 */
James Smart895427b2017-02-12 13:52:30 -08007560 io_channel = phba->io_channel_irqs;
7561 if (!io_channel)
James Smart67d12732012-08-03 12:36:13 -04007562 return -ERANGE;
James Smart5350d872011-10-10 21:33:49 -04007563
James Smart67d12732012-08-03 12:36:13 -04007564 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
7565 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
7566 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
7567 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
7568 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
7569 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
James Smart895427b2017-02-12 13:52:30 -08007570 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
7571 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
7572 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
7573 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart67d12732012-08-03 12:36:13 -04007574
James Smart895427b2017-02-12 13:52:30 -08007575 phba->sli4_hba.hba_eq = kcalloc(io_channel,
7576 sizeof(struct lpfc_queue *),
7577 GFP_KERNEL);
James Smart67d12732012-08-03 12:36:13 -04007578 if (!phba->sli4_hba.hba_eq) {
James Smartda0436e2009-05-22 14:51:39 -04007579 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007580 "2576 Failed allocate memory for "
7581 "fast-path EQ record array\n");
James Smartda0436e2009-05-22 14:51:39 -04007582 goto out_error;
7583 }
James Smart67d12732012-08-03 12:36:13 -04007584
James Smart895427b2017-02-12 13:52:30 -08007585 if (phba->cfg_fcp_io_channel) {
7586 phba->sli4_hba.fcp_cq = kcalloc(phba->cfg_fcp_io_channel,
7587 sizeof(struct lpfc_queue *),
7588 GFP_KERNEL);
7589 if (!phba->sli4_hba.fcp_cq) {
7590 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7591 "2577 Failed allocate memory for "
7592 "fast-path CQ record array\n");
7593 goto out_error;
7594 }
7595 phba->sli4_hba.fcp_wq = kcalloc(phba->cfg_fcp_io_channel,
7596 sizeof(struct lpfc_queue *),
7597 GFP_KERNEL);
7598 if (!phba->sli4_hba.fcp_wq) {
7599 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7600 "2578 Failed allocate memory for "
7601 "fast-path FCP WQ record array\n");
7602 goto out_error;
7603 }
7604 /*
7605 * Since the first EQ can have multiple CQs associated with it,
7606 * this array is used to quickly see if we have a FCP fast-path
7607 * CQ match.
7608 */
7609 phba->sli4_hba.fcp_cq_map = kcalloc(phba->cfg_fcp_io_channel,
7610 sizeof(uint16_t),
7611 GFP_KERNEL);
7612 if (!phba->sli4_hba.fcp_cq_map) {
7613 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7614 "2545 Failed allocate memory for "
7615 "fast-path CQ map\n");
7616 goto out_error;
7617 }
James Smart67d12732012-08-03 12:36:13 -04007618 }
7619
James Smart895427b2017-02-12 13:52:30 -08007620 if (phba->cfg_nvme_io_channel) {
7621 phba->sli4_hba.nvme_cq = kcalloc(phba->cfg_nvme_io_channel,
7622 sizeof(struct lpfc_queue *),
7623 GFP_KERNEL);
7624 if (!phba->sli4_hba.nvme_cq) {
7625 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7626 "6077 Failed allocate memory for "
7627 "fast-path CQ record array\n");
7628 goto out_error;
7629 }
7630
7631
7632 phba->sli4_hba.nvme_wq = kcalloc(phba->cfg_nvme_io_channel,
7633 sizeof(struct lpfc_queue *),
7634 GFP_KERNEL);
7635 if (!phba->sli4_hba.nvme_wq) {
7636 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7637 "2581 Failed allocate memory for "
7638 "fast-path NVME WQ record array\n");
7639 goto out_error;
7640 }
7641
7642 /*
7643 * Since the first EQ can have multiple CQs associated with it,
7644 * this array is used to quickly see if we have a NVME fast-path
7645 * CQ match.
7646 */
7647 phba->sli4_hba.nvme_cq_map = kcalloc(phba->cfg_nvme_io_channel,
7648 sizeof(uint16_t),
7649 GFP_KERNEL);
7650 if (!phba->sli4_hba.nvme_cq_map) {
7651 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7652 "6078 Failed allocate memory for "
7653 "fast-path CQ map\n");
7654 goto out_error;
7655 }
James Smart67d12732012-08-03 12:36:13 -04007656 }
James Smartda0436e2009-05-22 14:51:39 -04007657
James Smart895427b2017-02-12 13:52:30 -08007658 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
James Smart67d12732012-08-03 12:36:13 -04007659
James Smart895427b2017-02-12 13:52:30 -08007660 /* Create HBA Event Queues (EQs) */
7661 for (idx = 0; idx < io_channel; idx++) {
James Smart67d12732012-08-03 12:36:13 -04007662 /* Create EQs */
James Smartda0436e2009-05-22 14:51:39 -04007663 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
7664 phba->sli4_hba.eq_ecount);
7665 if (!qdesc) {
7666 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007667 "0497 Failed allocate EQ (%d)\n", idx);
7668 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007669 }
James Smart67d12732012-08-03 12:36:13 -04007670 phba->sli4_hba.hba_eq[idx] = qdesc;
James Smartda0436e2009-05-22 14:51:39 -04007671 }
7672
James Smart895427b2017-02-12 13:52:30 -08007673 /* FCP and NVME io channels are not required to be balanced */
7674
7675 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
7676 if (lpfc_alloc_fcp_wq_cq(phba, idx))
7677 goto out_error;
7678
7679 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
7680 if (lpfc_alloc_nvme_wq_cq(phba, idx))
7681 goto out_error;
James Smart67d12732012-08-03 12:36:13 -04007682
James Smartda0436e2009-05-22 14:51:39 -04007683 /*
James Smart67d12732012-08-03 12:36:13 -04007684 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04007685 */
7686
James Smartda0436e2009-05-22 14:51:39 -04007687 /* Create slow-path Mailbox Command Complete Queue */
7688 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7689 phba->sli4_hba.cq_ecount);
7690 if (!qdesc) {
7691 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7692 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04007693 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007694 }
7695 phba->sli4_hba.mbx_cq = qdesc;
7696
7697 /* Create slow-path ELS Complete Queue */
7698 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7699 phba->sli4_hba.cq_ecount);
7700 if (!qdesc) {
7701 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7702 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -04007703 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007704 }
7705 phba->sli4_hba.els_cq = qdesc;
7706
James Smartda0436e2009-05-22 14:51:39 -04007707
James Smart5350d872011-10-10 21:33:49 -04007708 /*
James Smart67d12732012-08-03 12:36:13 -04007709 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04007710 */
James Smartda0436e2009-05-22 14:51:39 -04007711
7712 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04007713
7714 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
7715 phba->sli4_hba.mq_ecount);
7716 if (!qdesc) {
7717 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7718 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04007719 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007720 }
7721 phba->sli4_hba.mbx_wq = qdesc;
7722
7723 /*
James Smart67d12732012-08-03 12:36:13 -04007724 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04007725 */
James Smartda0436e2009-05-22 14:51:39 -04007726
7727 /* Create slow-path ELS Work Queue */
7728 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
7729 phba->sli4_hba.wq_ecount);
7730 if (!qdesc) {
7731 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7732 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04007733 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007734 }
7735 phba->sli4_hba.els_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08007736 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
7737
7738 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
7739 /* Create NVME LS Complete Queue */
7740 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7741 phba->sli4_hba.cq_ecount);
7742 if (!qdesc) {
7743 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7744 "6079 Failed allocate NVME LS CQ\n");
7745 goto out_error;
7746 }
7747 phba->sli4_hba.nvmels_cq = qdesc;
7748
7749 /* Create NVME LS Work Queue */
7750 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
7751 phba->sli4_hba.wq_ecount);
7752 if (!qdesc) {
7753 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7754 "6080 Failed allocate NVME LS WQ\n");
7755 goto out_error;
7756 }
7757 phba->sli4_hba.nvmels_wq = qdesc;
7758 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
7759 }
James Smartda0436e2009-05-22 14:51:39 -04007760
James Smartda0436e2009-05-22 14:51:39 -04007761 /*
7762 * Create Receive Queue (RQ)
7763 */
James Smartda0436e2009-05-22 14:51:39 -04007764
7765 /* Create Receive Queue for header */
7766 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
7767 phba->sli4_hba.rq_ecount);
7768 if (!qdesc) {
7769 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7770 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04007771 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007772 }
7773 phba->sli4_hba.hdr_rq = qdesc;
7774
7775 /* Create Receive Queue for data */
7776 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
7777 phba->sli4_hba.rq_ecount);
7778 if (!qdesc) {
7779 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7780 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04007781 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007782 }
7783 phba->sli4_hba.dat_rq = qdesc;
7784
James Smart1ba981f2014-02-20 09:56:45 -05007785 /* Create the Queues needed for Flash Optimized Fabric operations */
7786 if (phba->cfg_fof)
7787 lpfc_fof_queue_create(phba);
James Smartda0436e2009-05-22 14:51:39 -04007788 return 0;
7789
James Smartda0436e2009-05-22 14:51:39 -04007790out_error:
James Smart67d12732012-08-03 12:36:13 -04007791 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04007792 return -ENOMEM;
7793}
7794
James Smart895427b2017-02-12 13:52:30 -08007795static inline void
7796__lpfc_sli4_release_queue(struct lpfc_queue **qp)
7797{
7798 if (*qp != NULL) {
7799 lpfc_sli4_queue_free(*qp);
7800 *qp = NULL;
7801 }
7802}
7803
7804static inline void
7805lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
7806{
7807 int idx;
7808
7809 if (*qs == NULL)
7810 return;
7811
7812 for (idx = 0; idx < max; idx++)
7813 __lpfc_sli4_release_queue(&(*qs)[idx]);
7814
7815 kfree(*qs);
7816 *qs = NULL;
7817}
7818
7819static inline void
7820lpfc_sli4_release_queue_map(uint16_t **qmap)
7821{
7822 if (*qmap != NULL) {
7823 kfree(*qmap);
7824 *qmap = NULL;
7825 }
7826}
7827
James Smartda0436e2009-05-22 14:51:39 -04007828/**
7829 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
7830 * @phba: pointer to lpfc hba data structure.
7831 *
7832 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
7833 * operation.
7834 *
7835 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007836 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007837 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007838 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007839 **/
James Smart5350d872011-10-10 21:33:49 -04007840void
James Smartda0436e2009-05-22 14:51:39 -04007841lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
7842{
James Smart1ba981f2014-02-20 09:56:45 -05007843 if (phba->cfg_fof)
7844 lpfc_fof_queue_destroy(phba);
7845
James Smart895427b2017-02-12 13:52:30 -08007846 /* Release HBA eqs */
7847 lpfc_sli4_release_queues(&phba->sli4_hba.hba_eq, phba->io_channel_irqs);
James Smart67d12732012-08-03 12:36:13 -04007848
James Smart895427b2017-02-12 13:52:30 -08007849 /* Release FCP cqs */
7850 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_cq,
7851 phba->cfg_fcp_io_channel);
James Smart67d12732012-08-03 12:36:13 -04007852
James Smart895427b2017-02-12 13:52:30 -08007853 /* Release FCP wqs */
7854 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_wq,
7855 phba->cfg_fcp_io_channel);
James Smart67d12732012-08-03 12:36:13 -04007856
7857 /* Release FCP CQ mapping array */
James Smart895427b2017-02-12 13:52:30 -08007858 lpfc_sli4_release_queue_map(&phba->sli4_hba.fcp_cq_map);
7859
7860 /* Release NVME cqs */
7861 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_cq,
7862 phba->cfg_nvme_io_channel);
7863
7864 /* Release NVME wqs */
7865 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_wq,
7866 phba->cfg_nvme_io_channel);
7867
7868 /* Release NVME CQ mapping array */
7869 lpfc_sli4_release_queue_map(&phba->sli4_hba.nvme_cq_map);
James Smartda0436e2009-05-22 14:51:39 -04007870
7871 /* Release mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08007872 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
James Smartda0436e2009-05-22 14:51:39 -04007873
7874 /* Release ELS work queue */
James Smart895427b2017-02-12 13:52:30 -08007875 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
7876
7877 /* Release ELS work queue */
7878 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
James Smartda0436e2009-05-22 14:51:39 -04007879
7880 /* Release unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08007881 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
7882 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
James Smartda0436e2009-05-22 14:51:39 -04007883
James Smartda0436e2009-05-22 14:51:39 -04007884 /* Release ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08007885 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
7886
7887 /* Release NVME LS complete queue */
7888 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
James Smartda0436e2009-05-22 14:51:39 -04007889
7890 /* Release mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08007891 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
7892
7893 /* Everything on this list has been freed */
7894 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
7895}
7896
7897int
7898lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq,
7899 struct lpfc_queue *drq, int count)
7900{
7901 int rc, i;
7902 struct lpfc_rqe hrqe;
7903 struct lpfc_rqe drqe;
7904 struct lpfc_rqb *rqbp;
7905 struct rqb_dmabuf *rqb_buffer;
7906 LIST_HEAD(rqb_buf_list);
7907
7908 rqbp = hrq->rqbp;
7909 for (i = 0; i < count; i++) {
7910 rqb_buffer = (rqbp->rqb_alloc_buffer)(phba);
7911 if (!rqb_buffer)
7912 break;
7913 rqb_buffer->hrq = hrq;
7914 rqb_buffer->drq = drq;
7915 list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list);
7916 }
7917 while (!list_empty(&rqb_buf_list)) {
7918 list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf,
7919 hbuf.list);
7920
7921 hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys);
7922 hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys);
7923 drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys);
7924 drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys);
7925 rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe);
7926 if (rc < 0) {
7927 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
7928 } else {
7929 list_add_tail(&rqb_buffer->hbuf.list,
7930 &rqbp->rqb_buffer_list);
7931 rqbp->buffer_count++;
7932 }
7933 }
7934 return 1;
7935}
7936
7937int
7938lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
7939{
7940 struct lpfc_rqb *rqbp;
7941 struct lpfc_dmabuf *h_buf;
7942 struct rqb_dmabuf *rqb_buffer;
7943
7944 rqbp = rq->rqbp;
7945 while (!list_empty(&rqbp->rqb_buffer_list)) {
7946 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
7947 struct lpfc_dmabuf, list);
7948
7949 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
7950 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
7951 rqbp->buffer_count--;
7952 }
7953 return 1;
7954}
7955
7956static int
7957lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
7958 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
7959 int qidx, uint32_t qtype)
7960{
7961 struct lpfc_sli_ring *pring;
7962 int rc;
7963
7964 if (!eq || !cq || !wq) {
7965 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7966 "6085 Fast-path %s (%d) not allocated\n",
7967 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
7968 return -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007969 }
James Smartda0436e2009-05-22 14:51:39 -04007970
James Smart895427b2017-02-12 13:52:30 -08007971 /* create the Cq first */
7972 rc = lpfc_cq_create(phba, cq, eq,
7973 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
7974 if (rc) {
7975 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7976 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
7977 qidx, (uint32_t)rc);
7978 return rc;
7979 }
7980
7981 if (qtype != LPFC_MBOX) {
7982 /* Setup nvme_cq_map for fast lookup */
7983 if (cq_map)
7984 *cq_map = cq->queue_id;
7985
7986 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7987 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
7988 qidx, cq->queue_id, qidx, eq->queue_id);
7989
7990 /* create the wq */
7991 rc = lpfc_wq_create(phba, wq, cq, qtype);
7992 if (rc) {
7993 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7994 "6123 Fail setup fastpath WQ (%d), rc = 0x%x\n",
7995 qidx, (uint32_t)rc);
7996 /* no need to tear down cq - caller will do so */
7997 return rc;
7998 }
7999
8000 /* Bind this CQ/WQ to the NVME ring */
8001 pring = wq->pring;
8002 pring->sli.sli4.wqp = (void *)wq;
8003 cq->pring = pring;
8004
8005 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8006 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
8007 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
8008 } else {
8009 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
8010 if (rc) {
8011 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8012 "0539 Failed setup of slow-path MQ: "
8013 "rc = 0x%x\n", rc);
8014 /* no need to tear down cq - caller will do so */
8015 return rc;
8016 }
8017
8018 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8019 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
8020 phba->sli4_hba.mbx_wq->queue_id,
8021 phba->sli4_hba.mbx_cq->queue_id);
8022 }
8023
8024 return 0;
James Smartda0436e2009-05-22 14:51:39 -04008025}
8026
8027/**
8028 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
8029 * @phba: pointer to lpfc hba data structure.
8030 *
8031 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
8032 * operation.
8033 *
8034 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008035 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008036 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008037 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008038 **/
8039int
8040lpfc_sli4_queue_setup(struct lpfc_hba *phba)
8041{
James Smart962bc512013-01-03 15:44:00 -05008042 uint32_t shdr_status, shdr_add_status;
8043 union lpfc_sli4_cfg_shdr *shdr;
8044 LPFC_MBOXQ_t *mboxq;
James Smart895427b2017-02-12 13:52:30 -08008045 int qidx;
8046 uint32_t length, io_channel;
8047 int rc = -ENOMEM;
James Smart962bc512013-01-03 15:44:00 -05008048
8049 /* Check for dual-ULP support */
8050 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8051 if (!mboxq) {
8052 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8053 "3249 Unable to allocate memory for "
8054 "QUERY_FW_CFG mailbox command\n");
8055 return -ENOMEM;
8056 }
8057 length = (sizeof(struct lpfc_mbx_query_fw_config) -
8058 sizeof(struct lpfc_sli4_cfg_mhdr));
8059 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8060 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
8061 length, LPFC_SLI4_MBX_EMBED);
8062
8063 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8064
8065 shdr = (union lpfc_sli4_cfg_shdr *)
8066 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
8067 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8068 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
8069 if (shdr_status || shdr_add_status || rc) {
8070 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8071 "3250 QUERY_FW_CFG mailbox failed with status "
8072 "x%x add_status x%x, mbx status x%x\n",
8073 shdr_status, shdr_add_status, rc);
8074 if (rc != MBX_TIMEOUT)
8075 mempool_free(mboxq, phba->mbox_mem_pool);
8076 rc = -ENXIO;
8077 goto out_error;
8078 }
8079
8080 phba->sli4_hba.fw_func_mode =
8081 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
8082 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
8083 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
James Smart8b017a32015-05-21 13:55:18 -04008084 phba->sli4_hba.physical_port =
8085 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
James Smart962bc512013-01-03 15:44:00 -05008086 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8087 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
8088 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
8089 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
8090
8091 if (rc != MBX_TIMEOUT)
8092 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04008093
8094 /*
James Smart67d12732012-08-03 12:36:13 -04008095 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04008096 */
James Smart895427b2017-02-12 13:52:30 -08008097 io_channel = phba->io_channel_irqs;
James Smartda0436e2009-05-22 14:51:39 -04008098
James Smart67d12732012-08-03 12:36:13 -04008099 /* Set up HBA event queue */
James Smart895427b2017-02-12 13:52:30 -08008100 if (io_channel && !phba->sli4_hba.hba_eq) {
James Smart2e90f4b2011-12-13 13:22:37 -05008101 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8102 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05008103 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04008104 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05008105 }
James Smart895427b2017-02-12 13:52:30 -08008106 for (qidx = 0; qidx < io_channel; qidx++) {
8107 if (!phba->sli4_hba.hba_eq[qidx]) {
James Smartda0436e2009-05-22 14:51:39 -04008108 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8109 "0522 Fast-path EQ (%d) not "
James Smart895427b2017-02-12 13:52:30 -08008110 "allocated\n", qidx);
James Smart1b511972011-12-13 13:23:09 -05008111 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008112 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008113 }
James Smart895427b2017-02-12 13:52:30 -08008114 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[qidx],
8115 phba->cfg_fcp_imax);
James Smartda0436e2009-05-22 14:51:39 -04008116 if (rc) {
8117 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8118 "0523 Failed setup of fast-path EQ "
James Smart895427b2017-02-12 13:52:30 -08008119 "(%d), rc = 0x%x\n", qidx,
James Smarta2fc4aef2014-09-03 12:57:55 -04008120 (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08008121 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008122 }
8123 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008124 "2584 HBA EQ setup: queue[%d]-id=%d\n",
8125 qidx, phba->sli4_hba.hba_eq[qidx]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04008126 }
8127
James Smart895427b2017-02-12 13:52:30 -08008128 if (phba->cfg_nvme_io_channel) {
8129 if (!phba->sli4_hba.nvme_cq || !phba->sli4_hba.nvme_wq) {
James Smart67d12732012-08-03 12:36:13 -04008130 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008131 "6084 Fast-path NVME %s array not allocated\n",
8132 (phba->sli4_hba.nvme_cq) ? "CQ" : "WQ");
James Smart67d12732012-08-03 12:36:13 -04008133 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008134 goto out_destroy;
James Smart67d12732012-08-03 12:36:13 -04008135 }
8136
James Smart895427b2017-02-12 13:52:30 -08008137 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
8138 rc = lpfc_create_wq_cq(phba,
8139 phba->sli4_hba.hba_eq[
8140 qidx % io_channel],
8141 phba->sli4_hba.nvme_cq[qidx],
8142 phba->sli4_hba.nvme_wq[qidx],
8143 &phba->sli4_hba.nvme_cq_map[qidx],
8144 qidx, LPFC_NVME);
8145 if (rc) {
8146 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8147 "6123 Failed to setup fastpath "
8148 "NVME WQ/CQ (%d), rc = 0x%x\n",
8149 qidx, (uint32_t)rc);
8150 goto out_destroy;
8151 }
8152 }
James Smart67d12732012-08-03 12:36:13 -04008153 }
8154
James Smart895427b2017-02-12 13:52:30 -08008155 if (phba->cfg_fcp_io_channel) {
8156 /* Set up fast-path FCP Response Complete Queue */
8157 if (!phba->sli4_hba.fcp_cq || !phba->sli4_hba.fcp_wq) {
James Smart67d12732012-08-03 12:36:13 -04008158 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008159 "3148 Fast-path FCP %s array not allocated\n",
8160 phba->sli4_hba.fcp_cq ? "WQ" : "CQ");
James Smart67d12732012-08-03 12:36:13 -04008161 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008162 goto out_destroy;
James Smart67d12732012-08-03 12:36:13 -04008163 }
8164
James Smart895427b2017-02-12 13:52:30 -08008165 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
8166 rc = lpfc_create_wq_cq(phba,
8167 phba->sli4_hba.hba_eq[
8168 qidx % io_channel],
8169 phba->sli4_hba.fcp_cq[qidx],
8170 phba->sli4_hba.fcp_wq[qidx],
8171 &phba->sli4_hba.fcp_cq_map[qidx],
8172 qidx, LPFC_FCP);
8173 if (rc) {
8174 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8175 "0535 Failed to setup fastpath "
8176 "FCP WQ/CQ (%d), rc = 0x%x\n",
8177 qidx, (uint32_t)rc);
8178 goto out_destroy;
8179 }
8180 }
James Smart67d12732012-08-03 12:36:13 -04008181 }
James Smartda0436e2009-05-22 14:51:39 -04008182
8183 /*
James Smart895427b2017-02-12 13:52:30 -08008184 * Set up Slow Path Complete Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04008185 */
8186
James Smart895427b2017-02-12 13:52:30 -08008187 /* Set up slow-path MBOX CQ/MQ */
8188
8189 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
James Smartda0436e2009-05-22 14:51:39 -04008190 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008191 "0528 %s not allocated\n",
8192 phba->sli4_hba.mbx_cq ?
8193 "Mailbox WQ" : "Mailbox CQ");
James Smart1b511972011-12-13 13:23:09 -05008194 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008195 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008196 }
James Smart895427b2017-02-12 13:52:30 -08008197
8198 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8199 phba->sli4_hba.mbx_cq,
8200 phba->sli4_hba.mbx_wq,
8201 NULL, 0, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04008202 if (rc) {
8203 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008204 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
8205 (uint32_t)rc);
8206 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008207 }
James Smartda0436e2009-05-22 14:51:39 -04008208
James Smart895427b2017-02-12 13:52:30 -08008209 /* Set up slow-path ELS WQ/CQ */
8210 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
James Smartda0436e2009-05-22 14:51:39 -04008211 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008212 "0530 ELS %s not allocated\n",
8213 phba->sli4_hba.els_cq ? "WQ" : "CQ");
James Smart1b511972011-12-13 13:23:09 -05008214 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008215 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008216 }
James Smart895427b2017-02-12 13:52:30 -08008217 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8218 phba->sli4_hba.els_cq,
8219 phba->sli4_hba.els_wq,
8220 NULL, 0, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04008221 if (rc) {
8222 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008223 "0529 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
8224 (uint32_t)rc);
8225 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008226 }
8227 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8228 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
8229 phba->sli4_hba.els_wq->queue_id,
8230 phba->sli4_hba.els_cq->queue_id);
8231
James Smart895427b2017-02-12 13:52:30 -08008232 if (phba->cfg_nvme_io_channel) {
8233 /* Set up NVME LS Complete Queue */
8234 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
8235 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8236 "6091 LS %s not allocated\n",
8237 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
8238 rc = -ENOMEM;
8239 goto out_destroy;
8240 }
8241 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8242 phba->sli4_hba.nvmels_cq,
8243 phba->sli4_hba.nvmels_wq,
8244 NULL, 0, LPFC_NVME_LS);
8245 if (rc) {
8246 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8247 "0529 Failed setup of NVVME LS WQ/CQ: "
8248 "rc = 0x%x\n", (uint32_t)rc);
8249 goto out_destroy;
8250 }
8251
8252 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8253 "6096 ELS WQ setup: wq-id=%d, "
8254 "parent cq-id=%d\n",
8255 phba->sli4_hba.nvmels_wq->queue_id,
8256 phba->sli4_hba.nvmels_cq->queue_id);
8257 }
8258
James Smartda0436e2009-05-22 14:51:39 -04008259 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
8260 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8261 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05008262 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008263 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008264 }
James Smart73d91e52011-10-10 21:32:10 -04008265
8266 lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
8267 lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
8268
James Smartda0436e2009-05-22 14:51:39 -04008269 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04008270 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04008271 if (rc) {
8272 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8273 "0541 Failed setup of Receive Queue: "
James Smarta2fc4aef2014-09-03 12:57:55 -04008274 "rc = 0x%x\n", (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08008275 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008276 }
James Smart73d91e52011-10-10 21:32:10 -04008277
James Smartda0436e2009-05-22 14:51:39 -04008278 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8279 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
8280 "parent cq-id=%d\n",
8281 phba->sli4_hba.hdr_rq->queue_id,
8282 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04008283 phba->sli4_hba.els_cq->queue_id);
James Smart1ba981f2014-02-20 09:56:45 -05008284
8285 if (phba->cfg_fof) {
8286 rc = lpfc_fof_queue_setup(phba);
8287 if (rc) {
8288 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8289 "0549 Failed setup of FOF Queues: "
8290 "rc = 0x%x\n", rc);
James Smart895427b2017-02-12 13:52:30 -08008291 goto out_destroy;
James Smart1ba981f2014-02-20 09:56:45 -05008292 }
8293 }
James Smart2c9c5a02015-04-07 15:07:15 -04008294
8295 /*
8296 * Configure EQ delay multipier for interrupt coalescing using
8297 * MODIFY_EQ_DELAY for all EQs created, LPFC_MAX_EQ_DELAY at a time.
8298 */
James Smart895427b2017-02-12 13:52:30 -08008299 for (qidx = 0; qidx < io_channel; qidx += LPFC_MAX_EQ_DELAY)
8300 lpfc_modify_hba_eq_delay(phba, qidx);
James Smartda0436e2009-05-22 14:51:39 -04008301 return 0;
8302
James Smart895427b2017-02-12 13:52:30 -08008303out_destroy:
8304 lpfc_sli4_queue_unset(phba);
James Smartda0436e2009-05-22 14:51:39 -04008305out_error:
8306 return rc;
8307}
8308
8309/**
8310 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
8311 * @phba: pointer to lpfc hba data structure.
8312 *
8313 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
8314 * operation.
8315 *
8316 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008317 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008318 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008319 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008320 **/
8321void
8322lpfc_sli4_queue_unset(struct lpfc_hba *phba)
8323{
James Smart895427b2017-02-12 13:52:30 -08008324 int qidx;
James Smartda0436e2009-05-22 14:51:39 -04008325
James Smart1ba981f2014-02-20 09:56:45 -05008326 /* Unset the queues created for Flash Optimized Fabric operations */
8327 if (phba->cfg_fof)
8328 lpfc_fof_queue_destroy(phba);
James Smart895427b2017-02-12 13:52:30 -08008329
James Smartda0436e2009-05-22 14:51:39 -04008330 /* Unset mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08008331 if (phba->sli4_hba.mbx_wq)
8332 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
8333
8334 /* Unset NVME LS work queue */
8335 if (phba->sli4_hba.nvmels_wq)
8336 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
8337
James Smartda0436e2009-05-22 14:51:39 -04008338 /* Unset ELS work queue */
James Smart895427b2017-02-12 13:52:30 -08008339 if (phba->sli4_hba.els_cq)
8340 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
8341
James Smartda0436e2009-05-22 14:51:39 -04008342 /* Unset unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08008343 if (phba->sli4_hba.hdr_rq)
8344 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
8345 phba->sli4_hba.dat_rq);
8346
James Smartda0436e2009-05-22 14:51:39 -04008347 /* Unset FCP work queue */
James Smart895427b2017-02-12 13:52:30 -08008348 if (phba->sli4_hba.fcp_wq)
8349 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
8350 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[qidx]);
8351
8352 /* Unset NVME work queue */
8353 if (phba->sli4_hba.nvme_wq) {
8354 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
8355 lpfc_wq_destroy(phba, phba->sli4_hba.nvme_wq[qidx]);
James Smart67d12732012-08-03 12:36:13 -04008356 }
James Smart895427b2017-02-12 13:52:30 -08008357
James Smartda0436e2009-05-22 14:51:39 -04008358 /* Unset mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08008359 if (phba->sli4_hba.mbx_cq)
8360 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
8361
James Smartda0436e2009-05-22 14:51:39 -04008362 /* Unset ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08008363 if (phba->sli4_hba.els_cq)
8364 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
8365
8366 /* Unset NVME LS complete queue */
8367 if (phba->sli4_hba.nvmels_cq)
8368 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
8369
8370 /* Unset NVME response complete queue */
8371 if (phba->sli4_hba.nvme_cq)
8372 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
8373 lpfc_cq_destroy(phba, phba->sli4_hba.nvme_cq[qidx]);
8374
James Smartda0436e2009-05-22 14:51:39 -04008375 /* Unset FCP response complete queue */
James Smart895427b2017-02-12 13:52:30 -08008376 if (phba->sli4_hba.fcp_cq)
8377 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
8378 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[qidx]);
8379
James Smartda0436e2009-05-22 14:51:39 -04008380 /* Unset fast-path event queue */
James Smart895427b2017-02-12 13:52:30 -08008381 if (phba->sli4_hba.hba_eq)
8382 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++)
8383 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[qidx]);
James Smartda0436e2009-05-22 14:51:39 -04008384}
8385
8386/**
8387 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
8388 * @phba: pointer to lpfc hba data structure.
8389 *
8390 * This routine is invoked to allocate and set up a pool of completion queue
8391 * events. The body of the completion queue event is a completion queue entry
8392 * CQE. For now, this pool is used for the interrupt service routine to queue
8393 * the following HBA completion queue events for the worker thread to process:
8394 * - Mailbox asynchronous events
8395 * - Receive queue completion unsolicited events
8396 * Later, this can be used for all the slow-path events.
8397 *
8398 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008399 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008400 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04008401 **/
8402static int
8403lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
8404{
8405 struct lpfc_cq_event *cq_event;
8406 int i;
8407
8408 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
8409 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
8410 if (!cq_event)
8411 goto out_pool_create_fail;
8412 list_add_tail(&cq_event->list,
8413 &phba->sli4_hba.sp_cqe_event_pool);
8414 }
8415 return 0;
8416
8417out_pool_create_fail:
8418 lpfc_sli4_cq_event_pool_destroy(phba);
8419 return -ENOMEM;
8420}
8421
8422/**
8423 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
8424 * @phba: pointer to lpfc hba data structure.
8425 *
8426 * This routine is invoked to free the pool of completion queue events at
8427 * driver unload time. Note that, it is the responsibility of the driver
8428 * cleanup routine to free all the outstanding completion-queue events
8429 * allocated from this pool back into the pool before invoking this routine
8430 * to destroy the pool.
8431 **/
8432static void
8433lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
8434{
8435 struct lpfc_cq_event *cq_event, *next_cq_event;
8436
8437 list_for_each_entry_safe(cq_event, next_cq_event,
8438 &phba->sli4_hba.sp_cqe_event_pool, list) {
8439 list_del(&cq_event->list);
8440 kfree(cq_event);
8441 }
8442}
8443
8444/**
8445 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
8446 * @phba: pointer to lpfc hba data structure.
8447 *
8448 * This routine is the lock free version of the API invoked to allocate a
8449 * completion-queue event from the free pool.
8450 *
8451 * Return: Pointer to the newly allocated completion-queue event if successful
8452 * NULL otherwise.
8453 **/
8454struct lpfc_cq_event *
8455__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
8456{
8457 struct lpfc_cq_event *cq_event = NULL;
8458
8459 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
8460 struct lpfc_cq_event, list);
8461 return cq_event;
8462}
8463
8464/**
8465 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
8466 * @phba: pointer to lpfc hba data structure.
8467 *
8468 * This routine is the lock version of the API invoked to allocate a
8469 * completion-queue event from the free pool.
8470 *
8471 * Return: Pointer to the newly allocated completion-queue event if successful
8472 * NULL otherwise.
8473 **/
8474struct lpfc_cq_event *
8475lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
8476{
8477 struct lpfc_cq_event *cq_event;
8478 unsigned long iflags;
8479
8480 spin_lock_irqsave(&phba->hbalock, iflags);
8481 cq_event = __lpfc_sli4_cq_event_alloc(phba);
8482 spin_unlock_irqrestore(&phba->hbalock, iflags);
8483 return cq_event;
8484}
8485
8486/**
8487 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
8488 * @phba: pointer to lpfc hba data structure.
8489 * @cq_event: pointer to the completion queue event to be freed.
8490 *
8491 * This routine is the lock free version of the API invoked to release a
8492 * completion-queue event back into the free pool.
8493 **/
8494void
8495__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
8496 struct lpfc_cq_event *cq_event)
8497{
8498 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
8499}
8500
8501/**
8502 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
8503 * @phba: pointer to lpfc hba data structure.
8504 * @cq_event: pointer to the completion queue event to be freed.
8505 *
8506 * This routine is the lock version of the API invoked to release a
8507 * completion-queue event back into the free pool.
8508 **/
8509void
8510lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
8511 struct lpfc_cq_event *cq_event)
8512{
8513 unsigned long iflags;
8514 spin_lock_irqsave(&phba->hbalock, iflags);
8515 __lpfc_sli4_cq_event_release(phba, cq_event);
8516 spin_unlock_irqrestore(&phba->hbalock, iflags);
8517}
8518
8519/**
8520 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
8521 * @phba: pointer to lpfc hba data structure.
8522 *
8523 * This routine is to free all the pending completion-queue events to the
8524 * back into the free pool for device reset.
8525 **/
8526static void
8527lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
8528{
8529 LIST_HEAD(cqelist);
8530 struct lpfc_cq_event *cqe;
8531 unsigned long iflags;
8532
8533 /* Retrieve all the pending WCQEs from pending WCQE lists */
8534 spin_lock_irqsave(&phba->hbalock, iflags);
8535 /* Pending FCP XRI abort events */
8536 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
8537 &cqelist);
8538 /* Pending ELS XRI abort events */
8539 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
8540 &cqelist);
8541 /* Pending asynnc events */
8542 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
8543 &cqelist);
8544 spin_unlock_irqrestore(&phba->hbalock, iflags);
8545
8546 while (!list_empty(&cqelist)) {
8547 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
8548 lpfc_sli4_cq_event_release(phba, cqe);
8549 }
8550}
8551
8552/**
8553 * lpfc_pci_function_reset - Reset pci function.
8554 * @phba: pointer to lpfc hba data structure.
8555 *
8556 * This routine is invoked to request a PCI function reset. It will destroys
8557 * all resources assigned to the PCI function which originates this request.
8558 *
8559 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008560 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008561 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008562 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008563 **/
8564int
8565lpfc_pci_function_reset(struct lpfc_hba *phba)
8566{
8567 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05008568 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04008569 uint32_t shdr_status, shdr_add_status;
James Smart2f6fa2c2014-09-03 12:57:08 -04008570 uint32_t rdy_chk;
8571 uint32_t port_reset = 0;
James Smartda0436e2009-05-22 14:51:39 -04008572 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05008573 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -05008574 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -04008575
James Smart2fcee4b2010-12-15 17:57:46 -05008576 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8577 switch (if_type) {
8578 case LPFC_SLI_INTF_IF_TYPE_0:
8579 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8580 GFP_KERNEL);
8581 if (!mboxq) {
8582 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8583 "0494 Unable to allocate memory for "
8584 "issuing SLI_FUNCTION_RESET mailbox "
8585 "command\n");
8586 return -ENOMEM;
8587 }
8588
8589 /* Setup PCI function reset mailbox-ioctl command */
8590 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8591 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
8592 LPFC_SLI4_MBX_EMBED);
8593 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8594 shdr = (union lpfc_sli4_cfg_shdr *)
8595 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
8596 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8597 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
8598 &shdr->response);
8599 if (rc != MBX_TIMEOUT)
8600 mempool_free(mboxq, phba->mbox_mem_pool);
8601 if (shdr_status || shdr_add_status || rc) {
8602 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8603 "0495 SLI_FUNCTION_RESET mailbox "
8604 "failed with status x%x add_status x%x,"
8605 " mbx status x%x\n",
8606 shdr_status, shdr_add_status, rc);
8607 rc = -ENXIO;
8608 }
8609 break;
8610 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2f6fa2c2014-09-03 12:57:08 -04008611wait:
8612 /*
8613 * Poll the Port Status Register and wait for RDY for
8614 * up to 30 seconds. If the port doesn't respond, treat
8615 * it as an error.
8616 */
James Smart77d093f2015-04-07 15:07:08 -04008617 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
James Smart2f6fa2c2014-09-03 12:57:08 -04008618 if (lpfc_readl(phba->sli4_hba.u.if_type2.
8619 STATUSregaddr, &reg_data.word0)) {
8620 rc = -ENODEV;
8621 goto out;
8622 }
8623 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
8624 break;
8625 msleep(20);
8626 }
8627
8628 if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
8629 phba->work_status[0] = readl(
8630 phba->sli4_hba.u.if_type2.ERR1regaddr);
8631 phba->work_status[1] = readl(
8632 phba->sli4_hba.u.if_type2.ERR2regaddr);
8633 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8634 "2890 Port not ready, port status reg "
8635 "0x%x error 1=0x%x, error 2=0x%x\n",
8636 reg_data.word0,
8637 phba->work_status[0],
8638 phba->work_status[1]);
8639 rc = -ENODEV;
8640 goto out;
8641 }
8642
8643 if (!port_reset) {
8644 /*
8645 * Reset the port now
8646 */
James Smart2fcee4b2010-12-15 17:57:46 -05008647 reg_data.word0 = 0;
8648 bf_set(lpfc_sliport_ctrl_end, &reg_data,
8649 LPFC_SLIPORT_LITTLE_ENDIAN);
8650 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
8651 LPFC_SLIPORT_INIT_PORT);
8652 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
8653 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -05008654 /* flush */
James Smart2b81f942012-03-01 22:37:18 -05008655 pci_read_config_word(phba->pcidev,
8656 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -05008657
James Smart2f6fa2c2014-09-03 12:57:08 -04008658 port_reset = 1;
8659 msleep(20);
8660 goto wait;
8661 } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
8662 rc = -ENODEV;
8663 goto out;
James Smart2fcee4b2010-12-15 17:57:46 -05008664 }
8665 break;
James Smart2f6fa2c2014-09-03 12:57:08 -04008666
James Smart2fcee4b2010-12-15 17:57:46 -05008667 case LPFC_SLI_INTF_IF_TYPE_1:
8668 default:
8669 break;
James Smartda0436e2009-05-22 14:51:39 -04008670 }
8671
James Smart73d91e52011-10-10 21:32:10 -04008672out:
James Smart2fcee4b2010-12-15 17:57:46 -05008673 /* Catch the not-ready port failure after a port reset. */
James Smart2f6fa2c2014-09-03 12:57:08 -04008674 if (rc) {
James Smart229adb02013-04-17 20:16:51 -04008675 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8676 "3317 HBA not functional: IP Reset Failed "
James Smart2f6fa2c2014-09-03 12:57:08 -04008677 "try: echo fw_reset > board_mode\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008678 rc = -ENODEV;
James Smart229adb02013-04-17 20:16:51 -04008679 }
James Smart2fcee4b2010-12-15 17:57:46 -05008680
James Smartda0436e2009-05-22 14:51:39 -04008681 return rc;
8682}
8683
8684/**
James Smartda0436e2009-05-22 14:51:39 -04008685 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
8686 * @phba: pointer to lpfc hba data structure.
8687 *
8688 * This routine is invoked to set up the PCI device memory space for device
8689 * with SLI-4 interface spec.
8690 *
8691 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008692 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008693 * other values - error
8694 **/
8695static int
8696lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
8697{
8698 struct pci_dev *pdev;
8699 unsigned long bar0map_len, bar1map_len, bar2map_len;
8700 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05008701 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04008702
8703 /* Obtain PCI device reference */
8704 if (!phba->pcidev)
8705 return error;
8706 else
8707 pdev = phba->pcidev;
8708
8709 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05008710 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
8711 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
8712 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
8713 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smartda0436e2009-05-22 14:51:39 -04008714 return error;
Michael Reed8e685972009-09-18 12:02:05 -05008715 }
8716 }
James Smartda0436e2009-05-22 14:51:39 -04008717
James Smart2fcee4b2010-12-15 17:57:46 -05008718 /*
8719 * The BARs and register set definitions and offset locations are
8720 * dependent on the if_type.
8721 */
8722 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
8723 &phba->sli4_hba.sli_intf.word0)) {
8724 return error;
8725 }
8726
8727 /* There is no SLI3 failback for SLI4 devices. */
8728 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
8729 LPFC_SLI_INTF_VALID) {
8730 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8731 "2894 SLI_INTF reg contents invalid "
8732 "sli_intf reg 0x%x\n",
8733 phba->sli4_hba.sli_intf.word0);
8734 return error;
8735 }
8736
8737 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8738 /*
8739 * Get the bus address of SLI4 device Bar regions and the
8740 * number of bytes required by each mapping. The mapping of the
8741 * particular PCI BARs regions is dependent on the type of
8742 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04008743 */
James Smartf5ca6f22013-09-06 12:21:09 -04008744 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
8745 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
8746 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
James Smart2fcee4b2010-12-15 17:57:46 -05008747
8748 /*
8749 * Map SLI4 PCI Config Space Register base to a kernel virtual
8750 * addr
8751 */
8752 phba->sli4_hba.conf_regs_memmap_p =
8753 ioremap(phba->pci_bar0_map, bar0map_len);
8754 if (!phba->sli4_hba.conf_regs_memmap_p) {
8755 dev_printk(KERN_ERR, &pdev->dev,
8756 "ioremap failed for SLI4 PCI config "
8757 "registers.\n");
8758 goto out;
8759 }
James Smartf5ca6f22013-09-06 12:21:09 -04008760 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008761 /* Set up BAR0 PCI config space register memory map */
8762 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05008763 } else {
8764 phba->pci_bar0_map = pci_resource_start(pdev, 1);
8765 bar0map_len = pci_resource_len(pdev, 1);
James Smart2fcee4b2010-12-15 17:57:46 -05008766 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
8767 dev_printk(KERN_ERR, &pdev->dev,
8768 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
8769 goto out;
8770 }
8771 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008772 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008773 if (!phba->sli4_hba.conf_regs_memmap_p) {
8774 dev_printk(KERN_ERR, &pdev->dev,
8775 "ioremap failed for SLI4 PCI config "
8776 "registers.\n");
8777 goto out;
8778 }
8779 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04008780 }
8781
James Smartc31098c2011-04-16 11:03:33 -04008782 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04008783 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
James Smart2fcee4b2010-12-15 17:57:46 -05008784 /*
8785 * Map SLI4 if type 0 HBA Control Register base to a kernel
8786 * virtual address and setup the registers.
8787 */
James Smartf5ca6f22013-09-06 12:21:09 -04008788 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
8789 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
James Smart2fcee4b2010-12-15 17:57:46 -05008790 phba->sli4_hba.ctrl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008791 ioremap(phba->pci_bar1_map, bar1map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008792 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
8793 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04008794 "ioremap failed for SLI4 HBA control registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008795 goto out_iounmap_conf;
8796 }
James Smartf5ca6f22013-09-06 12:21:09 -04008797 phba->pci_bar2_memmap_p = phba->sli4_hba.ctrl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008798 lpfc_sli4_bar1_register_memmap(phba);
James Smartda0436e2009-05-22 14:51:39 -04008799 }
8800
James Smartc31098c2011-04-16 11:03:33 -04008801 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04008802 (pci_resource_start(pdev, PCI_64BIT_BAR4))) {
James Smart2fcee4b2010-12-15 17:57:46 -05008803 /*
8804 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
8805 * virtual address and setup the registers.
8806 */
James Smartf5ca6f22013-09-06 12:21:09 -04008807 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
8808 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
James Smart2fcee4b2010-12-15 17:57:46 -05008809 phba->sli4_hba.drbl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008810 ioremap(phba->pci_bar2_map, bar2map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008811 if (!phba->sli4_hba.drbl_regs_memmap_p) {
8812 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04008813 "ioremap failed for SLI4 HBA doorbell registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008814 goto out_iounmap_ctrl;
8815 }
James Smartf5ca6f22013-09-06 12:21:09 -04008816 phba->pci_bar4_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008817 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
8818 if (error)
8819 goto out_iounmap_all;
James Smartda0436e2009-05-22 14:51:39 -04008820 }
8821
James Smartda0436e2009-05-22 14:51:39 -04008822 return 0;
8823
8824out_iounmap_all:
8825 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
8826out_iounmap_ctrl:
8827 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
8828out_iounmap_conf:
8829 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8830out:
8831 return error;
8832}
8833
8834/**
8835 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
8836 * @phba: pointer to lpfc hba data structure.
8837 *
8838 * This routine is invoked to unset the PCI device memory space for device
8839 * with SLI-4 interface spec.
8840 **/
8841static void
8842lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
8843{
James Smart2e90f4b2011-12-13 13:22:37 -05008844 uint32_t if_type;
8845 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -04008846
James Smart2e90f4b2011-12-13 13:22:37 -05008847 switch (if_type) {
8848 case LPFC_SLI_INTF_IF_TYPE_0:
8849 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
8850 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
8851 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8852 break;
8853 case LPFC_SLI_INTF_IF_TYPE_2:
8854 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8855 break;
8856 case LPFC_SLI_INTF_IF_TYPE_1:
8857 default:
8858 dev_printk(KERN_ERR, &phba->pcidev->dev,
8859 "FATAL - unsupported SLI4 interface type - %d\n",
8860 if_type);
8861 break;
8862 }
James Smartda0436e2009-05-22 14:51:39 -04008863}
8864
8865/**
James Smart3772a992009-05-22 14:50:54 -04008866 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
8867 * @phba: pointer to lpfc hba data structure.
8868 *
8869 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -08008870 * with SLI-3 interface specs.
James Smart3772a992009-05-22 14:50:54 -04008871 *
8872 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008873 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008874 * other values - error
8875 **/
8876static int
8877lpfc_sli_enable_msix(struct lpfc_hba *phba)
8878{
Christoph Hellwig45ffac12017-02-12 13:52:26 -08008879 int rc;
James Smart3772a992009-05-22 14:50:54 -04008880 LPFC_MBOXQ_t *pmb;
8881
8882 /* Set up MSI-X multi-message vectors */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08008883 rc = pci_alloc_irq_vectors(phba->pcidev,
8884 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
8885 if (rc < 0) {
James Smart3772a992009-05-22 14:50:54 -04008886 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8887 "0420 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02008888 goto vec_fail_out;
James Smart3772a992009-05-22 14:50:54 -04008889 }
Christoph Hellwig45ffac12017-02-12 13:52:26 -08008890
James Smart3772a992009-05-22 14:50:54 -04008891 /*
8892 * Assign MSI-X vectors to interrupt handlers
8893 */
8894
8895 /* vector-0 is associated to slow-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08008896 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
James Smarted243d32015-05-21 13:55:25 -04008897 &lpfc_sli_sp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04008898 LPFC_SP_DRIVER_HANDLER_NAME, phba);
8899 if (rc) {
8900 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8901 "0421 MSI-X slow-path request_irq failed "
8902 "(%d)\n", rc);
8903 goto msi_fail_out;
8904 }
8905
8906 /* vector-1 is associated to fast-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08008907 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
James Smarted243d32015-05-21 13:55:25 -04008908 &lpfc_sli_fp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04008909 LPFC_FP_DRIVER_HANDLER_NAME, phba);
8910
8911 if (rc) {
8912 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8913 "0429 MSI-X fast-path request_irq failed "
8914 "(%d)\n", rc);
8915 goto irq_fail_out;
8916 }
8917
8918 /*
8919 * Configure HBA MSI-X attention conditions to messages
8920 */
8921 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8922
8923 if (!pmb) {
8924 rc = -ENOMEM;
8925 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8926 "0474 Unable to allocate memory for issuing "
8927 "MBOX_CONFIG_MSI command\n");
8928 goto mem_fail_out;
8929 }
8930 rc = lpfc_config_msi(phba, pmb);
8931 if (rc)
8932 goto mbx_fail_out;
8933 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
8934 if (rc != MBX_SUCCESS) {
8935 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
8936 "0351 Config MSI mailbox command failed, "
8937 "mbxCmd x%x, mbxStatus x%x\n",
8938 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
8939 goto mbx_fail_out;
8940 }
8941
8942 /* Free memory allocated for mailbox command */
8943 mempool_free(pmb, phba->mbox_mem_pool);
8944 return rc;
8945
8946mbx_fail_out:
8947 /* Free memory allocated for mailbox command */
8948 mempool_free(pmb, phba->mbox_mem_pool);
8949
8950mem_fail_out:
8951 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08008952 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
James Smart3772a992009-05-22 14:50:54 -04008953
8954irq_fail_out:
8955 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08008956 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
James Smart3772a992009-05-22 14:50:54 -04008957
8958msi_fail_out:
8959 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08008960 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02008961
8962vec_fail_out:
James Smart3772a992009-05-22 14:50:54 -04008963 return rc;
8964}
8965
8966/**
James Smart3772a992009-05-22 14:50:54 -04008967 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
8968 * @phba: pointer to lpfc hba data structure.
8969 *
8970 * This routine is invoked to enable the MSI interrupt mode to device with
8971 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
8972 * enable the MSI vector. The device driver is responsible for calling the
8973 * request_irq() to register MSI vector with a interrupt the handler, which
8974 * is done in this function.
8975 *
8976 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008977 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008978 * other values - error
8979 */
8980static int
8981lpfc_sli_enable_msi(struct lpfc_hba *phba)
8982{
8983 int rc;
8984
8985 rc = pci_enable_msi(phba->pcidev);
8986 if (!rc)
8987 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8988 "0462 PCI enable MSI mode success.\n");
8989 else {
8990 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8991 "0471 PCI enable MSI mode failed (%d)\n", rc);
8992 return rc;
8993 }
8994
8995 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04008996 0, LPFC_DRIVER_NAME, phba);
James Smart3772a992009-05-22 14:50:54 -04008997 if (rc) {
8998 pci_disable_msi(phba->pcidev);
8999 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9000 "0478 MSI request_irq failed (%d)\n", rc);
9001 }
9002 return rc;
9003}
9004
9005/**
James Smart3772a992009-05-22 14:50:54 -04009006 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
9007 * @phba: pointer to lpfc hba data structure.
9008 *
9009 * This routine is invoked to enable device interrupt and associate driver's
9010 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
9011 * spec. Depends on the interrupt mode configured to the driver, the driver
9012 * will try to fallback from the configured interrupt mode to an interrupt
9013 * mode which is supported by the platform, kernel, and device in the order
9014 * of:
9015 * MSI-X -> MSI -> IRQ.
9016 *
9017 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009018 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009019 * other values - error
9020 **/
9021static uint32_t
9022lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9023{
9024 uint32_t intr_mode = LPFC_INTR_ERROR;
9025 int retval;
9026
9027 if (cfg_mode == 2) {
9028 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
9029 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
9030 if (!retval) {
9031 /* Now, try to enable MSI-X interrupt mode */
9032 retval = lpfc_sli_enable_msix(phba);
9033 if (!retval) {
9034 /* Indicate initialization to MSI-X mode */
9035 phba->intr_type = MSIX;
9036 intr_mode = 2;
9037 }
9038 }
9039 }
9040
9041 /* Fallback to MSI if MSI-X initialization failed */
9042 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9043 retval = lpfc_sli_enable_msi(phba);
9044 if (!retval) {
9045 /* Indicate initialization to MSI mode */
9046 phba->intr_type = MSI;
9047 intr_mode = 1;
9048 }
9049 }
9050
9051 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9052 if (phba->intr_type == NONE) {
9053 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
9054 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9055 if (!retval) {
9056 /* Indicate initialization to INTx mode */
9057 phba->intr_type = INTx;
9058 intr_mode = 0;
9059 }
9060 }
9061 return intr_mode;
9062}
9063
9064/**
9065 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
9066 * @phba: pointer to lpfc hba data structure.
9067 *
9068 * This routine is invoked to disable device interrupt and disassociate the
9069 * driver's interrupt handler(s) from interrupt vector(s) to device with
9070 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
9071 * release the interrupt vector(s) for the message signaled interrupt.
9072 **/
9073static void
9074lpfc_sli_disable_intr(struct lpfc_hba *phba)
9075{
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009076 int nr_irqs, i;
9077
James Smart3772a992009-05-22 14:50:54 -04009078 if (phba->intr_type == MSIX)
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009079 nr_irqs = LPFC_MSIX_VECTORS;
9080 else
9081 nr_irqs = 1;
9082
9083 for (i = 0; i < nr_irqs; i++)
9084 free_irq(pci_irq_vector(phba->pcidev, i), phba);
9085 pci_free_irq_vectors(phba->pcidev);
James Smart3772a992009-05-22 14:50:54 -04009086
9087 /* Reset interrupt management states */
9088 phba->intr_type = NONE;
9089 phba->sli.slistat.sli_intr = 0;
James Smart3772a992009-05-22 14:50:54 -04009090}
9091
9092/**
James Smart895427b2017-02-12 13:52:30 -08009093 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
James Smart7bb03bb2013-04-17 20:19:16 -04009094 * @phba: pointer to lpfc hba data structure.
James Smart895427b2017-02-12 13:52:30 -08009095 * @vectors: number of msix vectors allocated.
James Smart7bb03bb2013-04-17 20:19:16 -04009096 *
James Smart895427b2017-02-12 13:52:30 -08009097 * The routine will figure out the CPU affinity assignment for every
9098 * MSI-X vector allocated for the HBA. The hba_eq_hdl will be updated
9099 * with a pointer to the CPU mask that defines ALL the CPUs this vector
9100 * can be associated with. If the vector can be unquely associated with
9101 * a single CPU, that CPU will be recorded in hba_eq_hdl[index].cpu.
9102 * In addition, the CPU to IO channel mapping will be calculated
9103 * and the phba->sli4_hba.cpu_map array will reflect this.
James Smart7bb03bb2013-04-17 20:19:16 -04009104 */
James Smart895427b2017-02-12 13:52:30 -08009105static void
9106lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
James Smart7bb03bb2013-04-17 20:19:16 -04009107{
9108 struct lpfc_vector_map_info *cpup;
James Smart895427b2017-02-12 13:52:30 -08009109 int index = 0;
9110 int vec = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04009111 int cpu;
James Smart7bb03bb2013-04-17 20:19:16 -04009112#ifdef CONFIG_X86
9113 struct cpuinfo_x86 *cpuinfo;
9114#endif
James Smart7bb03bb2013-04-17 20:19:16 -04009115
9116 /* Init cpu_map array */
9117 memset(phba->sli4_hba.cpu_map, 0xff,
9118 (sizeof(struct lpfc_vector_map_info) *
James Smart895427b2017-02-12 13:52:30 -08009119 phba->sli4_hba.num_present_cpu));
James Smart7bb03bb2013-04-17 20:19:16 -04009120
9121 /* Update CPU map with physical id and core id of each CPU */
9122 cpup = phba->sli4_hba.cpu_map;
9123 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
9124#ifdef CONFIG_X86
9125 cpuinfo = &cpu_data(cpu);
9126 cpup->phys_id = cpuinfo->phys_proc_id;
9127 cpup->core_id = cpuinfo->cpu_core_id;
9128#else
9129 /* No distinction between CPUs for other platforms */
9130 cpup->phys_id = 0;
9131 cpup->core_id = 0;
9132#endif
James Smart895427b2017-02-12 13:52:30 -08009133 cpup->channel_id = index; /* For now round robin */
9134 cpup->irq = pci_irq_vector(phba->pcidev, vec);
9135 vec++;
9136 if (vec >= vectors)
9137 vec = 0;
9138 index++;
9139 if (index >= phba->cfg_fcp_io_channel)
9140 index = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04009141 cpup++;
9142 }
James Smart7bb03bb2013-04-17 20:19:16 -04009143}
9144
9145
9146/**
James Smartda0436e2009-05-22 14:51:39 -04009147 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
9148 * @phba: pointer to lpfc hba data structure.
9149 *
9150 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009151 * with SLI-4 interface spec.
James Smartda0436e2009-05-22 14:51:39 -04009152 *
9153 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009154 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009155 * other values - error
9156 **/
9157static int
9158lpfc_sli4_enable_msix(struct lpfc_hba *phba)
9159{
James Smart75baf692010-06-08 18:31:21 -04009160 int vectors, rc, index;
James Smartda0436e2009-05-22 14:51:39 -04009161
9162 /* Set up MSI-X multi-message vectors */
James Smart895427b2017-02-12 13:52:30 -08009163 vectors = phba->io_channel_irqs;
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009164 if (phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05009165 vectors++;
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009166
James Smart895427b2017-02-12 13:52:30 -08009167 rc = pci_alloc_irq_vectors(phba->pcidev, 2, vectors,
9168 PCI_IRQ_MSIX | PCI_IRQ_AFFINITY);
Alexander Gordeev4f871e12014-09-03 12:56:29 -04009169 if (rc < 0) {
James Smartda0436e2009-05-22 14:51:39 -04009170 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9171 "0484 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009172 goto vec_fail_out;
James Smartda0436e2009-05-22 14:51:39 -04009173 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -04009174 vectors = rc;
James Smart75baf692010-06-08 18:31:21 -04009175
James Smart7bb03bb2013-04-17 20:19:16 -04009176 /* Assign MSI-X vectors to interrupt handlers */
James Smart67d12732012-08-03 12:36:13 -04009177 for (index = 0; index < vectors; index++) {
James Smart4305f182012-08-03 12:36:33 -04009178 memset(&phba->sli4_hba.handler_name[index], 0, 16);
James Smarta2fc4aef2014-09-03 12:57:55 -04009179 snprintf((char *)&phba->sli4_hba.handler_name[index],
9180 LPFC_SLI4_HANDLER_NAME_SZ,
James Smart4305f182012-08-03 12:36:33 -04009181 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -04009182
James Smart895427b2017-02-12 13:52:30 -08009183 phba->sli4_hba.hba_eq_hdl[index].idx = index;
9184 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
9185 atomic_set(&phba->sli4_hba.hba_eq_hdl[index].hba_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -05009186 if (phba->cfg_fof && (index == (vectors - 1)))
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009187 rc = request_irq(pci_irq_vector(phba->pcidev, index),
James Smarted243d32015-05-21 13:55:25 -04009188 &lpfc_sli4_fof_intr_handler, 0,
James Smart1ba981f2014-02-20 09:56:45 -05009189 (char *)&phba->sli4_hba.handler_name[index],
James Smart895427b2017-02-12 13:52:30 -08009190 &phba->sli4_hba.hba_eq_hdl[index]);
James Smart1ba981f2014-02-20 09:56:45 -05009191 else
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009192 rc = request_irq(pci_irq_vector(phba->pcidev, index),
James Smarted243d32015-05-21 13:55:25 -04009193 &lpfc_sli4_hba_intr_handler, 0,
James Smart4305f182012-08-03 12:36:33 -04009194 (char *)&phba->sli4_hba.handler_name[index],
James Smart895427b2017-02-12 13:52:30 -08009195 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -04009196 if (rc) {
9197 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9198 "0486 MSI-X fast-path (%d) "
9199 "request_irq failed (%d)\n", index, rc);
9200 goto cfg_fail_out;
9201 }
9202 }
9203
James Smart1ba981f2014-02-20 09:56:45 -05009204 if (phba->cfg_fof)
9205 vectors--;
9206
James Smart895427b2017-02-12 13:52:30 -08009207 if (vectors != phba->io_channel_irqs) {
James Smart82c3e9b2012-09-29 11:29:50 -04009208 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9209 "3238 Reducing IO channels to match number of "
9210 "MSI-X vectors, requested %d got %d\n",
James Smart895427b2017-02-12 13:52:30 -08009211 phba->io_channel_irqs, vectors);
9212 if (phba->cfg_fcp_io_channel > vectors)
9213 phba->cfg_fcp_io_channel = vectors;
9214 if (phba->cfg_nvme_io_channel > vectors)
9215 phba->cfg_nvme_io_channel = vectors;
9216 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
9217 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
9218 else
9219 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
James Smart82c3e9b2012-09-29 11:29:50 -04009220 }
James Smart895427b2017-02-12 13:52:30 -08009221 lpfc_cpu_affinity_check(phba, vectors);
James Smart7bb03bb2013-04-17 20:19:16 -04009222
James Smartda0436e2009-05-22 14:51:39 -04009223 return rc;
9224
9225cfg_fail_out:
9226 /* free the irq already requested */
James Smart895427b2017-02-12 13:52:30 -08009227 for (--index; index >= 0; index--)
9228 free_irq(pci_irq_vector(phba->pcidev, index),
9229 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -04009230
James Smartda0436e2009-05-22 14:51:39 -04009231 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009232 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009233
9234vec_fail_out:
James Smartda0436e2009-05-22 14:51:39 -04009235 return rc;
9236}
9237
9238/**
James Smartda0436e2009-05-22 14:51:39 -04009239 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
9240 * @phba: pointer to lpfc hba data structure.
9241 *
9242 * This routine is invoked to enable the MSI interrupt mode to device with
9243 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
9244 * to enable the MSI vector. The device driver is responsible for calling
9245 * the request_irq() to register MSI vector with a interrupt the handler,
9246 * which is done in this function.
9247 *
9248 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009249 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009250 * other values - error
9251 **/
9252static int
9253lpfc_sli4_enable_msi(struct lpfc_hba *phba)
9254{
9255 int rc, index;
9256
9257 rc = pci_enable_msi(phba->pcidev);
9258 if (!rc)
9259 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9260 "0487 PCI enable MSI mode success.\n");
9261 else {
9262 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9263 "0488 PCI enable MSI mode failed (%d)\n", rc);
9264 return rc;
9265 }
9266
9267 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04009268 0, LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -04009269 if (rc) {
9270 pci_disable_msi(phba->pcidev);
9271 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9272 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -04009273 return rc;
James Smartda0436e2009-05-22 14:51:39 -04009274 }
9275
James Smart895427b2017-02-12 13:52:30 -08009276 for (index = 0; index < phba->io_channel_irqs; index++) {
9277 phba->sli4_hba.hba_eq_hdl[index].idx = index;
9278 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smartda0436e2009-05-22 14:51:39 -04009279 }
9280
James Smart1ba981f2014-02-20 09:56:45 -05009281 if (phba->cfg_fof) {
James Smart895427b2017-02-12 13:52:30 -08009282 phba->sli4_hba.hba_eq_hdl[index].idx = index;
9283 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smart1ba981f2014-02-20 09:56:45 -05009284 }
James Smart75baf692010-06-08 18:31:21 -04009285 return 0;
James Smartda0436e2009-05-22 14:51:39 -04009286}
9287
9288/**
James Smartda0436e2009-05-22 14:51:39 -04009289 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
9290 * @phba: pointer to lpfc hba data structure.
9291 *
9292 * This routine is invoked to enable device interrupt and associate driver's
9293 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
9294 * interface spec. Depends on the interrupt mode configured to the driver,
9295 * the driver will try to fallback from the configured interrupt mode to an
9296 * interrupt mode which is supported by the platform, kernel, and device in
9297 * the order of:
9298 * MSI-X -> MSI -> IRQ.
9299 *
9300 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009301 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009302 * other values - error
9303 **/
9304static uint32_t
9305lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9306{
9307 uint32_t intr_mode = LPFC_INTR_ERROR;
James Smart895427b2017-02-12 13:52:30 -08009308 int retval, idx;
James Smartda0436e2009-05-22 14:51:39 -04009309
9310 if (cfg_mode == 2) {
9311 /* Preparation before conf_msi mbox cmd */
9312 retval = 0;
9313 if (!retval) {
9314 /* Now, try to enable MSI-X interrupt mode */
9315 retval = lpfc_sli4_enable_msix(phba);
9316 if (!retval) {
9317 /* Indicate initialization to MSI-X mode */
9318 phba->intr_type = MSIX;
9319 intr_mode = 2;
9320 }
9321 }
9322 }
9323
9324 /* Fallback to MSI if MSI-X initialization failed */
9325 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9326 retval = lpfc_sli4_enable_msi(phba);
9327 if (!retval) {
9328 /* Indicate initialization to MSI mode */
9329 phba->intr_type = MSI;
9330 intr_mode = 1;
9331 }
9332 }
9333
9334 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9335 if (phba->intr_type == NONE) {
9336 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
9337 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9338 if (!retval) {
James Smart895427b2017-02-12 13:52:30 -08009339 struct lpfc_hba_eq_hdl *eqhdl;
9340
James Smartda0436e2009-05-22 14:51:39 -04009341 /* Indicate initialization to INTx mode */
9342 phba->intr_type = INTx;
9343 intr_mode = 0;
James Smart895427b2017-02-12 13:52:30 -08009344
9345 for (idx = 0; idx < phba->io_channel_irqs; idx++) {
9346 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
9347 eqhdl->idx = idx;
9348 eqhdl->phba = phba;
9349 atomic_set(&eqhdl->hba_eq_in_use, 1);
James Smartda0436e2009-05-22 14:51:39 -04009350 }
James Smart1ba981f2014-02-20 09:56:45 -05009351 if (phba->cfg_fof) {
James Smart895427b2017-02-12 13:52:30 -08009352 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
9353 eqhdl->idx = idx;
9354 eqhdl->phba = phba;
9355 atomic_set(&eqhdl->hba_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -05009356 }
James Smartda0436e2009-05-22 14:51:39 -04009357 }
9358 }
9359 return intr_mode;
9360}
9361
9362/**
9363 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
9364 * @phba: pointer to lpfc hba data structure.
9365 *
9366 * This routine is invoked to disable device interrupt and disassociate
9367 * the driver's interrupt handler(s) from interrupt vector(s) to device
9368 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
9369 * will release the interrupt vector(s) for the message signaled interrupt.
9370 **/
9371static void
9372lpfc_sli4_disable_intr(struct lpfc_hba *phba)
9373{
9374 /* Disable the currently initialized interrupt mode */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009375 if (phba->intr_type == MSIX) {
9376 int index;
9377
9378 /* Free up MSI-X multi-message vectors */
James Smart895427b2017-02-12 13:52:30 -08009379 for (index = 0; index < phba->io_channel_irqs; index++)
9380 free_irq(pci_irq_vector(phba->pcidev, index),
9381 &phba->sli4_hba.hba_eq_hdl[index]);
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009382
9383 if (phba->cfg_fof)
James Smart895427b2017-02-12 13:52:30 -08009384 free_irq(pci_irq_vector(phba->pcidev, index),
9385 &phba->sli4_hba.hba_eq_hdl[index]);
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009386 } else {
James Smartda0436e2009-05-22 14:51:39 -04009387 free_irq(phba->pcidev->irq, phba);
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009388 }
9389
9390 pci_free_irq_vectors(phba->pcidev);
James Smartda0436e2009-05-22 14:51:39 -04009391
9392 /* Reset interrupt management states */
9393 phba->intr_type = NONE;
9394 phba->sli.slistat.sli_intr = 0;
James Smartda0436e2009-05-22 14:51:39 -04009395}
9396
9397/**
James Smart3772a992009-05-22 14:50:54 -04009398 * lpfc_unset_hba - Unset SLI3 hba device initialization
9399 * @phba: pointer to lpfc hba data structure.
9400 *
9401 * This routine is invoked to unset the HBA device initialization steps to
9402 * a device with SLI-3 interface spec.
9403 **/
9404static void
9405lpfc_unset_hba(struct lpfc_hba *phba)
9406{
9407 struct lpfc_vport *vport = phba->pport;
9408 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9409
9410 spin_lock_irq(shost->host_lock);
9411 vport->load_flag |= FC_UNLOADING;
9412 spin_unlock_irq(shost->host_lock);
9413
James Smart72859902012-01-18 16:25:38 -05009414 kfree(phba->vpi_bmask);
9415 kfree(phba->vpi_ids);
9416
James Smart3772a992009-05-22 14:50:54 -04009417 lpfc_stop_hba_timers(phba);
9418
9419 phba->pport->work_port_events = 0;
9420
9421 lpfc_sli_hba_down(phba);
9422
9423 lpfc_sli_brdrestart(phba);
9424
9425 lpfc_sli_disable_intr(phba);
9426
9427 return;
9428}
9429
9430/**
James Smart5af5eee2010-10-22 11:06:38 -04009431 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
9432 * @phba: Pointer to HBA context object.
9433 *
9434 * This function is called in the SLI4 code path to wait for completion
9435 * of device's XRIs exchange busy. It will check the XRI exchange busy
9436 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
9437 * that, it will check the XRI exchange busy on outstanding FCP and ELS
9438 * I/Os every 30 seconds, log error message, and wait forever. Only when
9439 * all XRI exchange busy complete, the driver unload shall proceed with
9440 * invoking the function reset ioctl mailbox command to the CNA and the
9441 * the rest of the driver unload resource release.
9442 **/
9443static void
9444lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
9445{
9446 int wait_time = 0;
James Smart895427b2017-02-12 13:52:30 -08009447 int nvme_xri_cmpl = 1;
9448 int fcp_xri_cmpl = 1;
James Smart5af5eee2010-10-22 11:06:38 -04009449 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9450
James Smart895427b2017-02-12 13:52:30 -08009451 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
9452 fcp_xri_cmpl =
9453 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
9454 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
9455 nvme_xri_cmpl =
9456 list_empty(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
9457
9458 while (!fcp_xri_cmpl || !els_xri_cmpl || !nvme_xri_cmpl) {
James Smart5af5eee2010-10-22 11:06:38 -04009459 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
James Smart895427b2017-02-12 13:52:30 -08009460 if (!nvme_xri_cmpl)
9461 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9462 "6100 NVME XRI exchange busy "
9463 "wait time: %d seconds.\n",
9464 wait_time/1000);
James Smart5af5eee2010-10-22 11:06:38 -04009465 if (!fcp_xri_cmpl)
9466 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9467 "2877 FCP XRI exchange busy "
9468 "wait time: %d seconds.\n",
9469 wait_time/1000);
9470 if (!els_xri_cmpl)
9471 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9472 "2878 ELS XRI exchange busy "
9473 "wait time: %d seconds.\n",
9474 wait_time/1000);
9475 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
9476 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
9477 } else {
9478 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
9479 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
9480 }
James Smart895427b2017-02-12 13:52:30 -08009481 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
9482 nvme_xri_cmpl = list_empty(
9483 &phba->sli4_hba.lpfc_abts_nvme_buf_list);
9484
9485 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
9486 fcp_xri_cmpl = list_empty(
9487 &phba->sli4_hba.lpfc_abts_scsi_buf_list);
9488
James Smart5af5eee2010-10-22 11:06:38 -04009489 els_xri_cmpl =
9490 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9491 }
9492}
9493
9494/**
James Smartda0436e2009-05-22 14:51:39 -04009495 * lpfc_sli4_hba_unset - Unset the fcoe hba
9496 * @phba: Pointer to HBA context object.
9497 *
9498 * This function is called in the SLI4 code path to reset the HBA's FCoE
9499 * function. The caller is not required to hold any lock. This routine
9500 * issues PCI function reset mailbox command to reset the FCoE function.
9501 * At the end of the function, it calls lpfc_hba_down_post function to
9502 * free any pending commands.
9503 **/
9504static void
9505lpfc_sli4_hba_unset(struct lpfc_hba *phba)
9506{
9507 int wait_cnt = 0;
9508 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -04009509 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -04009510
9511 lpfc_stop_hba_timers(phba);
9512 phba->sli4_hba.intr_enable = 0;
9513
9514 /*
9515 * Gracefully wait out the potential current outstanding asynchronous
9516 * mailbox command.
9517 */
9518
9519 /* First, block any pending async mailbox command from posted */
9520 spin_lock_irq(&phba->hbalock);
9521 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
9522 spin_unlock_irq(&phba->hbalock);
9523 /* Now, trying to wait it out if we can */
9524 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9525 msleep(10);
9526 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
9527 break;
9528 }
9529 /* Forcefully release the outstanding mailbox command if timed out */
9530 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9531 spin_lock_irq(&phba->hbalock);
9532 mboxq = phba->sli.mbox_active;
9533 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
9534 __lpfc_mbox_cmpl_put(phba, mboxq);
9535 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9536 phba->sli.mbox_active = NULL;
9537 spin_unlock_irq(&phba->hbalock);
9538 }
9539
James Smart5af5eee2010-10-22 11:06:38 -04009540 /* Abort all iocbs associated with the hba */
9541 lpfc_sli_hba_iocb_abort(phba);
9542
9543 /* Wait for completion of device XRI exchange busy */
9544 lpfc_sli4_xri_exchange_busy_wait(phba);
9545
James Smartda0436e2009-05-22 14:51:39 -04009546 /* Disable PCI subsystem interrupt */
9547 lpfc_sli4_disable_intr(phba);
9548
James Smart912e3ac2011-05-24 11:42:11 -04009549 /* Disable SR-IOV if enabled */
9550 if (phba->cfg_sriov_nr_virtfn)
9551 pci_disable_sriov(pdev);
9552
James Smartda0436e2009-05-22 14:51:39 -04009553 /* Stop kthread signal shall trigger work_done one more time */
9554 kthread_stop(phba->worker_thread);
9555
James Smart3677a3a2010-09-29 11:19:14 -04009556 /* Reset SLI4 HBA FCoE function */
9557 lpfc_pci_function_reset(phba);
James Smart5350d872011-10-10 21:33:49 -04009558 lpfc_sli4_queue_destroy(phba);
James Smart3677a3a2010-09-29 11:19:14 -04009559
James Smartda0436e2009-05-22 14:51:39 -04009560 /* Stop the SLI4 device port */
9561 phba->pport->work_port_events = 0;
9562}
9563
James Smart28baac72010-02-12 14:42:03 -05009564 /**
9565 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
9566 * @phba: Pointer to HBA context object.
9567 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9568 *
9569 * This function is called in the SLI4 code path to read the port's
9570 * sli4 capabilities.
9571 *
9572 * This function may be be called from any context that can block-wait
9573 * for the completion. The expectation is that this routine is called
9574 * typically from probe_one or from the online routine.
9575 **/
9576int
9577lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9578{
9579 int rc;
9580 struct lpfc_mqe *mqe;
9581 struct lpfc_pc_sli4_params *sli4_params;
9582 uint32_t mbox_tmo;
9583
9584 rc = 0;
9585 mqe = &mboxq->u.mqe;
9586
9587 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -05009588 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -05009589 if (!phba->sli4_hba.intr_enable)
9590 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9591 else {
James Smarta183a152011-10-10 21:32:43 -04009592 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -05009593 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
9594 }
9595
9596 if (unlikely(rc))
9597 return 1;
9598
9599 sli4_params = &phba->sli4_hba.pc_sli4_params;
9600 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
9601 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
9602 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
9603 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
9604 &mqe->un.sli4_params);
9605 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
9606 &mqe->un.sli4_params);
9607 sli4_params->proto_types = mqe->un.sli4_params.word3;
9608 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
9609 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
9610 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
9611 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
9612 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
9613 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
9614 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
9615 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
9616 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
9617 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
9618 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
9619 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
9620 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
9621 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
9622 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
9623 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
9624 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
9625 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
9626 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
9627 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -04009628
9629 /* Make sure that sge_supp_len can be handled by the driver */
9630 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
9631 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
9632
James Smart28baac72010-02-12 14:42:03 -05009633 return rc;
9634}
9635
James Smartda0436e2009-05-22 14:51:39 -04009636/**
James Smartfedd3b72011-02-16 12:39:24 -05009637 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
9638 * @phba: Pointer to HBA context object.
9639 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9640 *
9641 * This function is called in the SLI4 code path to read the port's
9642 * sli4 capabilities.
9643 *
9644 * This function may be be called from any context that can block-wait
9645 * for the completion. The expectation is that this routine is called
9646 * typically from probe_one or from the online routine.
9647 **/
9648int
9649lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9650{
9651 int rc;
9652 struct lpfc_mqe *mqe = &mboxq->u.mqe;
9653 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -04009654 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -05009655 int length;
9656 struct lpfc_sli4_parameters *mbx_sli4_parameters;
9657
James Smart6d368e52011-05-24 11:44:12 -04009658 /*
9659 * By default, the driver assumes the SLI4 port requires RPI
9660 * header postings. The SLI4_PARAM response will correct this
9661 * assumption.
9662 */
9663 phba->sli4_hba.rpi_hdrs_in_use = 1;
9664
James Smartfedd3b72011-02-16 12:39:24 -05009665 /* Read the port's SLI4 Config Parameters */
9666 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
9667 sizeof(struct lpfc_sli4_cfg_mhdr));
9668 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9669 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
9670 length, LPFC_SLI4_MBX_EMBED);
9671 if (!phba->sli4_hba.intr_enable)
9672 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -04009673 else {
9674 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
9675 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
9676 }
James Smartfedd3b72011-02-16 12:39:24 -05009677 if (unlikely(rc))
9678 return rc;
9679 sli4_params = &phba->sli4_hba.pc_sli4_params;
9680 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
9681 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
9682 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
9683 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
9684 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
9685 mbx_sli4_parameters);
9686 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
9687 mbx_sli4_parameters);
9688 if (bf_get(cfg_phwq, mbx_sli4_parameters))
9689 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
9690 else
9691 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
9692 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
9693 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
James Smart1ba981f2014-02-20 09:56:45 -05009694 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -05009695 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
9696 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
9697 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
9698 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
James Smart0c651872013-07-15 18:33:23 -04009699 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -05009700 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
9701 mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -08009702 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -05009703 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
9704 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -04009705 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
9706 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -08009707 phba->nvme_support = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
9708 bf_get(cfg_xib, mbx_sli4_parameters));
9709
9710 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) ||
9711 !phba->nvme_support) {
9712 phba->nvme_support = 0;
9713 phba->nvmet_support = 0;
9714 phba->cfg_nvme_io_channel = 0;
9715 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
9716 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
9717 "6101 Disabling NVME support: "
9718 "Not supported by firmware: %d %d\n",
9719 bf_get(cfg_nvme, mbx_sli4_parameters),
9720 bf_get(cfg_xib, mbx_sli4_parameters));
9721
9722 /* If firmware doesn't support NVME, just use SCSI support */
9723 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
9724 return -ENODEV;
9725 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
9726 }
James Smart05580562011-05-24 11:40:48 -04009727
9728 /* Make sure that sge_supp_len can be handled by the driver */
9729 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
9730 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
9731
James Smartb5c53952016-03-31 14:12:30 -07009732 /*
9733 * Issue IOs with CDB embedded in WQE to minimized the number
9734 * of DMAs the firmware has to do. Setting this to 1 also forces
9735 * the driver to use 128 bytes WQEs for FCP IOs.
9736 */
9737 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
9738 phba->fcp_embed_io = 1;
9739 else
9740 phba->fcp_embed_io = 0;
James Smart7bdedb32016-07-06 12:36:00 -07009741
9742 /*
9743 * Check if the SLI port supports MDS Diagnostics
9744 */
9745 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
9746 phba->mds_diags_support = 1;
9747 else
9748 phba->mds_diags_support = 0;
James Smartfedd3b72011-02-16 12:39:24 -05009749 return 0;
9750}
9751
9752/**
James Smart3772a992009-05-22 14:50:54 -04009753 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
9754 * @pdev: pointer to PCI device
9755 * @pid: pointer to PCI device identifier
9756 *
9757 * This routine is to be called to attach a device with SLI-3 interface spec
9758 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9759 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
9760 * information of the device and driver to see if the driver state that it can
9761 * support this kind of device. If the match is successful, the driver core
9762 * invokes this routine. If this routine determines it can claim the HBA, it
9763 * does all the initialization that it needs to do to handle the HBA properly.
9764 *
9765 * Return code
9766 * 0 - driver can claim the device
9767 * negative value - driver can not claim the device
9768 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009769static int
James Smart3772a992009-05-22 14:50:54 -04009770lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
9771{
9772 struct lpfc_hba *phba;
9773 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -04009774 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -04009775 int error;
9776 uint32_t cfg_mode, intr_mode;
9777
9778 /* Allocate memory for HBA structure */
9779 phba = lpfc_hba_alloc(pdev);
9780 if (!phba)
9781 return -ENOMEM;
9782
9783 /* Perform generic PCI device enabling operation */
9784 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -04009785 if (error)
James Smart3772a992009-05-22 14:50:54 -04009786 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -04009787
9788 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
9789 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
9790 if (error)
9791 goto out_disable_pci_dev;
9792
9793 /* Set up SLI-3 specific device PCI memory space */
9794 error = lpfc_sli_pci_mem_setup(phba);
9795 if (error) {
9796 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9797 "1402 Failed to set up pci memory space.\n");
9798 goto out_disable_pci_dev;
9799 }
9800
James Smart3772a992009-05-22 14:50:54 -04009801 /* Set up SLI-3 specific device driver resources */
9802 error = lpfc_sli_driver_resource_setup(phba);
9803 if (error) {
9804 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9805 "1404 Failed to set up driver resource.\n");
9806 goto out_unset_pci_mem_s3;
9807 }
9808
9809 /* Initialize and populate the iocb list per host */
9810 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
9811 if (error) {
9812 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9813 "1405 Failed to initialize iocb list.\n");
9814 goto out_unset_driver_resource_s3;
9815 }
9816
9817 /* Set up common device driver resources */
9818 error = lpfc_setup_driver_resource_phase2(phba);
9819 if (error) {
9820 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9821 "1406 Failed to set up driver resource.\n");
9822 goto out_free_iocb_list;
9823 }
9824
James Smart079b5c92011-08-21 21:48:49 -04009825 /* Get the default values for Model Name and Description */
9826 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
9827
James Smart3772a992009-05-22 14:50:54 -04009828 /* Create SCSI host to the physical port */
9829 error = lpfc_create_shost(phba);
9830 if (error) {
9831 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9832 "1407 Failed to create scsi host.\n");
9833 goto out_unset_driver_resource;
9834 }
9835
9836 /* Configure sysfs attributes */
9837 vport = phba->pport;
9838 error = lpfc_alloc_sysfs_attr(vport);
9839 if (error) {
9840 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9841 "1476 Failed to allocate sysfs attr\n");
9842 goto out_destroy_shost;
9843 }
9844
James Smart6669f9b2009-10-02 15:16:45 -04009845 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -04009846 /* Now, trying to enable interrupt and bring up the device */
9847 cfg_mode = phba->cfg_use_msi;
9848 while (true) {
9849 /* Put device to a known state before enabling interrupt */
9850 lpfc_stop_port(phba);
9851 /* Configure and enable interrupt */
9852 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
9853 if (intr_mode == LPFC_INTR_ERROR) {
9854 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9855 "0431 Failed to enable interrupt.\n");
9856 error = -ENODEV;
9857 goto out_free_sysfs_attr;
9858 }
9859 /* SLI-3 HBA setup */
9860 if (lpfc_sli_hba_setup(phba)) {
9861 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9862 "1477 Failed to set up hba\n");
9863 error = -ENODEV;
9864 goto out_remove_device;
9865 }
9866
9867 /* Wait 50ms for the interrupts of previous mailbox commands */
9868 msleep(50);
9869 /* Check active interrupts on message signaled interrupts */
9870 if (intr_mode == 0 ||
9871 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
9872 /* Log the current active interrupt mode */
9873 phba->intr_mode = intr_mode;
9874 lpfc_log_intr_mode(phba, intr_mode);
9875 break;
9876 } else {
9877 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9878 "0447 Configure interrupt mode (%d) "
9879 "failed active interrupt test.\n",
9880 intr_mode);
9881 /* Disable the current interrupt mode */
9882 lpfc_sli_disable_intr(phba);
9883 /* Try next level of interrupt mode */
9884 cfg_mode = --intr_mode;
9885 }
9886 }
9887
9888 /* Perform post initialization setup */
9889 lpfc_post_init_setup(phba);
9890
9891 /* Check if there are static vports to be created. */
9892 lpfc_create_static_vport(phba);
9893
9894 return 0;
9895
9896out_remove_device:
9897 lpfc_unset_hba(phba);
9898out_free_sysfs_attr:
9899 lpfc_free_sysfs_attr(vport);
9900out_destroy_shost:
9901 lpfc_destroy_shost(phba);
9902out_unset_driver_resource:
9903 lpfc_unset_driver_resource_phase2(phba);
9904out_free_iocb_list:
9905 lpfc_free_iocb_list(phba);
9906out_unset_driver_resource_s3:
9907 lpfc_sli_driver_resource_unset(phba);
9908out_unset_pci_mem_s3:
9909 lpfc_sli_pci_mem_unset(phba);
9910out_disable_pci_dev:
9911 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -04009912 if (shost)
9913 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -04009914out_free_phba:
9915 lpfc_hba_free(phba);
9916 return error;
9917}
9918
9919/**
9920 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -04009921 * @pdev: pointer to PCI device
9922 *
James Smart3772a992009-05-22 14:50:54 -04009923 * This routine is to be called to disattach a device with SLI-3 interface
9924 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9925 * removed from PCI bus, it performs all the necessary cleanup for the HBA
9926 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -04009927 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009928static void
James Smart3772a992009-05-22 14:50:54 -04009929lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -05009930{
James Smart2e0fef82007-06-17 19:56:36 -05009931 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9932 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -05009933 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -05009934 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -05009935 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05009936
James Smart549e55c2007-08-02 11:09:51 -04009937 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04009938 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04009939 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05009940
James Smart858c9f62007-06-17 19:56:39 -05009941 lpfc_free_sysfs_attr(vport);
9942
James Smarteada2722008-12-04 22:39:13 -05009943 /* Release all the vports against this physical port */
9944 vports = lpfc_create_vport_work_array(phba);
9945 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -04009946 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9947 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
9948 continue;
James Smarteada2722008-12-04 22:39:13 -05009949 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -04009950 }
James Smarteada2722008-12-04 22:39:13 -05009951 lpfc_destroy_vport_work_array(phba, vports);
9952
9953 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -05009954 fc_remove_host(shost);
9955 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04009956 lpfc_cleanup(vport);
9957
James Smart2e0fef82007-06-17 19:56:36 -05009958 /*
9959 * Bring down the SLI Layer. This step disable all interrupts,
9960 * clears the rings, discards all mailbox commands, and resets
9961 * the HBA.
9962 */
James Smarta257bf92009-04-06 18:48:10 -04009963
Justin P. Mattock48e34d02010-12-30 15:07:58 -08009964 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -05009965 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -04009966 /* Stop kthread signal shall trigger work_done one more time */
9967 kthread_stop(phba->worker_thread);
9968 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -05009969 lpfc_sli_brdrestart(phba);
9970
James Smart72859902012-01-18 16:25:38 -05009971 kfree(phba->vpi_bmask);
9972 kfree(phba->vpi_ids);
9973
James Smart3772a992009-05-22 14:50:54 -04009974 lpfc_stop_hba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05009975 spin_lock_irq(&phba->hbalock);
9976 list_del_init(&vport->listentry);
9977 spin_unlock_irq(&phba->hbalock);
9978
James Smart858c9f62007-06-17 19:56:39 -05009979 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05009980
James Smart912e3ac2011-05-24 11:42:11 -04009981 /* Disable SR-IOV if enabled */
9982 if (phba->cfg_sriov_nr_virtfn)
9983 pci_disable_sriov(pdev);
9984
James Smart5b75da22008-12-04 22:39:35 -05009985 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -04009986 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -05009987
James Smart858c9f62007-06-17 19:56:39 -05009988 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -05009989
9990 /*
9991 * Call scsi_free before mem_free since scsi bufs are released to their
9992 * corresponding pools here.
9993 */
9994 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -04009995 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -05009996
James Smart34b02dc2008-08-24 21:49:55 -04009997 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
9998 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -05009999
James Smart2e0fef82007-06-17 19:56:36 -050010000 /* Free resources associated with SLI2 interface */
10001 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -040010002 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -050010003
10004 /* unmap adapter SLIM and Control Registers */
10005 iounmap(phba->ctrl_regs_memmap_p);
10006 iounmap(phba->slim_memmap_p);
10007
James Smart3772a992009-05-22 14:50:54 -040010008 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -050010009
Johannes Thumshirne0c04832016-06-07 09:44:03 +020010010 pci_release_mem_regions(pdev);
James Smart2e0fef82007-06-17 19:56:36 -050010011 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -050010012}
10013
Linas Vepstas8d63f372007-02-14 14:28:36 -060010014/**
James Smart3772a992009-05-22 14:50:54 -040010015 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050010016 * @pdev: pointer to PCI device
10017 * @msg: power management message
10018 *
James Smart3772a992009-05-22 14:50:54 -040010019 * This routine is to be called from the kernel's PCI subsystem to support
10020 * system Power Management (PM) to device with SLI-3 interface spec. When
10021 * PM invokes this method, it quiesces the device by stopping the driver's
10022 * worker thread for the device, turning off device's interrupt and DMA,
10023 * and bring the device offline. Note that as the driver implements the
10024 * minimum PM requirements to a power-aware driver's PM support for the
10025 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10026 * to the suspend() method call will be treated as SUSPEND and the driver will
10027 * fully reinitialize its device during resume() method call, the driver will
10028 * set device to PCI_D3hot state in PCI config space instead of setting it
10029 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -050010030 *
10031 * Return code
James Smart3772a992009-05-22 14:50:54 -040010032 * 0 - driver suspended the device
10033 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050010034 **/
10035static int
James Smart3772a992009-05-22 14:50:54 -040010036lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -050010037{
10038 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10039 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10040
10041 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10042 "0473 PCI device Power Management suspend.\n");
10043
10044 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040010045 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -050010046 lpfc_offline(phba);
10047 kthread_stop(phba->worker_thread);
10048
10049 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -040010050 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -050010051
10052 /* Save device state to PCI config space */
10053 pci_save_state(pdev);
10054 pci_set_power_state(pdev, PCI_D3hot);
10055
10056 return 0;
10057}
10058
10059/**
James Smart3772a992009-05-22 14:50:54 -040010060 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050010061 * @pdev: pointer to PCI device
10062 *
James Smart3772a992009-05-22 14:50:54 -040010063 * This routine is to be called from the kernel's PCI subsystem to support
10064 * system Power Management (PM) to device with SLI-3 interface spec. When PM
10065 * invokes this method, it restores the device's PCI config space state and
10066 * fully reinitializes the device and brings it online. Note that as the
10067 * driver implements the minimum PM requirements to a power-aware driver's
10068 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
10069 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
10070 * driver will fully reinitialize its device during resume() method call,
10071 * the device will be set to PCI_D0 directly in PCI config space before
10072 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -050010073 *
10074 * Return code
James Smart3772a992009-05-22 14:50:54 -040010075 * 0 - driver suspended the device
10076 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050010077 **/
10078static int
James Smart3772a992009-05-22 14:50:54 -040010079lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -050010080{
10081 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10082 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -050010083 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050010084 int error;
10085
10086 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10087 "0452 PCI device Power Management resume.\n");
10088
10089 /* Restore device state from PCI config space */
10090 pci_set_power_state(pdev, PCI_D0);
10091 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -040010092
James Smart1dfb5a42010-02-12 14:40:50 -050010093 /*
10094 * As the new kernel behavior of pci_restore_state() API call clears
10095 * device saved_state flag, need to save the restored state again.
10096 */
10097 pci_save_state(pdev);
10098
James Smart3a55b532008-12-04 22:38:54 -050010099 if (pdev->is_busmaster)
10100 pci_set_master(pdev);
10101
10102 /* Startup the kernel thread for this host adapter. */
10103 phba->worker_thread = kthread_run(lpfc_do_work, phba,
10104 "lpfc_worker_%d", phba->brd_no);
10105 if (IS_ERR(phba->worker_thread)) {
10106 error = PTR_ERR(phba->worker_thread);
10107 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10108 "0434 PM resume failed to start worker "
10109 "thread: error=x%x.\n", error);
10110 return error;
10111 }
10112
James Smart5b75da22008-12-04 22:39:35 -050010113 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040010114 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050010115 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -050010116 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -050010117 "0430 PM resume Failed to enable interrupt\n");
10118 return -EIO;
10119 } else
10120 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050010121
10122 /* Restart HBA and bring it online */
10123 lpfc_sli_brdrestart(phba);
10124 lpfc_online(phba);
10125
James Smart5b75da22008-12-04 22:39:35 -050010126 /* Log the current active interrupt mode */
10127 lpfc_log_intr_mode(phba, phba->intr_mode);
10128
James Smart3a55b532008-12-04 22:38:54 -050010129 return 0;
10130}
10131
10132/**
James Smart891478a2009-11-18 15:40:23 -050010133 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
10134 * @phba: pointer to lpfc hba data structure.
10135 *
10136 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -040010137 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -050010138 **/
10139static void
10140lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
10141{
10142 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10143 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -040010144
10145 /*
10146 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10147 * and let the SCSI mid-layer to retry them to recover.
10148 */
James Smartdb55fba2014-04-04 13:52:02 -040010149 lpfc_sli_abort_fcp_rings(phba);
James Smart891478a2009-11-18 15:40:23 -050010150}
10151
10152/**
James Smart0d878412009-10-02 15:16:56 -040010153 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
10154 * @phba: pointer to lpfc hba data structure.
10155 *
10156 * This routine is called to prepare the SLI3 device for PCI slot reset. It
10157 * disables the device interrupt and pci device, and aborts the internal FCP
10158 * pending I/Os.
10159 **/
10160static void
10161lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
10162{
James Smart0d878412009-10-02 15:16:56 -040010163 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050010164 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -040010165
James Smart75baf692010-06-08 18:31:21 -040010166 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040010167 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010168
James Smarte2af0d22010-03-15 11:25:32 -040010169 /* Block all SCSI devices' I/Os on the host */
10170 lpfc_scsi_dev_block(phba);
10171
James Smartea714f32013-04-17 20:18:47 -040010172 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10173 lpfc_sli_flush_fcp_rings(phba);
10174
James Smarte2af0d22010-03-15 11:25:32 -040010175 /* stop all timers */
10176 lpfc_stop_hba_timers(phba);
10177
James Smart0d878412009-10-02 15:16:56 -040010178 /* Disable interrupt and pci device */
10179 lpfc_sli_disable_intr(phba);
10180 pci_disable_device(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -040010181}
10182
10183/**
10184 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
10185 * @phba: pointer to lpfc hba data structure.
10186 *
10187 * This routine is called to prepare the SLI3 device for PCI slot permanently
10188 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10189 * pending I/Os.
10190 **/
10191static void
James Smart75baf692010-06-08 18:31:21 -040010192lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -040010193{
10194 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050010195 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -040010196 /* Block all SCSI devices' I/Os on the host */
10197 lpfc_scsi_dev_block(phba);
10198
10199 /* stop all timers */
10200 lpfc_stop_hba_timers(phba);
10201
James Smart0d878412009-10-02 15:16:56 -040010202 /* Clean up all driver's outstanding SCSI I/Os */
10203 lpfc_sli_flush_fcp_rings(phba);
10204}
10205
10206/**
James Smart3772a992009-05-22 14:50:54 -040010207 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -040010208 * @pdev: pointer to PCI device.
10209 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010210 *
James Smart3772a992009-05-22 14:50:54 -040010211 * This routine is called from the PCI subsystem for I/O error handling to
10212 * device with SLI-3 interface spec. This function is called by the PCI
10213 * subsystem after a PCI bus error affecting this device has been detected.
10214 * When this function is invoked, it will need to stop all the I/Os and
10215 * interrupt(s) to the device. Once that is done, it will return
10216 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
10217 * as desired.
James Smarte59058c2008-08-24 21:49:00 -040010218 *
10219 * Return codes
James Smart0d878412009-10-02 15:16:56 -040010220 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -040010221 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10222 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -040010223 **/
James Smart3772a992009-05-22 14:50:54 -040010224static pci_ers_result_t
10225lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010226{
James Smart51ef4c22007-08-02 11:10:31 -040010227 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10228 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010229
James Smart0d878412009-10-02 15:16:56 -040010230 switch (state) {
10231 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -050010232 /* Non-fatal error, prepare for recovery */
10233 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -040010234 return PCI_ERS_RESULT_CAN_RECOVER;
10235 case pci_channel_io_frozen:
10236 /* Fatal error, prepare for slot reset */
10237 lpfc_sli_prep_dev_for_reset(phba);
10238 return PCI_ERS_RESULT_NEED_RESET;
10239 case pci_channel_io_perm_failure:
10240 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -040010241 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010242 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -040010243 default:
10244 /* Unknown state, prepare and request slot reset */
10245 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10246 "0472 Unknown PCI error state: x%x\n", state);
10247 lpfc_sli_prep_dev_for_reset(phba);
10248 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -040010249 }
Linas Vepstas8d63f372007-02-14 14:28:36 -060010250}
10251
10252/**
James Smart3772a992009-05-22 14:50:54 -040010253 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -040010254 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010255 *
James Smart3772a992009-05-22 14:50:54 -040010256 * This routine is called from the PCI subsystem for error handling to
10257 * device with SLI-3 interface spec. This is called after PCI bus has been
10258 * reset to restart the PCI card from scratch, as if from a cold-boot.
10259 * During the PCI subsystem error recovery, after driver returns
10260 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10261 * recovery and then call this routine before calling the .resume method
10262 * to recover the device. This function will initialize the HBA device,
10263 * enable the interrupt, but it will just put the HBA to offline state
10264 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -040010265 *
10266 * Return codes
James Smart3772a992009-05-22 14:50:54 -040010267 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10268 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -060010269 */
James Smart3772a992009-05-22 14:50:54 -040010270static pci_ers_result_t
10271lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010272{
James Smart51ef4c22007-08-02 11:10:31 -040010273 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10274 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010275 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -050010276 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010277
10278 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +110010279 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -060010280 printk(KERN_ERR "lpfc: Cannot re-enable "
10281 "PCI device after reset.\n");
10282 return PCI_ERS_RESULT_DISCONNECT;
10283 }
10284
James Smart97207482008-12-04 22:39:19 -050010285 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050010286
10287 /*
10288 * As the new kernel behavior of pci_restore_state() API call clears
10289 * device saved_state flag, need to save the restored state again.
10290 */
10291 pci_save_state(pdev);
10292
James Smart97207482008-12-04 22:39:19 -050010293 if (pdev->is_busmaster)
10294 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010295
James Smart92d7f7b2007-06-17 19:56:38 -050010296 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040010297 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -050010298 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010299
James Smart5b75da22008-12-04 22:39:35 -050010300 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040010301 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050010302 if (intr_mode == LPFC_INTR_ERROR) {
10303 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10304 "0427 Cannot re-enable interrupt after "
10305 "slot reset.\n");
10306 return PCI_ERS_RESULT_DISCONNECT;
10307 } else
10308 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010309
James Smart75baf692010-06-08 18:31:21 -040010310 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -040010311 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010312 lpfc_offline(phba);
10313 lpfc_sli_brdrestart(phba);
10314
James Smart5b75da22008-12-04 22:39:35 -050010315 /* Log the current active interrupt mode */
10316 lpfc_log_intr_mode(phba, phba->intr_mode);
10317
Linas Vepstas8d63f372007-02-14 14:28:36 -060010318 return PCI_ERS_RESULT_RECOVERED;
10319}
10320
10321/**
James Smart3772a992009-05-22 14:50:54 -040010322 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -040010323 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -060010324 *
James Smart3772a992009-05-22 14:50:54 -040010325 * This routine is called from the PCI subsystem for error handling to device
10326 * with SLI-3 interface spec. It is called when kernel error recovery tells
10327 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10328 * error recovery. After this call, traffic can start to flow from this device
10329 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010330 */
James Smart3772a992009-05-22 14:50:54 -040010331static void
10332lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010333{
James Smart51ef4c22007-08-02 11:10:31 -040010334 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10335 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010336
James Smarte2af0d22010-03-15 11:25:32 -040010337 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -040010338 lpfc_online(phba);
James Smart0d878412009-10-02 15:16:56 -040010339
10340 /* Clean up Advanced Error Reporting (AER) if needed */
10341 if (phba->hba_flag & HBA_AER_ENABLED)
10342 pci_cleanup_aer_uncorrect_error_status(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010343}
10344
James Smart3772a992009-05-22 14:50:54 -040010345/**
James Smartda0436e2009-05-22 14:51:39 -040010346 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
10347 * @phba: pointer to lpfc hba data structure.
10348 *
10349 * returns the number of ELS/CT IOCBs to reserve
10350 **/
10351int
10352lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
10353{
10354 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
10355
James Smartf1126682009-06-10 17:22:44 -040010356 if (phba->sli_rev == LPFC_SLI_REV4) {
10357 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -040010358 return 10;
James Smartf1126682009-06-10 17:22:44 -040010359 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -040010360 return 25;
James Smartf1126682009-06-10 17:22:44 -040010361 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -040010362 return 50;
James Smartf1126682009-06-10 17:22:44 -040010363 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -040010364 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -040010365 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -040010366 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -040010367 else if (max_xri <= 2048)
10368 return 200;
10369 else
10370 return 250;
James Smartf1126682009-06-10 17:22:44 -040010371 } else
10372 return 0;
James Smartda0436e2009-05-22 14:51:39 -040010373}
10374
10375/**
James Smart895427b2017-02-12 13:52:30 -080010376 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
10377 * @phba: pointer to lpfc hba data structure.
10378 *
10379 * returns the number of ELS/CT
10380 **/
10381int
10382lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
10383{
10384 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
10385
10386 return max_xri;
10387}
10388
10389
10390/**
James Smart52d52442011-05-24 11:42:45 -040010391 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -040010392 * @fw: pointer to firmware image returned from request_firmware.
James Smartce396282012-09-29 11:30:56 -040010393 * @phba: pointer to lpfc hba data structure.
James Smart52d52442011-05-24 11:42:45 -040010394 *
James Smart52d52442011-05-24 11:42:45 -040010395 **/
James Smartce396282012-09-29 11:30:56 -040010396static void
10397lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -040010398{
James Smartce396282012-09-29 11:30:56 -040010399 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -050010400 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -040010401 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -040010402 struct list_head dma_buffer_list;
10403 int i, rc = 0;
10404 struct lpfc_dmabuf *dmabuf, *next;
10405 uint32_t offset = 0, temp_offset = 0;
James Smart6b6ef5d2016-10-13 15:06:17 -070010406 uint32_t magic_number, ftype, fid, fsize;
James Smart52d52442011-05-24 11:42:45 -040010407
James Smartc71ab862012-10-31 14:44:33 -040010408 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -040010409 if (!fw) {
10410 rc = -ENXIO;
10411 goto out;
10412 }
10413 image = (struct lpfc_grp_hdr *)fw->data;
10414
James Smart6b6ef5d2016-10-13 15:06:17 -070010415 magic_number = be32_to_cpu(image->magic_number);
10416 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
10417 fid = bf_get_be32(lpfc_grp_hdr_id, image),
10418 fsize = be32_to_cpu(image->size);
10419
James Smart52d52442011-05-24 11:42:45 -040010420 INIT_LIST_HEAD(&dma_buffer_list);
James Smart6b6ef5d2016-10-13 15:06:17 -070010421 if ((magic_number != LPFC_GROUP_OJECT_MAGIC_G5 &&
10422 magic_number != LPFC_GROUP_OJECT_MAGIC_G6) ||
10423 ftype != LPFC_FILE_TYPE_GROUP || fsize != fw->size) {
James Smart52d52442011-05-24 11:42:45 -040010424 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10425 "3022 Invalid FW image found. "
Arnd Bergmannefe583c2016-10-17 14:35:46 +020010426 "Magic:%x Type:%x ID:%x Size %d %zd\n",
James Smart6b6ef5d2016-10-13 15:06:17 -070010427 magic_number, ftype, fid, fsize, fw->size);
James Smartce396282012-09-29 11:30:56 -040010428 rc = -EINVAL;
10429 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010430 }
10431 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -040010432 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -040010433 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartce396282012-09-29 11:30:56 -040010434 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -040010435 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -040010436 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -040010437 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
10438 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
10439 GFP_KERNEL);
10440 if (!dmabuf) {
10441 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040010442 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010443 }
10444 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
10445 SLI4_PAGE_SIZE,
10446 &dmabuf->phys,
10447 GFP_KERNEL);
10448 if (!dmabuf->virt) {
10449 kfree(dmabuf);
10450 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040010451 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010452 }
10453 list_add_tail(&dmabuf->list, &dma_buffer_list);
10454 }
10455 while (offset < fw->size) {
10456 temp_offset = offset;
10457 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -040010458 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -040010459 memcpy(dmabuf->virt,
10460 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -040010461 fw->size - temp_offset);
10462 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -040010463 break;
10464 }
James Smart52d52442011-05-24 11:42:45 -040010465 memcpy(dmabuf->virt, fw->data + temp_offset,
10466 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -040010467 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -040010468 }
10469 rc = lpfc_wr_object(phba, &dma_buffer_list,
10470 (fw->size - offset), &offset);
James Smartce396282012-09-29 11:30:56 -040010471 if (rc)
10472 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010473 }
10474 rc = offset;
10475 }
James Smartce396282012-09-29 11:30:56 -040010476
10477release_out:
James Smart52d52442011-05-24 11:42:45 -040010478 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
10479 list_del(&dmabuf->list);
10480 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
10481 dmabuf->virt, dmabuf->phys);
10482 kfree(dmabuf);
10483 }
James Smartce396282012-09-29 11:30:56 -040010484 release_firmware(fw);
10485out:
10486 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc71ab862012-10-31 14:44:33 -040010487 "3024 Firmware update done: %d.\n", rc);
James Smartce396282012-09-29 11:30:56 -040010488 return;
James Smart52d52442011-05-24 11:42:45 -040010489}
10490
10491/**
James Smartc71ab862012-10-31 14:44:33 -040010492 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
10493 * @phba: pointer to lpfc hba data structure.
10494 *
10495 * This routine is called to perform Linux generic firmware upgrade on device
10496 * that supports such feature.
10497 **/
10498int
10499lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
10500{
10501 uint8_t file_name[ELX_MODEL_NAME_SIZE];
10502 int ret;
10503 const struct firmware *fw;
10504
10505 /* Only supported on SLI4 interface type 2 for now */
10506 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
10507 LPFC_SLI_INTF_IF_TYPE_2)
10508 return -EPERM;
10509
10510 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
10511
10512 if (fw_upgrade == INT_FW_UPGRADE) {
10513 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
10514 file_name, &phba->pcidev->dev,
10515 GFP_KERNEL, (void *)phba,
10516 lpfc_write_firmware);
10517 } else if (fw_upgrade == RUN_FW_UPGRADE) {
10518 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
10519 if (!ret)
10520 lpfc_write_firmware(fw, (void *)phba);
10521 } else {
10522 ret = -EINVAL;
10523 }
10524
10525 return ret;
10526}
10527
10528/**
James Smartda0436e2009-05-22 14:51:39 -040010529 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
10530 * @pdev: pointer to PCI device
10531 * @pid: pointer to PCI device identifier
10532 *
10533 * This routine is called from the kernel's PCI subsystem to device with
10534 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10535 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10536 * information of the device and driver to see if the driver state that it
10537 * can support this kind of device. If the match is successful, the driver
10538 * core invokes this routine. If this routine determines it can claim the HBA,
10539 * it does all the initialization that it needs to do to handle the HBA
10540 * properly.
10541 *
10542 * Return code
10543 * 0 - driver can claim the device
10544 * negative value - driver can not claim the device
10545 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010546static int
James Smartda0436e2009-05-22 14:51:39 -040010547lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
10548{
10549 struct lpfc_hba *phba;
10550 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040010551 struct Scsi_Host *shost = NULL;
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040010552 int error;
James Smartda0436e2009-05-22 14:51:39 -040010553 uint32_t cfg_mode, intr_mode;
James Smartda0436e2009-05-22 14:51:39 -040010554
10555 /* Allocate memory for HBA structure */
10556 phba = lpfc_hba_alloc(pdev);
10557 if (!phba)
10558 return -ENOMEM;
10559
10560 /* Perform generic PCI device enabling operation */
10561 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040010562 if (error)
James Smartda0436e2009-05-22 14:51:39 -040010563 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -040010564
10565 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
10566 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
10567 if (error)
10568 goto out_disable_pci_dev;
10569
10570 /* Set up SLI-4 specific device PCI memory space */
10571 error = lpfc_sli4_pci_mem_setup(phba);
10572 if (error) {
10573 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10574 "1410 Failed to set up pci memory space.\n");
10575 goto out_disable_pci_dev;
10576 }
10577
James Smartda0436e2009-05-22 14:51:39 -040010578 /* Set up SLI-4 Specific device driver resources */
10579 error = lpfc_sli4_driver_resource_setup(phba);
10580 if (error) {
10581 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10582 "1412 Failed to set up driver resource.\n");
10583 goto out_unset_pci_mem_s4;
10584 }
10585
10586 /* Initialize and populate the iocb list per host */
James Smart2a9bf3d2010-06-07 15:24:45 -040010587
10588 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10589 "2821 initialize iocb list %d.\n",
10590 phba->cfg_iocb_cnt*1024);
10591 error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
10592
James Smartda0436e2009-05-22 14:51:39 -040010593 if (error) {
10594 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10595 "1413 Failed to initialize iocb list.\n");
10596 goto out_unset_driver_resource_s4;
10597 }
10598
James Smart19ca7602010-11-20 23:11:55 -050010599 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -040010600 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -050010601
James Smartda0436e2009-05-22 14:51:39 -040010602 /* Set up common device driver resources */
10603 error = lpfc_setup_driver_resource_phase2(phba);
10604 if (error) {
10605 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10606 "1414 Failed to set up driver resource.\n");
10607 goto out_free_iocb_list;
10608 }
10609
James Smart079b5c92011-08-21 21:48:49 -040010610 /* Get the default values for Model Name and Description */
10611 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
10612
James Smartda0436e2009-05-22 14:51:39 -040010613 /* Create SCSI host to the physical port */
10614 error = lpfc_create_shost(phba);
10615 if (error) {
10616 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10617 "1415 Failed to create scsi host.\n");
10618 goto out_unset_driver_resource;
10619 }
10620
10621 /* Configure sysfs attributes */
10622 vport = phba->pport;
10623 error = lpfc_alloc_sysfs_attr(vport);
10624 if (error) {
10625 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10626 "1416 Failed to allocate sysfs attr\n");
10627 goto out_destroy_shost;
10628 }
10629
James Smart6669f9b2009-10-02 15:16:45 -040010630 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -040010631 /* Now, trying to enable interrupt and bring up the device */
10632 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -040010633
James Smart7b15db32013-01-03 15:43:29 -050010634 /* Put device to a known state before enabling interrupt */
10635 lpfc_stop_port(phba);
James Smart895427b2017-02-12 13:52:30 -080010636
James Smart7b15db32013-01-03 15:43:29 -050010637 /* Configure and enable interrupt */
10638 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
10639 if (intr_mode == LPFC_INTR_ERROR) {
10640 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10641 "0426 Failed to enable interrupt.\n");
10642 error = -ENODEV;
10643 goto out_free_sysfs_attr;
James Smartda0436e2009-05-22 14:51:39 -040010644 }
James Smart7b15db32013-01-03 15:43:29 -050010645 /* Default to single EQ for non-MSI-X */
James Smart895427b2017-02-12 13:52:30 -080010646 if (phba->intr_type != MSIX) {
10647 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
10648 phba->cfg_fcp_io_channel = 1;
10649 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
10650 phba->cfg_nvme_io_channel = 1;
10651 phba->io_channel_irqs = 1;
10652 }
10653
10654
James Smart7b15db32013-01-03 15:43:29 -050010655 /* Set up SLI-4 HBA */
10656 if (lpfc_sli4_hba_setup(phba)) {
10657 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10658 "1421 Failed to set up hba\n");
10659 error = -ENODEV;
10660 goto out_disable_intr;
10661 }
10662
10663 /* Log the current active interrupt mode */
10664 phba->intr_mode = intr_mode;
10665 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -040010666
10667 /* Perform post initialization setup */
10668 lpfc_post_init_setup(phba);
10669
James Smart01649562017-02-12 13:52:32 -080010670 /* NVME support in FW earlier in the driver load corrects the
10671 * FC4 type making a check for nvme_support unnecessary.
10672 */
10673 if ((phba->nvmet_support == 0) &&
10674 (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
10675 /* Create NVME binding with nvme_fc_transport. This
10676 * ensures the vport is initialized.
10677 */
10678 error = lpfc_nvme_create_localport(vport);
10679 if (error) {
10680 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10681 "6004 NVME registration failed, "
10682 "error x%x\n",
10683 error);
10684 goto out_disable_intr;
10685 }
10686 }
James Smart895427b2017-02-12 13:52:30 -080010687
James Smartc71ab862012-10-31 14:44:33 -040010688 /* check for firmware upgrade or downgrade */
10689 if (phba->cfg_request_firmware_upgrade)
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040010690 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -040010691
James Smart1c6834a2009-07-19 10:01:26 -040010692 /* Check if there are static vports to be created. */
10693 lpfc_create_static_vport(phba);
James Smartda0436e2009-05-22 14:51:39 -040010694 return 0;
10695
10696out_disable_intr:
10697 lpfc_sli4_disable_intr(phba);
10698out_free_sysfs_attr:
10699 lpfc_free_sysfs_attr(vport);
10700out_destroy_shost:
10701 lpfc_destroy_shost(phba);
10702out_unset_driver_resource:
10703 lpfc_unset_driver_resource_phase2(phba);
10704out_free_iocb_list:
10705 lpfc_free_iocb_list(phba);
10706out_unset_driver_resource_s4:
10707 lpfc_sli4_driver_resource_unset(phba);
10708out_unset_pci_mem_s4:
10709 lpfc_sli4_pci_mem_unset(phba);
10710out_disable_pci_dev:
10711 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040010712 if (shost)
10713 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -040010714out_free_phba:
10715 lpfc_hba_free(phba);
10716 return error;
10717}
10718
10719/**
10720 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
10721 * @pdev: pointer to PCI device
10722 *
10723 * This routine is called from the kernel's PCI subsystem to device with
10724 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10725 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10726 * device to be removed from the PCI subsystem properly.
10727 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010728static void
James Smartda0436e2009-05-22 14:51:39 -040010729lpfc_pci_remove_one_s4(struct pci_dev *pdev)
10730{
10731 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10732 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
10733 struct lpfc_vport **vports;
10734 struct lpfc_hba *phba = vport->phba;
10735 int i;
10736
10737 /* Mark the device unloading flag */
10738 spin_lock_irq(&phba->hbalock);
10739 vport->load_flag |= FC_UNLOADING;
10740 spin_unlock_irq(&phba->hbalock);
10741
10742 /* Free the HBA sysfs attributes */
10743 lpfc_free_sysfs_attr(vport);
10744
10745 /* Release all the vports against this physical port */
10746 vports = lpfc_create_vport_work_array(phba);
10747 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040010748 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10749 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
10750 continue;
James Smartda0436e2009-05-22 14:51:39 -040010751 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040010752 }
James Smartda0436e2009-05-22 14:51:39 -040010753 lpfc_destroy_vport_work_array(phba, vports);
10754
10755 /* Remove FC host and then SCSI host with the physical port */
10756 fc_remove_host(shost);
10757 scsi_remove_host(shost);
10758
James Smart895427b2017-02-12 13:52:30 -080010759 /* Perform ndlp cleanup on the physical port. The nvme localport
10760 * is destroyed after to ensure all rports are io-disabled.
10761 */
James Smart01649562017-02-12 13:52:32 -080010762 lpfc_nvme_destroy_localport(vport);
James Smartda0436e2009-05-22 14:51:39 -040010763 lpfc_cleanup(vport);
10764
10765 /*
10766 * Bring down the SLI Layer. This step disables all interrupts,
10767 * clears the rings, discards all mailbox commands, and resets
10768 * the HBA FCoE function.
10769 */
10770 lpfc_debugfs_terminate(vport);
10771 lpfc_sli4_hba_unset(phba);
10772
10773 spin_lock_irq(&phba->hbalock);
10774 list_del_init(&vport->listentry);
10775 spin_unlock_irq(&phba->hbalock);
10776
James Smart3677a3a2010-09-29 11:19:14 -040010777 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -040010778 * buffers are released to their corresponding pools here.
10779 */
10780 lpfc_scsi_free(phba);
James Smart895427b2017-02-12 13:52:30 -080010781 lpfc_nvme_free(phba);
James Smart01649562017-02-12 13:52:32 -080010782 lpfc_free_iocb_list(phba);
James Smart67d12732012-08-03 12:36:13 -040010783
James Smartda0436e2009-05-22 14:51:39 -040010784 lpfc_sli4_driver_resource_unset(phba);
10785
10786 /* Unmap adapter Control and Doorbell registers */
10787 lpfc_sli4_pci_mem_unset(phba);
10788
10789 /* Release PCI resources and disable device's PCI function */
10790 scsi_host_put(shost);
10791 lpfc_disable_pci_dev(phba);
10792
10793 /* Finally, free the driver's device data structure */
10794 lpfc_hba_free(phba);
10795
10796 return;
10797}
10798
10799/**
10800 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
10801 * @pdev: pointer to PCI device
10802 * @msg: power management message
10803 *
10804 * This routine is called from the kernel's PCI subsystem to support system
10805 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
10806 * this method, it quiesces the device by stopping the driver's worker
10807 * thread for the device, turning off device's interrupt and DMA, and bring
10808 * the device offline. Note that as the driver implements the minimum PM
10809 * requirements to a power-aware driver's PM support for suspend/resume -- all
10810 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
10811 * method call will be treated as SUSPEND and the driver will fully
10812 * reinitialize its device during resume() method call, the driver will set
10813 * device to PCI_D3hot state in PCI config space instead of setting it
10814 * according to the @msg provided by the PM.
10815 *
10816 * Return code
10817 * 0 - driver suspended the device
10818 * Error otherwise
10819 **/
10820static int
10821lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
10822{
10823 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10824 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10825
10826 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -040010827 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -040010828
10829 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040010830 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -040010831 lpfc_offline(phba);
10832 kthread_stop(phba->worker_thread);
10833
10834 /* Disable interrupt from device */
10835 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040010836 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040010837
10838 /* Save device state to PCI config space */
10839 pci_save_state(pdev);
10840 pci_set_power_state(pdev, PCI_D3hot);
10841
10842 return 0;
10843}
10844
10845/**
10846 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
10847 * @pdev: pointer to PCI device
10848 *
10849 * This routine is called from the kernel's PCI subsystem to support system
10850 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
10851 * this method, it restores the device's PCI config space state and fully
10852 * reinitializes the device and brings it online. Note that as the driver
10853 * implements the minimum PM requirements to a power-aware driver's PM for
10854 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10855 * to the suspend() method call will be treated as SUSPEND and the driver
10856 * will fully reinitialize its device during resume() method call, the device
10857 * will be set to PCI_D0 directly in PCI config space before restoring the
10858 * state.
10859 *
10860 * Return code
10861 * 0 - driver suspended the device
10862 * Error otherwise
10863 **/
10864static int
10865lpfc_pci_resume_one_s4(struct pci_dev *pdev)
10866{
10867 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10868 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10869 uint32_t intr_mode;
10870 int error;
10871
10872 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10873 "0292 PCI device Power Management resume.\n");
10874
10875 /* Restore device state from PCI config space */
10876 pci_set_power_state(pdev, PCI_D0);
10877 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050010878
10879 /*
10880 * As the new kernel behavior of pci_restore_state() API call clears
10881 * device saved_state flag, need to save the restored state again.
10882 */
10883 pci_save_state(pdev);
10884
James Smartda0436e2009-05-22 14:51:39 -040010885 if (pdev->is_busmaster)
10886 pci_set_master(pdev);
10887
10888 /* Startup the kernel thread for this host adapter. */
10889 phba->worker_thread = kthread_run(lpfc_do_work, phba,
10890 "lpfc_worker_%d", phba->brd_no);
10891 if (IS_ERR(phba->worker_thread)) {
10892 error = PTR_ERR(phba->worker_thread);
10893 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10894 "0293 PM resume failed to start worker "
10895 "thread: error=x%x.\n", error);
10896 return error;
10897 }
10898
10899 /* Configure and enable interrupt */
10900 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
10901 if (intr_mode == LPFC_INTR_ERROR) {
10902 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10903 "0294 PM resume Failed to enable interrupt\n");
10904 return -EIO;
10905 } else
10906 phba->intr_mode = intr_mode;
10907
10908 /* Restart HBA and bring it online */
10909 lpfc_sli_brdrestart(phba);
10910 lpfc_online(phba);
10911
10912 /* Log the current active interrupt mode */
10913 lpfc_log_intr_mode(phba, phba->intr_mode);
10914
10915 return 0;
10916}
10917
10918/**
James Smart75baf692010-06-08 18:31:21 -040010919 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
10920 * @phba: pointer to lpfc hba data structure.
10921 *
10922 * This routine is called to prepare the SLI4 device for PCI slot recover. It
10923 * aborts all the outstanding SCSI I/Os to the pci device.
10924 **/
10925static void
10926lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
10927{
James Smart75baf692010-06-08 18:31:21 -040010928 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10929 "2828 PCI channel I/O abort preparing for recovery\n");
10930 /*
10931 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10932 * and let the SCSI mid-layer to retry them to recover.
10933 */
James Smartdb55fba2014-04-04 13:52:02 -040010934 lpfc_sli_abort_fcp_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040010935}
10936
10937/**
10938 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
10939 * @phba: pointer to lpfc hba data structure.
10940 *
10941 * This routine is called to prepare the SLI4 device for PCI slot reset. It
10942 * disables the device interrupt and pci device, and aborts the internal FCP
10943 * pending I/Os.
10944 **/
10945static void
10946lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
10947{
10948 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10949 "2826 PCI channel disable preparing for reset\n");
10950
10951 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040010952 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010953
10954 /* Block all SCSI devices' I/Os on the host */
10955 lpfc_scsi_dev_block(phba);
10956
James Smartea714f32013-04-17 20:18:47 -040010957 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10958 lpfc_sli_flush_fcp_rings(phba);
10959
James Smart75baf692010-06-08 18:31:21 -040010960 /* stop all timers */
10961 lpfc_stop_hba_timers(phba);
10962
10963 /* Disable interrupt and pci device */
10964 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040010965 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -040010966 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -040010967}
10968
10969/**
10970 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
10971 * @phba: pointer to lpfc hba data structure.
10972 *
10973 * This routine is called to prepare the SLI4 device for PCI slot permanently
10974 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10975 * pending I/Os.
10976 **/
10977static void
10978lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
10979{
10980 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10981 "2827 PCI channel permanent disable for failure\n");
10982
10983 /* Block all SCSI devices' I/Os on the host */
10984 lpfc_scsi_dev_block(phba);
10985
10986 /* stop all timers */
10987 lpfc_stop_hba_timers(phba);
10988
10989 /* Clean up all driver's outstanding SCSI I/Os */
10990 lpfc_sli_flush_fcp_rings(phba);
10991}
10992
10993/**
James Smartda0436e2009-05-22 14:51:39 -040010994 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
10995 * @pdev: pointer to PCI device.
10996 * @state: the current PCI connection state.
10997 *
10998 * This routine is called from the PCI subsystem for error handling to device
10999 * with SLI-4 interface spec. This function is called by the PCI subsystem
11000 * after a PCI bus error affecting this device has been detected. When this
11001 * function is invoked, it will need to stop all the I/Os and interrupt(s)
11002 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
11003 * for the PCI subsystem to perform proper recovery as desired.
11004 *
11005 * Return codes
11006 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11007 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11008 **/
11009static pci_ers_result_t
11010lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
11011{
James Smart75baf692010-06-08 18:31:21 -040011012 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11013 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11014
11015 switch (state) {
11016 case pci_channel_io_normal:
11017 /* Non-fatal error, prepare for recovery */
11018 lpfc_sli4_prep_dev_for_recover(phba);
11019 return PCI_ERS_RESULT_CAN_RECOVER;
11020 case pci_channel_io_frozen:
11021 /* Fatal error, prepare for slot reset */
11022 lpfc_sli4_prep_dev_for_reset(phba);
11023 return PCI_ERS_RESULT_NEED_RESET;
11024 case pci_channel_io_perm_failure:
11025 /* Permanent failure, prepare for device down */
11026 lpfc_sli4_prep_dev_for_perm_failure(phba);
11027 return PCI_ERS_RESULT_DISCONNECT;
11028 default:
11029 /* Unknown state, prepare and request slot reset */
11030 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11031 "2825 Unknown PCI error state: x%x\n", state);
11032 lpfc_sli4_prep_dev_for_reset(phba);
11033 return PCI_ERS_RESULT_NEED_RESET;
11034 }
James Smartda0436e2009-05-22 14:51:39 -040011035}
11036
11037/**
11038 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
11039 * @pdev: pointer to PCI device.
11040 *
11041 * This routine is called from the PCI subsystem for error handling to device
11042 * with SLI-4 interface spec. It is called after PCI bus has been reset to
11043 * restart the PCI card from scratch, as if from a cold-boot. During the
11044 * PCI subsystem error recovery, after the driver returns
11045 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
11046 * recovery and then call this routine before calling the .resume method to
11047 * recover the device. This function will initialize the HBA device, enable
11048 * the interrupt, but it will just put the HBA to offline state without
11049 * passing any I/O traffic.
11050 *
11051 * Return codes
11052 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11053 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11054 */
11055static pci_ers_result_t
11056lpfc_io_slot_reset_s4(struct pci_dev *pdev)
11057{
James Smart75baf692010-06-08 18:31:21 -040011058 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11059 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11060 struct lpfc_sli *psli = &phba->sli;
11061 uint32_t intr_mode;
11062
11063 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
11064 if (pci_enable_device_mem(pdev)) {
11065 printk(KERN_ERR "lpfc: Cannot re-enable "
11066 "PCI device after reset.\n");
11067 return PCI_ERS_RESULT_DISCONNECT;
11068 }
11069
11070 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040011071
11072 /*
11073 * As the new kernel behavior of pci_restore_state() API call clears
11074 * device saved_state flag, need to save the restored state again.
11075 */
11076 pci_save_state(pdev);
11077
James Smart75baf692010-06-08 18:31:21 -040011078 if (pdev->is_busmaster)
11079 pci_set_master(pdev);
11080
11081 spin_lock_irq(&phba->hbalock);
11082 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
11083 spin_unlock_irq(&phba->hbalock);
11084
11085 /* Configure and enable interrupt */
11086 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
11087 if (intr_mode == LPFC_INTR_ERROR) {
11088 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11089 "2824 Cannot re-enable interrupt after "
11090 "slot reset.\n");
11091 return PCI_ERS_RESULT_DISCONNECT;
11092 } else
11093 phba->intr_mode = intr_mode;
11094
11095 /* Log the current active interrupt mode */
11096 lpfc_log_intr_mode(phba, phba->intr_mode);
11097
James Smartda0436e2009-05-22 14:51:39 -040011098 return PCI_ERS_RESULT_RECOVERED;
11099}
11100
11101/**
11102 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
11103 * @pdev: pointer to PCI device
11104 *
11105 * This routine is called from the PCI subsystem for error handling to device
11106 * with SLI-4 interface spec. It is called when kernel error recovery tells
11107 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
11108 * error recovery. After this call, traffic can start to flow from this device
11109 * again.
11110 **/
11111static void
11112lpfc_io_resume_s4(struct pci_dev *pdev)
11113{
James Smart75baf692010-06-08 18:31:21 -040011114 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11115 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11116
11117 /*
11118 * In case of slot reset, as function reset is performed through
11119 * mailbox command which needs DMA to be enabled, this operation
11120 * has to be moved to the io resume phase. Taking device offline
11121 * will perform the necessary cleanup.
11122 */
11123 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
11124 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040011125 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040011126 lpfc_offline(phba);
11127 lpfc_sli_brdrestart(phba);
11128 /* Bring the device back online */
11129 lpfc_online(phba);
11130 }
11131
11132 /* Clean up Advanced Error Reporting (AER) if needed */
11133 if (phba->hba_flag & HBA_AER_ENABLED)
11134 pci_cleanup_aer_uncorrect_error_status(pdev);
James Smartda0436e2009-05-22 14:51:39 -040011135}
11136
11137/**
James Smart3772a992009-05-22 14:50:54 -040011138 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
11139 * @pdev: pointer to PCI device
11140 * @pid: pointer to PCI device identifier
11141 *
11142 * This routine is to be registered to the kernel's PCI subsystem. When an
11143 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
11144 * at PCI device-specific information of the device and driver to see if the
11145 * driver state that it can support this kind of device. If the match is
11146 * successful, the driver core invokes this routine. This routine dispatches
11147 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
11148 * do all the initialization that it needs to do to handle the HBA device
11149 * properly.
11150 *
11151 * Return code
11152 * 0 - driver can claim the device
11153 * negative value - driver can not claim the device
11154 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011155static int
James Smart3772a992009-05-22 14:50:54 -040011156lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
11157{
11158 int rc;
James Smart8fa38512009-07-19 10:01:03 -040011159 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040011160
James Smart28baac72010-02-12 14:42:03 -050011161 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040011162 return -ENODEV;
11163
James Smart8fa38512009-07-19 10:01:03 -040011164 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050011165 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040011166 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040011167 else
James Smart3772a992009-05-22 14:50:54 -040011168 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040011169
James Smart3772a992009-05-22 14:50:54 -040011170 return rc;
11171}
11172
11173/**
11174 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
11175 * @pdev: pointer to PCI device
11176 *
11177 * This routine is to be registered to the kernel's PCI subsystem. When an
11178 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
11179 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
11180 * remove routine, which will perform all the necessary cleanup for the
11181 * device to be removed from the PCI subsystem properly.
11182 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011183static void
James Smart3772a992009-05-22 14:50:54 -040011184lpfc_pci_remove_one(struct pci_dev *pdev)
11185{
11186 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11187 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11188
11189 switch (phba->pci_dev_grp) {
11190 case LPFC_PCI_DEV_LP:
11191 lpfc_pci_remove_one_s3(pdev);
11192 break;
James Smartda0436e2009-05-22 14:51:39 -040011193 case LPFC_PCI_DEV_OC:
11194 lpfc_pci_remove_one_s4(pdev);
11195 break;
James Smart3772a992009-05-22 14:50:54 -040011196 default:
11197 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11198 "1424 Invalid PCI device group: 0x%x\n",
11199 phba->pci_dev_grp);
11200 break;
11201 }
11202 return;
11203}
11204
11205/**
11206 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
11207 * @pdev: pointer to PCI device
11208 * @msg: power management message
11209 *
11210 * This routine is to be registered to the kernel's PCI subsystem to support
11211 * system Power Management (PM). When PM invokes this method, it dispatches
11212 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
11213 * suspend the device.
11214 *
11215 * Return code
11216 * 0 - driver suspended the device
11217 * Error otherwise
11218 **/
11219static int
11220lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
11221{
11222 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11223 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11224 int rc = -ENODEV;
11225
11226 switch (phba->pci_dev_grp) {
11227 case LPFC_PCI_DEV_LP:
11228 rc = lpfc_pci_suspend_one_s3(pdev, msg);
11229 break;
James Smartda0436e2009-05-22 14:51:39 -040011230 case LPFC_PCI_DEV_OC:
11231 rc = lpfc_pci_suspend_one_s4(pdev, msg);
11232 break;
James Smart3772a992009-05-22 14:50:54 -040011233 default:
11234 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11235 "1425 Invalid PCI device group: 0x%x\n",
11236 phba->pci_dev_grp);
11237 break;
11238 }
11239 return rc;
11240}
11241
11242/**
11243 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
11244 * @pdev: pointer to PCI device
11245 *
11246 * This routine is to be registered to the kernel's PCI subsystem to support
11247 * system Power Management (PM). When PM invokes this method, it dispatches
11248 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
11249 * resume the device.
11250 *
11251 * Return code
11252 * 0 - driver suspended the device
11253 * Error otherwise
11254 **/
11255static int
11256lpfc_pci_resume_one(struct pci_dev *pdev)
11257{
11258 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11259 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11260 int rc = -ENODEV;
11261
11262 switch (phba->pci_dev_grp) {
11263 case LPFC_PCI_DEV_LP:
11264 rc = lpfc_pci_resume_one_s3(pdev);
11265 break;
James Smartda0436e2009-05-22 14:51:39 -040011266 case LPFC_PCI_DEV_OC:
11267 rc = lpfc_pci_resume_one_s4(pdev);
11268 break;
James Smart3772a992009-05-22 14:50:54 -040011269 default:
11270 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11271 "1426 Invalid PCI device group: 0x%x\n",
11272 phba->pci_dev_grp);
11273 break;
11274 }
11275 return rc;
11276}
11277
11278/**
11279 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
11280 * @pdev: pointer to PCI device.
11281 * @state: the current PCI connection state.
11282 *
11283 * This routine is registered to the PCI subsystem for error handling. This
11284 * function is called by the PCI subsystem after a PCI bus error affecting
11285 * this device has been detected. When this routine is invoked, it dispatches
11286 * the action to the proper SLI-3 or SLI-4 device error detected handling
11287 * routine, which will perform the proper error detected operation.
11288 *
11289 * Return codes
11290 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11291 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11292 **/
11293static pci_ers_result_t
11294lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
11295{
11296 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11297 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11298 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11299
11300 switch (phba->pci_dev_grp) {
11301 case LPFC_PCI_DEV_LP:
11302 rc = lpfc_io_error_detected_s3(pdev, state);
11303 break;
James Smartda0436e2009-05-22 14:51:39 -040011304 case LPFC_PCI_DEV_OC:
11305 rc = lpfc_io_error_detected_s4(pdev, state);
11306 break;
James Smart3772a992009-05-22 14:50:54 -040011307 default:
11308 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11309 "1427 Invalid PCI device group: 0x%x\n",
11310 phba->pci_dev_grp);
11311 break;
11312 }
11313 return rc;
11314}
11315
11316/**
11317 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
11318 * @pdev: pointer to PCI device.
11319 *
11320 * This routine is registered to the PCI subsystem for error handling. This
11321 * function is called after PCI bus has been reset to restart the PCI card
11322 * from scratch, as if from a cold-boot. When this routine is invoked, it
11323 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
11324 * routine, which will perform the proper device reset.
11325 *
11326 * Return codes
11327 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11328 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11329 **/
11330static pci_ers_result_t
11331lpfc_io_slot_reset(struct pci_dev *pdev)
11332{
11333 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11334 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11335 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11336
11337 switch (phba->pci_dev_grp) {
11338 case LPFC_PCI_DEV_LP:
11339 rc = lpfc_io_slot_reset_s3(pdev);
11340 break;
James Smartda0436e2009-05-22 14:51:39 -040011341 case LPFC_PCI_DEV_OC:
11342 rc = lpfc_io_slot_reset_s4(pdev);
11343 break;
James Smart3772a992009-05-22 14:50:54 -040011344 default:
11345 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11346 "1428 Invalid PCI device group: 0x%x\n",
11347 phba->pci_dev_grp);
11348 break;
11349 }
11350 return rc;
11351}
11352
11353/**
11354 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
11355 * @pdev: pointer to PCI device
11356 *
11357 * This routine is registered to the PCI subsystem for error handling. It
11358 * is called when kernel error recovery tells the lpfc driver that it is
11359 * OK to resume normal PCI operation after PCI bus error recovery. When
11360 * this routine is invoked, it dispatches the action to the proper SLI-3
11361 * or SLI-4 device io_resume routine, which will resume the device operation.
11362 **/
11363static void
11364lpfc_io_resume(struct pci_dev *pdev)
11365{
11366 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11367 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11368
11369 switch (phba->pci_dev_grp) {
11370 case LPFC_PCI_DEV_LP:
11371 lpfc_io_resume_s3(pdev);
11372 break;
James Smartda0436e2009-05-22 14:51:39 -040011373 case LPFC_PCI_DEV_OC:
11374 lpfc_io_resume_s4(pdev);
11375 break;
James Smart3772a992009-05-22 14:50:54 -040011376 default:
11377 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11378 "1429 Invalid PCI device group: 0x%x\n",
11379 phba->pci_dev_grp);
11380 break;
11381 }
11382 return;
11383}
11384
James Smart1ba981f2014-02-20 09:56:45 -050011385/**
11386 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
11387 * @phba: pointer to lpfc hba data structure.
11388 *
11389 * This routine checks to see if OAS is supported for this adapter. If
11390 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
11391 * the enable oas flag is cleared and the pool created for OAS device data
11392 * is destroyed.
11393 *
11394 **/
11395void
11396lpfc_sli4_oas_verify(struct lpfc_hba *phba)
11397{
11398
11399 if (!phba->cfg_EnableXLane)
11400 return;
11401
11402 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
11403 phba->cfg_fof = 1;
11404 } else {
James Smartf38fa0b2014-04-04 13:52:21 -040011405 phba->cfg_fof = 0;
James Smart1ba981f2014-02-20 09:56:45 -050011406 if (phba->device_data_mem_pool)
11407 mempool_destroy(phba->device_data_mem_pool);
11408 phba->device_data_mem_pool = NULL;
11409 }
11410
11411 return;
11412}
11413
11414/**
11415 * lpfc_fof_queue_setup - Set up all the fof queues
11416 * @phba: pointer to lpfc hba data structure.
11417 *
11418 * This routine is invoked to set up all the fof queues for the FC HBA
11419 * operation.
11420 *
11421 * Return codes
11422 * 0 - successful
11423 * -ENOMEM - No available memory
11424 **/
11425int
11426lpfc_fof_queue_setup(struct lpfc_hba *phba)
11427{
James Smart895427b2017-02-12 13:52:30 -080011428 struct lpfc_sli_ring *pring;
James Smart1ba981f2014-02-20 09:56:45 -050011429 int rc;
11430
11431 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
11432 if (rc)
11433 return -ENOMEM;
11434
James Smartf38fa0b2014-04-04 13:52:21 -040011435 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050011436
11437 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
11438 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
11439 if (rc)
11440 goto out_oas_cq;
11441
11442 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
11443 phba->sli4_hba.oas_cq, LPFC_FCP);
11444 if (rc)
11445 goto out_oas_wq;
11446
James Smart895427b2017-02-12 13:52:30 -080011447 /* Bind this CQ/WQ to the NVME ring */
11448 pring = phba->sli4_hba.oas_wq->pring;
11449 pring->sli.sli4.wqp =
11450 (void *)phba->sli4_hba.oas_wq;
11451 phba->sli4_hba.oas_cq->pring = pring;
James Smart1ba981f2014-02-20 09:56:45 -050011452 }
11453
11454 return 0;
11455
11456out_oas_wq:
James Smartf38fa0b2014-04-04 13:52:21 -040011457 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
James Smart1ba981f2014-02-20 09:56:45 -050011458out_oas_cq:
11459 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
11460 return rc;
11461
11462}
11463
11464/**
11465 * lpfc_fof_queue_create - Create all the fof queues
11466 * @phba: pointer to lpfc hba data structure.
11467 *
11468 * This routine is invoked to allocate all the fof queues for the FC HBA
11469 * operation. For each SLI4 queue type, the parameters such as queue entry
11470 * count (queue depth) shall be taken from the module parameter. For now,
11471 * we just use some constant number as place holder.
11472 *
11473 * Return codes
11474 * 0 - successful
11475 * -ENOMEM - No availble memory
11476 * -EIO - The mailbox failed to complete successfully.
11477 **/
11478int
11479lpfc_fof_queue_create(struct lpfc_hba *phba)
11480{
11481 struct lpfc_queue *qdesc;
11482
11483 /* Create FOF EQ */
11484 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
11485 phba->sli4_hba.eq_ecount);
11486 if (!qdesc)
11487 goto out_error;
11488
11489 phba->sli4_hba.fof_eq = qdesc;
11490
James Smartf38fa0b2014-04-04 13:52:21 -040011491 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050011492
11493 /* Create OAS CQ */
11494 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
11495 phba->sli4_hba.cq_ecount);
11496 if (!qdesc)
11497 goto out_error;
11498
11499 phba->sli4_hba.oas_cq = qdesc;
11500
11501 /* Create OAS WQ */
11502 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
11503 phba->sli4_hba.wq_ecount);
11504 if (!qdesc)
11505 goto out_error;
11506
11507 phba->sli4_hba.oas_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -080011508 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
James Smart1ba981f2014-02-20 09:56:45 -050011509
11510 }
11511 return 0;
11512
11513out_error:
11514 lpfc_fof_queue_destroy(phba);
11515 return -ENOMEM;
11516}
11517
11518/**
11519 * lpfc_fof_queue_destroy - Destroy all the fof queues
11520 * @phba: pointer to lpfc hba data structure.
11521 *
11522 * This routine is invoked to release all the SLI4 queues with the FC HBA
11523 * operation.
11524 *
11525 * Return codes
11526 * 0 - successful
11527 **/
11528int
11529lpfc_fof_queue_destroy(struct lpfc_hba *phba)
11530{
11531 /* Release FOF Event queue */
11532 if (phba->sli4_hba.fof_eq != NULL) {
11533 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
11534 phba->sli4_hba.fof_eq = NULL;
11535 }
11536
11537 /* Release OAS Completion queue */
11538 if (phba->sli4_hba.oas_cq != NULL) {
11539 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
11540 phba->sli4_hba.oas_cq = NULL;
11541 }
11542
11543 /* Release OAS Work queue */
11544 if (phba->sli4_hba.oas_wq != NULL) {
11545 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
11546 phba->sli4_hba.oas_wq = NULL;
11547 }
11548 return 0;
11549}
11550
dea31012005-04-17 16:05:31 -050011551MODULE_DEVICE_TABLE(pci, lpfc_id_table);
11552
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070011553static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060011554 .error_detected = lpfc_io_error_detected,
11555 .slot_reset = lpfc_io_slot_reset,
11556 .resume = lpfc_io_resume,
11557};
11558
dea31012005-04-17 16:05:31 -050011559static struct pci_driver lpfc_driver = {
11560 .name = LPFC_DRIVER_NAME,
11561 .id_table = lpfc_id_table,
11562 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011563 .remove = lpfc_pci_remove_one,
James Smart3a55b532008-12-04 22:38:54 -050011564 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040011565 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050011566 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050011567};
11568
James Smart3ef6d242012-01-18 16:23:48 -050011569static const struct file_operations lpfc_mgmt_fop = {
Al Viro858feac2013-04-14 22:39:37 -040011570 .owner = THIS_MODULE,
James Smart3ef6d242012-01-18 16:23:48 -050011571};
11572
11573static struct miscdevice lpfc_mgmt_dev = {
11574 .minor = MISC_DYNAMIC_MINOR,
11575 .name = "lpfcmgmt",
11576 .fops = &lpfc_mgmt_fop,
11577};
11578
James Smarte59058c2008-08-24 21:49:00 -040011579/**
James Smart3621a712009-04-06 18:47:14 -040011580 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040011581 *
11582 * This routine is to be invoked when the lpfc module is loaded into the
11583 * kernel. The special kernel macro module_init() is used to indicate the
11584 * role of this routine to the kernel as lpfc module entry point.
11585 *
11586 * Return codes
11587 * 0 - successful
11588 * -ENOMEM - FC attach transport failed
11589 * all others - failed
11590 */
dea31012005-04-17 16:05:31 -050011591static int __init
11592lpfc_init(void)
11593{
11594 int error = 0;
11595
11596 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040011597 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050011598
James Smart3ef6d242012-01-18 16:23:48 -050011599 error = misc_register(&lpfc_mgmt_dev);
11600 if (error)
11601 printk(KERN_ERR "Could not register lpfcmgmt device, "
11602 "misc_register returned with status %d", error);
11603
James Smart458c0832016-07-06 12:36:07 -070011604 lpfc_transport_functions.vport_create = lpfc_vport_create;
11605 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
dea31012005-04-17 16:05:31 -050011606 lpfc_transport_template =
11607 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040011608 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050011609 return -ENOMEM;
James Smart458c0832016-07-06 12:36:07 -070011610 lpfc_vport_transport_template =
11611 fc_attach_transport(&lpfc_vport_transport_functions);
11612 if (lpfc_vport_transport_template == NULL) {
11613 fc_release_transport(lpfc_transport_template);
11614 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040011615 }
James Smart7bb03bb2013-04-17 20:19:16 -040011616
11617 /* Initialize in case vector mapping is needed */
James Smartb246de12013-05-31 17:03:07 -040011618 lpfc_used_cpu = NULL;
James Smart2ea259e2017-02-12 13:52:27 -080011619 lpfc_present_cpu = num_present_cpus();
James Smart7bb03bb2013-04-17 20:19:16 -040011620
dea31012005-04-17 16:05:31 -050011621 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050011622 if (error) {
dea31012005-04-17 16:05:31 -050011623 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070011624 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050011625 }
dea31012005-04-17 16:05:31 -050011626
11627 return error;
11628}
11629
James Smarte59058c2008-08-24 21:49:00 -040011630/**
James Smart3621a712009-04-06 18:47:14 -040011631 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040011632 *
11633 * This routine is invoked when the lpfc module is removed from the kernel.
11634 * The special kernel macro module_exit() is used to indicate the role of
11635 * this routine to the kernel as lpfc module exit point.
11636 */
dea31012005-04-17 16:05:31 -050011637static void __exit
11638lpfc_exit(void)
11639{
James Smart3ef6d242012-01-18 16:23:48 -050011640 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050011641 pci_unregister_driver(&lpfc_driver);
11642 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070011643 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050011644 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040011645 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
11646 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050011647 (1L << _dump_buf_data_order), _dump_buf_data);
11648 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
11649 }
11650
11651 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040011652 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
11653 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050011654 (1L << _dump_buf_dif_order), _dump_buf_dif);
11655 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
11656 }
James Smartb246de12013-05-31 17:03:07 -040011657 kfree(lpfc_used_cpu);
Johannes Thumshirn79739672015-08-31 16:48:11 -040011658 idr_destroy(&lpfc_hba_index);
dea31012005-04-17 16:05:31 -050011659}
11660
11661module_init(lpfc_init);
11662module_exit(lpfc_exit);
11663MODULE_LICENSE("GPL");
11664MODULE_DESCRIPTION(LPFC_MODULE_DESC);
11665MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
11666MODULE_VERSION("0:" LPFC_DRIVER_VERSION);