blob: e609afaa472a0f192d5a7184300e14b9260606dc [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;
3131 struct lpfc_iocbq *io, *io_next;
3132
James Smart895427b2017-02-12 13:52:30 -08003133 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3134 return;
3135
James Smart2e0fef82007-06-17 19:56:36 -05003136 spin_lock_irq(&phba->hbalock);
James Smarta40fc5f2013-04-17 20:17:40 -04003137
dea31012005-04-17 16:05:31 -05003138 /* Release all the lpfc_scsi_bufs maintained by this host. */
James Smarta40fc5f2013-04-17 20:17:40 -04003139
3140 spin_lock(&phba->scsi_buf_list_put_lock);
3141 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
3142 list) {
dea31012005-04-17 16:05:31 -05003143 list_del(&sb->list);
James Smart895427b2017-02-12 13:52:30 -08003144 pci_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smart92d7f7b2007-06-17 19:56:38 -05003145 sb->dma_handle);
dea31012005-04-17 16:05:31 -05003146 kfree(sb);
3147 phba->total_scsi_bufs--;
3148 }
James Smarta40fc5f2013-04-17 20:17:40 -04003149 spin_unlock(&phba->scsi_buf_list_put_lock);
3150
3151 spin_lock(&phba->scsi_buf_list_get_lock);
3152 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
3153 list) {
3154 list_del(&sb->list);
James Smart895427b2017-02-12 13:52:30 -08003155 pci_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data,
James Smarta40fc5f2013-04-17 20:17:40 -04003156 sb->dma_handle);
3157 kfree(sb);
3158 phba->total_scsi_bufs--;
3159 }
3160 spin_unlock(&phba->scsi_buf_list_get_lock);
dea31012005-04-17 16:05:31 -05003161
3162 /* Release all the lpfc_iocbq entries maintained by this host. */
3163 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
3164 list_del(&io->list);
3165 kfree(io);
3166 phba->total_iocbq_bufs--;
3167 }
James Smart6d368e52011-05-24 11:44:12 -04003168
James Smart2e0fef82007-06-17 19:56:36 -05003169 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003170}
James Smart8a9d2e82012-05-09 21:16:12 -04003171/**
James Smart895427b2017-02-12 13:52:30 -08003172 * lpfc_nvme_free - Free all the NVME buffers and IOCBs from driver lists
3173 * @phba: pointer to lpfc hba data structure.
3174 *
3175 * This routine is to free all the NVME buffers and IOCBs from the driver
3176 * list back to kernel. It is called from lpfc_pci_remove_one to free
3177 * the internal resources before the device is removed from the system.
3178 **/
3179static void
3180lpfc_nvme_free(struct lpfc_hba *phba)
3181{
3182 struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next;
3183 struct lpfc_iocbq *io, *io_next;
3184
3185 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3186 return;
3187
3188 spin_lock_irq(&phba->hbalock);
3189
3190 /* Release all the lpfc_nvme_bufs maintained by this host. */
3191 spin_lock(&phba->nvme_buf_list_put_lock);
3192 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3193 &phba->lpfc_nvme_buf_list_put, list) {
3194 list_del(&lpfc_ncmd->list);
3195 pci_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
3196 lpfc_ncmd->dma_handle);
3197 kfree(lpfc_ncmd);
3198 phba->total_nvme_bufs--;
3199 }
3200 spin_unlock(&phba->nvme_buf_list_put_lock);
3201
3202 spin_lock(&phba->nvme_buf_list_get_lock);
3203 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3204 &phba->lpfc_nvme_buf_list_get, list) {
3205 list_del(&lpfc_ncmd->list);
3206 pci_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data,
3207 lpfc_ncmd->dma_handle);
3208 kfree(lpfc_ncmd);
3209 phba->total_nvme_bufs--;
3210 }
3211 spin_unlock(&phba->nvme_buf_list_get_lock);
3212
3213 /* Release all the lpfc_iocbq entries maintained by this host. */
3214 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
3215 list_del(&io->list);
3216 kfree(io);
3217 phba->total_iocbq_bufs--;
3218 }
3219
3220 spin_unlock_irq(&phba->hbalock);
3221}
3222/**
3223 * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping
James Smart8a9d2e82012-05-09 21:16:12 -04003224 * @phba: pointer to lpfc hba data structure.
3225 *
3226 * This routine first calculates the sizes of the current els and allocated
3227 * scsi sgl lists, and then goes through all sgls to updates the physical
3228 * XRIs assigned due to port function reset. During port initialization, the
3229 * current els and allocated scsi sgl lists are 0s.
3230 *
3231 * Return codes
3232 * 0 - successful (for now, it always returns 0)
3233 **/
3234int
James Smart895427b2017-02-12 13:52:30 -08003235lpfc_sli4_els_sgl_update(struct lpfc_hba *phba)
James Smart8a9d2e82012-05-09 21:16:12 -04003236{
3237 struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL;
James Smart895427b2017-02-12 13:52:30 -08003238 uint16_t i, lxri, xri_cnt, els_xri_cnt;
James Smart8a9d2e82012-05-09 21:16:12 -04003239 LIST_HEAD(els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003240 int rc;
3241
3242 /*
3243 * update on pci function's els xri-sgl list
3244 */
3245 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
James Smart895427b2017-02-12 13:52:30 -08003246
James Smart8a9d2e82012-05-09 21:16:12 -04003247 if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) {
3248 /* els xri-sgl expanded */
3249 xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt;
3250 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3251 "3157 ELS xri-sgl count increased from "
3252 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3253 els_xri_cnt);
3254 /* allocate the additional els sgls */
3255 for (i = 0; i < xri_cnt; i++) {
3256 sglq_entry = kzalloc(sizeof(struct lpfc_sglq),
3257 GFP_KERNEL);
3258 if (sglq_entry == NULL) {
3259 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3260 "2562 Failure to allocate an "
3261 "ELS sgl entry:%d\n", i);
3262 rc = -ENOMEM;
3263 goto out_free_mem;
3264 }
3265 sglq_entry->buff_type = GEN_BUFF_TYPE;
3266 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0,
3267 &sglq_entry->phys);
3268 if (sglq_entry->virt == NULL) {
3269 kfree(sglq_entry);
3270 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3271 "2563 Failure to allocate an "
3272 "ELS mbuf:%d\n", i);
3273 rc = -ENOMEM;
3274 goto out_free_mem;
3275 }
3276 sglq_entry->sgl = sglq_entry->virt;
3277 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3278 sglq_entry->state = SGL_FREED;
3279 list_add_tail(&sglq_entry->list, &els_sgl_list);
3280 }
James Smart38c20672013-03-01 16:37:44 -05003281 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003282 spin_lock(&phba->sli4_hba.sgl_list_lock);
3283 list_splice_init(&els_sgl_list,
3284 &phba->sli4_hba.lpfc_els_sgl_list);
3285 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart38c20672013-03-01 16:37:44 -05003286 spin_unlock_irq(&phba->hbalock);
James Smart8a9d2e82012-05-09 21:16:12 -04003287 } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) {
3288 /* els xri-sgl shrinked */
3289 xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt;
3290 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3291 "3158 ELS xri-sgl count decreased from "
3292 "%d to %d\n", phba->sli4_hba.els_xri_cnt,
3293 els_xri_cnt);
3294 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08003295 spin_lock(&phba->sli4_hba.sgl_list_lock);
3296 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list,
3297 &els_sgl_list);
James Smart8a9d2e82012-05-09 21:16:12 -04003298 /* release extra els sgls from list */
3299 for (i = 0; i < xri_cnt; i++) {
3300 list_remove_head(&els_sgl_list,
3301 sglq_entry, struct lpfc_sglq, list);
3302 if (sglq_entry) {
James Smart895427b2017-02-12 13:52:30 -08003303 __lpfc_mbuf_free(phba, sglq_entry->virt,
3304 sglq_entry->phys);
James Smart8a9d2e82012-05-09 21:16:12 -04003305 kfree(sglq_entry);
3306 }
3307 }
James Smart895427b2017-02-12 13:52:30 -08003308 list_splice_init(&els_sgl_list,
3309 &phba->sli4_hba.lpfc_els_sgl_list);
3310 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003311 spin_unlock_irq(&phba->hbalock);
3312 } else
3313 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3314 "3163 ELS xri-sgl count unchanged: %d\n",
3315 els_xri_cnt);
3316 phba->sli4_hba.els_xri_cnt = els_xri_cnt;
3317
3318 /* update xris to els sgls on the list */
3319 sglq_entry = NULL;
3320 sglq_entry_next = NULL;
3321 list_for_each_entry_safe(sglq_entry, sglq_entry_next,
James Smart895427b2017-02-12 13:52:30 -08003322 &phba->sli4_hba.lpfc_els_sgl_list, list) {
James Smart8a9d2e82012-05-09 21:16:12 -04003323 lxri = lpfc_sli4_next_xritag(phba);
3324 if (lxri == NO_XRI) {
3325 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3326 "2400 Failed to allocate xri for "
3327 "ELS sgl\n");
3328 rc = -ENOMEM;
3329 goto out_free_mem;
3330 }
3331 sglq_entry->sli4_lxritag = lxri;
3332 sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3333 }
James Smart895427b2017-02-12 13:52:30 -08003334 return 0;
3335
3336out_free_mem:
3337 lpfc_free_els_sgl_list(phba);
3338 return rc;
3339}
3340
3341/**
3342 * lpfc_sli4_scsi_sgl_update - update xri-sgl sizing and mapping
3343 * @phba: pointer to lpfc hba data structure.
3344 *
3345 * This routine first calculates the sizes of the current els and allocated
3346 * scsi sgl lists, and then goes through all sgls to updates the physical
3347 * XRIs assigned due to port function reset. During port initialization, the
3348 * current els and allocated scsi sgl lists are 0s.
3349 *
3350 * Return codes
3351 * 0 - successful (for now, it always returns 0)
3352 **/
3353int
3354lpfc_sli4_scsi_sgl_update(struct lpfc_hba *phba)
3355{
3356 struct lpfc_scsi_buf *psb, *psb_next;
3357 uint16_t i, lxri, els_xri_cnt, scsi_xri_cnt;
3358 LIST_HEAD(scsi_sgl_list);
3359 int rc;
3360
3361 /*
3362 * update on pci function's els xri-sgl list
3363 */
3364 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3365 phba->total_scsi_bufs = 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003366
3367 /*
3368 * update on pci function's allocated scsi xri-sgl list
3369 */
James Smart8a9d2e82012-05-09 21:16:12 -04003370 /* maximum number of xris available for scsi buffers */
3371 phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri -
3372 els_xri_cnt;
3373
James Smart895427b2017-02-12 13:52:30 -08003374 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
3375 return 0;
3376
3377 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
3378 phba->sli4_hba.scsi_xri_max = /* Split them up */
3379 (phba->sli4_hba.scsi_xri_max *
3380 phba->cfg_xri_split) / 100;
James Smart8a9d2e82012-05-09 21:16:12 -04003381
James Smarta40fc5f2013-04-17 20:17:40 -04003382 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003383 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003384 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3385 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
James Smart164cecd2013-09-06 12:22:38 -04003386 spin_unlock(&phba->scsi_buf_list_put_lock);
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 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
3390 /* max scsi xri shrinked below the allocated scsi buffers */
3391 scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt -
3392 phba->sli4_hba.scsi_xri_max;
3393 /* release the extra allocated scsi buffers */
3394 for (i = 0; i < scsi_xri_cnt; i++) {
3395 list_remove_head(&scsi_sgl_list, psb,
3396 struct lpfc_scsi_buf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04003397 if (psb) {
James Smart895427b2017-02-12 13:52:30 -08003398 pci_pool_free(phba->lpfc_sg_dma_buf_pool,
James Smarta2fc4aef2014-09-03 12:57:55 -04003399 psb->data, psb->dma_handle);
3400 kfree(psb);
3401 }
James Smart8a9d2e82012-05-09 21:16:12 -04003402 }
James Smarta40fc5f2013-04-17 20:17:40 -04003403 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003404 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
James Smarta40fc5f2013-04-17 20:17:40 -04003405 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
James Smart8a9d2e82012-05-09 21:16:12 -04003406 }
3407
3408 /* update xris associated to remaining allocated scsi buffers */
3409 psb = NULL;
3410 psb_next = NULL;
3411 list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) {
3412 lxri = lpfc_sli4_next_xritag(phba);
3413 if (lxri == NO_XRI) {
3414 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3415 "2560 Failed to allocate xri for "
3416 "scsi buffer\n");
3417 rc = -ENOMEM;
3418 goto out_free_mem;
3419 }
3420 psb->cur_iocbq.sli4_lxritag = lxri;
3421 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3422 }
James Smarta40fc5f2013-04-17 20:17:40 -04003423 spin_lock_irq(&phba->scsi_buf_list_get_lock);
James Smart164cecd2013-09-06 12:22:38 -04003424 spin_lock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003425 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3426 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
James Smart164cecd2013-09-06 12:22:38 -04003427 spin_unlock(&phba->scsi_buf_list_put_lock);
James Smarta40fc5f2013-04-17 20:17:40 -04003428 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
dea31012005-04-17 16:05:31 -05003429 return 0;
James Smart8a9d2e82012-05-09 21:16:12 -04003430
3431out_free_mem:
James Smart8a9d2e82012-05-09 21:16:12 -04003432 lpfc_scsi_free(phba);
3433 return rc;
dea31012005-04-17 16:05:31 -05003434}
3435
James Smarte59058c2008-08-24 21:49:00 -04003436/**
James Smart895427b2017-02-12 13:52:30 -08003437 * lpfc_sli4_nvme_sgl_update - update xri-sgl sizing and mapping
3438 * @phba: pointer to lpfc hba data structure.
3439 *
3440 * This routine first calculates the sizes of the current els and allocated
3441 * scsi sgl lists, and then goes through all sgls to updates the physical
3442 * XRIs assigned due to port function reset. During port initialization, the
3443 * current els and allocated scsi sgl lists are 0s.
3444 *
3445 * Return codes
3446 * 0 - successful (for now, it always returns 0)
3447 **/
3448int
3449lpfc_sli4_nvme_sgl_update(struct lpfc_hba *phba)
3450{
3451 struct lpfc_nvme_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL;
3452 uint16_t i, lxri, els_xri_cnt;
3453 uint16_t nvme_xri_cnt, nvme_xri_max;
3454 LIST_HEAD(nvme_sgl_list);
3455 int rc;
3456
3457 phba->total_nvme_bufs = 0;
3458
3459 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME))
3460 return 0;
3461 /*
3462 * update on pci function's allocated nvme xri-sgl list
3463 */
3464
3465 /* maximum number of xris available for nvme buffers */
3466 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3467 nvme_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3468 phba->sli4_hba.nvme_xri_max = nvme_xri_max;
3469 phba->sli4_hba.nvme_xri_max -= phba->sli4_hba.scsi_xri_max;
3470
3471 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3472 "6074 Current allocated NVME xri-sgl count:%d, "
3473 "maximum NVME xri count:%d\n",
3474 phba->sli4_hba.nvme_xri_cnt,
3475 phba->sli4_hba.nvme_xri_max);
3476
3477 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3478 spin_lock(&phba->nvme_buf_list_put_lock);
3479 list_splice_init(&phba->lpfc_nvme_buf_list_get, &nvme_sgl_list);
3480 list_splice(&phba->lpfc_nvme_buf_list_put, &nvme_sgl_list);
3481 spin_unlock(&phba->nvme_buf_list_put_lock);
3482 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3483
3484 if (phba->sli4_hba.nvme_xri_cnt > phba->sli4_hba.nvme_xri_max) {
3485 /* max nvme xri shrunk below the allocated nvme buffers */
3486 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3487 nvme_xri_cnt = phba->sli4_hba.nvme_xri_cnt -
3488 phba->sli4_hba.nvme_xri_max;
3489 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3490 /* release the extra allocated nvme buffers */
3491 for (i = 0; i < nvme_xri_cnt; i++) {
3492 list_remove_head(&nvme_sgl_list, lpfc_ncmd,
3493 struct lpfc_nvme_buf, list);
3494 if (lpfc_ncmd) {
3495 pci_pool_free(phba->lpfc_sg_dma_buf_pool,
3496 lpfc_ncmd->data,
3497 lpfc_ncmd->dma_handle);
3498 kfree(lpfc_ncmd);
3499 }
3500 }
3501 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3502 phba->sli4_hba.nvme_xri_cnt -= nvme_xri_cnt;
3503 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3504 }
3505
3506 /* update xris associated to remaining allocated nvme buffers */
3507 lpfc_ncmd = NULL;
3508 lpfc_ncmd_next = NULL;
3509 list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
3510 &nvme_sgl_list, list) {
3511 lxri = lpfc_sli4_next_xritag(phba);
3512 if (lxri == NO_XRI) {
3513 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3514 "6075 Failed to allocate xri for "
3515 "nvme buffer\n");
3516 rc = -ENOMEM;
3517 goto out_free_mem;
3518 }
3519 lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri;
3520 lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3521 }
3522 spin_lock_irq(&phba->nvme_buf_list_get_lock);
3523 spin_lock(&phba->nvme_buf_list_put_lock);
3524 list_splice_init(&nvme_sgl_list, &phba->lpfc_nvme_buf_list_get);
3525 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
3526 spin_unlock(&phba->nvme_buf_list_put_lock);
3527 spin_unlock_irq(&phba->nvme_buf_list_get_lock);
3528 return 0;
3529
3530out_free_mem:
3531 lpfc_nvme_free(phba);
3532 return rc;
3533}
3534
3535/**
James Smart3621a712009-04-06 18:47:14 -04003536 * lpfc_create_port - Create an FC port
James Smarte59058c2008-08-24 21:49:00 -04003537 * @phba: pointer to lpfc hba data structure.
3538 * @instance: a unique integer ID to this FC port.
3539 * @dev: pointer to the device data structure.
3540 *
3541 * This routine creates a FC port for the upper layer protocol. The FC port
3542 * can be created on top of either a physical port or a virtual port provided
3543 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3544 * and associates the FC port created before adding the shost into the SCSI
3545 * layer.
3546 *
3547 * Return codes
3548 * @vport - pointer to the virtual N_Port data structure.
3549 * NULL - port create failed.
3550 **/
James Smart2e0fef82007-06-17 19:56:36 -05003551struct lpfc_vport *
James Smart3de2a652007-08-02 11:09:59 -04003552lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
James Smart47a86172007-04-25 09:53:22 -04003553{
James Smart2e0fef82007-06-17 19:56:36 -05003554 struct lpfc_vport *vport;
James Smart895427b2017-02-12 13:52:30 -08003555 struct Scsi_Host *shost = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003556 int error = 0;
James Smart47a86172007-04-25 09:53:22 -04003557
James Smart895427b2017-02-12 13:52:30 -08003558 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
3559 if (dev != &phba->pcidev->dev) {
3560 shost = scsi_host_alloc(&lpfc_vport_template,
3561 sizeof(struct lpfc_vport));
3562 } else {
3563 if (phba->sli_rev == LPFC_SLI_REV4)
3564 shost = scsi_host_alloc(&lpfc_template,
3565 sizeof(struct lpfc_vport));
3566 else
3567 shost = scsi_host_alloc(&lpfc_template_s3,
3568 sizeof(struct lpfc_vport));
3569 }
3570 } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
3571 shost = scsi_host_alloc(&lpfc_template_nvme,
James Smartea4142f2015-04-07 15:07:13 -04003572 sizeof(struct lpfc_vport));
3573 }
James Smart2e0fef82007-06-17 19:56:36 -05003574 if (!shost)
3575 goto out;
James Smart47a86172007-04-25 09:53:22 -04003576
James Smart2e0fef82007-06-17 19:56:36 -05003577 vport = (struct lpfc_vport *) shost->hostdata;
3578 vport->phba = phba;
James Smart2e0fef82007-06-17 19:56:36 -05003579 vport->load_flag |= FC_LOADING;
James Smart92d7f7b2007-06-17 19:56:38 -05003580 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart7f5f3d02008-02-08 18:50:14 -05003581 vport->fc_rscn_flush = 0;
James Smart3de2a652007-08-02 11:09:59 -04003582 lpfc_get_vport_cfgparam(vport);
James Smart895427b2017-02-12 13:52:30 -08003583
James Smart2e0fef82007-06-17 19:56:36 -05003584 shost->unique_id = instance;
3585 shost->max_id = LPFC_MAX_TARGET;
James Smart3de2a652007-08-02 11:09:59 -04003586 shost->max_lun = vport->cfg_max_luns;
James Smart2e0fef82007-06-17 19:56:36 -05003587 shost->this_id = -1;
3588 shost->max_cmd_len = 16;
James Smart8b0dff12015-05-22 10:42:38 -04003589 shost->nr_hw_queues = phba->cfg_fcp_io_channel;
James Smartda0436e2009-05-22 14:51:39 -04003590 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart28baac72010-02-12 14:42:03 -05003591 shost->dma_boundary =
James Smartcb5172e2010-03-15 11:25:07 -04003592 phba->sli4_hba.pc_sli4_params.sge_supp_len-1;
James Smartda0436e2009-05-22 14:51:39 -04003593 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
3594 }
James Smart81301a92008-12-04 22:39:46 -05003595
James Smart47a86172007-04-25 09:53:22 -04003596 /*
James Smart2e0fef82007-06-17 19:56:36 -05003597 * Set initial can_queue value since 0 is no longer supported and
3598 * scsi_add_host will fail. This will be adjusted later based on the
3599 * max xri value determined in hba setup.
James Smart47a86172007-04-25 09:53:22 -04003600 */
James Smart2e0fef82007-06-17 19:56:36 -05003601 shost->can_queue = phba->cfg_hba_queue_depth - 10;
James Smart3de2a652007-08-02 11:09:59 -04003602 if (dev != &phba->pcidev->dev) {
James Smart92d7f7b2007-06-17 19:56:38 -05003603 shost->transportt = lpfc_vport_transport_template;
3604 vport->port_type = LPFC_NPIV_PORT;
3605 } else {
3606 shost->transportt = lpfc_transport_template;
3607 vport->port_type = LPFC_PHYSICAL_PORT;
3608 }
James Smart47a86172007-04-25 09:53:22 -04003609
James Smart2e0fef82007-06-17 19:56:36 -05003610 /* Initialize all internally managed lists. */
3611 INIT_LIST_HEAD(&vport->fc_nodes);
James Smartda0436e2009-05-22 14:51:39 -04003612 INIT_LIST_HEAD(&vport->rcv_buffer_list);
James Smart2e0fef82007-06-17 19:56:36 -05003613 spin_lock_init(&vport->work_port_lock);
James Smart47a86172007-04-25 09:53:22 -04003614
James Smart2e0fef82007-06-17 19:56:36 -05003615 init_timer(&vport->fc_disctmo);
3616 vport->fc_disctmo.function = lpfc_disc_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003617 vport->fc_disctmo.data = (unsigned long)vport;
James Smart47a86172007-04-25 09:53:22 -04003618
James Smart2e0fef82007-06-17 19:56:36 -05003619 init_timer(&vport->els_tmofunc);
3620 vport->els_tmofunc.function = lpfc_els_timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003621 vport->els_tmofunc.data = (unsigned long)vport;
James Smart92494142011-02-16 12:39:44 -05003622
3623 init_timer(&vport->delayed_disc_tmo);
3624 vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo;
3625 vport->delayed_disc_tmo.data = (unsigned long)vport;
3626
James Bottomleyd139b9b2009-11-05 13:33:12 -06003627 error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05003628 if (error)
3629 goto out_put_shost;
James Smart47a86172007-04-25 09:53:22 -04003630
James Smart549e55c2007-08-02 11:09:51 -04003631 spin_lock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003632 list_add_tail(&vport->listentry, &phba->port_list);
James Smart549e55c2007-08-02 11:09:51 -04003633 spin_unlock_irq(&phba->hbalock);
James Smart2e0fef82007-06-17 19:56:36 -05003634 return vport;
James Smart47a86172007-04-25 09:53:22 -04003635
James Smart2e0fef82007-06-17 19:56:36 -05003636out_put_shost:
3637 scsi_host_put(shost);
3638out:
3639 return NULL;
James Smart47a86172007-04-25 09:53:22 -04003640}
3641
James Smarte59058c2008-08-24 21:49:00 -04003642/**
James Smart3621a712009-04-06 18:47:14 -04003643 * destroy_port - destroy an FC port
James Smarte59058c2008-08-24 21:49:00 -04003644 * @vport: pointer to an lpfc virtual N_Port data structure.
3645 *
3646 * This routine destroys a FC port from the upper layer protocol. All the
3647 * resources associated with the port are released.
3648 **/
James Smart2e0fef82007-06-17 19:56:36 -05003649void
3650destroy_port(struct lpfc_vport *vport)
James Smart47a86172007-04-25 09:53:22 -04003651{
James Smart92d7f7b2007-06-17 19:56:38 -05003652 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3653 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003654
James Smart858c9f62007-06-17 19:56:39 -05003655 lpfc_debugfs_terminate(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05003656 fc_remove_host(shost);
3657 scsi_remove_host(shost);
James Smart47a86172007-04-25 09:53:22 -04003658
James Smart92d7f7b2007-06-17 19:56:38 -05003659 spin_lock_irq(&phba->hbalock);
3660 list_del_init(&vport->listentry);
3661 spin_unlock_irq(&phba->hbalock);
James Smart47a86172007-04-25 09:53:22 -04003662
James Smart92d7f7b2007-06-17 19:56:38 -05003663 lpfc_cleanup(vport);
James Smart47a86172007-04-25 09:53:22 -04003664 return;
James Smart47a86172007-04-25 09:53:22 -04003665}
3666
James Smarte59058c2008-08-24 21:49:00 -04003667/**
James Smart3621a712009-04-06 18:47:14 -04003668 * lpfc_get_instance - Get a unique integer ID
James Smarte59058c2008-08-24 21:49:00 -04003669 *
3670 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3671 * uses the kernel idr facility to perform the task.
3672 *
3673 * Return codes:
3674 * instance - a unique integer ID allocated as the new instance.
3675 * -1 - lpfc get instance failed.
3676 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003677int
3678lpfc_get_instance(void)
3679{
Tejun Heoab516032013-02-27 17:04:44 -08003680 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003681
Tejun Heoab516032013-02-27 17:04:44 -08003682 ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
3683 return ret < 0 ? -1 : ret;
James Smart92d7f7b2007-06-17 19:56:38 -05003684}
3685
James Smarte59058c2008-08-24 21:49:00 -04003686/**
James Smart3621a712009-04-06 18:47:14 -04003687 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
James Smarte59058c2008-08-24 21:49:00 -04003688 * @shost: pointer to SCSI host data structure.
3689 * @time: elapsed time of the scan in jiffies.
3690 *
3691 * This routine is called by the SCSI layer with a SCSI host to determine
3692 * whether the scan host is finished.
3693 *
3694 * Note: there is no scan_start function as adapter initialization will have
3695 * asynchronously kicked off the link initialization.
3696 *
3697 * Return codes
3698 * 0 - SCSI host scan is not over yet.
3699 * 1 - SCSI host scan is over.
3700 **/
James Smart47a86172007-04-25 09:53:22 -04003701int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
3702{
James Smart2e0fef82007-06-17 19:56:36 -05003703 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3704 struct lpfc_hba *phba = vport->phba;
James Smart858c9f62007-06-17 19:56:39 -05003705 int stat = 0;
James Smart47a86172007-04-25 09:53:22 -04003706
James Smart858c9f62007-06-17 19:56:39 -05003707 spin_lock_irq(shost->host_lock);
3708
James Smart51ef4c22007-08-02 11:10:31 -04003709 if (vport->load_flag & FC_UNLOADING) {
James Smart858c9f62007-06-17 19:56:39 -05003710 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003711 goto finished;
James Smart858c9f62007-06-17 19:56:39 -05003712 }
James Smart256ec0d2013-04-17 20:14:58 -04003713 if (time >= msecs_to_jiffies(30 * 1000)) {
James Smart2e0fef82007-06-17 19:56:36 -05003714 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003715 "0461 Scanning longer than 30 "
3716 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003717 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003718 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003719 }
James Smart256ec0d2013-04-17 20:14:58 -04003720 if (time >= msecs_to_jiffies(15 * 1000) &&
3721 phba->link_state <= LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05003722 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04003723 "0465 Link down longer than 15 "
3724 "seconds. Continuing initialization\n");
James Smart858c9f62007-06-17 19:56:39 -05003725 stat = 1;
James Smart2e0fef82007-06-17 19:56:36 -05003726 goto finished;
James Smart47a86172007-04-25 09:53:22 -04003727 }
3728
James Smart2e0fef82007-06-17 19:56:36 -05003729 if (vport->port_state != LPFC_VPORT_READY)
James Smart858c9f62007-06-17 19:56:39 -05003730 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003731 if (vport->num_disc_nodes || vport->fc_prli_sent)
James Smart858c9f62007-06-17 19:56:39 -05003732 goto finished;
James Smart256ec0d2013-04-17 20:14:58 -04003733 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
James Smart858c9f62007-06-17 19:56:39 -05003734 goto finished;
James Smart2e0fef82007-06-17 19:56:36 -05003735 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
James Smart858c9f62007-06-17 19:56:39 -05003736 goto finished;
3737
3738 stat = 1;
James Smart47a86172007-04-25 09:53:22 -04003739
3740finished:
James Smart858c9f62007-06-17 19:56:39 -05003741 spin_unlock_irq(shost->host_lock);
3742 return stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003743}
3744
James Smarte59058c2008-08-24 21:49:00 -04003745/**
James Smart3621a712009-04-06 18:47:14 -04003746 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
James Smarte59058c2008-08-24 21:49:00 -04003747 * @shost: pointer to SCSI host data structure.
3748 *
3749 * This routine initializes a given SCSI host attributes on a FC port. The
3750 * SCSI host can be either on top of a physical port or a virtual port.
3751 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003752void lpfc_host_attrib_init(struct Scsi_Host *shost)
3753{
3754 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3755 struct lpfc_hba *phba = vport->phba;
James Smart47a86172007-04-25 09:53:22 -04003756 /*
James Smart2e0fef82007-06-17 19:56:36 -05003757 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
James Smart47a86172007-04-25 09:53:22 -04003758 */
3759
James Smart2e0fef82007-06-17 19:56:36 -05003760 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
3761 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart47a86172007-04-25 09:53:22 -04003762 fc_host_supported_classes(shost) = FC_COS_CLASS3;
3763
3764 memset(fc_host_supported_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003765 sizeof(fc_host_supported_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003766 fc_host_supported_fc4s(shost)[2] = 1;
3767 fc_host_supported_fc4s(shost)[7] = 1;
3768
James Smart92d7f7b2007-06-17 19:56:38 -05003769 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
3770 sizeof fc_host_symbolic_name(shost));
James Smart47a86172007-04-25 09:53:22 -04003771
3772 fc_host_supported_speeds(shost) = 0;
James Smartd38dd522015-08-31 16:48:17 -04003773 if (phba->lmt & LMT_32Gb)
3774 fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT;
James Smart88a2cfb2011-07-22 18:36:33 -04003775 if (phba->lmt & LMT_16Gb)
3776 fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT;
James Smart47a86172007-04-25 09:53:22 -04003777 if (phba->lmt & LMT_10Gb)
3778 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
James Smarta8adb832007-10-27 13:37:53 -04003779 if (phba->lmt & LMT_8Gb)
3780 fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
James Smart47a86172007-04-25 09:53:22 -04003781 if (phba->lmt & LMT_4Gb)
3782 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
3783 if (phba->lmt & LMT_2Gb)
3784 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
3785 if (phba->lmt & LMT_1Gb)
3786 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
3787
3788 fc_host_maxframe_size(shost) =
James Smart2e0fef82007-06-17 19:56:36 -05003789 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
3790 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
James Smart47a86172007-04-25 09:53:22 -04003791
Mike Christie0af5d702010-09-15 16:52:31 -05003792 fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo;
3793
James Smart47a86172007-04-25 09:53:22 -04003794 /* This value is also unchanging */
3795 memset(fc_host_active_fc4s(shost), 0,
James Smart2e0fef82007-06-17 19:56:36 -05003796 sizeof(fc_host_active_fc4s(shost)));
James Smart47a86172007-04-25 09:53:22 -04003797 fc_host_active_fc4s(shost)[2] = 1;
3798 fc_host_active_fc4s(shost)[7] = 1;
3799
James Smart92d7f7b2007-06-17 19:56:38 -05003800 fc_host_max_npiv_vports(shost) = phba->max_vpi;
James Smart47a86172007-04-25 09:53:22 -04003801 spin_lock_irq(shost->host_lock);
James Smart51ef4c22007-08-02 11:10:31 -04003802 vport->load_flag &= ~FC_LOADING;
James Smart47a86172007-04-25 09:53:22 -04003803 spin_unlock_irq(shost->host_lock);
James Smart47a86172007-04-25 09:53:22 -04003804}
dea31012005-04-17 16:05:31 -05003805
James Smarte59058c2008-08-24 21:49:00 -04003806/**
James Smartda0436e2009-05-22 14:51:39 -04003807 * lpfc_stop_port_s3 - Stop SLI3 device port
James Smarte59058c2008-08-24 21:49:00 -04003808 * @phba: pointer to lpfc hba data structure.
3809 *
James Smartda0436e2009-05-22 14:51:39 -04003810 * This routine is invoked to stop an SLI3 device port, it stops the device
3811 * from generating interrupts and stops the device driver's timers for the
3812 * device.
James Smarte59058c2008-08-24 21:49:00 -04003813 **/
James Smartdb2378e2008-02-08 18:49:51 -05003814static void
James Smartda0436e2009-05-22 14:51:39 -04003815lpfc_stop_port_s3(struct lpfc_hba *phba)
James Smartdb2378e2008-02-08 18:49:51 -05003816{
James Smartda0436e2009-05-22 14:51:39 -04003817 /* Clear all interrupt enable conditions */
3818 writel(0, phba->HCregaddr);
3819 readl(phba->HCregaddr); /* flush */
3820 /* Clear all pending interrupts */
3821 writel(0xffffffff, phba->HAregaddr);
3822 readl(phba->HAregaddr); /* flush */
James Smart93996272008-08-24 21:50:30 -04003823
James Smartda0436e2009-05-22 14:51:39 -04003824 /* Reset some HBA SLI setup states */
3825 lpfc_stop_hba_timers(phba);
3826 phba->pport->work_port_events = 0;
James Smartdb2378e2008-02-08 18:49:51 -05003827}
3828
James Smarte59058c2008-08-24 21:49:00 -04003829/**
James Smartda0436e2009-05-22 14:51:39 -04003830 * lpfc_stop_port_s4 - Stop SLI4 device port
James Smart5b75da22008-12-04 22:39:35 -05003831 * @phba: pointer to lpfc hba data structure.
3832 *
James Smartda0436e2009-05-22 14:51:39 -04003833 * This routine is invoked to stop an SLI4 device port, it stops the device
3834 * from generating interrupts and stops the device driver's timers for the
3835 * device.
3836 **/
3837static void
3838lpfc_stop_port_s4(struct lpfc_hba *phba)
3839{
3840 /* Reset some HBA SLI4 setup states */
3841 lpfc_stop_hba_timers(phba);
3842 phba->pport->work_port_events = 0;
3843 phba->sli4_hba.intr_enable = 0;
James Smartda0436e2009-05-22 14:51:39 -04003844}
3845
3846/**
3847 * lpfc_stop_port - Wrapper function for stopping hba port
3848 * @phba: Pointer to HBA context object.
James Smart5b75da22008-12-04 22:39:35 -05003849 *
James Smartda0436e2009-05-22 14:51:39 -04003850 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3851 * the API jump table function pointer from the lpfc_hba struct.
3852 **/
3853void
3854lpfc_stop_port(struct lpfc_hba *phba)
3855{
3856 phba->lpfc_stop_port(phba);
3857}
3858
3859/**
James Smartecfd03c2010-02-12 14:41:27 -05003860 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3861 * @phba: Pointer to hba for which this call is being executed.
3862 *
3863 * This routine starts the timer waiting for the FCF rediscovery to complete.
3864 **/
3865void
3866lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
3867{
3868 unsigned long fcf_redisc_wait_tmo =
3869 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
3870 /* Start fcf rediscovery wait period timer */
3871 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
3872 spin_lock_irq(&phba->hbalock);
3873 /* Allow action to new fcf asynchronous event */
3874 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
3875 /* Mark the FCF rediscovery pending state */
3876 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
3877 spin_unlock_irq(&phba->hbalock);
3878}
3879
3880/**
3881 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
3882 * @ptr: Map to lpfc_hba data structure pointer.
3883 *
3884 * This routine is invoked when waiting for FCF table rediscover has been
3885 * timed out. If new FCF record(s) has (have) been discovered during the
3886 * wait period, a new FCF event shall be added to the FCOE async event
3887 * list, and then worker thread shall be waked up for processing from the
3888 * worker thread context.
3889 **/
Rashika Kheriae399b222014-09-03 12:55:28 -04003890static void
James Smartecfd03c2010-02-12 14:41:27 -05003891lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
3892{
3893 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
3894
3895 /* Don't send FCF rediscovery event if timer cancelled */
3896 spin_lock_irq(&phba->hbalock);
3897 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
3898 spin_unlock_irq(&phba->hbalock);
3899 return;
3900 }
3901 /* Clear FCF rediscovery timer pending flag */
3902 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
3903 /* FCF rediscovery event to worker thread */
3904 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
3905 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003906 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04003907 "2776 FCF rediscover quiescent timer expired\n");
James Smartecfd03c2010-02-12 14:41:27 -05003908 /* wake up worker thread */
3909 lpfc_worker_wake_up(phba);
3910}
3911
3912/**
James Smartda0436e2009-05-22 14:51:39 -04003913 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
3914 * @phba: pointer to lpfc hba data structure.
3915 * @acqe_link: pointer to the async link completion queue entry.
3916 *
3917 * This routine is to parse the SLI4 link-attention link fault code and
3918 * translate it into the base driver's read link attention mailbox command
3919 * status.
3920 *
3921 * Return: Link-attention status in terms of base driver's coding.
3922 **/
3923static uint16_t
3924lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
3925 struct lpfc_acqe_link *acqe_link)
3926{
3927 uint16_t latt_fault;
3928
3929 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
3930 case LPFC_ASYNC_LINK_FAULT_NONE:
3931 case LPFC_ASYNC_LINK_FAULT_LOCAL:
3932 case LPFC_ASYNC_LINK_FAULT_REMOTE:
3933 latt_fault = 0;
3934 break;
3935 default:
3936 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3937 "0398 Invalid link fault code: x%x\n",
3938 bf_get(lpfc_acqe_link_fault, acqe_link));
3939 latt_fault = MBXERR_ERROR;
3940 break;
3941 }
3942 return latt_fault;
3943}
3944
3945/**
3946 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
3947 * @phba: pointer to lpfc hba data structure.
3948 * @acqe_link: pointer to the async link completion queue entry.
3949 *
3950 * This routine is to parse the SLI4 link attention type and translate it
3951 * into the base driver's link attention type coding.
3952 *
3953 * Return: Link attention type in terms of base driver's coding.
3954 **/
3955static uint8_t
3956lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
3957 struct lpfc_acqe_link *acqe_link)
3958{
3959 uint8_t att_type;
3960
3961 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
3962 case LPFC_ASYNC_LINK_STATUS_DOWN:
3963 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
James Smart76a95d72010-11-20 23:11:48 -05003964 att_type = LPFC_ATT_LINK_DOWN;
James Smartda0436e2009-05-22 14:51:39 -04003965 break;
3966 case LPFC_ASYNC_LINK_STATUS_UP:
3967 /* Ignore physical link up events - wait for logical link up */
James Smart76a95d72010-11-20 23:11:48 -05003968 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003969 break;
3970 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
James Smart76a95d72010-11-20 23:11:48 -05003971 att_type = LPFC_ATT_LINK_UP;
James Smartda0436e2009-05-22 14:51:39 -04003972 break;
3973 default:
3974 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3975 "0399 Invalid link attention type: x%x\n",
3976 bf_get(lpfc_acqe_link_status, acqe_link));
James Smart76a95d72010-11-20 23:11:48 -05003977 att_type = LPFC_ATT_RESERVED;
James Smartda0436e2009-05-22 14:51:39 -04003978 break;
3979 }
3980 return att_type;
3981}
3982
3983/**
James Smart8b68cd52012-09-29 11:32:37 -04003984 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
3985 * @phba: pointer to lpfc hba data structure.
3986 *
3987 * This routine is to get an SLI3 FC port's link speed in Mbps.
3988 *
3989 * Return: link speed in terms of Mbps.
3990 **/
3991uint32_t
3992lpfc_sli_port_speed_get(struct lpfc_hba *phba)
3993{
3994 uint32_t link_speed;
3995
3996 if (!lpfc_is_link_up(phba))
3997 return 0;
3998
James Smarta085e872015-12-16 18:12:02 -05003999 if (phba->sli_rev <= LPFC_SLI_REV3) {
4000 switch (phba->fc_linkspeed) {
4001 case LPFC_LINK_SPEED_1GHZ:
4002 link_speed = 1000;
4003 break;
4004 case LPFC_LINK_SPEED_2GHZ:
4005 link_speed = 2000;
4006 break;
4007 case LPFC_LINK_SPEED_4GHZ:
4008 link_speed = 4000;
4009 break;
4010 case LPFC_LINK_SPEED_8GHZ:
4011 link_speed = 8000;
4012 break;
4013 case LPFC_LINK_SPEED_10GHZ:
4014 link_speed = 10000;
4015 break;
4016 case LPFC_LINK_SPEED_16GHZ:
4017 link_speed = 16000;
4018 break;
4019 default:
4020 link_speed = 0;
4021 }
4022 } else {
4023 if (phba->sli4_hba.link_state.logical_speed)
4024 link_speed =
4025 phba->sli4_hba.link_state.logical_speed;
4026 else
4027 link_speed = phba->sli4_hba.link_state.speed;
James Smart8b68cd52012-09-29 11:32:37 -04004028 }
4029 return link_speed;
4030}
4031
4032/**
4033 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
4034 * @phba: pointer to lpfc hba data structure.
4035 * @evt_code: asynchronous event code.
4036 * @speed_code: asynchronous event link speed code.
4037 *
4038 * This routine is to parse the giving SLI4 async event link speed code into
4039 * value of Mbps for the link speed.
4040 *
4041 * Return: link speed in terms of Mbps.
4042 **/
4043static uint32_t
4044lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code,
4045 uint8_t speed_code)
4046{
4047 uint32_t port_speed;
4048
4049 switch (evt_code) {
4050 case LPFC_TRAILER_CODE_LINK:
4051 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004052 case LPFC_ASYNC_LINK_SPEED_ZERO:
James Smart8b68cd52012-09-29 11:32:37 -04004053 port_speed = 0;
4054 break;
James Smart26d830e2015-04-07 15:07:17 -04004055 case LPFC_ASYNC_LINK_SPEED_10MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004056 port_speed = 10;
4057 break;
James Smart26d830e2015-04-07 15:07:17 -04004058 case LPFC_ASYNC_LINK_SPEED_100MBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004059 port_speed = 100;
4060 break;
James Smart26d830e2015-04-07 15:07:17 -04004061 case LPFC_ASYNC_LINK_SPEED_1GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004062 port_speed = 1000;
4063 break;
James Smart26d830e2015-04-07 15:07:17 -04004064 case LPFC_ASYNC_LINK_SPEED_10GBPS:
James Smart8b68cd52012-09-29 11:32:37 -04004065 port_speed = 10000;
4066 break;
James Smart26d830e2015-04-07 15:07:17 -04004067 case LPFC_ASYNC_LINK_SPEED_20GBPS:
4068 port_speed = 20000;
4069 break;
4070 case LPFC_ASYNC_LINK_SPEED_25GBPS:
4071 port_speed = 25000;
4072 break;
4073 case LPFC_ASYNC_LINK_SPEED_40GBPS:
4074 port_speed = 40000;
4075 break;
James Smart8b68cd52012-09-29 11:32:37 -04004076 default:
4077 port_speed = 0;
4078 }
4079 break;
4080 case LPFC_TRAILER_CODE_FC:
4081 switch (speed_code) {
James Smart26d830e2015-04-07 15:07:17 -04004082 case LPFC_FC_LA_SPEED_UNKNOWN:
James Smart8b68cd52012-09-29 11:32:37 -04004083 port_speed = 0;
4084 break;
James Smart26d830e2015-04-07 15:07:17 -04004085 case LPFC_FC_LA_SPEED_1G:
James Smart8b68cd52012-09-29 11:32:37 -04004086 port_speed = 1000;
4087 break;
James Smart26d830e2015-04-07 15:07:17 -04004088 case LPFC_FC_LA_SPEED_2G:
James Smart8b68cd52012-09-29 11:32:37 -04004089 port_speed = 2000;
4090 break;
James Smart26d830e2015-04-07 15:07:17 -04004091 case LPFC_FC_LA_SPEED_4G:
James Smart8b68cd52012-09-29 11:32:37 -04004092 port_speed = 4000;
4093 break;
James Smart26d830e2015-04-07 15:07:17 -04004094 case LPFC_FC_LA_SPEED_8G:
James Smart8b68cd52012-09-29 11:32:37 -04004095 port_speed = 8000;
4096 break;
James Smart26d830e2015-04-07 15:07:17 -04004097 case LPFC_FC_LA_SPEED_10G:
James Smart8b68cd52012-09-29 11:32:37 -04004098 port_speed = 10000;
4099 break;
James Smart26d830e2015-04-07 15:07:17 -04004100 case LPFC_FC_LA_SPEED_16G:
James Smart8b68cd52012-09-29 11:32:37 -04004101 port_speed = 16000;
4102 break;
James Smartd38dd522015-08-31 16:48:17 -04004103 case LPFC_FC_LA_SPEED_32G:
4104 port_speed = 32000;
4105 break;
James Smart8b68cd52012-09-29 11:32:37 -04004106 default:
4107 port_speed = 0;
4108 }
4109 break;
4110 default:
4111 port_speed = 0;
4112 }
4113 return port_speed;
4114}
4115
4116/**
James Smart70f3c072010-12-15 17:57:33 -05004117 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
James Smartda0436e2009-05-22 14:51:39 -04004118 * @phba: pointer to lpfc hba data structure.
4119 * @acqe_link: pointer to the async link completion queue entry.
4120 *
James Smart70f3c072010-12-15 17:57:33 -05004121 * This routine is to handle the SLI4 asynchronous FCoE link event.
James Smartda0436e2009-05-22 14:51:39 -04004122 **/
4123static void
4124lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
4125 struct lpfc_acqe_link *acqe_link)
4126{
4127 struct lpfc_dmabuf *mp;
4128 LPFC_MBOXQ_t *pmb;
4129 MAILBOX_t *mb;
James Smart76a95d72010-11-20 23:11:48 -05004130 struct lpfc_mbx_read_top *la;
James Smartda0436e2009-05-22 14:51:39 -04004131 uint8_t att_type;
James Smart76a95d72010-11-20 23:11:48 -05004132 int rc;
James Smartda0436e2009-05-22 14:51:39 -04004133
4134 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
James Smart76a95d72010-11-20 23:11:48 -05004135 if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP)
James Smartda0436e2009-05-22 14:51:39 -04004136 return;
James Smart32b97932009-07-19 10:01:21 -04004137 phba->fcoe_eventtag = acqe_link->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004138 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4139 if (!pmb) {
4140 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4141 "0395 The mboxq allocation failed\n");
4142 return;
4143 }
4144 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4145 if (!mp) {
4146 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4147 "0396 The lpfc_dmabuf allocation failed\n");
4148 goto out_free_pmb;
4149 }
4150 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4151 if (!mp->virt) {
4152 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4153 "0397 The mbuf allocation failed\n");
4154 goto out_free_dmabuf;
4155 }
4156
4157 /* Cleanup any outstanding ELS commands */
4158 lpfc_els_flush_all_cmd(phba);
4159
4160 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004161 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smartda0436e2009-05-22 14:51:39 -04004162
4163 /* Update link event statistics */
4164 phba->sli.slistat.link_event++;
4165
James Smart76a95d72010-11-20 23:11:48 -05004166 /* Create lpfc_handle_latt mailbox command from link ACQE */
4167 lpfc_read_topology(phba, pmb, mp);
4168 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
James Smartda0436e2009-05-22 14:51:39 -04004169 pmb->vport = phba->pport;
4170
James Smartda0436e2009-05-22 14:51:39 -04004171 /* Keep the link status for extra SLI4 state machine reference */
4172 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004173 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK,
4174 bf_get(lpfc_acqe_link_speed, acqe_link));
James Smartda0436e2009-05-22 14:51:39 -04004175 phba->sli4_hba.link_state.duplex =
4176 bf_get(lpfc_acqe_link_duplex, acqe_link);
4177 phba->sli4_hba.link_state.status =
4178 bf_get(lpfc_acqe_link_status, acqe_link);
James Smart70f3c072010-12-15 17:57:33 -05004179 phba->sli4_hba.link_state.type =
4180 bf_get(lpfc_acqe_link_type, acqe_link);
4181 phba->sli4_hba.link_state.number =
4182 bf_get(lpfc_acqe_link_number, acqe_link);
James Smartda0436e2009-05-22 14:51:39 -04004183 phba->sli4_hba.link_state.fault =
4184 bf_get(lpfc_acqe_link_fault, acqe_link);
James Smart65467b62010-01-26 23:08:29 -05004185 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004186 bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10;
4187
James Smart70f3c072010-12-15 17:57:33 -05004188 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smartc31098c2011-04-16 11:03:33 -04004189 "2900 Async FC/FCoE Link event - Speed:%dGBit "
4190 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
4191 "Logical speed:%dMbps Fault:%d\n",
James Smart70f3c072010-12-15 17:57:33 -05004192 phba->sli4_hba.link_state.speed,
4193 phba->sli4_hba.link_state.topology,
4194 phba->sli4_hba.link_state.status,
4195 phba->sli4_hba.link_state.type,
4196 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004197 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004198 phba->sli4_hba.link_state.fault);
James Smart76a95d72010-11-20 23:11:48 -05004199 /*
4200 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
4201 * topology info. Note: Optional for non FC-AL ports.
4202 */
4203 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
4204 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4205 if (rc == MBX_NOT_FINISHED)
4206 goto out_free_dmabuf;
4207 return;
4208 }
4209 /*
4210 * For FCoE Mode: fill in all the topology information we need and call
4211 * the READ_TOPOLOGY completion routine to continue without actually
4212 * sending the READ_TOPOLOGY mailbox command to the port.
4213 */
4214 /* Parse and translate status field */
4215 mb = &pmb->u.mb;
4216 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
4217
4218 /* Parse and translate link attention fields */
4219 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
4220 la->eventTag = acqe_link->event_tag;
4221 bf_set(lpfc_mbx_read_top_att_type, la, att_type);
4222 bf_set(lpfc_mbx_read_top_link_spd, la,
James Smarta085e872015-12-16 18:12:02 -05004223 (bf_get(lpfc_acqe_link_speed, acqe_link)));
James Smart76a95d72010-11-20 23:11:48 -05004224
4225 /* Fake the the following irrelvant fields */
4226 bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT);
4227 bf_set(lpfc_mbx_read_top_alpa_granted, la, 0);
4228 bf_set(lpfc_mbx_read_top_il, la, 0);
4229 bf_set(lpfc_mbx_read_top_pb, la, 0);
4230 bf_set(lpfc_mbx_read_top_fa, la, 0);
4231 bf_set(lpfc_mbx_read_top_mm, la, 0);
James Smartda0436e2009-05-22 14:51:39 -04004232
4233 /* Invoke the lpfc_handle_latt mailbox command callback function */
James Smart76a95d72010-11-20 23:11:48 -05004234 lpfc_mbx_cmpl_read_topology(phba, pmb);
James Smartda0436e2009-05-22 14:51:39 -04004235
4236 return;
4237
4238out_free_dmabuf:
4239 kfree(mp);
4240out_free_pmb:
4241 mempool_free(pmb, phba->mbox_mem_pool);
4242}
4243
4244/**
James Smart70f3c072010-12-15 17:57:33 -05004245 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
4246 * @phba: pointer to lpfc hba data structure.
4247 * @acqe_fc: pointer to the async fc completion queue entry.
4248 *
4249 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
4250 * that the event was received and then issue a read_topology mailbox command so
4251 * that the rest of the driver will treat it the same as SLI3.
4252 **/
4253static void
4254lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc)
4255{
4256 struct lpfc_dmabuf *mp;
4257 LPFC_MBOXQ_t *pmb;
James Smart7bdedb32016-07-06 12:36:00 -07004258 MAILBOX_t *mb;
4259 struct lpfc_mbx_read_top *la;
James Smart70f3c072010-12-15 17:57:33 -05004260 int rc;
4261
4262 if (bf_get(lpfc_trailer_type, acqe_fc) !=
4263 LPFC_FC_LA_EVENT_TYPE_FC_LINK) {
4264 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4265 "2895 Non FC link Event detected.(%d)\n",
4266 bf_get(lpfc_trailer_type, acqe_fc));
4267 return;
4268 }
4269 /* Keep the link status for extra SLI4 state machine reference */
4270 phba->sli4_hba.link_state.speed =
James Smart8b68cd52012-09-29 11:32:37 -04004271 lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC,
4272 bf_get(lpfc_acqe_fc_la_speed, acqe_fc));
James Smart70f3c072010-12-15 17:57:33 -05004273 phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL;
4274 phba->sli4_hba.link_state.topology =
4275 bf_get(lpfc_acqe_fc_la_topology, acqe_fc);
4276 phba->sli4_hba.link_state.status =
4277 bf_get(lpfc_acqe_fc_la_att_type, acqe_fc);
4278 phba->sli4_hba.link_state.type =
4279 bf_get(lpfc_acqe_fc_la_port_type, acqe_fc);
4280 phba->sli4_hba.link_state.number =
4281 bf_get(lpfc_acqe_fc_la_port_number, acqe_fc);
4282 phba->sli4_hba.link_state.fault =
4283 bf_get(lpfc_acqe_link_fault, acqe_fc);
4284 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004285 bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10;
James Smart70f3c072010-12-15 17:57:33 -05004286 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4287 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
4288 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
4289 "%dMbps Fault:%d\n",
4290 phba->sli4_hba.link_state.speed,
4291 phba->sli4_hba.link_state.topology,
4292 phba->sli4_hba.link_state.status,
4293 phba->sli4_hba.link_state.type,
4294 phba->sli4_hba.link_state.number,
James Smart8b68cd52012-09-29 11:32:37 -04004295 phba->sli4_hba.link_state.logical_speed,
James Smart70f3c072010-12-15 17:57:33 -05004296 phba->sli4_hba.link_state.fault);
4297 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4298 if (!pmb) {
4299 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4300 "2897 The mboxq allocation failed\n");
4301 return;
4302 }
4303 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4304 if (!mp) {
4305 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4306 "2898 The lpfc_dmabuf allocation failed\n");
4307 goto out_free_pmb;
4308 }
4309 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
4310 if (!mp->virt) {
4311 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4312 "2899 The mbuf allocation failed\n");
4313 goto out_free_dmabuf;
4314 }
4315
4316 /* Cleanup any outstanding ELS commands */
4317 lpfc_els_flush_all_cmd(phba);
4318
4319 /* Block ELS IOCBs until we have done process link event */
James Smart895427b2017-02-12 13:52:30 -08004320 phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT;
James Smart70f3c072010-12-15 17:57:33 -05004321
4322 /* Update link event statistics */
4323 phba->sli.slistat.link_event++;
4324
4325 /* Create lpfc_handle_latt mailbox command from link ACQE */
4326 lpfc_read_topology(phba, pmb, mp);
4327 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology;
4328 pmb->vport = phba->pport;
4329
James Smart7bdedb32016-07-06 12:36:00 -07004330 if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) {
4331 /* Parse and translate status field */
4332 mb = &pmb->u.mb;
4333 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba,
4334 (void *)acqe_fc);
4335
4336 /* Parse and translate link attention fields */
4337 la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop;
4338 la->eventTag = acqe_fc->event_tag;
4339 bf_set(lpfc_mbx_read_top_att_type, la,
4340 LPFC_FC_LA_TYPE_LINK_DOWN);
4341
4342 /* Invoke the mailbox command callback function */
4343 lpfc_mbx_cmpl_read_topology(phba, pmb);
4344
4345 return;
4346 }
4347
James Smart70f3c072010-12-15 17:57:33 -05004348 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
4349 if (rc == MBX_NOT_FINISHED)
4350 goto out_free_dmabuf;
4351 return;
4352
4353out_free_dmabuf:
4354 kfree(mp);
4355out_free_pmb:
4356 mempool_free(pmb, phba->mbox_mem_pool);
4357}
4358
4359/**
4360 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
4361 * @phba: pointer to lpfc hba data structure.
4362 * @acqe_fc: pointer to the async SLI completion queue entry.
4363 *
4364 * This routine is to handle the SLI4 asynchronous SLI events.
4365 **/
4366static void
4367lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli)
4368{
James Smart4b8bae02012-06-12 13:55:07 -04004369 char port_name;
James Smart8c1312e2012-10-31 14:45:09 -04004370 char message[128];
James Smart4b8bae02012-06-12 13:55:07 -04004371 uint8_t status;
James Smart946727d2015-04-07 15:07:09 -04004372 uint8_t evt_type;
James Smart448193b2015-12-16 18:12:05 -05004373 uint8_t operational = 0;
James Smart946727d2015-04-07 15:07:09 -04004374 struct temp_event temp_event_data;
James Smart4b8bae02012-06-12 13:55:07 -04004375 struct lpfc_acqe_misconfigured_event *misconfigured;
James Smart946727d2015-04-07 15:07:09 -04004376 struct Scsi_Host *shost;
James Smart4b8bae02012-06-12 13:55:07 -04004377
James Smart946727d2015-04-07 15:07:09 -04004378 evt_type = bf_get(lpfc_trailer_type, acqe_sli);
4379
James Smart448193b2015-12-16 18:12:05 -05004380 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4381 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
4382 "x%08x SLI Event Type:%d\n",
4383 acqe_sli->event_data1, acqe_sli->event_data2,
4384 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004385
4386 port_name = phba->Port[0];
4387 if (port_name == 0x00)
4388 port_name = '?'; /* get port name is empty */
4389
James Smart946727d2015-04-07 15:07:09 -04004390 switch (evt_type) {
4391 case LPFC_SLI_EVENT_TYPE_OVER_TEMP:
4392 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4393 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
4394 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4395
4396 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
4397 "3190 Over Temperature:%d Celsius- Port Name %c\n",
4398 acqe_sli->event_data1, port_name);
4399
James Smart310429e2016-07-06 12:35:54 -07004400 phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE;
James Smart946727d2015-04-07 15:07:09 -04004401 shost = lpfc_shost_from_vport(phba->pport);
4402 fc_host_post_vendor_event(shost, fc_get_event_number(),
4403 sizeof(temp_event_data),
4404 (char *)&temp_event_data,
4405 SCSI_NL_VID_TYPE_PCI
4406 | PCI_VENDOR_ID_EMULEX);
4407 break;
4408 case LPFC_SLI_EVENT_TYPE_NORM_TEMP:
4409 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
4410 temp_event_data.event_code = LPFC_NORMAL_TEMP;
4411 temp_event_data.data = (uint32_t)acqe_sli->event_data1;
4412
4413 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4414 "3191 Normal Temperature:%d Celsius - Port Name %c\n",
4415 acqe_sli->event_data1, port_name);
4416
4417 shost = lpfc_shost_from_vport(phba->pport);
4418 fc_host_post_vendor_event(shost, fc_get_event_number(),
4419 sizeof(temp_event_data),
4420 (char *)&temp_event_data,
4421 SCSI_NL_VID_TYPE_PCI
4422 | PCI_VENDOR_ID_EMULEX);
4423 break;
4424 case LPFC_SLI_EVENT_TYPE_MISCONFIGURED:
4425 misconfigured = (struct lpfc_acqe_misconfigured_event *)
James Smart4b8bae02012-06-12 13:55:07 -04004426 &acqe_sli->event_data1;
4427
James Smart946727d2015-04-07 15:07:09 -04004428 /* fetch the status for this port */
4429 switch (phba->sli4_hba.lnk_info.lnk_no) {
4430 case LPFC_LINK_NUMBER_0:
James Smart448193b2015-12-16 18:12:05 -05004431 status = bf_get(lpfc_sli_misconfigured_port0_state,
4432 &misconfigured->theEvent);
4433 operational = bf_get(lpfc_sli_misconfigured_port0_op,
James Smart4b8bae02012-06-12 13:55:07 -04004434 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004435 break;
4436 case LPFC_LINK_NUMBER_1:
James Smart448193b2015-12-16 18:12:05 -05004437 status = bf_get(lpfc_sli_misconfigured_port1_state,
4438 &misconfigured->theEvent);
4439 operational = bf_get(lpfc_sli_misconfigured_port1_op,
James Smart4b8bae02012-06-12 13:55:07 -04004440 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004441 break;
4442 case LPFC_LINK_NUMBER_2:
James Smart448193b2015-12-16 18:12:05 -05004443 status = bf_get(lpfc_sli_misconfigured_port2_state,
4444 &misconfigured->theEvent);
4445 operational = bf_get(lpfc_sli_misconfigured_port2_op,
James Smart4b8bae02012-06-12 13:55:07 -04004446 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004447 break;
4448 case LPFC_LINK_NUMBER_3:
James Smart448193b2015-12-16 18:12:05 -05004449 status = bf_get(lpfc_sli_misconfigured_port3_state,
4450 &misconfigured->theEvent);
4451 operational = bf_get(lpfc_sli_misconfigured_port3_op,
James Smart4b8bae02012-06-12 13:55:07 -04004452 &misconfigured->theEvent);
James Smart946727d2015-04-07 15:07:09 -04004453 break;
4454 default:
James Smart448193b2015-12-16 18:12:05 -05004455 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4456 "3296 "
4457 "LPFC_SLI_EVENT_TYPE_MISCONFIGURED "
4458 "event: Invalid link %d",
4459 phba->sli4_hba.lnk_info.lnk_no);
4460 return;
James Smart946727d2015-04-07 15:07:09 -04004461 }
James Smart4b8bae02012-06-12 13:55:07 -04004462
James Smart448193b2015-12-16 18:12:05 -05004463 /* Skip if optic state unchanged */
4464 if (phba->sli4_hba.lnk_info.optic_state == status)
4465 return;
4466
James Smart946727d2015-04-07 15:07:09 -04004467 switch (status) {
4468 case LPFC_SLI_EVENT_STATUS_VALID:
James Smart448193b2015-12-16 18:12:05 -05004469 sprintf(message, "Physical Link is functional");
4470 break;
James Smart946727d2015-04-07 15:07:09 -04004471 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT:
4472 sprintf(message, "Optics faulted/incorrectly "
4473 "installed/not installed - Reseat optics, "
4474 "if issue not resolved, replace.");
4475 break;
4476 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE:
4477 sprintf(message,
4478 "Optics of two types installed - Remove one "
4479 "optic or install matching pair of optics.");
4480 break;
4481 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED:
4482 sprintf(message, "Incompatible optics - Replace with "
James Smart292098b2012-09-29 11:31:41 -04004483 "compatible optics for card to function.");
James Smart946727d2015-04-07 15:07:09 -04004484 break;
James Smart448193b2015-12-16 18:12:05 -05004485 case LPFC_SLI_EVENT_STATUS_UNQUALIFIED:
4486 sprintf(message, "Unqualified optics - Replace with "
4487 "Avago optics for Warranty and Technical "
4488 "Support - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08004489 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05004490 break;
4491 case LPFC_SLI_EVENT_STATUS_UNCERTIFIED:
4492 sprintf(message, "Uncertified optics - Replace with "
4493 "Avago-certified optics to enable link "
4494 "operation - Link is%s operational",
James Smart2ea259e2017-02-12 13:52:27 -08004495 (operational) ? " not" : "");
James Smart448193b2015-12-16 18:12:05 -05004496 break;
James Smart946727d2015-04-07 15:07:09 -04004497 default:
4498 /* firmware is reporting a status we don't know about */
4499 sprintf(message, "Unknown event status x%02x", status);
4500 break;
4501 }
James Smart448193b2015-12-16 18:12:05 -05004502 phba->sli4_hba.lnk_info.optic_state = status;
James Smart946727d2015-04-07 15:07:09 -04004503 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smart448193b2015-12-16 18:12:05 -05004504 "3176 Port Name %c %s\n", port_name, message);
James Smart946727d2015-04-07 15:07:09 -04004505 break;
4506 case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT:
4507 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4508 "3192 Remote DPort Test Initiated - "
4509 "Event Data1:x%08x Event Data2: x%08x\n",
4510 acqe_sli->event_data1, acqe_sli->event_data2);
James Smart4b8bae02012-06-12 13:55:07 -04004511 break;
4512 default:
James Smart946727d2015-04-07 15:07:09 -04004513 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4514 "3193 Async SLI event - Event Data1:x%08x Event Data2:"
4515 "x%08x SLI Event Type:%d\n",
4516 acqe_sli->event_data1, acqe_sli->event_data2,
4517 evt_type);
James Smart4b8bae02012-06-12 13:55:07 -04004518 break;
4519 }
James Smart70f3c072010-12-15 17:57:33 -05004520}
4521
4522/**
James Smartfc2b9892010-02-26 14:15:29 -05004523 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
4524 * @vport: pointer to vport data structure.
4525 *
4526 * This routine is to perform Clear Virtual Link (CVL) on a vport in
4527 * response to a CVL event.
4528 *
4529 * Return the pointer to the ndlp with the vport if successful, otherwise
4530 * return NULL.
4531 **/
4532static struct lpfc_nodelist *
4533lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
4534{
4535 struct lpfc_nodelist *ndlp;
4536 struct Scsi_Host *shost;
4537 struct lpfc_hba *phba;
4538
4539 if (!vport)
4540 return NULL;
James Smartfc2b9892010-02-26 14:15:29 -05004541 phba = vport->phba;
4542 if (!phba)
4543 return NULL;
James Smart78730cf2010-04-06 15:06:30 -04004544 ndlp = lpfc_findnode_did(vport, Fabric_DID);
4545 if (!ndlp) {
4546 /* Cannot find existing Fabric ndlp, so allocate a new one */
4547 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4548 if (!ndlp)
4549 return 0;
4550 lpfc_nlp_init(vport, ndlp, Fabric_DID);
4551 /* Set the node type */
4552 ndlp->nlp_type |= NLP_FABRIC;
4553 /* Put ndlp onto node list */
4554 lpfc_enqueue_node(vport, ndlp);
4555 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4556 /* re-setup ndlp without removing from node list */
4557 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4558 if (!ndlp)
4559 return 0;
4560 }
James Smart63e801c2010-11-20 23:14:19 -05004561 if ((phba->pport->port_state < LPFC_FLOGI) &&
4562 (phba->pport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004563 return NULL;
4564 /* If virtual link is not yet instantiated ignore CVL */
James Smart63e801c2010-11-20 23:14:19 -05004565 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC)
4566 && (vport->port_state != LPFC_VPORT_FAILED))
James Smartfc2b9892010-02-26 14:15:29 -05004567 return NULL;
4568 shost = lpfc_shost_from_vport(vport);
4569 if (!shost)
4570 return NULL;
4571 lpfc_linkdown_port(vport);
4572 lpfc_cleanup_pending_mbox(vport);
4573 spin_lock_irq(shost->host_lock);
4574 vport->fc_flag |= FC_VPORT_CVL_RCVD;
4575 spin_unlock_irq(shost->host_lock);
4576
4577 return ndlp;
4578}
4579
4580/**
4581 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4582 * @vport: pointer to lpfc hba data structure.
4583 *
4584 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4585 * response to a FCF dead event.
4586 **/
4587static void
4588lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba)
4589{
4590 struct lpfc_vport **vports;
4591 int i;
4592
4593 vports = lpfc_create_vport_work_array(phba);
4594 if (vports)
4595 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
4596 lpfc_sli4_perform_vport_cvl(vports[i]);
4597 lpfc_destroy_vport_work_array(phba, vports);
4598}
4599
4600/**
James Smart76a95d72010-11-20 23:11:48 -05004601 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
James Smartda0436e2009-05-22 14:51:39 -04004602 * @phba: pointer to lpfc hba data structure.
4603 * @acqe_link: pointer to the async fcoe completion queue entry.
4604 *
4605 * This routine is to handle the SLI4 asynchronous fcoe event.
4606 **/
4607static void
James Smart76a95d72010-11-20 23:11:48 -05004608lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
James Smart70f3c072010-12-15 17:57:33 -05004609 struct lpfc_acqe_fip *acqe_fip)
James Smartda0436e2009-05-22 14:51:39 -04004610{
James Smart70f3c072010-12-15 17:57:33 -05004611 uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004612 int rc;
James Smart6669f9b2009-10-02 15:16:45 -04004613 struct lpfc_vport *vport;
4614 struct lpfc_nodelist *ndlp;
4615 struct Scsi_Host *shost;
James Smart695a8142010-01-26 23:08:03 -05004616 int active_vlink_present;
4617 struct lpfc_vport **vports;
4618 int i;
James Smartda0436e2009-05-22 14:51:39 -04004619
James Smart70f3c072010-12-15 17:57:33 -05004620 phba->fc_eventTag = acqe_fip->event_tag;
4621 phba->fcoe_eventtag = acqe_fip->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004622 switch (event_type) {
James Smart70f3c072010-12-15 17:57:33 -05004623 case LPFC_FIP_EVENT_TYPE_NEW_FCF:
4624 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD:
4625 if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF)
James Smart999d8132010-03-15 11:24:56 -04004626 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4627 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004628 "2546 New FCF event, evt_tag:x%x, "
4629 "index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004630 acqe_fip->event_tag,
4631 acqe_fip->index);
James Smart999d8132010-03-15 11:24:56 -04004632 else
4633 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP |
4634 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004635 "2788 FCF param modified event, "
4636 "evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004637 acqe_fip->event_tag,
4638 acqe_fip->index);
James Smart38b92ef2010-08-04 16:11:39 -04004639 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004640 /*
4641 * During period of FCF discovery, read the FCF
4642 * table record indexed by the event to update
James Smarta93ff372010-10-22 11:06:08 -04004643 * FCF roundrobin failover eligible FCF bmask.
James Smart0c9ab6f2010-02-26 14:15:57 -05004644 */
4645 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4646 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004647 "2779 Read FCF (x%x) for updating "
4648 "roundrobin FCF failover bmask\n",
James Smart70f3c072010-12-15 17:57:33 -05004649 acqe_fip->index);
4650 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004651 }
James Smart38b92ef2010-08-04 16:11:39 -04004652
4653 /* If the FCF discovery is in progress, do nothing. */
James Smart3804dc82010-07-14 15:31:37 -04004654 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04004655 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart38b92ef2010-08-04 16:11:39 -04004656 spin_unlock_irq(&phba->hbalock);
4657 break;
4658 }
4659 /* If fast FCF failover rescan event is pending, do nothing */
4660 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
4661 spin_unlock_irq(&phba->hbalock);
4662 break;
4663 }
4664
James Smartc2b97122013-05-31 17:05:36 -04004665 /* If the FCF has been in discovered state, do nothing. */
4666 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
James Smart3804dc82010-07-14 15:31:37 -04004667 spin_unlock_irq(&phba->hbalock);
4668 break;
4669 }
4670 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04004671
James Smart0c9ab6f2010-02-26 14:15:57 -05004672 /* Otherwise, scan the entire FCF table and re-discover SAN */
4673 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004674 "2770 Start FCF table scan per async FCF "
4675 "event, evt_tag:x%x, index:x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004676 acqe_fip->event_tag, acqe_fip->index);
James Smart0c9ab6f2010-02-26 14:15:57 -05004677 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
4678 LPFC_FCOE_FCF_GET_FIRST);
James Smartda0436e2009-05-22 14:51:39 -04004679 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004680 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4681 "2547 Issue FCF scan read FCF mailbox "
James Smarta93ff372010-10-22 11:06:08 -04004682 "command failed (x%x)\n", rc);
James Smartda0436e2009-05-22 14:51:39 -04004683 break;
4684
James Smart70f3c072010-12-15 17:57:33 -05004685 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL:
James Smartda0436e2009-05-22 14:51:39 -04004686 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
James Smarte4e74272009-07-19 10:01:38 -04004687 "2548 FCF Table full count 0x%x tag 0x%x\n",
James Smart70f3c072010-12-15 17:57:33 -05004688 bf_get(lpfc_acqe_fip_fcf_count, acqe_fip),
4689 acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004690 break;
4691
James Smart70f3c072010-12-15 17:57:33 -05004692 case LPFC_FIP_EVENT_TYPE_FCF_DEAD:
James Smart80c17842012-03-01 22:35:45 -05004693 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004694 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004695 "2549 FCF (x%x) disconnected from network, "
James Smart70f3c072010-12-15 17:57:33 -05004696 "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart38b92ef2010-08-04 16:11:39 -04004697 /*
4698 * If we are in the middle of FCF failover process, clear
4699 * the corresponding FCF bit in the roundrobin bitmap.
James Smartda0436e2009-05-22 14:51:39 -04004700 */
James Smartfc2b9892010-02-26 14:15:29 -05004701 spin_lock_irq(&phba->hbalock);
James Smarta1cadfe2016-07-06 12:36:02 -07004702 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
4703 (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) {
James Smartfc2b9892010-02-26 14:15:29 -05004704 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004705 /* Update FLOGI FCF failover eligible FCF bmask */
James Smart70f3c072010-12-15 17:57:33 -05004706 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004707 break;
4708 }
James Smart38b92ef2010-08-04 16:11:39 -04004709 spin_unlock_irq(&phba->hbalock);
4710
4711 /* If the event is not for currently used fcf do nothing */
James Smart70f3c072010-12-15 17:57:33 -05004712 if (phba->fcf.current_rec.fcf_indx != acqe_fip->index)
James Smart38b92ef2010-08-04 16:11:39 -04004713 break;
4714
4715 /*
4716 * Otherwise, request the port to rediscover the entire FCF
4717 * table for a fast recovery from case that the current FCF
4718 * is no longer valid as we are not in the middle of FCF
4719 * failover process already.
4720 */
James Smartc2b97122013-05-31 17:05:36 -04004721 spin_lock_irq(&phba->hbalock);
4722 /* Mark the fast failover process in progress */
4723 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
4724 spin_unlock_irq(&phba->hbalock);
4725
4726 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
4727 "2771 Start FCF fast failover process due to "
4728 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
4729 "\n", acqe_fip->event_tag, acqe_fip->index);
4730 rc = lpfc_sli4_redisc_fcf_table(phba);
4731 if (rc) {
4732 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4733 LOG_DISCOVERY,
4734 "2772 Issue FCF rediscover mabilbox "
4735 "command failed, fail through to FCF "
4736 "dead event\n");
4737 spin_lock_irq(&phba->hbalock);
4738 phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
4739 spin_unlock_irq(&phba->hbalock);
4740 /*
4741 * Last resort will fail over by treating this
4742 * as a link down to FCF registration.
4743 */
4744 lpfc_sli4_fcf_dead_failthrough(phba);
4745 } else {
4746 /* Reset FCF roundrobin bmask for new discovery */
4747 lpfc_sli4_clear_fcf_rr_bmask(phba);
4748 /*
4749 * Handling fast FCF failover to a DEAD FCF event is
4750 * considered equalivant to receiving CVL to all vports.
4751 */
4752 lpfc_sli4_perform_all_vport_cvl(phba);
4753 }
James Smartda0436e2009-05-22 14:51:39 -04004754 break;
James Smart70f3c072010-12-15 17:57:33 -05004755 case LPFC_FIP_EVENT_TYPE_CVL:
James Smart80c17842012-03-01 22:35:45 -05004756 phba->fcoe_cvl_eventtag = acqe_fip->event_tag;
James Smart0c9ab6f2010-02-26 14:15:57 -05004757 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
James Smart6669f9b2009-10-02 15:16:45 -04004758 "2718 Clear Virtual Link Received for VPI 0x%x"
James Smart70f3c072010-12-15 17:57:33 -05004759 " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag);
James Smart6d368e52011-05-24 11:44:12 -04004760
James Smart6669f9b2009-10-02 15:16:45 -04004761 vport = lpfc_find_vport_by_vpid(phba,
James Smart5248a742011-07-22 18:37:06 -04004762 acqe_fip->index);
James Smartfc2b9892010-02-26 14:15:29 -05004763 ndlp = lpfc_sli4_perform_vport_cvl(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004764 if (!ndlp)
4765 break;
James Smart695a8142010-01-26 23:08:03 -05004766 active_vlink_present = 0;
4767
4768 vports = lpfc_create_vport_work_array(phba);
4769 if (vports) {
4770 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
4771 i++) {
4772 if ((!(vports[i]->fc_flag &
4773 FC_VPORT_CVL_RCVD)) &&
4774 (vports[i]->port_state > LPFC_FDISC)) {
4775 active_vlink_present = 1;
4776 break;
4777 }
4778 }
4779 lpfc_destroy_vport_work_array(phba, vports);
4780 }
4781
James Smartcc823552015-05-21 13:55:26 -04004782 /*
4783 * Don't re-instantiate if vport is marked for deletion.
4784 * If we are here first then vport_delete is going to wait
4785 * for discovery to complete.
4786 */
4787 if (!(vport->load_flag & FC_UNLOADING) &&
4788 active_vlink_present) {
James Smart695a8142010-01-26 23:08:03 -05004789 /*
4790 * If there are other active VLinks present,
4791 * re-instantiate the Vlink using FDISC.
4792 */
James Smart256ec0d2013-04-17 20:14:58 -04004793 mod_timer(&ndlp->nlp_delayfunc,
4794 jiffies + msecs_to_jiffies(1000));
James Smartfc2b9892010-02-26 14:15:29 -05004795 shost = lpfc_shost_from_vport(vport);
James Smart6669f9b2009-10-02 15:16:45 -04004796 spin_lock_irq(shost->host_lock);
4797 ndlp->nlp_flag |= NLP_DELAY_TMO;
4798 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05004799 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
4800 vport->port_state = LPFC_FDISC;
4801 } else {
James Smartecfd03c2010-02-12 14:41:27 -05004802 /*
4803 * Otherwise, we request port to rediscover
4804 * the entire FCF table for a fast recovery
4805 * from possible case that the current FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05004806 * is no longer valid if we are not already
4807 * in the FCF failover process.
James Smartecfd03c2010-02-12 14:41:27 -05004808 */
James Smartfc2b9892010-02-26 14:15:29 -05004809 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004810 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
James Smartfc2b9892010-02-26 14:15:29 -05004811 spin_unlock_irq(&phba->hbalock);
4812 break;
4813 }
4814 /* Mark the fast failover process in progress */
James Smart0c9ab6f2010-02-26 14:15:57 -05004815 phba->fcf.fcf_flag |= FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004816 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004817 lpfc_printf_log(phba, KERN_INFO, LOG_FIP |
4818 LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004819 "2773 Start FCF failover per CVL, "
James Smart70f3c072010-12-15 17:57:33 -05004820 "evt_tag:x%x\n", acqe_fip->event_tag);
James Smartecfd03c2010-02-12 14:41:27 -05004821 rc = lpfc_sli4_redisc_fcf_table(phba);
James Smartfc2b9892010-02-26 14:15:29 -05004822 if (rc) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004823 lpfc_printf_log(phba, KERN_ERR, LOG_FIP |
4824 LOG_DISCOVERY,
4825 "2774 Issue FCF rediscover "
4826 "mabilbox command failed, "
4827 "through to CVL event\n");
James Smartfc2b9892010-02-26 14:15:29 -05004828 spin_lock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05004829 phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
James Smartfc2b9892010-02-26 14:15:29 -05004830 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05004831 /*
4832 * Last resort will be re-try on the
4833 * the current registered FCF entry.
4834 */
4835 lpfc_retry_pport_discovery(phba);
James Smart38b92ef2010-08-04 16:11:39 -04004836 } else
4837 /*
4838 * Reset FCF roundrobin bmask for new
4839 * discovery.
4840 */
James Smart7d791df2011-07-22 18:37:52 -04004841 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart6669f9b2009-10-02 15:16:45 -04004842 }
4843 break;
James Smartda0436e2009-05-22 14:51:39 -04004844 default:
4845 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4846 "0288 Unknown FCoE event type 0x%x event tag "
James Smart70f3c072010-12-15 17:57:33 -05004847 "0x%x\n", event_type, acqe_fip->event_tag);
James Smartda0436e2009-05-22 14:51:39 -04004848 break;
4849 }
4850}
4851
4852/**
4853 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
4854 * @phba: pointer to lpfc hba data structure.
4855 * @acqe_link: pointer to the async dcbx completion queue entry.
4856 *
4857 * This routine is to handle the SLI4 asynchronous dcbx event.
4858 **/
4859static void
4860lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
4861 struct lpfc_acqe_dcbx *acqe_dcbx)
4862{
James Smart4d9ab992009-10-02 15:16:39 -04004863 phba->fc_eventTag = acqe_dcbx->event_tag;
James Smartda0436e2009-05-22 14:51:39 -04004864 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4865 "0290 The SLI4 DCBX asynchronous event is not "
4866 "handled yet\n");
4867}
4868
4869/**
James Smartb19a0612010-04-06 14:48:51 -04004870 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
4871 * @phba: pointer to lpfc hba data structure.
4872 * @acqe_link: pointer to the async grp5 completion queue entry.
4873 *
4874 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
4875 * is an asynchronous notified of a logical link speed change. The Port
4876 * reports the logical link speed in units of 10Mbps.
4877 **/
4878static void
4879lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba,
4880 struct lpfc_acqe_grp5 *acqe_grp5)
4881{
4882 uint16_t prev_ll_spd;
4883
4884 phba->fc_eventTag = acqe_grp5->event_tag;
4885 phba->fcoe_eventtag = acqe_grp5->event_tag;
4886 prev_ll_spd = phba->sli4_hba.link_state.logical_speed;
4887 phba->sli4_hba.link_state.logical_speed =
James Smart8b68cd52012-09-29 11:32:37 -04004888 (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10;
James Smartb19a0612010-04-06 14:48:51 -04004889 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4890 "2789 GRP5 Async Event: Updating logical link speed "
James Smart8b68cd52012-09-29 11:32:37 -04004891 "from %dMbps to %dMbps\n", prev_ll_spd,
4892 phba->sli4_hba.link_state.logical_speed);
James Smartb19a0612010-04-06 14:48:51 -04004893}
4894
4895/**
James Smartda0436e2009-05-22 14:51:39 -04004896 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
4897 * @phba: pointer to lpfc hba data structure.
4898 *
4899 * This routine is invoked by the worker thread to process all the pending
4900 * SLI4 asynchronous events.
4901 **/
4902void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
4903{
4904 struct lpfc_cq_event *cq_event;
4905
4906 /* First, declare the async event has been handled */
4907 spin_lock_irq(&phba->hbalock);
4908 phba->hba_flag &= ~ASYNC_EVENT;
4909 spin_unlock_irq(&phba->hbalock);
4910 /* Now, handle all the async events */
4911 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
4912 /* Get the first event from the head of the event queue */
4913 spin_lock_irq(&phba->hbalock);
4914 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
4915 cq_event, struct lpfc_cq_event, list);
4916 spin_unlock_irq(&phba->hbalock);
4917 /* Process the asynchronous event */
4918 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
4919 case LPFC_TRAILER_CODE_LINK:
4920 lpfc_sli4_async_link_evt(phba,
4921 &cq_event->cqe.acqe_link);
4922 break;
4923 case LPFC_TRAILER_CODE_FCOE:
James Smart70f3c072010-12-15 17:57:33 -05004924 lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip);
James Smartda0436e2009-05-22 14:51:39 -04004925 break;
4926 case LPFC_TRAILER_CODE_DCBX:
4927 lpfc_sli4_async_dcbx_evt(phba,
4928 &cq_event->cqe.acqe_dcbx);
4929 break;
James Smartb19a0612010-04-06 14:48:51 -04004930 case LPFC_TRAILER_CODE_GRP5:
4931 lpfc_sli4_async_grp5_evt(phba,
4932 &cq_event->cqe.acqe_grp5);
4933 break;
James Smart70f3c072010-12-15 17:57:33 -05004934 case LPFC_TRAILER_CODE_FC:
4935 lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc);
4936 break;
4937 case LPFC_TRAILER_CODE_SLI:
4938 lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli);
4939 break;
James Smartda0436e2009-05-22 14:51:39 -04004940 default:
4941 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4942 "1804 Invalid asynchrous event code: "
4943 "x%x\n", bf_get(lpfc_trailer_code,
4944 &cq_event->cqe.mcqe_cmpl));
4945 break;
4946 }
4947 /* Free the completion event processed to the free pool */
4948 lpfc_sli4_cq_event_release(phba, cq_event);
4949 }
4950}
4951
4952/**
James Smartecfd03c2010-02-12 14:41:27 -05004953 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
4954 * @phba: pointer to lpfc hba data structure.
4955 *
4956 * This routine is invoked by the worker thread to process FCF table
4957 * rediscovery pending completion event.
4958 **/
4959void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
4960{
4961 int rc;
4962
4963 spin_lock_irq(&phba->hbalock);
4964 /* Clear FCF rediscovery timeout event */
4965 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
4966 /* Clear driver fast failover FCF record flag */
4967 phba->fcf.failover_rec.flag = 0;
4968 /* Set state for FCF fast failover */
4969 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
4970 spin_unlock_irq(&phba->hbalock);
4971
4972 /* Scan FCF table from the first entry to re-discover SAN */
James Smart0c9ab6f2010-02-26 14:15:57 -05004973 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
James Smarta93ff372010-10-22 11:06:08 -04004974 "2777 Start post-quiescent FCF table scan\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05004975 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smartecfd03c2010-02-12 14:41:27 -05004976 if (rc)
James Smart0c9ab6f2010-02-26 14:15:57 -05004977 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
4978 "2747 Issue FCF scan read FCF mailbox "
4979 "command failed 0x%x\n", rc);
James Smartecfd03c2010-02-12 14:41:27 -05004980}
4981
4982/**
James Smartda0436e2009-05-22 14:51:39 -04004983 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
4984 * @phba: pointer to lpfc hba data structure.
4985 * @dev_grp: The HBA PCI-Device group number.
4986 *
4987 * This routine is invoked to set up the per HBA PCI-Device group function
4988 * API jump table entries.
4989 *
4990 * Return: 0 if success, otherwise -ENODEV
4991 **/
4992int
4993lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
James Smart5b75da22008-12-04 22:39:35 -05004994{
4995 int rc;
4996
James Smartda0436e2009-05-22 14:51:39 -04004997 /* Set up lpfc PCI-device group */
4998 phba->pci_dev_grp = dev_grp;
James Smart5b75da22008-12-04 22:39:35 -05004999
James Smartda0436e2009-05-22 14:51:39 -04005000 /* The LPFC_PCI_DEV_OC uses SLI4 */
5001 if (dev_grp == LPFC_PCI_DEV_OC)
5002 phba->sli_rev = LPFC_SLI_REV4;
James Smart5b75da22008-12-04 22:39:35 -05005003
James Smartda0436e2009-05-22 14:51:39 -04005004 /* Set up device INIT API function jump table */
5005 rc = lpfc_init_api_table_setup(phba, dev_grp);
5006 if (rc)
5007 return -ENODEV;
5008 /* Set up SCSI API function jump table */
5009 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
5010 if (rc)
5011 return -ENODEV;
5012 /* Set up SLI API function jump table */
5013 rc = lpfc_sli_api_table_setup(phba, dev_grp);
5014 if (rc)
5015 return -ENODEV;
5016 /* Set up MBOX API function jump table */
5017 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
5018 if (rc)
5019 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05005020
James Smartda0436e2009-05-22 14:51:39 -04005021 return 0;
James Smart5b75da22008-12-04 22:39:35 -05005022}
5023
5024/**
James Smart3621a712009-04-06 18:47:14 -04005025 * lpfc_log_intr_mode - Log the active interrupt mode
James Smart5b75da22008-12-04 22:39:35 -05005026 * @phba: pointer to lpfc hba data structure.
5027 * @intr_mode: active interrupt mode adopted.
5028 *
5029 * This routine it invoked to log the currently used active interrupt mode
5030 * to the device.
James Smart3772a992009-05-22 14:50:54 -04005031 **/
5032static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
James Smart5b75da22008-12-04 22:39:35 -05005033{
5034 switch (intr_mode) {
5035 case 0:
5036 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5037 "0470 Enable INTx interrupt mode.\n");
5038 break;
5039 case 1:
5040 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5041 "0481 Enabled MSI interrupt mode.\n");
5042 break;
5043 case 2:
5044 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5045 "0480 Enabled MSI-X interrupt mode.\n");
5046 break;
5047 default:
5048 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5049 "0482 Illegal interrupt mode.\n");
5050 break;
5051 }
5052 return;
5053}
5054
James Smart5b75da22008-12-04 22:39:35 -05005055/**
James Smart3772a992009-05-22 14:50:54 -04005056 * lpfc_enable_pci_dev - Enable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05005057 * @phba: pointer to lpfc hba data structure.
5058 *
James Smart3772a992009-05-22 14:50:54 -04005059 * This routine is invoked to enable the PCI device that is common to all
5060 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05005061 *
5062 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005063 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005064 * other values - error
James Smart5b75da22008-12-04 22:39:35 -05005065 **/
James Smart3772a992009-05-22 14:50:54 -04005066static int
5067lpfc_enable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05005068{
James Smart3772a992009-05-22 14:50:54 -04005069 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05005070
James Smart3772a992009-05-22 14:50:54 -04005071 /* Obtain PCI device reference */
5072 if (!phba->pcidev)
5073 goto out_error;
5074 else
5075 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04005076 /* Enable PCI device */
5077 if (pci_enable_device_mem(pdev))
5078 goto out_error;
5079 /* Request PCI resource for the device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005080 if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME))
James Smart3772a992009-05-22 14:50:54 -04005081 goto out_disable_device;
5082 /* Set up device as PCI master and save state for EEH */
5083 pci_set_master(pdev);
5084 pci_try_set_mwi(pdev);
5085 pci_save_state(pdev);
James Smart5b75da22008-12-04 22:39:35 -05005086
James Smart05580562011-05-24 11:40:48 -04005087 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
Jon Mason453193e2013-09-11 15:38:13 -07005088 if (pci_is_pcie(pdev))
James Smart05580562011-05-24 11:40:48 -04005089 pdev->needs_freset = 1;
5090
James Smart3772a992009-05-22 14:50:54 -04005091 return 0;
James Smart5b75da22008-12-04 22:39:35 -05005092
James Smart3772a992009-05-22 14:50:54 -04005093out_disable_device:
5094 pci_disable_device(pdev);
5095out_error:
James Smart079b5c92011-08-21 21:48:49 -04005096 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005097 "1401 Failed to enable pci device\n");
James Smart3772a992009-05-22 14:50:54 -04005098 return -ENODEV;
James Smart5b75da22008-12-04 22:39:35 -05005099}
5100
5101/**
James Smart3772a992009-05-22 14:50:54 -04005102 * lpfc_disable_pci_dev - Disable a generic PCI device.
James Smart5b75da22008-12-04 22:39:35 -05005103 * @phba: pointer to lpfc hba data structure.
5104 *
James Smart3772a992009-05-22 14:50:54 -04005105 * This routine is invoked to disable the PCI device that is common to all
5106 * PCI devices.
James Smart5b75da22008-12-04 22:39:35 -05005107 **/
5108static void
James Smart3772a992009-05-22 14:50:54 -04005109lpfc_disable_pci_dev(struct lpfc_hba *phba)
James Smart5b75da22008-12-04 22:39:35 -05005110{
James Smart3772a992009-05-22 14:50:54 -04005111 struct pci_dev *pdev;
James Smart5b75da22008-12-04 22:39:35 -05005112
James Smart3772a992009-05-22 14:50:54 -04005113 /* Obtain PCI device reference */
5114 if (!phba->pcidev)
5115 return;
5116 else
5117 pdev = phba->pcidev;
James Smart3772a992009-05-22 14:50:54 -04005118 /* Release PCI resource and disable PCI device */
Johannes Thumshirne0c04832016-06-07 09:44:03 +02005119 pci_release_mem_regions(pdev);
James Smart3772a992009-05-22 14:50:54 -04005120 pci_disable_device(pdev);
James Smart5b75da22008-12-04 22:39:35 -05005121
5122 return;
5123}
5124
5125/**
James Smart3772a992009-05-22 14:50:54 -04005126 * lpfc_reset_hba - Reset a hba
5127 * @phba: pointer to lpfc hba data structure.
James Smarte59058c2008-08-24 21:49:00 -04005128 *
James Smart3772a992009-05-22 14:50:54 -04005129 * This routine is invoked to reset a hba device. It brings the HBA
5130 * offline, performs a board restart, and then brings the board back
5131 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
5132 * on outstanding mailbox commands.
James Smarte59058c2008-08-24 21:49:00 -04005133 **/
James Smart3772a992009-05-22 14:50:54 -04005134void
5135lpfc_reset_hba(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05005136{
James Smart3772a992009-05-22 14:50:54 -04005137 /* If resets are disabled then set error state and return. */
5138 if (!phba->cfg_enable_hba_reset) {
5139 phba->link_state = LPFC_HBA_ERROR;
5140 return;
5141 }
James Smartee620212014-04-04 13:51:53 -04005142 if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
5143 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
5144 else
5145 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
James Smart3772a992009-05-22 14:50:54 -04005146 lpfc_offline(phba);
5147 lpfc_sli_brdrestart(phba);
5148 lpfc_online(phba);
5149 lpfc_unblock_mgmt_io(phba);
5150}
dea31012005-04-17 16:05:31 -05005151
James Smart3772a992009-05-22 14:50:54 -04005152/**
James Smart0a96e972011-07-22 18:37:28 -04005153 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
5154 * @phba: pointer to lpfc hba data structure.
5155 *
5156 * This function enables the PCI SR-IOV virtual functions to a physical
5157 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5158 * enable the number of virtual functions to the physical function. As
5159 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5160 * API call does not considered as an error condition for most of the device.
5161 **/
5162uint16_t
5163lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba)
5164{
5165 struct pci_dev *pdev = phba->pcidev;
5166 uint16_t nr_virtfn;
5167 int pos;
5168
James Smart0a96e972011-07-22 18:37:28 -04005169 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
5170 if (pos == 0)
5171 return 0;
5172
5173 pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn);
5174 return nr_virtfn;
5175}
5176
5177/**
James Smart912e3ac2011-05-24 11:42:11 -04005178 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
5179 * @phba: pointer to lpfc hba data structure.
5180 * @nr_vfn: number of virtual functions to be enabled.
5181 *
5182 * This function enables the PCI SR-IOV virtual functions to a physical
5183 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
5184 * enable the number of virtual functions to the physical function. As
5185 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
5186 * API call does not considered as an error condition for most of the device.
5187 **/
5188int
5189lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn)
5190{
5191 struct pci_dev *pdev = phba->pcidev;
James Smart0a96e972011-07-22 18:37:28 -04005192 uint16_t max_nr_vfn;
James Smart912e3ac2011-05-24 11:42:11 -04005193 int rc;
5194
James Smart0a96e972011-07-22 18:37:28 -04005195 max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba);
5196 if (nr_vfn > max_nr_vfn) {
5197 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5198 "3057 Requested vfs (%d) greater than "
5199 "supported vfs (%d)", nr_vfn, max_nr_vfn);
5200 return -EINVAL;
5201 }
5202
James Smart912e3ac2011-05-24 11:42:11 -04005203 rc = pci_enable_sriov(pdev, nr_vfn);
5204 if (rc) {
5205 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5206 "2806 Failed to enable sriov on this device "
5207 "with vfn number nr_vf:%d, rc:%d\n",
5208 nr_vfn, rc);
5209 } else
5210 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5211 "2807 Successful enable sriov on this device "
5212 "with vfn number nr_vf:%d\n", nr_vfn);
5213 return rc;
5214}
5215
5216/**
James Smart895427b2017-02-12 13:52:30 -08005217 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
James Smart3772a992009-05-22 14:50:54 -04005218 * @phba: pointer to lpfc hba data structure.
5219 *
James Smart895427b2017-02-12 13:52:30 -08005220 * This routine is invoked to set up the driver internal resources before the
5221 * device specific resource setup to support the HBA device it attached to.
James Smart3772a992009-05-22 14:50:54 -04005222 *
5223 * Return codes
James Smart895427b2017-02-12 13:52:30 -08005224 * 0 - successful
5225 * other values - error
James Smart3772a992009-05-22 14:50:54 -04005226 **/
5227static int
James Smart895427b2017-02-12 13:52:30 -08005228lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
James Smart3772a992009-05-22 14:50:54 -04005229{
James Smart895427b2017-02-12 13:52:30 -08005230 struct lpfc_sli *psli = &phba->sli;
dea31012005-04-17 16:05:31 -05005231
James Smart3772a992009-05-22 14:50:54 -04005232 /*
James Smart895427b2017-02-12 13:52:30 -08005233 * Driver resources common to all SLI revisions
James Smart3772a992009-05-22 14:50:54 -04005234 */
James Smart895427b2017-02-12 13:52:30 -08005235 atomic_set(&phba->fast_event_count, 0);
5236 spin_lock_init(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005237
James Smart895427b2017-02-12 13:52:30 -08005238 /* Initialize ndlp management spinlock */
5239 spin_lock_init(&phba->ndlp_lock);
James Smart3772a992009-05-22 14:50:54 -04005240
James Smart895427b2017-02-12 13:52:30 -08005241 INIT_LIST_HEAD(&phba->port_list);
5242 INIT_LIST_HEAD(&phba->work_list);
5243 init_waitqueue_head(&phba->wait_4_mlo_m_q);
5244
5245 /* Initialize the wait queue head for the kernel thread */
5246 init_waitqueue_head(&phba->work_waitq);
5247
5248 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5249 "1403 Protocols supported %s %s\n",
5250 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ?
5251 "SCSI" : " "),
5252 ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ?
5253 "NVME" : " "));
5254
5255 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5256 /* Initialize the scsi buffer list used by driver for scsi IO */
5257 spin_lock_init(&phba->scsi_buf_list_get_lock);
5258 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5259 spin_lock_init(&phba->scsi_buf_list_put_lock);
5260 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
5261 }
5262
5263 if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) &&
5264 (phba->nvmet_support == 0)) {
5265 /* Initialize the NVME buffer list used by driver for NVME IO */
5266 spin_lock_init(&phba->nvme_buf_list_get_lock);
5267 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_get);
5268 spin_lock_init(&phba->nvme_buf_list_put_lock);
5269 INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put);
5270 }
5271
5272 /* Initialize the fabric iocb list */
5273 INIT_LIST_HEAD(&phba->fabric_iocb_list);
5274
5275 /* Initialize list to save ELS buffers */
5276 INIT_LIST_HEAD(&phba->elsbuf);
5277
5278 /* Initialize FCF connection rec list */
5279 INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
5280
5281 /* Initialize OAS configuration list */
5282 spin_lock_init(&phba->devicelock);
5283 INIT_LIST_HEAD(&phba->luns);
5284
James Smart3772a992009-05-22 14:50:54 -04005285 /* MBOX heartbeat timer */
5286 init_timer(&psli->mbox_tmo);
5287 psli->mbox_tmo.function = lpfc_mbox_timeout;
5288 psli->mbox_tmo.data = (unsigned long) phba;
James Smart3772a992009-05-22 14:50:54 -04005289 /* Fabric block timer */
5290 init_timer(&phba->fabric_block_timer);
5291 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
5292 phba->fabric_block_timer.data = (unsigned long) phba;
5293 /* EA polling mode timer */
5294 init_timer(&phba->eratt_poll);
5295 phba->eratt_poll.function = lpfc_poll_eratt;
5296 phba->eratt_poll.data = (unsigned long) phba;
James Smart895427b2017-02-12 13:52:30 -08005297 /* Heartbeat timer */
5298 init_timer(&phba->hb_tmofunc);
5299 phba->hb_tmofunc.function = lpfc_hb_timeout;
5300 phba->hb_tmofunc.data = (unsigned long)phba;
5301
5302 return 0;
5303}
5304
5305/**
5306 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev
5307 * @phba: pointer to lpfc hba data structure.
5308 *
5309 * This routine is invoked to set up the driver internal resources specific to
5310 * support the SLI-3 HBA device it attached to.
5311 *
5312 * Return codes
5313 * 0 - successful
5314 * other values - error
5315 **/
5316static int
5317lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
5318{
5319 int rc;
5320
5321 /*
5322 * Initialize timers used by driver
5323 */
5324
5325 /* FCP polling mode timer */
5326 init_timer(&phba->fcp_poll_timer);
5327 phba->fcp_poll_timer.function = lpfc_poll_timeout;
5328 phba->fcp_poll_timer.data = (unsigned long) phba;
James Smart3772a992009-05-22 14:50:54 -04005329
5330 /* Host attention work mask setup */
5331 phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
5332 phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
5333
5334 /* Get all the module params for configuring this host */
5335 lpfc_get_cfgparam(phba);
James Smart895427b2017-02-12 13:52:30 -08005336 /* Set up phase-1 common device driver resources */
5337
5338 rc = lpfc_setup_driver_resource_phase1(phba);
5339 if (rc)
5340 return -ENODEV;
5341
James Smart49198b32010-04-06 15:04:33 -04005342 if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) {
5343 phba->menlo_flag |= HBA_MENLO_SUPPORT;
5344 /* check for menlo minimum sg count */
5345 if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT)
5346 phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT;
5347 }
5348
James Smart895427b2017-02-12 13:52:30 -08005349 if (!phba->sli.sli3_ring)
5350 phba->sli.sli3_ring = kzalloc(LPFC_SLI3_MAX_RING *
James Smart2a76a282012-08-03 12:35:54 -04005351 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
James Smart895427b2017-02-12 13:52:30 -08005352 if (!phba->sli.sli3_ring)
James Smart2a76a282012-08-03 12:35:54 -04005353 return -ENOMEM;
5354
James Smart3772a992009-05-22 14:50:54 -04005355 /*
James Smart96f70772013-04-17 20:16:15 -04005356 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
James Smart3772a992009-05-22 14:50:54 -04005357 * used to create the sg_dma_buf_pool must be dynamically calculated.
James Smart3772a992009-05-22 14:50:54 -04005358 */
James Smart3772a992009-05-22 14:50:54 -04005359
James Smart96f70772013-04-17 20:16:15 -04005360 /* Initialize the host templates the configured values. */
James Smart3772a992009-05-22 14:50:54 -04005361 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
Bodo Stroesser5f406fa2015-08-31 16:48:10 -04005362 lpfc_template_s3.sg_tablesize = phba->cfg_sg_seg_cnt;
James Smart3772a992009-05-22 14:50:54 -04005363
James Smart96f70772013-04-17 20:16:15 -04005364 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
5365 if (phba->cfg_enable_bg) {
5366 /*
5367 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
5368 * the FCP rsp, and a BDE for each. Sice we have no control
5369 * over how many protection data segments the SCSI Layer
5370 * will hand us (ie: there could be one for every block
5371 * in the IO), we just allocate enough BDEs to accomidate
5372 * our max amount and we need to limit lpfc_sg_seg_cnt to
5373 * minimize the risk of running out.
5374 */
5375 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5376 sizeof(struct fcp_rsp) +
5377 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
5378
5379 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
5380 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
5381
5382 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
5383 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
5384 } else {
5385 /*
5386 * The scsi_buf for a regular I/O will hold the FCP cmnd,
5387 * the FCP rsp, a BDE for each, and a BDE for up to
5388 * cfg_sg_seg_cnt data segments.
5389 */
5390 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
5391 sizeof(struct fcp_rsp) +
5392 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
5393
5394 /* Total BDEs in BPL for scsi_sg_list */
5395 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
5396 }
5397
5398 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5399 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
5400 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5401 phba->cfg_total_seg_cnt);
5402
James Smart3772a992009-05-22 14:50:54 -04005403 phba->max_vpi = LPFC_MAX_VPI;
5404 /* This will be set to correct value after config_port mbox */
5405 phba->max_vports = 0;
5406
5407 /*
5408 * Initialize the SLI Layer to run with lpfc HBAs.
5409 */
5410 lpfc_sli_setup(phba);
James Smart895427b2017-02-12 13:52:30 -08005411 lpfc_sli_queue_init(phba);
James Smart3772a992009-05-22 14:50:54 -04005412
5413 /* Allocate device driver memory */
5414 if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
5415 return -ENOMEM;
5416
James Smart912e3ac2011-05-24 11:42:11 -04005417 /*
5418 * Enable sr-iov virtual functions if supported and configured
5419 * through the module parameter.
5420 */
5421 if (phba->cfg_sriov_nr_virtfn > 0) {
5422 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5423 phba->cfg_sriov_nr_virtfn);
5424 if (rc) {
5425 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5426 "2808 Requested number of SR-IOV "
5427 "virtual functions (%d) is not "
5428 "supported\n",
5429 phba->cfg_sriov_nr_virtfn);
5430 phba->cfg_sriov_nr_virtfn = 0;
5431 }
5432 }
5433
James Smart3772a992009-05-22 14:50:54 -04005434 return 0;
5435}
5436
5437/**
5438 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
5439 * @phba: pointer to lpfc hba data structure.
5440 *
5441 * This routine is invoked to unset the driver internal resources set up
5442 * specific for supporting the SLI-3 HBA device it attached to.
5443 **/
5444static void
5445lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
5446{
5447 /* Free device driver memory allocated */
5448 lpfc_mem_free_all(phba);
5449
5450 return;
5451}
5452
5453/**
James Smartda0436e2009-05-22 14:51:39 -04005454 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
5455 * @phba: pointer to lpfc hba data structure.
5456 *
5457 * This routine is invoked to set up the driver internal resources specific to
5458 * support the SLI-4 HBA device it attached to.
5459 *
5460 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005461 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04005462 * other values - error
5463 **/
5464static int
5465lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5466{
James Smart28baac72010-02-12 14:42:03 -05005467 LPFC_MBOXQ_t *mboxq;
James Smart895427b2017-02-12 13:52:30 -08005468 int rc, i, max_buf_size;
James Smart28baac72010-02-12 14:42:03 -05005469 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
5470 struct lpfc_mqe *mqe;
James Smart09294d42013-04-17 20:16:05 -04005471 int longs;
James Smart1ba981f2014-02-20 09:56:45 -05005472 int fof_vectors = 0;
James Smartda0436e2009-05-22 14:51:39 -04005473
James Smart895427b2017-02-12 13:52:30 -08005474 phba->sli4_hba.num_online_cpu = num_online_cpus();
5475 phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
5476 phba->sli4_hba.curr_disp_cpu = 0;
5477
James Smart716d3bc2013-09-06 12:18:28 -04005478 /* Get all the module params for configuring this host */
5479 lpfc_get_cfgparam(phba);
5480
James Smart895427b2017-02-12 13:52:30 -08005481 /* Set up phase-1 common device driver resources */
5482 rc = lpfc_setup_driver_resource_phase1(phba);
5483 if (rc)
5484 return -ENODEV;
5485
James Smartda0436e2009-05-22 14:51:39 -04005486 /* Before proceed, wait for POST done and device ready */
5487 rc = lpfc_sli4_post_status_check(phba);
5488 if (rc)
5489 return -ENODEV;
5490
5491 /*
5492 * Initialize timers used by driver
5493 */
5494
James Smart19ca7602010-11-20 23:11:55 -05005495 init_timer(&phba->rrq_tmr);
5496 phba->rrq_tmr.function = lpfc_rrq_timeout;
5497 phba->rrq_tmr.data = (unsigned long)phba;
James Smartda0436e2009-05-22 14:51:39 -04005498
James Smartecfd03c2010-02-12 14:41:27 -05005499 /* FCF rediscover timer */
5500 init_timer(&phba->fcf.redisc_wait);
5501 phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
5502 phba->fcf.redisc_wait.data = (unsigned long)phba;
5503
James Smartda0436e2009-05-22 14:51:39 -04005504 /*
James Smart7ad20aa2011-05-24 11:44:28 -04005505 * Control structure for handling external multi-buffer mailbox
5506 * command pass-through.
5507 */
5508 memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0,
5509 sizeof(struct lpfc_mbox_ext_buf_ctx));
5510 INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list);
5511
James Smartda0436e2009-05-22 14:51:39 -04005512 phba->max_vpi = LPFC_MAX_VPI;
James Smart67d12732012-08-03 12:36:13 -04005513
James Smartda0436e2009-05-22 14:51:39 -04005514 /* This will be set to correct value after the read_config mbox */
5515 phba->max_vports = 0;
5516
5517 /* Program the default value of vlan_id and fc_map */
5518 phba->valid_vlan = 0;
5519 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
5520 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
5521 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
5522
5523 /*
James Smart2a76a282012-08-03 12:35:54 -04005524 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
James Smart895427b2017-02-12 13:52:30 -08005525 * we will associate a new ring, for each EQ/CQ/WQ tuple.
5526 * The WQ create will allocate the ring.
James Smart2a76a282012-08-03 12:35:54 -04005527 */
James Smart085c6472010-11-20 23:11:37 -05005528
James Smart09294d42013-04-17 20:16:05 -04005529 /*
5530 * It doesn't matter what family our adapter is in, we are
5531 * limited to 2 Pages, 512 SGEs, for our SGL.
5532 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
5533 */
5534 max_buf_size = (2 * SLI4_PAGE_SIZE);
5535 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2)
5536 phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2;
James Smart09294d42013-04-17 20:16:05 -04005537
James Smartda0436e2009-05-22 14:51:39 -04005538 /*
James Smart895427b2017-02-12 13:52:30 -08005539 * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size
5540 * used to create the sg_dma_buf_pool must be calculated.
James Smart28baac72010-02-12 14:42:03 -05005541 */
James Smart96f70772013-04-17 20:16:15 -04005542 if (phba->cfg_enable_bg) {
5543 /*
James Smart895427b2017-02-12 13:52:30 -08005544 * The scsi_buf for a T10-DIF I/O holds the FCP cmnd,
5545 * the FCP rsp, and a SGE. Sice we have no control
5546 * over how many protection segments the SCSI Layer
James Smart96f70772013-04-17 20:16:15 -04005547 * will hand us (ie: there could be one for every block
James Smart895427b2017-02-12 13:52:30 -08005548 * in the IO), just allocate enough SGEs to accomidate
5549 * our max amount and we need to limit lpfc_sg_seg_cnt
5550 * to minimize the risk of running out.
James Smart96f70772013-04-17 20:16:15 -04005551 */
5552 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08005553 sizeof(struct fcp_rsp) + max_buf_size;
James Smart96f70772013-04-17 20:16:15 -04005554
5555 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
5556 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
5557
5558 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
James Smart895427b2017-02-12 13:52:30 -08005559 phba->cfg_sg_seg_cnt =
5560 LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
James Smart96f70772013-04-17 20:16:15 -04005561 } else {
5562 /*
James Smart895427b2017-02-12 13:52:30 -08005563 * The scsi_buf for a regular I/O holds the FCP cmnd,
James Smart96f70772013-04-17 20:16:15 -04005564 * the FCP rsp, a SGE for each, and a SGE for up to
5565 * cfg_sg_seg_cnt data segments.
5566 */
5567 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
James Smart895427b2017-02-12 13:52:30 -08005568 sizeof(struct fcp_rsp) +
5569 ((phba->cfg_sg_seg_cnt + 2) *
5570 sizeof(struct sli4_sge));
James Smart96f70772013-04-17 20:16:15 -04005571
5572 /* Total SGEs for scsi_sg_list */
5573 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
James Smart895427b2017-02-12 13:52:30 -08005574
James Smart96f70772013-04-17 20:16:15 -04005575 /*
James Smart895427b2017-02-12 13:52:30 -08005576 * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only
5577 * need to post 1 page for the SGL.
James Smart96f70772013-04-17 20:16:15 -04005578 */
James Smart085c6472010-11-20 23:11:37 -05005579 }
James Smartacd68592012-01-18 16:25:09 -05005580
James Smart96f70772013-04-17 20:16:15 -04005581 /* Initialize the host templates with the updated values. */
5582 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5583 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
5584
5585 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
5586 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
5587 else
5588 phba->cfg_sg_dma_buf_size =
5589 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
5590
5591 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5592 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
5593 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5594 phba->cfg_total_seg_cnt);
James Smartda0436e2009-05-22 14:51:39 -04005595
5596 /* Initialize buffer queue management fields */
James Smart895427b2017-02-12 13:52:30 -08005597 INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list);
James Smartda0436e2009-05-22 14:51:39 -04005598 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
5599 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
5600
5601 /*
5602 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
5603 */
James Smart895427b2017-02-12 13:52:30 -08005604 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) {
5605 /* Initialize the Abort scsi buffer list used by driver */
5606 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
5607 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
5608 }
5609
5610 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
5611 /* Initialize the Abort nvme buffer list used by driver */
5612 spin_lock_init(&phba->sli4_hba.abts_nvme_buf_list_lock);
5613 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
5614 }
5615
James Smartda0436e2009-05-22 14:51:39 -04005616 /* This abort list used by worker thread */
James Smart895427b2017-02-12 13:52:30 -08005617 spin_lock_init(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04005618
5619 /*
James Smart6d368e52011-05-24 11:44:12 -04005620 * Initialize driver internal slow-path work queues
James Smartda0436e2009-05-22 14:51:39 -04005621 */
5622
5623 /* Driver internel slow-path CQ Event pool */
5624 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
5625 /* Response IOCB work queue list */
James Smart45ed1192009-10-02 15:17:02 -04005626 INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
James Smartda0436e2009-05-22 14:51:39 -04005627 /* Asynchronous event CQ Event work queue list */
5628 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
5629 /* Fast-path XRI aborted CQ Event work queue list */
5630 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
5631 /* Slow-path XRI aborted CQ Event work queue list */
5632 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
5633 /* Receive queue CQ Event work queue list */
5634 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
5635
James Smart6d368e52011-05-24 11:44:12 -04005636 /* Initialize extent block lists. */
5637 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list);
5638 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list);
5639 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list);
5640 INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list);
5641
James Smart448193b2015-12-16 18:12:05 -05005642 /* initialize optic_state to 0xFF */
5643 phba->sli4_hba.lnk_info.optic_state = 0xff;
5644
James Smartda0436e2009-05-22 14:51:39 -04005645 /* Allocate device driver memory */
5646 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
5647 if (rc)
5648 return -ENOMEM;
5649
James Smart2fcee4b2010-12-15 17:57:46 -05005650 /* IF Type 2 ports get initialized now. */
5651 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5652 LPFC_SLI_INTF_IF_TYPE_2) {
5653 rc = lpfc_pci_function_reset(phba);
James Smart895427b2017-02-12 13:52:30 -08005654 if (unlikely(rc)) {
5655 rc = -ENODEV;
5656 goto out_free_mem;
5657 }
James Smart946727d2015-04-07 15:07:09 -04005658 phba->temp_sensor_support = 1;
James Smart2fcee4b2010-12-15 17:57:46 -05005659 }
5660
James Smartda0436e2009-05-22 14:51:39 -04005661 /* Create the bootstrap mailbox command */
5662 rc = lpfc_create_bootstrap_mbox(phba);
5663 if (unlikely(rc))
5664 goto out_free_mem;
5665
5666 /* Set up the host's endian order with the device. */
5667 rc = lpfc_setup_endian_order(phba);
5668 if (unlikely(rc))
5669 goto out_free_bsmbx;
5670
5671 /* Set up the hba's configuration parameters. */
5672 rc = lpfc_sli4_read_config(phba);
5673 if (unlikely(rc))
5674 goto out_free_bsmbx;
James Smartcff261f2013-12-17 20:29:47 -05005675 rc = lpfc_mem_alloc_active_rrq_pool_s4(phba);
5676 if (unlikely(rc))
5677 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005678
James Smart2fcee4b2010-12-15 17:57:46 -05005679 /* IF Type 0 ports get initialized now. */
5680 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
5681 LPFC_SLI_INTF_IF_TYPE_0) {
5682 rc = lpfc_pci_function_reset(phba);
5683 if (unlikely(rc))
5684 goto out_free_bsmbx;
5685 }
James Smartda0436e2009-05-22 14:51:39 -04005686
James Smartcb5172e2010-03-15 11:25:07 -04005687 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
5688 GFP_KERNEL);
5689 if (!mboxq) {
5690 rc = -ENOMEM;
5691 goto out_free_bsmbx;
5692 }
5693
James Smart895427b2017-02-12 13:52:30 -08005694 phba->nvmet_support = 0;
5695
5696 lpfc_nvme_mod_param_dep(phba);
5697
James Smartfedd3b72011-02-16 12:39:24 -05005698 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
James Smartcb5172e2010-03-15 11:25:07 -04005699 lpfc_supported_pages(mboxq);
5700 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smartfedd3b72011-02-16 12:39:24 -05005701 if (!rc) {
5702 mqe = &mboxq->u.mqe;
5703 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
5704 LPFC_MAX_SUPPORTED_PAGES);
5705 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
5706 switch (pn_page[i]) {
5707 case LPFC_SLI4_PARAMETERS:
5708 phba->sli4_hba.pc_sli4_params.supported = 1;
5709 break;
5710 default:
5711 break;
5712 }
5713 }
5714 /* Read the port's SLI4 Parameters capabilities if supported. */
5715 if (phba->sli4_hba.pc_sli4_params.supported)
5716 rc = lpfc_pc_sli4_params_get(phba, mboxq);
5717 if (rc) {
5718 mempool_free(mboxq, phba->mbox_mem_pool);
5719 rc = -EIO;
5720 goto out_free_bsmbx;
James Smartcb5172e2010-03-15 11:25:07 -04005721 }
5722 }
James Smart65791f12016-07-06 12:35:56 -07005723
James Smartfedd3b72011-02-16 12:39:24 -05005724 /*
5725 * Get sli4 parameters that override parameters from Port capabilities.
James Smart6d368e52011-05-24 11:44:12 -04005726 * If this call fails, it isn't critical unless the SLI4 parameters come
5727 * back in conflict.
James Smartfedd3b72011-02-16 12:39:24 -05005728 */
James Smart6d368e52011-05-24 11:44:12 -04005729 rc = lpfc_get_sli4_parameters(phba, mboxq);
5730 if (rc) {
5731 if (phba->sli4_hba.extents_in_use &&
5732 phba->sli4_hba.rpi_hdrs_in_use) {
5733 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5734 "2999 Unsupported SLI4 Parameters "
5735 "Extents and RPI headers enabled.\n");
James Smart6d368e52011-05-24 11:44:12 -04005736 }
James Smart895427b2017-02-12 13:52:30 -08005737 mempool_free(mboxq, phba->mbox_mem_pool);
5738 goto out_free_bsmbx;
James Smart6d368e52011-05-24 11:44:12 -04005739 }
James Smart895427b2017-02-12 13:52:30 -08005740
James Smartcb5172e2010-03-15 11:25:07 -04005741 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1ba981f2014-02-20 09:56:45 -05005742
5743 /* Verify OAS is supported */
5744 lpfc_sli4_oas_verify(phba);
5745 if (phba->cfg_fof)
5746 fof_vectors = 1;
5747
James Smart5350d872011-10-10 21:33:49 -04005748 /* Verify all the SLI4 queues */
5749 rc = lpfc_sli4_queue_verify(phba);
James Smartda0436e2009-05-22 14:51:39 -04005750 if (rc)
5751 goto out_free_bsmbx;
5752
5753 /* Create driver internal CQE event pool */
5754 rc = lpfc_sli4_cq_event_pool_create(phba);
5755 if (rc)
James Smart5350d872011-10-10 21:33:49 -04005756 goto out_free_bsmbx;
James Smartda0436e2009-05-22 14:51:39 -04005757
James Smart8a9d2e82012-05-09 21:16:12 -04005758 /* Initialize sgl lists per host */
5759 lpfc_init_sgl_list(phba);
5760
5761 /* Allocate and initialize active sgl array */
James Smartda0436e2009-05-22 14:51:39 -04005762 rc = lpfc_init_active_sgl_array(phba);
5763 if (rc) {
5764 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5765 "1430 Failed to initialize sgl list.\n");
James Smart8a9d2e82012-05-09 21:16:12 -04005766 goto out_destroy_cq_event_pool;
James Smartda0436e2009-05-22 14:51:39 -04005767 }
James Smartda0436e2009-05-22 14:51:39 -04005768 rc = lpfc_sli4_init_rpi_hdrs(phba);
5769 if (rc) {
5770 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5771 "1432 Failed to initialize rpi headers.\n");
5772 goto out_free_active_sgl;
5773 }
5774
James Smarta93ff372010-10-22 11:06:08 -04005775 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
James Smart0c9ab6f2010-02-26 14:15:57 -05005776 longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG;
5777 phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long),
5778 GFP_KERNEL);
5779 if (!phba->fcf.fcf_rr_bmask) {
5780 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5781 "2759 Failed allocate memory for FCF round "
5782 "robin failover bmask\n");
James Smart05580562011-05-24 11:40:48 -04005783 rc = -ENOMEM;
James Smart0c9ab6f2010-02-26 14:15:57 -05005784 goto out_remove_rpi_hdrs;
5785 }
5786
James Smart895427b2017-02-12 13:52:30 -08005787 phba->sli4_hba.hba_eq_hdl = kcalloc(fof_vectors + phba->io_channel_irqs,
5788 sizeof(struct lpfc_hba_eq_hdl),
5789 GFP_KERNEL);
5790 if (!phba->sli4_hba.hba_eq_hdl) {
James Smart67d12732012-08-03 12:36:13 -04005791 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5792 "2572 Failed allocate memory for "
5793 "fast-path per-EQ handle array\n");
5794 rc = -ENOMEM;
5795 goto out_free_fcf_rr_bmask;
James Smartda0436e2009-05-22 14:51:39 -04005796 }
5797
James Smart895427b2017-02-12 13:52:30 -08005798 phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_present_cpu,
5799 sizeof(struct lpfc_vector_map_info),
5800 GFP_KERNEL);
James Smart7bb03bb2013-04-17 20:19:16 -04005801 if (!phba->sli4_hba.cpu_map) {
5802 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5803 "3327 Failed allocate memory for msi-x "
5804 "interrupt vector mapping\n");
5805 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08005806 goto out_free_hba_eq_hdl;
James Smart7bb03bb2013-04-17 20:19:16 -04005807 }
James Smartb246de12013-05-31 17:03:07 -04005808 if (lpfc_used_cpu == NULL) {
James Smart895427b2017-02-12 13:52:30 -08005809 lpfc_used_cpu = kcalloc(lpfc_present_cpu, sizeof(uint16_t),
5810 GFP_KERNEL);
James Smartb246de12013-05-31 17:03:07 -04005811 if (!lpfc_used_cpu) {
5812 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5813 "3335 Failed allocate memory for msi-x "
5814 "interrupt vector mapping\n");
5815 kfree(phba->sli4_hba.cpu_map);
5816 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08005817 goto out_free_hba_eq_hdl;
James Smartb246de12013-05-31 17:03:07 -04005818 }
5819 for (i = 0; i < lpfc_present_cpu; i++)
5820 lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY;
5821 }
5822
James Smart912e3ac2011-05-24 11:42:11 -04005823 /*
5824 * Enable sr-iov virtual functions if supported and configured
5825 * through the module parameter.
5826 */
5827 if (phba->cfg_sriov_nr_virtfn > 0) {
5828 rc = lpfc_sli_probe_sriov_nr_virtfn(phba,
5829 phba->cfg_sriov_nr_virtfn);
5830 if (rc) {
5831 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5832 "3020 Requested number of SR-IOV "
5833 "virtual functions (%d) is not "
5834 "supported\n",
5835 phba->cfg_sriov_nr_virtfn);
5836 phba->cfg_sriov_nr_virtfn = 0;
5837 }
5838 }
5839
James Smart5248a742011-07-22 18:37:06 -04005840 return 0;
James Smartda0436e2009-05-22 14:51:39 -04005841
James Smart895427b2017-02-12 13:52:30 -08005842out_free_hba_eq_hdl:
5843 kfree(phba->sli4_hba.hba_eq_hdl);
James Smart0c9ab6f2010-02-26 14:15:57 -05005844out_free_fcf_rr_bmask:
5845 kfree(phba->fcf.fcf_rr_bmask);
James Smartda0436e2009-05-22 14:51:39 -04005846out_remove_rpi_hdrs:
5847 lpfc_sli4_remove_rpi_hdrs(phba);
5848out_free_active_sgl:
5849 lpfc_free_active_sgl(phba);
James Smartda0436e2009-05-22 14:51:39 -04005850out_destroy_cq_event_pool:
5851 lpfc_sli4_cq_event_pool_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04005852out_free_bsmbx:
5853 lpfc_destroy_bootstrap_mbox(phba);
5854out_free_mem:
5855 lpfc_mem_free(phba);
5856 return rc;
5857}
5858
5859/**
5860 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
5861 * @phba: pointer to lpfc hba data structure.
5862 *
5863 * This routine is invoked to unset the driver internal resources set up
5864 * specific for supporting the SLI-4 HBA device it attached to.
5865 **/
5866static void
5867lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
5868{
5869 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
5870
James Smart7bb03bb2013-04-17 20:19:16 -04005871 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
5872 kfree(phba->sli4_hba.cpu_map);
5873 phba->sli4_hba.num_present_cpu = 0;
5874 phba->sli4_hba.num_online_cpu = 0;
James Smart76fd07a2014-02-20 09:57:18 -05005875 phba->sli4_hba.curr_disp_cpu = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04005876
James Smartda0436e2009-05-22 14:51:39 -04005877 /* Free memory allocated for fast-path work queue handles */
James Smart895427b2017-02-12 13:52:30 -08005878 kfree(phba->sli4_hba.hba_eq_hdl);
James Smartda0436e2009-05-22 14:51:39 -04005879
5880 /* Free the allocated rpi headers. */
5881 lpfc_sli4_remove_rpi_hdrs(phba);
James Smartd11e31d2009-06-10 17:23:06 -04005882 lpfc_sli4_remove_rpis(phba);
James Smartda0436e2009-05-22 14:51:39 -04005883
James Smart0c9ab6f2010-02-26 14:15:57 -05005884 /* Free eligible FCF index bmask */
5885 kfree(phba->fcf.fcf_rr_bmask);
5886
James Smartda0436e2009-05-22 14:51:39 -04005887 /* Free the ELS sgl list */
5888 lpfc_free_active_sgl(phba);
James Smart8a9d2e82012-05-09 21:16:12 -04005889 lpfc_free_els_sgl_list(phba);
James Smartda0436e2009-05-22 14:51:39 -04005890
James Smartda0436e2009-05-22 14:51:39 -04005891 /* Free the completion queue EQ event pool */
5892 lpfc_sli4_cq_event_release_all(phba);
5893 lpfc_sli4_cq_event_pool_destroy(phba);
5894
James Smart6d368e52011-05-24 11:44:12 -04005895 /* Release resource identifiers. */
5896 lpfc_sli4_dealloc_resource_identifiers(phba);
5897
James Smartda0436e2009-05-22 14:51:39 -04005898 /* Free the bsmbx region. */
5899 lpfc_destroy_bootstrap_mbox(phba);
5900
5901 /* Free the SLI Layer memory with SLI4 HBAs */
5902 lpfc_mem_free_all(phba);
5903
5904 /* Free the current connect table */
5905 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04005906 &phba->fcf_conn_rec_list, list) {
5907 list_del_init(&conn_entry->list);
James Smartda0436e2009-05-22 14:51:39 -04005908 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04005909 }
James Smartda0436e2009-05-22 14:51:39 -04005910
5911 return;
5912}
5913
5914/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005915 * lpfc_init_api_table_setup - Set up init api function jump table
James Smart3772a992009-05-22 14:50:54 -04005916 * @phba: The hba struct for which this call is being executed.
5917 * @dev_grp: The HBA PCI-Device group number.
5918 *
5919 * This routine sets up the device INIT interface API function jump table
5920 * in @phba struct.
5921 *
5922 * Returns: 0 - success, -ENODEV - failure.
5923 **/
5924int
5925lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
5926{
James Smart84d1b002010-02-12 14:42:33 -05005927 phba->lpfc_hba_init_link = lpfc_hba_init_link;
5928 phba->lpfc_hba_down_link = lpfc_hba_down_link;
James Smart7f860592011-03-11 16:05:52 -05005929 phba->lpfc_selective_reset = lpfc_selective_reset;
James Smart3772a992009-05-22 14:50:54 -04005930 switch (dev_grp) {
5931 case LPFC_PCI_DEV_LP:
5932 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
5933 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
5934 phba->lpfc_stop_port = lpfc_stop_port_s3;
5935 break;
James Smartda0436e2009-05-22 14:51:39 -04005936 case LPFC_PCI_DEV_OC:
5937 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
5938 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
5939 phba->lpfc_stop_port = lpfc_stop_port_s4;
5940 break;
James Smart3772a992009-05-22 14:50:54 -04005941 default:
5942 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5943 "1431 Invalid HBA PCI-device group: 0x%x\n",
5944 dev_grp);
5945 return -ENODEV;
5946 break;
5947 }
5948 return 0;
5949}
5950
5951/**
James Smart3772a992009-05-22 14:50:54 -04005952 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
5953 * @phba: pointer to lpfc hba data structure.
5954 *
5955 * This routine is invoked to set up the driver internal resources after the
5956 * device specific resource setup to support the HBA device it attached to.
5957 *
5958 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005959 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04005960 * other values - error
5961 **/
5962static int
5963lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
5964{
5965 int error;
5966
5967 /* Startup the kernel thread for this host adapter. */
5968 phba->worker_thread = kthread_run(lpfc_do_work, phba,
5969 "lpfc_worker_%d", phba->brd_no);
5970 if (IS_ERR(phba->worker_thread)) {
5971 error = PTR_ERR(phba->worker_thread);
5972 return error;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05005973 }
5974
James Smart3772a992009-05-22 14:50:54 -04005975 return 0;
5976}
5977
5978/**
5979 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
5980 * @phba: pointer to lpfc hba data structure.
5981 *
5982 * This routine is invoked to unset the driver internal resources set up after
5983 * the device specific resource setup for supporting the HBA device it
5984 * attached to.
5985 **/
5986static void
5987lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
5988{
5989 /* Stop kernel worker thread */
5990 kthread_stop(phba->worker_thread);
5991}
5992
5993/**
5994 * lpfc_free_iocb_list - Free iocb list.
5995 * @phba: pointer to lpfc hba data structure.
5996 *
5997 * This routine is invoked to free the driver's IOCB list and memory.
5998 **/
5999static void
6000lpfc_free_iocb_list(struct lpfc_hba *phba)
6001{
6002 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
6003
6004 spin_lock_irq(&phba->hbalock);
6005 list_for_each_entry_safe(iocbq_entry, iocbq_next,
6006 &phba->lpfc_iocb_list, list) {
6007 list_del(&iocbq_entry->list);
6008 kfree(iocbq_entry);
6009 phba->total_iocbq_bufs--;
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006010 }
James Smart3772a992009-05-22 14:50:54 -04006011 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006012
James Smart3772a992009-05-22 14:50:54 -04006013 return;
6014}
dea31012005-04-17 16:05:31 -05006015
James Smart3772a992009-05-22 14:50:54 -04006016/**
6017 * lpfc_init_iocb_list - Allocate and initialize iocb list.
6018 * @phba: pointer to lpfc hba data structure.
6019 *
6020 * This routine is invoked to allocate and initizlize the driver's IOCB
6021 * list and set up the IOCB tag array accordingly.
6022 *
6023 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006024 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006025 * other values - error
6026 **/
6027static int
6028lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
6029{
6030 struct lpfc_iocbq *iocbq_entry = NULL;
6031 uint16_t iotag;
6032 int i;
dea31012005-04-17 16:05:31 -05006033
6034 /* Initialize and populate the iocb list per host. */
6035 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
James Smart3772a992009-05-22 14:50:54 -04006036 for (i = 0; i < iocb_count; i++) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07006037 iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
dea31012005-04-17 16:05:31 -05006038 if (iocbq_entry == NULL) {
6039 printk(KERN_ERR "%s: only allocated %d iocbs of "
6040 "expected %d count. Unloading driver.\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07006041 __func__, i, LPFC_IOCB_LIST_CNT);
dea31012005-04-17 16:05:31 -05006042 goto out_free_iocbq;
6043 }
6044
James Bottomley604a3e32005-10-29 10:28:33 -05006045 iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
6046 if (iotag == 0) {
James Smart3772a992009-05-22 14:50:54 -04006047 kfree(iocbq_entry);
James Bottomley604a3e32005-10-29 10:28:33 -05006048 printk(KERN_ERR "%s: failed to allocate IOTAG. "
James Smart3772a992009-05-22 14:50:54 -04006049 "Unloading driver.\n", __func__);
James Bottomley604a3e32005-10-29 10:28:33 -05006050 goto out_free_iocbq;
6051 }
James Smart6d368e52011-05-24 11:44:12 -04006052 iocbq_entry->sli4_lxritag = NO_XRI;
James Smart3772a992009-05-22 14:50:54 -04006053 iocbq_entry->sli4_xritag = NO_XRI;
James Smart2e0fef82007-06-17 19:56:36 -05006054
6055 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006056 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
6057 phba->total_iocbq_bufs++;
James Smart2e0fef82007-06-17 19:56:36 -05006058 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006059 }
6060
James Smart3772a992009-05-22 14:50:54 -04006061 return 0;
6062
6063out_free_iocbq:
6064 lpfc_free_iocb_list(phba);
6065
6066 return -ENOMEM;
6067}
6068
6069/**
James Smart8a9d2e82012-05-09 21:16:12 -04006070 * lpfc_free_sgl_list - Free a given sgl list.
James Smartda0436e2009-05-22 14:51:39 -04006071 * @phba: pointer to lpfc hba data structure.
James Smart8a9d2e82012-05-09 21:16:12 -04006072 * @sglq_list: pointer to the head of sgl list.
James Smartda0436e2009-05-22 14:51:39 -04006073 *
James Smart8a9d2e82012-05-09 21:16:12 -04006074 * This routine is invoked to free a give sgl list and memory.
James Smartda0436e2009-05-22 14:51:39 -04006075 **/
James Smart8a9d2e82012-05-09 21:16:12 -04006076void
6077lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list)
James Smartda0436e2009-05-22 14:51:39 -04006078{
6079 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
James Smart8a9d2e82012-05-09 21:16:12 -04006080
6081 list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) {
6082 list_del(&sglq_entry->list);
6083 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
6084 kfree(sglq_entry);
6085 }
6086}
6087
6088/**
6089 * lpfc_free_els_sgl_list - Free els sgl list.
6090 * @phba: pointer to lpfc hba data structure.
6091 *
6092 * This routine is invoked to free the driver's els sgl list and memory.
6093 **/
6094static void
6095lpfc_free_els_sgl_list(struct lpfc_hba *phba)
6096{
James Smartda0436e2009-05-22 14:51:39 -04006097 LIST_HEAD(sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04006098
James Smart8a9d2e82012-05-09 21:16:12 -04006099 /* Retrieve all els sgls from driver list */
James Smartda0436e2009-05-22 14:51:39 -04006100 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08006101 spin_lock(&phba->sli4_hba.sgl_list_lock);
6102 list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list);
6103 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smartda0436e2009-05-22 14:51:39 -04006104 spin_unlock_irq(&phba->hbalock);
6105
James Smart8a9d2e82012-05-09 21:16:12 -04006106 /* Now free the sgl list */
6107 lpfc_free_sgl_list(phba, &sglq_list);
James Smartda0436e2009-05-22 14:51:39 -04006108}
6109
6110/**
6111 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
6112 * @phba: pointer to lpfc hba data structure.
6113 *
6114 * This routine is invoked to allocate the driver's active sgl memory.
6115 * This array will hold the sglq_entry's for active IOs.
6116 **/
6117static int
6118lpfc_init_active_sgl_array(struct lpfc_hba *phba)
6119{
6120 int size;
6121 size = sizeof(struct lpfc_sglq *);
6122 size *= phba->sli4_hba.max_cfg_param.max_xri;
6123
6124 phba->sli4_hba.lpfc_sglq_active_list =
6125 kzalloc(size, GFP_KERNEL);
6126 if (!phba->sli4_hba.lpfc_sglq_active_list)
6127 return -ENOMEM;
6128 return 0;
6129}
6130
6131/**
6132 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
6133 * @phba: pointer to lpfc hba data structure.
6134 *
6135 * This routine is invoked to walk through the array of active sglq entries
6136 * and free all of the resources.
6137 * This is just a place holder for now.
6138 **/
6139static void
6140lpfc_free_active_sgl(struct lpfc_hba *phba)
6141{
6142 kfree(phba->sli4_hba.lpfc_sglq_active_list);
6143}
6144
6145/**
6146 * lpfc_init_sgl_list - Allocate and initialize sgl list.
6147 * @phba: pointer to lpfc hba data structure.
6148 *
6149 * This routine is invoked to allocate and initizlize the driver's sgl
6150 * list and set up the sgl xritag tag array accordingly.
6151 *
James Smartda0436e2009-05-22 14:51:39 -04006152 **/
James Smart8a9d2e82012-05-09 21:16:12 -04006153static void
James Smartda0436e2009-05-22 14:51:39 -04006154lpfc_init_sgl_list(struct lpfc_hba *phba)
6155{
James Smartda0436e2009-05-22 14:51:39 -04006156 /* Initialize and populate the sglq list per host/VF. */
James Smart895427b2017-02-12 13:52:30 -08006157 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list);
James Smartda0436e2009-05-22 14:51:39 -04006158 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
6159
James Smart8a9d2e82012-05-09 21:16:12 -04006160 /* els xri-sgl book keeping */
6161 phba->sli4_hba.els_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04006162
James Smart8a9d2e82012-05-09 21:16:12 -04006163 /* scsi xri-buffer book keeping */
James Smartda0436e2009-05-22 14:51:39 -04006164 phba->sli4_hba.scsi_xri_cnt = 0;
James Smart895427b2017-02-12 13:52:30 -08006165
6166 /* nvme xri-buffer book keeping */
6167 phba->sli4_hba.nvme_xri_cnt = 0;
James Smartda0436e2009-05-22 14:51:39 -04006168}
6169
6170/**
6171 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
6172 * @phba: pointer to lpfc hba data structure.
6173 *
6174 * This routine is invoked to post rpi header templates to the
James Smart88a2cfb2011-07-22 18:36:33 -04006175 * port for those SLI4 ports that do not support extents. This routine
James Smartda0436e2009-05-22 14:51:39 -04006176 * posts a PAGE_SIZE memory region to the port to hold up to
James Smart88a2cfb2011-07-22 18:36:33 -04006177 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
6178 * and should be called only when interrupts are disabled.
James Smartda0436e2009-05-22 14:51:39 -04006179 *
6180 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006181 * 0 - successful
James Smart88a2cfb2011-07-22 18:36:33 -04006182 * -ERROR - otherwise.
James Smartda0436e2009-05-22 14:51:39 -04006183 **/
6184int
6185lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
6186{
6187 int rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04006188 struct lpfc_rpi_hdr *rpi_hdr;
6189
6190 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
James Smartff78d8f2011-12-13 13:21:35 -05006191 if (!phba->sli4_hba.rpi_hdrs_in_use)
James Smart6d368e52011-05-24 11:44:12 -04006192 return rc;
James Smart6d368e52011-05-24 11:44:12 -04006193 if (phba->sli4_hba.extents_in_use)
6194 return -EIO;
James Smartda0436e2009-05-22 14:51:39 -04006195
6196 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
6197 if (!rpi_hdr) {
6198 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
6199 "0391 Error during rpi post operation\n");
6200 lpfc_sli4_remove_rpis(phba);
6201 rc = -ENODEV;
6202 }
6203
6204 return rc;
6205}
6206
6207/**
6208 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
6209 * @phba: pointer to lpfc hba data structure.
6210 *
6211 * This routine is invoked to allocate a single 4KB memory region to
6212 * support rpis and stores them in the phba. This single region
6213 * provides support for up to 64 rpis. The region is used globally
6214 * by the device.
6215 *
6216 * Returns:
6217 * A valid rpi hdr on success.
6218 * A NULL pointer on any failure.
6219 **/
6220struct lpfc_rpi_hdr *
6221lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
6222{
6223 uint16_t rpi_limit, curr_rpi_range;
6224 struct lpfc_dmabuf *dmabuf;
6225 struct lpfc_rpi_hdr *rpi_hdr;
James Smart9589b0622011-04-16 11:03:17 -04006226 uint32_t rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04006227
James Smart6d368e52011-05-24 11:44:12 -04006228 /*
6229 * If the SLI4 port supports extents, posting the rpi header isn't
6230 * required. Set the expected maximum count and let the actual value
6231 * get set when extents are fully allocated.
6232 */
6233 if (!phba->sli4_hba.rpi_hdrs_in_use)
6234 return NULL;
6235 if (phba->sli4_hba.extents_in_use)
6236 return NULL;
6237
6238 /* The limit on the logical index is just the max_rpi count. */
James Smartda0436e2009-05-22 14:51:39 -04006239 rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
James Smart6d368e52011-05-24 11:44:12 -04006240 phba->sli4_hba.max_cfg_param.max_rpi - 1;
James Smartda0436e2009-05-22 14:51:39 -04006241
6242 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006243 /*
6244 * Establish the starting RPI in this header block. The starting
6245 * rpi is normalized to a zero base because the physical rpi is
6246 * port based.
6247 */
James Smart97f2ecf2012-03-01 22:35:23 -05006248 curr_rpi_range = phba->sli4_hba.next_rpi;
James Smartda0436e2009-05-22 14:51:39 -04006249 spin_unlock_irq(&phba->hbalock);
6250
6251 /*
6252 * The port has a limited number of rpis. The increment here
6253 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
6254 * and to allow the full max_rpi range per port.
6255 */
6256 if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
James Smart9589b0622011-04-16 11:03:17 -04006257 rpi_count = rpi_limit - curr_rpi_range;
6258 else
6259 rpi_count = LPFC_RPI_HDR_COUNT;
James Smartda0436e2009-05-22 14:51:39 -04006260
James Smart6d368e52011-05-24 11:44:12 -04006261 if (!rpi_count)
6262 return NULL;
James Smartda0436e2009-05-22 14:51:39 -04006263 /*
6264 * First allocate the protocol header region for the port. The
6265 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
6266 */
6267 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
6268 if (!dmabuf)
6269 return NULL;
6270
Joe Perches1aee3832014-09-03 12:56:12 -04006271 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev,
6272 LPFC_HDR_TEMPLATE_SIZE,
6273 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04006274 if (!dmabuf->virt) {
6275 rpi_hdr = NULL;
6276 goto err_free_dmabuf;
6277 }
6278
James Smartda0436e2009-05-22 14:51:39 -04006279 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
6280 rpi_hdr = NULL;
6281 goto err_free_coherent;
6282 }
6283
6284 /* Save the rpi header data for cleanup later. */
6285 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
6286 if (!rpi_hdr)
6287 goto err_free_coherent;
6288
6289 rpi_hdr->dmabuf = dmabuf;
6290 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
6291 rpi_hdr->page_count = 1;
6292 spin_lock_irq(&phba->hbalock);
James Smart6d368e52011-05-24 11:44:12 -04006293
6294 /* The rpi_hdr stores the logical index only. */
6295 rpi_hdr->start_rpi = curr_rpi_range;
James Smartda0436e2009-05-22 14:51:39 -04006296 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
6297
6298 /*
James Smart6d368e52011-05-24 11:44:12 -04006299 * The next_rpi stores the next logical module-64 rpi value used
6300 * to post physical rpis in subsequent rpi postings.
James Smartda0436e2009-05-22 14:51:39 -04006301 */
James Smart9589b0622011-04-16 11:03:17 -04006302 phba->sli4_hba.next_rpi += rpi_count;
James Smartda0436e2009-05-22 14:51:39 -04006303 spin_unlock_irq(&phba->hbalock);
6304 return rpi_hdr;
6305
6306 err_free_coherent:
6307 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
6308 dmabuf->virt, dmabuf->phys);
6309 err_free_dmabuf:
6310 kfree(dmabuf);
6311 return NULL;
6312}
6313
6314/**
6315 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
6316 * @phba: pointer to lpfc hba data structure.
6317 *
6318 * This routine is invoked to remove all memory resources allocated
James Smart6d368e52011-05-24 11:44:12 -04006319 * to support rpis for SLI4 ports not supporting extents. This routine
6320 * presumes the caller has released all rpis consumed by fabric or port
6321 * logins and is prepared to have the header pages removed.
James Smartda0436e2009-05-22 14:51:39 -04006322 **/
6323void
6324lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
6325{
6326 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
6327
James Smart6d368e52011-05-24 11:44:12 -04006328 if (!phba->sli4_hba.rpi_hdrs_in_use)
6329 goto exit;
6330
James Smartda0436e2009-05-22 14:51:39 -04006331 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
6332 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
6333 list_del(&rpi_hdr->list);
6334 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
6335 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
6336 kfree(rpi_hdr->dmabuf);
6337 kfree(rpi_hdr);
6338 }
James Smart6d368e52011-05-24 11:44:12 -04006339 exit:
6340 /* There are no rpis available to the port now. */
6341 phba->sli4_hba.next_rpi = 0;
James Smartda0436e2009-05-22 14:51:39 -04006342}
6343
6344/**
James Smart3772a992009-05-22 14:50:54 -04006345 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
6346 * @pdev: pointer to pci device data structure.
6347 *
6348 * This routine is invoked to allocate the driver hba data structure for an
6349 * HBA device. If the allocation is successful, the phba reference to the
6350 * PCI device data structure is set.
6351 *
6352 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006353 * pointer to @phba - successful
James Smart3772a992009-05-22 14:50:54 -04006354 * NULL - error
6355 **/
6356static struct lpfc_hba *
6357lpfc_hba_alloc(struct pci_dev *pdev)
6358{
6359 struct lpfc_hba *phba;
6360
6361 /* Allocate memory for HBA structure */
6362 phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
6363 if (!phba) {
Jiri Slabye34ccdf2009-07-13 23:25:54 +02006364 dev_err(&pdev->dev, "failed to allocate hba struct\n");
James Smart3772a992009-05-22 14:50:54 -04006365 return NULL;
6366 }
6367
6368 /* Set reference to PCI device in HBA structure */
6369 phba->pcidev = pdev;
6370
6371 /* Assign an unused board number */
6372 phba->brd_no = lpfc_get_instance();
6373 if (phba->brd_no < 0) {
6374 kfree(phba);
6375 return NULL;
6376 }
James Smart65791f12016-07-06 12:35:56 -07006377 phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL;
James Smart3772a992009-05-22 14:50:54 -04006378
James Smart4fede782010-01-26 23:08:55 -05006379 spin_lock_init(&phba->ct_ev_lock);
James Smartf1c3b0f2009-07-19 10:01:32 -04006380 INIT_LIST_HEAD(&phba->ct_ev_waiters);
6381
James Smart3772a992009-05-22 14:50:54 -04006382 return phba;
6383}
6384
6385/**
6386 * lpfc_hba_free - Free driver hba data structure with a device.
6387 * @phba: pointer to lpfc hba data structure.
6388 *
6389 * This routine is invoked to free the driver hba data structure with an
6390 * HBA device.
6391 **/
6392static void
6393lpfc_hba_free(struct lpfc_hba *phba)
6394{
6395 /* Release the driver assigned board number */
6396 idr_remove(&lpfc_hba_index, phba->brd_no);
6397
James Smart895427b2017-02-12 13:52:30 -08006398 /* Free memory allocated with sli3 rings */
6399 kfree(phba->sli.sli3_ring);
6400 phba->sli.sli3_ring = NULL;
James Smart2a76a282012-08-03 12:35:54 -04006401
James Smart3772a992009-05-22 14:50:54 -04006402 kfree(phba);
6403 return;
6404}
6405
6406/**
6407 * lpfc_create_shost - Create hba physical port with associated scsi host.
6408 * @phba: pointer to lpfc hba data structure.
6409 *
6410 * This routine is invoked to create HBA physical port and associate a SCSI
6411 * host with it.
6412 *
6413 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006414 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006415 * other values - error
6416 **/
6417static int
6418lpfc_create_shost(struct lpfc_hba *phba)
6419{
6420 struct lpfc_vport *vport;
6421 struct Scsi_Host *shost;
6422
6423 /* Initialize HBA FC structure */
dea31012005-04-17 16:05:31 -05006424 phba->fc_edtov = FF_DEF_EDTOV;
6425 phba->fc_ratov = FF_DEF_RATOV;
6426 phba->fc_altov = FF_DEF_ALTOV;
6427 phba->fc_arbtov = FF_DEF_ARBTOV;
6428
James Smartd7c47992010-06-08 18:31:54 -04006429 atomic_set(&phba->sdev_cnt, 0);
James Smart3de2a652007-08-02 11:09:59 -04006430 vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
James Smart2e0fef82007-06-17 19:56:36 -05006431 if (!vport)
James Smart3772a992009-05-22 14:50:54 -04006432 return -ENODEV;
James Smart2e0fef82007-06-17 19:56:36 -05006433
6434 shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05006435 phba->pport = vport;
James Smart2ea259e2017-02-12 13:52:27 -08006436
James Smart858c9f62007-06-17 19:56:39 -05006437 lpfc_debugfs_initialize(vport);
James Smart3772a992009-05-22 14:50:54 -04006438 /* Put reference to SCSI host to driver's device private data */
6439 pci_set_drvdata(phba->pcidev, shost);
James Smart2e0fef82007-06-17 19:56:36 -05006440
James Smart4258e982015-12-16 18:11:58 -05006441 /*
6442 * At this point we are fully registered with PSA. In addition,
6443 * any initial discovery should be completed.
6444 */
6445 vport->load_flag |= FC_ALLOW_FDMI;
James Smart8663cbb2016-03-31 14:12:33 -07006446 if (phba->cfg_enable_SmartSAN ||
6447 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -05006448
6449 /* Setup appropriate attribute masks */
6450 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -07006451 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -05006452 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
6453 else
6454 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
6455 }
James Smart3772a992009-05-22 14:50:54 -04006456 return 0;
6457}
dea31012005-04-17 16:05:31 -05006458
James Smart3772a992009-05-22 14:50:54 -04006459/**
6460 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
6461 * @phba: pointer to lpfc hba data structure.
6462 *
6463 * This routine is invoked to destroy HBA physical port and the associated
6464 * SCSI host.
6465 **/
6466static void
6467lpfc_destroy_shost(struct lpfc_hba *phba)
6468{
6469 struct lpfc_vport *vport = phba->pport;
James Smart93996272008-08-24 21:50:30 -04006470
James Smart3772a992009-05-22 14:50:54 -04006471 /* Destroy physical port that associated with the SCSI host */
6472 destroy_port(vport);
6473
6474 return;
6475}
6476
6477/**
6478 * lpfc_setup_bg - Setup Block guard structures and debug areas.
6479 * @phba: pointer to lpfc hba data structure.
6480 * @shost: the shost to be used to detect Block guard settings.
6481 *
6482 * This routine sets up the local Block guard protocol settings for @shost.
6483 * This routine also allocates memory for debugging bg buffers.
6484 **/
6485static void
6486lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
6487{
James Smartbbeb79b2012-06-12 13:54:27 -04006488 uint32_t old_mask;
6489 uint32_t old_guard;
6490
James Smart3772a992009-05-22 14:50:54 -04006491 int pagecnt = 10;
James Smartb3b98b72016-10-13 15:06:06 -07006492 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
James Smart3772a992009-05-22 14:50:54 -04006493 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6494 "1478 Registering BlockGuard with the "
6495 "SCSI layer\n");
James Smartbbeb79b2012-06-12 13:54:27 -04006496
James Smartb3b98b72016-10-13 15:06:06 -07006497 old_mask = phba->cfg_prot_mask;
6498 old_guard = phba->cfg_prot_guard;
James Smartbbeb79b2012-06-12 13:54:27 -04006499
6500 /* Only allow supported values */
James Smartb3b98b72016-10-13 15:06:06 -07006501 phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION |
James Smartbbeb79b2012-06-12 13:54:27 -04006502 SHOST_DIX_TYPE0_PROTECTION |
6503 SHOST_DIX_TYPE1_PROTECTION);
James Smartb3b98b72016-10-13 15:06:06 -07006504 phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP |
6505 SHOST_DIX_GUARD_CRC);
James Smartbbeb79b2012-06-12 13:54:27 -04006506
6507 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
James Smartb3b98b72016-10-13 15:06:06 -07006508 if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION)
6509 phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION;
James Smartbbeb79b2012-06-12 13:54:27 -04006510
James Smartb3b98b72016-10-13 15:06:06 -07006511 if (phba->cfg_prot_mask && phba->cfg_prot_guard) {
6512 if ((old_mask != phba->cfg_prot_mask) ||
6513 (old_guard != phba->cfg_prot_guard))
James Smartbbeb79b2012-06-12 13:54:27 -04006514 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6515 "1475 Registering BlockGuard with the "
6516 "SCSI layer: mask %d guard %d\n",
James Smartb3b98b72016-10-13 15:06:06 -07006517 phba->cfg_prot_mask,
6518 phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04006519
James Smartb3b98b72016-10-13 15:06:06 -07006520 scsi_host_set_prot(shost, phba->cfg_prot_mask);
6521 scsi_host_set_guard(shost, phba->cfg_prot_guard);
James Smartbbeb79b2012-06-12 13:54:27 -04006522 } else
6523 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6524 "1479 Not Registering BlockGuard with the SCSI "
6525 "layer, Bad protection parameters: %d %d\n",
6526 old_mask, old_guard);
James Smart98c9ea52007-10-27 13:37:33 -04006527 }
James Smartbbeb79b2012-06-12 13:54:27 -04006528
James Smart81301a92008-12-04 22:39:46 -05006529 if (!_dump_buf_data) {
James Smart81301a92008-12-04 22:39:46 -05006530 while (pagecnt) {
6531 spin_lock_init(&_dump_buf_lock);
6532 _dump_buf_data =
6533 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6534 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -04006535 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6536 "9043 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04006537 "_dump_buf_data at 0x%p\n",
6538 (1 << pagecnt), _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05006539 _dump_buf_data_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04006540 memset(_dump_buf_data, 0,
6541 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05006542 break;
James Smart3772a992009-05-22 14:50:54 -04006543 } else
James Smart81301a92008-12-04 22:39:46 -05006544 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05006545 }
James Smart81301a92008-12-04 22:39:46 -05006546 if (!_dump_buf_data_order)
James Smart6a9c52c2009-10-02 15:16:51 -04006547 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6548 "9044 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04006549 "memory for hexdump\n");
6550 } else
James Smart6a9c52c2009-10-02 15:16:51 -04006551 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6552 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
James Smart81301a92008-12-04 22:39:46 -05006553 "\n", _dump_buf_data);
James Smart81301a92008-12-04 22:39:46 -05006554 if (!_dump_buf_dif) {
James Smart81301a92008-12-04 22:39:46 -05006555 while (pagecnt) {
6556 _dump_buf_dif =
6557 (char *) __get_free_pages(GFP_KERNEL, pagecnt);
6558 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -04006559 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6560 "9046 BLKGRD: allocated %d pages for "
James Smart3772a992009-05-22 14:50:54 -04006561 "_dump_buf_dif at 0x%p\n",
6562 (1 << pagecnt), _dump_buf_dif);
James Smart81301a92008-12-04 22:39:46 -05006563 _dump_buf_dif_order = pagecnt;
James Smart3772a992009-05-22 14:50:54 -04006564 memset(_dump_buf_dif, 0,
6565 ((1 << PAGE_SHIFT) << pagecnt));
James Smart81301a92008-12-04 22:39:46 -05006566 break;
James Smart3772a992009-05-22 14:50:54 -04006567 } else
James Smart81301a92008-12-04 22:39:46 -05006568 --pagecnt;
James Smart81301a92008-12-04 22:39:46 -05006569 }
James Smart81301a92008-12-04 22:39:46 -05006570 if (!_dump_buf_dif_order)
James Smart6a9c52c2009-10-02 15:16:51 -04006571 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6572 "9047 BLKGRD: ERROR unable to allocate "
James Smart3772a992009-05-22 14:50:54 -04006573 "memory for hexdump\n");
6574 } else
James Smart6a9c52c2009-10-02 15:16:51 -04006575 lpfc_printf_log(phba, KERN_ERR, LOG_BG,
6576 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
James Smart3772a992009-05-22 14:50:54 -04006577 _dump_buf_dif);
6578}
6579
6580/**
6581 * lpfc_post_init_setup - Perform necessary device post initialization setup.
6582 * @phba: pointer to lpfc hba data structure.
6583 *
6584 * This routine is invoked to perform all the necessary post initialization
6585 * setup for the device.
6586 **/
6587static void
6588lpfc_post_init_setup(struct lpfc_hba *phba)
6589{
6590 struct Scsi_Host *shost;
6591 struct lpfc_adapter_event_header adapter_event;
6592
6593 /* Get the default values for Model Name and Description */
6594 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
6595
6596 /*
6597 * hba setup may have changed the hba_queue_depth so we need to
6598 * adjust the value of can_queue.
6599 */
6600 shost = pci_get_drvdata(phba->pcidev);
6601 shost->can_queue = phba->cfg_hba_queue_depth - 10;
6602 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
6603 lpfc_setup_bg(phba, shost);
James Smart858c9f62007-06-17 19:56:39 -05006604
6605 lpfc_host_attrib_init(shost);
6606
James Smart2e0fef82007-06-17 19:56:36 -05006607 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
6608 spin_lock_irq(shost->host_lock);
6609 lpfc_poll_start_timer(phba);
6610 spin_unlock_irq(shost->host_lock);
6611 }
James Smart8f6d98d2006-08-01 07:34:00 -04006612
James Smart93996272008-08-24 21:50:30 -04006613 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6614 "0428 Perform SCSI scan\n");
James Smartea2151b2008-09-07 11:52:10 -04006615 /* Send board arrival event to upper layer */
6616 adapter_event.event_type = FC_REG_ADAPTER_EVENT;
6617 adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
6618 fc_host_post_vendor_event(shost, fc_get_event_number(),
James Smart3772a992009-05-22 14:50:54 -04006619 sizeof(adapter_event),
6620 (char *) &adapter_event,
6621 LPFC_NL_VENDOR_ID);
6622 return;
6623}
6624
6625/**
6626 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
6627 * @phba: pointer to lpfc hba data structure.
6628 *
6629 * This routine is invoked to set up the PCI device memory space for device
6630 * with SLI-3 interface spec.
6631 *
6632 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006633 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04006634 * other values - error
6635 **/
6636static int
6637lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
6638{
6639 struct pci_dev *pdev;
6640 unsigned long bar0map_len, bar2map_len;
6641 int i, hbq_count;
6642 void *ptr;
6643 int error = -ENODEV;
6644
6645 /* Obtain PCI device reference */
6646 if (!phba->pcidev)
6647 return error;
6648 else
6649 pdev = phba->pcidev;
6650
6651 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05006652 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
6653 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
6654 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
6655 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smart3772a992009-05-22 14:50:54 -04006656 return error;
Michael Reed8e685972009-09-18 12:02:05 -05006657 }
6658 }
James Smart3772a992009-05-22 14:50:54 -04006659
6660 /* Get the bus address of Bar0 and Bar2 and the number of bytes
6661 * required by each mapping.
6662 */
6663 phba->pci_bar0_map = pci_resource_start(pdev, 0);
6664 bar0map_len = pci_resource_len(pdev, 0);
6665
6666 phba->pci_bar2_map = pci_resource_start(pdev, 2);
6667 bar2map_len = pci_resource_len(pdev, 2);
6668
6669 /* Map HBA SLIM to a kernel virtual address. */
6670 phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
6671 if (!phba->slim_memmap_p) {
6672 dev_printk(KERN_ERR, &pdev->dev,
6673 "ioremap failed for SLIM memory.\n");
6674 goto out;
6675 }
6676
6677 /* Map HBA Control Registers to a kernel virtual address. */
6678 phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
6679 if (!phba->ctrl_regs_memmap_p) {
6680 dev_printk(KERN_ERR, &pdev->dev,
6681 "ioremap failed for HBA control registers.\n");
6682 goto out_iounmap_slim;
6683 }
6684
6685 /* Allocate memory for SLI-2 structures */
Joe Perches1aee3832014-09-03 12:56:12 -04006686 phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6687 &phba->slim2p.phys, GFP_KERNEL);
James Smart3772a992009-05-22 14:50:54 -04006688 if (!phba->slim2p.virt)
6689 goto out_iounmap;
6690
James Smart3772a992009-05-22 14:50:54 -04006691 phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
James Smart7a470272010-03-15 11:25:20 -04006692 phba->mbox_ext = (phba->slim2p.virt +
6693 offsetof(struct lpfc_sli2_slim, mbx_ext_words));
James Smart3772a992009-05-22 14:50:54 -04006694 phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
6695 phba->IOCBs = (phba->slim2p.virt +
6696 offsetof(struct lpfc_sli2_slim, IOCBs));
6697
6698 phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
6699 lpfc_sli_hbq_size(),
6700 &phba->hbqslimp.phys,
6701 GFP_KERNEL);
6702 if (!phba->hbqslimp.virt)
6703 goto out_free_slim;
6704
6705 hbq_count = lpfc_sli_hbq_count();
6706 ptr = phba->hbqslimp.virt;
6707 for (i = 0; i < hbq_count; ++i) {
6708 phba->hbqs[i].hbq_virt = ptr;
6709 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
6710 ptr += (lpfc_hbq_defs[i]->entry_count *
6711 sizeof(struct lpfc_hbq_entry));
6712 }
6713 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
6714 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
6715
6716 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
6717
James Smart3772a992009-05-22 14:50:54 -04006718 phba->MBslimaddr = phba->slim_memmap_p;
6719 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
6720 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
6721 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
6722 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
James Smartea2151b2008-09-07 11:52:10 -04006723
dea31012005-04-17 16:05:31 -05006724 return 0;
6725
dea31012005-04-17 16:05:31 -05006726out_free_slim:
James Smart34b02dc2008-08-24 21:49:55 -04006727 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6728 phba->slim2p.virt, phba->slim2p.phys);
dea31012005-04-17 16:05:31 -05006729out_iounmap:
6730 iounmap(phba->ctrl_regs_memmap_p);
Jamie Wellnitz901a9202006-02-28 19:25:19 -05006731out_iounmap_slim:
dea31012005-04-17 16:05:31 -05006732 iounmap(phba->slim_memmap_p);
dea31012005-04-17 16:05:31 -05006733out:
6734 return error;
6735}
6736
James Smarte59058c2008-08-24 21:49:00 -04006737/**
James Smart3772a992009-05-22 14:50:54 -04006738 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
6739 * @phba: pointer to lpfc hba data structure.
6740 *
6741 * This routine is invoked to unset the PCI device memory space for device
6742 * with SLI-3 interface spec.
6743 **/
6744static void
6745lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
6746{
6747 struct pci_dev *pdev;
6748
6749 /* Obtain PCI device reference */
6750 if (!phba->pcidev)
6751 return;
6752 else
6753 pdev = phba->pcidev;
6754
6755 /* Free coherent DMA memory allocated */
6756 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
6757 phba->hbqslimp.virt, phba->hbqslimp.phys);
6758 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
6759 phba->slim2p.virt, phba->slim2p.phys);
6760
6761 /* I/O memory unmap */
6762 iounmap(phba->ctrl_regs_memmap_p);
6763 iounmap(phba->slim_memmap_p);
6764
6765 return;
6766}
6767
6768/**
James Smartda0436e2009-05-22 14:51:39 -04006769 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
6770 * @phba: pointer to lpfc hba data structure.
6771 *
6772 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
6773 * done and check status.
6774 *
6775 * Return 0 if successful, otherwise -ENODEV.
6776 **/
6777int
6778lpfc_sli4_post_status_check(struct lpfc_hba *phba)
6779{
James Smart2fcee4b2010-12-15 17:57:46 -05006780 struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg;
6781 struct lpfc_register reg_data;
6782 int i, port_error = 0;
6783 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04006784
James Smart9940b972011-03-11 16:06:12 -05006785 memset(&portsmphr_reg, 0, sizeof(portsmphr_reg));
6786 memset(&reg_data, 0, sizeof(reg_data));
James Smart2fcee4b2010-12-15 17:57:46 -05006787 if (!phba->sli4_hba.PSMPHRregaddr)
James Smartda0436e2009-05-22 14:51:39 -04006788 return -ENODEV;
6789
James Smartda0436e2009-05-22 14:51:39 -04006790 /* Wait up to 30 seconds for the SLI Port POST done and ready */
6791 for (i = 0; i < 3000; i++) {
James Smart9940b972011-03-11 16:06:12 -05006792 if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
6793 &portsmphr_reg.word0) ||
6794 (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006795 /* Port has a fatal POST error, break out */
James Smartda0436e2009-05-22 14:51:39 -04006796 port_error = -ENODEV;
6797 break;
6798 }
James Smart2fcee4b2010-12-15 17:57:46 -05006799 if (LPFC_POST_STAGE_PORT_READY ==
6800 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg))
James Smartda0436e2009-05-22 14:51:39 -04006801 break;
James Smartda0436e2009-05-22 14:51:39 -04006802 msleep(10);
6803 }
6804
James Smart2fcee4b2010-12-15 17:57:46 -05006805 /*
6806 * If there was a port error during POST, then don't proceed with
6807 * other register reads as the data may not be valid. Just exit.
6808 */
6809 if (port_error) {
James Smartda0436e2009-05-22 14:51:39 -04006810 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006811 "1408 Port Failed POST - portsmphr=0x%x, "
6812 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
6813 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
6814 portsmphr_reg.word0,
6815 bf_get(lpfc_port_smphr_perr, &portsmphr_reg),
6816 bf_get(lpfc_port_smphr_sfi, &portsmphr_reg),
6817 bf_get(lpfc_port_smphr_nip, &portsmphr_reg),
6818 bf_get(lpfc_port_smphr_ipc, &portsmphr_reg),
6819 bf_get(lpfc_port_smphr_scr1, &portsmphr_reg),
6820 bf_get(lpfc_port_smphr_scr2, &portsmphr_reg),
6821 bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg),
6822 bf_get(lpfc_port_smphr_port_status, &portsmphr_reg));
6823 } else {
James Smart28baac72010-02-12 14:42:03 -05006824 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart2fcee4b2010-12-15 17:57:46 -05006825 "2534 Device Info: SLIFamily=0x%x, "
6826 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
6827 "SLIHint_2=0x%x, FT=0x%x\n",
James Smart28baac72010-02-12 14:42:03 -05006828 bf_get(lpfc_sli_intf_sli_family,
6829 &phba->sli4_hba.sli_intf),
6830 bf_get(lpfc_sli_intf_slirev,
6831 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006832 bf_get(lpfc_sli_intf_if_type,
James Smart28baac72010-02-12 14:42:03 -05006833 &phba->sli4_hba.sli_intf),
James Smart085c6472010-11-20 23:11:37 -05006834 bf_get(lpfc_sli_intf_sli_hint1,
6835 &phba->sli4_hba.sli_intf),
6836 bf_get(lpfc_sli_intf_sli_hint2,
6837 &phba->sli4_hba.sli_intf),
6838 bf_get(lpfc_sli_intf_func_type,
James Smart28baac72010-02-12 14:42:03 -05006839 &phba->sli4_hba.sli_intf));
James Smart2fcee4b2010-12-15 17:57:46 -05006840 /*
6841 * Check for other Port errors during the initialization
6842 * process. Fail the load if the port did not come up
6843 * correctly.
6844 */
6845 if_type = bf_get(lpfc_sli_intf_if_type,
6846 &phba->sli4_hba.sli_intf);
6847 switch (if_type) {
6848 case LPFC_SLI_INTF_IF_TYPE_0:
6849 phba->sli4_hba.ue_mask_lo =
6850 readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr);
6851 phba->sli4_hba.ue_mask_hi =
6852 readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr);
6853 uerrlo_reg.word0 =
6854 readl(phba->sli4_hba.u.if_type0.UERRLOregaddr);
6855 uerrhi_reg.word0 =
6856 readl(phba->sli4_hba.u.if_type0.UERRHIregaddr);
6857 if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
6858 (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
6859 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6860 "1422 Unrecoverable Error "
6861 "Detected during POST "
6862 "uerr_lo_reg=0x%x, "
6863 "uerr_hi_reg=0x%x, "
6864 "ue_mask_lo_reg=0x%x, "
6865 "ue_mask_hi_reg=0x%x\n",
6866 uerrlo_reg.word0,
6867 uerrhi_reg.word0,
6868 phba->sli4_hba.ue_mask_lo,
6869 phba->sli4_hba.ue_mask_hi);
6870 port_error = -ENODEV;
6871 }
6872 break;
6873 case LPFC_SLI_INTF_IF_TYPE_2:
6874 /* Final checks. The port status should be clean. */
James Smart9940b972011-03-11 16:06:12 -05006875 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
6876 &reg_data.word0) ||
James Smart05580562011-05-24 11:40:48 -04006877 (bf_get(lpfc_sliport_status_err, &reg_data) &&
6878 !bf_get(lpfc_sliport_status_rn, &reg_data))) {
James Smart2fcee4b2010-12-15 17:57:46 -05006879 phba->work_status[0] =
6880 readl(phba->sli4_hba.u.if_type2.
6881 ERR1regaddr);
6882 phba->work_status[1] =
6883 readl(phba->sli4_hba.u.if_type2.
6884 ERR2regaddr);
6885 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart8fcb8ac2012-03-01 22:35:58 -05006886 "2888 Unrecoverable port error "
6887 "following POST: port status reg "
6888 "0x%x, port_smphr reg 0x%x, "
James Smart2fcee4b2010-12-15 17:57:46 -05006889 "error 1=0x%x, error 2=0x%x\n",
6890 reg_data.word0,
6891 portsmphr_reg.word0,
6892 phba->work_status[0],
6893 phba->work_status[1]);
6894 port_error = -ENODEV;
6895 }
6896 break;
6897 case LPFC_SLI_INTF_IF_TYPE_1:
6898 default:
6899 break;
6900 }
James Smart28baac72010-02-12 14:42:03 -05006901 }
James Smartda0436e2009-05-22 14:51:39 -04006902 return port_error;
6903}
6904
6905/**
6906 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
6907 * @phba: pointer to lpfc hba data structure.
James Smart2fcee4b2010-12-15 17:57:46 -05006908 * @if_type: The SLI4 interface type getting configured.
James Smartda0436e2009-05-22 14:51:39 -04006909 *
6910 * This routine is invoked to set up SLI4 BAR0 PCI config space register
6911 * memory map.
6912 **/
6913static void
James Smart2fcee4b2010-12-15 17:57:46 -05006914lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type)
James Smartda0436e2009-05-22 14:51:39 -04006915{
James Smart2fcee4b2010-12-15 17:57:46 -05006916 switch (if_type) {
6917 case LPFC_SLI_INTF_IF_TYPE_0:
6918 phba->sli4_hba.u.if_type0.UERRLOregaddr =
6919 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO;
6920 phba->sli4_hba.u.if_type0.UERRHIregaddr =
6921 phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI;
6922 phba->sli4_hba.u.if_type0.UEMASKLOregaddr =
6923 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO;
6924 phba->sli4_hba.u.if_type0.UEMASKHIregaddr =
6925 phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI;
6926 phba->sli4_hba.SLIINTFregaddr =
6927 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6928 break;
6929 case LPFC_SLI_INTF_IF_TYPE_2:
6930 phba->sli4_hba.u.if_type2.ERR1regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006931 phba->sli4_hba.conf_regs_memmap_p +
6932 LPFC_CTL_PORT_ER1_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006933 phba->sli4_hba.u.if_type2.ERR2regaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006934 phba->sli4_hba.conf_regs_memmap_p +
6935 LPFC_CTL_PORT_ER2_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006936 phba->sli4_hba.u.if_type2.CTRLregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006937 phba->sli4_hba.conf_regs_memmap_p +
6938 LPFC_CTL_PORT_CTL_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006939 phba->sli4_hba.u.if_type2.STATUSregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006940 phba->sli4_hba.conf_regs_memmap_p +
6941 LPFC_CTL_PORT_STA_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006942 phba->sli4_hba.SLIINTFregaddr =
6943 phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF;
6944 phba->sli4_hba.PSMPHRregaddr =
James Smart88a2cfb2011-07-22 18:36:33 -04006945 phba->sli4_hba.conf_regs_memmap_p +
6946 LPFC_CTL_PORT_SEM_OFFSET;
James Smart2fcee4b2010-12-15 17:57:46 -05006947 phba->sli4_hba.RQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006948 phba->sli4_hba.conf_regs_memmap_p +
6949 LPFC_ULP0_RQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006950 phba->sli4_hba.WQDBregaddr =
James Smart962bc512013-01-03 15:44:00 -05006951 phba->sli4_hba.conf_regs_memmap_p +
6952 LPFC_ULP0_WQ_DOORBELL;
James Smart2fcee4b2010-12-15 17:57:46 -05006953 phba->sli4_hba.EQCQDBregaddr =
6954 phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL;
6955 phba->sli4_hba.MQDBregaddr =
6956 phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL;
6957 phba->sli4_hba.BMBXregaddr =
6958 phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX;
6959 break;
6960 case LPFC_SLI_INTF_IF_TYPE_1:
6961 default:
6962 dev_printk(KERN_ERR, &phba->pcidev->dev,
6963 "FATAL - unsupported SLI4 interface type - %d\n",
6964 if_type);
6965 break;
6966 }
James Smartda0436e2009-05-22 14:51:39 -04006967}
6968
6969/**
6970 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
6971 * @phba: pointer to lpfc hba data structure.
6972 *
6973 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
6974 * memory map.
6975 **/
6976static void
6977lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
6978{
James Smart2fcee4b2010-12-15 17:57:46 -05006979 phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
6980 LPFC_SLIPORT_IF0_SMPHR;
James Smartda0436e2009-05-22 14:51:39 -04006981 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006982 LPFC_HST_ISR0;
James Smartda0436e2009-05-22 14:51:39 -04006983 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006984 LPFC_HST_IMR0;
James Smartda0436e2009-05-22 14:51:39 -04006985 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
James Smart2fcee4b2010-12-15 17:57:46 -05006986 LPFC_HST_ISCR0;
James Smartda0436e2009-05-22 14:51:39 -04006987}
6988
6989/**
6990 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
6991 * @phba: pointer to lpfc hba data structure.
6992 * @vf: virtual function number
6993 *
6994 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
6995 * based on the given viftual function number, @vf.
6996 *
6997 * Return 0 if successful, otherwise -ENODEV.
6998 **/
6999static int
7000lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
7001{
7002 if (vf > LPFC_VIR_FUNC_MAX)
7003 return -ENODEV;
7004
7005 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05007006 vf * LPFC_VFR_PAGE_SIZE +
7007 LPFC_ULP0_RQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04007008 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
James Smart962bc512013-01-03 15:44:00 -05007009 vf * LPFC_VFR_PAGE_SIZE +
7010 LPFC_ULP0_WQ_DOORBELL);
James Smartda0436e2009-05-22 14:51:39 -04007011 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7012 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
7013 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7014 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
7015 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
7016 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
7017 return 0;
7018}
7019
7020/**
7021 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
7022 * @phba: pointer to lpfc hba data structure.
7023 *
7024 * This routine is invoked to create the bootstrap mailbox
7025 * region consistent with the SLI-4 interface spec. This
7026 * routine allocates all memory necessary to communicate
7027 * mailbox commands to the port and sets up all alignment
7028 * needs. No locks are expected to be held when calling
7029 * this routine.
7030 *
7031 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007032 * 0 - successful
James Smartd439d282010-09-29 11:18:45 -04007033 * -ENOMEM - could not allocated memory.
James Smartda0436e2009-05-22 14:51:39 -04007034 **/
7035static int
7036lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
7037{
7038 uint32_t bmbx_size;
7039 struct lpfc_dmabuf *dmabuf;
7040 struct dma_address *dma_address;
7041 uint32_t pa_addr;
7042 uint64_t phys_addr;
7043
7044 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
7045 if (!dmabuf)
7046 return -ENOMEM;
7047
7048 /*
7049 * The bootstrap mailbox region is comprised of 2 parts
7050 * plus an alignment restriction of 16 bytes.
7051 */
7052 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
Joe Perches1aee3832014-09-03 12:56:12 -04007053 dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size,
7054 &dmabuf->phys, GFP_KERNEL);
James Smartda0436e2009-05-22 14:51:39 -04007055 if (!dmabuf->virt) {
7056 kfree(dmabuf);
7057 return -ENOMEM;
7058 }
James Smartda0436e2009-05-22 14:51:39 -04007059
7060 /*
7061 * Initialize the bootstrap mailbox pointers now so that the register
7062 * operations are simple later. The mailbox dma address is required
7063 * to be 16-byte aligned. Also align the virtual memory as each
7064 * maibox is copied into the bmbx mailbox region before issuing the
7065 * command to the port.
7066 */
7067 phba->sli4_hba.bmbx.dmabuf = dmabuf;
7068 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
7069
7070 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
7071 LPFC_ALIGN_16_BYTE);
7072 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
7073 LPFC_ALIGN_16_BYTE);
7074
7075 /*
7076 * Set the high and low physical addresses now. The SLI4 alignment
7077 * requirement is 16 bytes and the mailbox is posted to the port
7078 * as two 30-bit addresses. The other data is a bit marking whether
7079 * the 30-bit address is the high or low address.
7080 * Upcast bmbx aphys to 64bits so shift instruction compiles
7081 * clean on 32 bit machines.
7082 */
7083 dma_address = &phba->sli4_hba.bmbx.dma_address;
7084 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
7085 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
7086 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
7087 LPFC_BMBX_BIT1_ADDR_HI);
7088
7089 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
7090 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
7091 LPFC_BMBX_BIT1_ADDR_LO);
7092 return 0;
7093}
7094
7095/**
7096 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
7097 * @phba: pointer to lpfc hba data structure.
7098 *
7099 * This routine is invoked to teardown the bootstrap mailbox
7100 * region and release all host resources. This routine requires
7101 * the caller to ensure all mailbox commands recovered, no
7102 * additional mailbox comands are sent, and interrupts are disabled
7103 * before calling this routine.
7104 *
7105 **/
7106static void
7107lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
7108{
7109 dma_free_coherent(&phba->pcidev->dev,
7110 phba->sli4_hba.bmbx.bmbx_size,
7111 phba->sli4_hba.bmbx.dmabuf->virt,
7112 phba->sli4_hba.bmbx.dmabuf->phys);
7113
7114 kfree(phba->sli4_hba.bmbx.dmabuf);
7115 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
7116}
7117
7118/**
7119 * lpfc_sli4_read_config - Get the config parameters.
7120 * @phba: pointer to lpfc hba data structure.
7121 *
7122 * This routine is invoked to read the configuration parameters from the HBA.
7123 * The configuration parameters are used to set the base and maximum values
7124 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
7125 * allocation for the port.
7126 *
7127 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007128 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007129 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007130 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007131 **/
James Smartff78d8f2011-12-13 13:21:35 -05007132int
James Smartda0436e2009-05-22 14:51:39 -04007133lpfc_sli4_read_config(struct lpfc_hba *phba)
7134{
7135 LPFC_MBOXQ_t *pmb;
7136 struct lpfc_mbx_read_config *rd_config;
James Smart912e3ac2011-05-24 11:42:11 -04007137 union lpfc_sli4_cfg_shdr *shdr;
7138 uint32_t shdr_status, shdr_add_status;
7139 struct lpfc_mbx_get_func_cfg *get_func_cfg;
7140 struct lpfc_rsrc_desc_fcfcoe *desc;
James Smart8aa134a2012-08-14 14:25:29 -04007141 char *pdesc_0;
James Smartc6918162016-10-13 15:06:16 -07007142 uint16_t forced_link_speed;
7143 uint32_t if_type;
James Smart8aa134a2012-08-14 14:25:29 -04007144 int length, i, rc = 0, rc2;
James Smartda0436e2009-05-22 14:51:39 -04007145
7146 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7147 if (!pmb) {
7148 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7149 "2011 Unable to allocate memory for issuing "
7150 "SLI_CONFIG_SPECIAL mailbox command\n");
7151 return -ENOMEM;
7152 }
7153
7154 lpfc_read_config(phba, pmb);
7155
7156 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
7157 if (rc != MBX_SUCCESS) {
7158 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7159 "2012 Mailbox failed , mbxCmd x%x "
7160 "READ_CONFIG, mbxStatus x%x\n",
7161 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7162 bf_get(lpfc_mqe_status, &pmb->u.mqe));
7163 rc = -EIO;
7164 } else {
7165 rd_config = &pmb->u.mqe.un.rd_config;
James Smartff78d8f2011-12-13 13:21:35 -05007166 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) {
7167 phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
7168 phba->sli4_hba.lnk_info.lnk_tp =
7169 bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config);
7170 phba->sli4_hba.lnk_info.lnk_no =
7171 bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config);
7172 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7173 "3081 lnk_type:%d, lnk_numb:%d\n",
7174 phba->sli4_hba.lnk_info.lnk_tp,
7175 phba->sli4_hba.lnk_info.lnk_no);
7176 } else
7177 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
7178 "3082 Mailbox (x%x) returned ldv:x0\n",
7179 bf_get(lpfc_mqe_command, &pmb->u.mqe));
James Smart6d368e52011-05-24 11:44:12 -04007180 phba->sli4_hba.extents_in_use =
7181 bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04007182 phba->sli4_hba.max_cfg_param.max_xri =
7183 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
7184 phba->sli4_hba.max_cfg_param.xri_base =
7185 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
7186 phba->sli4_hba.max_cfg_param.max_vpi =
7187 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
7188 phba->sli4_hba.max_cfg_param.vpi_base =
7189 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
7190 phba->sli4_hba.max_cfg_param.max_rpi =
7191 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
7192 phba->sli4_hba.max_cfg_param.rpi_base =
7193 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
7194 phba->sli4_hba.max_cfg_param.max_vfi =
7195 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
7196 phba->sli4_hba.max_cfg_param.vfi_base =
7197 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
7198 phba->sli4_hba.max_cfg_param.max_fcfi =
7199 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
James Smartda0436e2009-05-22 14:51:39 -04007200 phba->sli4_hba.max_cfg_param.max_eq =
7201 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
7202 phba->sli4_hba.max_cfg_param.max_rq =
7203 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
7204 phba->sli4_hba.max_cfg_param.max_wq =
7205 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
7206 phba->sli4_hba.max_cfg_param.max_cq =
7207 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
7208 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
7209 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
7210 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
7211 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
James Smart5ffc2662009-11-18 15:39:44 -05007212 phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
7213 (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
James Smartda0436e2009-05-22 14:51:39 -04007214 phba->max_vports = phba->max_vpi;
7215 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
James Smart6d368e52011-05-24 11:44:12 -04007216 "2003 cfg params Extents? %d "
7217 "XRI(B:%d M:%d), "
James Smartda0436e2009-05-22 14:51:39 -04007218 "VPI(B:%d M:%d) "
7219 "VFI(B:%d M:%d) "
7220 "RPI(B:%d M:%d) "
James Smart2ea259e2017-02-12 13:52:27 -08007221 "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n",
James Smart6d368e52011-05-24 11:44:12 -04007222 phba->sli4_hba.extents_in_use,
James Smartda0436e2009-05-22 14:51:39 -04007223 phba->sli4_hba.max_cfg_param.xri_base,
7224 phba->sli4_hba.max_cfg_param.max_xri,
7225 phba->sli4_hba.max_cfg_param.vpi_base,
7226 phba->sli4_hba.max_cfg_param.max_vpi,
7227 phba->sli4_hba.max_cfg_param.vfi_base,
7228 phba->sli4_hba.max_cfg_param.max_vfi,
7229 phba->sli4_hba.max_cfg_param.rpi_base,
7230 phba->sli4_hba.max_cfg_param.max_rpi,
James Smart2ea259e2017-02-12 13:52:27 -08007231 phba->sli4_hba.max_cfg_param.max_fcfi,
7232 phba->sli4_hba.max_cfg_param.max_eq,
7233 phba->sli4_hba.max_cfg_param.max_cq,
7234 phba->sli4_hba.max_cfg_param.max_wq,
7235 phba->sli4_hba.max_cfg_param.max_rq);
7236
James Smartda0436e2009-05-22 14:51:39 -04007237 }
James Smart912e3ac2011-05-24 11:42:11 -04007238
7239 if (rc)
7240 goto read_cfg_out;
James Smartda0436e2009-05-22 14:51:39 -04007241
James Smartc6918162016-10-13 15:06:16 -07007242 /* Update link speed if forced link speed is supported */
7243 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7244 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
7245 forced_link_speed =
7246 bf_get(lpfc_mbx_rd_conf_link_speed, rd_config);
7247 if (forced_link_speed) {
7248 phba->hba_flag |= HBA_FORCED_LINK_SPEED;
7249
7250 switch (forced_link_speed) {
7251 case LINK_SPEED_1G:
7252 phba->cfg_link_speed =
7253 LPFC_USER_LINK_SPEED_1G;
7254 break;
7255 case LINK_SPEED_2G:
7256 phba->cfg_link_speed =
7257 LPFC_USER_LINK_SPEED_2G;
7258 break;
7259 case LINK_SPEED_4G:
7260 phba->cfg_link_speed =
7261 LPFC_USER_LINK_SPEED_4G;
7262 break;
7263 case LINK_SPEED_8G:
7264 phba->cfg_link_speed =
7265 LPFC_USER_LINK_SPEED_8G;
7266 break;
7267 case LINK_SPEED_10G:
7268 phba->cfg_link_speed =
7269 LPFC_USER_LINK_SPEED_10G;
7270 break;
7271 case LINK_SPEED_16G:
7272 phba->cfg_link_speed =
7273 LPFC_USER_LINK_SPEED_16G;
7274 break;
7275 case LINK_SPEED_32G:
7276 phba->cfg_link_speed =
7277 LPFC_USER_LINK_SPEED_32G;
7278 break;
7279 case 0xffff:
7280 phba->cfg_link_speed =
7281 LPFC_USER_LINK_SPEED_AUTO;
7282 break;
7283 default:
7284 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7285 "0047 Unrecognized link "
7286 "speed : %d\n",
7287 forced_link_speed);
7288 phba->cfg_link_speed =
7289 LPFC_USER_LINK_SPEED_AUTO;
7290 }
7291 }
7292 }
7293
James Smartda0436e2009-05-22 14:51:39 -04007294 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
James Smart572709e2013-07-15 18:32:43 -04007295 length = phba->sli4_hba.max_cfg_param.max_xri -
7296 lpfc_sli4_get_els_iocb_cnt(phba);
7297 if (phba->cfg_hba_queue_depth > length) {
7298 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
7299 "3361 HBA queue depth changed from %d to %d\n",
7300 phba->cfg_hba_queue_depth, length);
7301 phba->cfg_hba_queue_depth = length;
7302 }
James Smart912e3ac2011-05-24 11:42:11 -04007303
7304 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
7305 LPFC_SLI_INTF_IF_TYPE_2)
7306 goto read_cfg_out;
7307
7308 /* get the pf# and vf# for SLI4 if_type 2 port */
7309 length = (sizeof(struct lpfc_mbx_get_func_cfg) -
7310 sizeof(struct lpfc_sli4_cfg_mhdr));
7311 lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON,
7312 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG,
7313 length, LPFC_SLI4_MBX_EMBED);
7314
James Smart8aa134a2012-08-14 14:25:29 -04007315 rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
James Smart912e3ac2011-05-24 11:42:11 -04007316 shdr = (union lpfc_sli4_cfg_shdr *)
7317 &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
7318 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
7319 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart8aa134a2012-08-14 14:25:29 -04007320 if (rc2 || shdr_status || shdr_add_status) {
James Smart912e3ac2011-05-24 11:42:11 -04007321 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7322 "3026 Mailbox failed , mbxCmd x%x "
7323 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
7324 bf_get(lpfc_mqe_command, &pmb->u.mqe),
7325 bf_get(lpfc_mqe_status, &pmb->u.mqe));
James Smart912e3ac2011-05-24 11:42:11 -04007326 goto read_cfg_out;
7327 }
7328
7329 /* search for fc_fcoe resrouce descriptor */
7330 get_func_cfg = &pmb->u.mqe.un.get_func_cfg;
James Smart912e3ac2011-05-24 11:42:11 -04007331
James Smart8aa134a2012-08-14 14:25:29 -04007332 pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0];
7333 desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0;
7334 length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc);
7335 if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD)
7336 length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH;
7337 else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH)
7338 goto read_cfg_out;
7339
James Smart912e3ac2011-05-24 11:42:11 -04007340 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
James Smart8aa134a2012-08-14 14:25:29 -04007341 desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i);
James Smart912e3ac2011-05-24 11:42:11 -04007342 if (LPFC_RSRC_DESC_TYPE_FCFCOE ==
James Smart8aa134a2012-08-14 14:25:29 -04007343 bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) {
James Smart912e3ac2011-05-24 11:42:11 -04007344 phba->sli4_hba.iov.pf_number =
7345 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc);
7346 phba->sli4_hba.iov.vf_number =
7347 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc);
7348 break;
7349 }
7350 }
7351
7352 if (i < LPFC_RSRC_DESC_MAX_NUM)
7353 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
7354 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
7355 "vf_number:%d\n", phba->sli4_hba.iov.pf_number,
7356 phba->sli4_hba.iov.vf_number);
James Smart8aa134a2012-08-14 14:25:29 -04007357 else
James Smart912e3ac2011-05-24 11:42:11 -04007358 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
7359 "3028 GET_FUNCTION_CONFIG: failed to find "
7360 "Resrouce Descriptor:x%x\n",
7361 LPFC_RSRC_DESC_TYPE_FCFCOE);
James Smart912e3ac2011-05-24 11:42:11 -04007362
7363read_cfg_out:
7364 mempool_free(pmb, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04007365 return rc;
7366}
7367
7368/**
James Smart2fcee4b2010-12-15 17:57:46 -05007369 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
James Smartda0436e2009-05-22 14:51:39 -04007370 * @phba: pointer to lpfc hba data structure.
7371 *
James Smart2fcee4b2010-12-15 17:57:46 -05007372 * This routine is invoked to setup the port-side endian order when
7373 * the port if_type is 0. This routine has no function for other
7374 * if_types.
James Smartda0436e2009-05-22 14:51:39 -04007375 *
7376 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007377 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007378 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007379 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007380 **/
7381static int
7382lpfc_setup_endian_order(struct lpfc_hba *phba)
7383{
7384 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05007385 uint32_t if_type, rc = 0;
James Smartda0436e2009-05-22 14:51:39 -04007386 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
7387 HOST_ENDIAN_HIGH_WORD1};
7388
James Smart2fcee4b2010-12-15 17:57:46 -05007389 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
7390 switch (if_type) {
7391 case LPFC_SLI_INTF_IF_TYPE_0:
7392 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
7393 GFP_KERNEL);
7394 if (!mboxq) {
7395 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7396 "0492 Unable to allocate memory for "
7397 "issuing SLI_CONFIG_SPECIAL mailbox "
7398 "command\n");
7399 return -ENOMEM;
7400 }
James Smartda0436e2009-05-22 14:51:39 -04007401
James Smart2fcee4b2010-12-15 17:57:46 -05007402 /*
7403 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
7404 * two words to contain special data values and no other data.
7405 */
7406 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
7407 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
7408 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7409 if (rc != MBX_SUCCESS) {
7410 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7411 "0493 SLI_CONFIG_SPECIAL mailbox "
7412 "failed with status x%x\n",
7413 rc);
7414 rc = -EIO;
7415 }
7416 mempool_free(mboxq, phba->mbox_mem_pool);
7417 break;
7418 case LPFC_SLI_INTF_IF_TYPE_2:
7419 case LPFC_SLI_INTF_IF_TYPE_1:
7420 default:
7421 break;
James Smartda0436e2009-05-22 14:51:39 -04007422 }
James Smartda0436e2009-05-22 14:51:39 -04007423 return rc;
7424}
7425
7426/**
James Smart895427b2017-02-12 13:52:30 -08007427 * lpfc_sli4_queue_verify - Verify and update EQ counts
James Smartda0436e2009-05-22 14:51:39 -04007428 * @phba: pointer to lpfc hba data structure.
7429 *
James Smart895427b2017-02-12 13:52:30 -08007430 * This routine is invoked to check the user settable queue counts for EQs.
7431 * After this routine is called the counts will be set to valid values that
James Smart5350d872011-10-10 21:33:49 -04007432 * adhere to the constraints of the system's interrupt vectors and the port's
7433 * queue resources.
James Smartda0436e2009-05-22 14:51:39 -04007434 *
7435 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007436 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007437 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04007438 **/
7439static int
James Smart5350d872011-10-10 21:33:49 -04007440lpfc_sli4_queue_verify(struct lpfc_hba *phba)
James Smartda0436e2009-05-22 14:51:39 -04007441{
James Smart895427b2017-02-12 13:52:30 -08007442 int io_channel;
James Smart1ba981f2014-02-20 09:56:45 -05007443 int fof_vectors = phba->cfg_fof ? 1 : 0;
James Smartda0436e2009-05-22 14:51:39 -04007444
7445 /*
James Smart67d12732012-08-03 12:36:13 -04007446 * Sanity check for configured queue parameters against the run-time
James Smartda0436e2009-05-22 14:51:39 -04007447 * device parameters
7448 */
7449
James Smart67d12732012-08-03 12:36:13 -04007450 /* Sanity check on HBA EQ parameters */
James Smart895427b2017-02-12 13:52:30 -08007451 io_channel = phba->io_channel_irqs;
James Smartda0436e2009-05-22 14:51:39 -04007452
James Smart895427b2017-02-12 13:52:30 -08007453 if (phba->sli4_hba.num_online_cpu < io_channel) {
James Smart82c3e9b2012-09-29 11:29:50 -04007454 lpfc_printf_log(phba,
7455 KERN_ERR, LOG_INIT,
James Smart90695ee2012-08-14 14:25:36 -04007456 "3188 Reducing IO channels to match number of "
James Smart7bb03bb2013-04-17 20:19:16 -04007457 "online CPUs: from %d to %d\n",
James Smart895427b2017-02-12 13:52:30 -08007458 io_channel, phba->sli4_hba.num_online_cpu);
7459 io_channel = phba->sli4_hba.num_online_cpu;
James Smart90695ee2012-08-14 14:25:36 -04007460 }
7461
James Smart895427b2017-02-12 13:52:30 -08007462 if (io_channel + fof_vectors > phba->sli4_hba.max_cfg_param.max_eq) {
James Smart82c3e9b2012-09-29 11:29:50 -04007463 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7464 "2575 Reducing IO channels to match number of "
7465 "available EQs: from %d to %d\n",
James Smart895427b2017-02-12 13:52:30 -08007466 io_channel,
James Smart82c3e9b2012-09-29 11:29:50 -04007467 phba->sli4_hba.max_cfg_param.max_eq);
James Smart895427b2017-02-12 13:52:30 -08007468 io_channel = phba->sli4_hba.max_cfg_param.max_eq - fof_vectors;
James Smartda0436e2009-05-22 14:51:39 -04007469 }
James Smart67d12732012-08-03 12:36:13 -04007470
James Smart895427b2017-02-12 13:52:30 -08007471 /* The actual number of FCP / NVME event queues adopted */
7472 if (io_channel != phba->io_channel_irqs)
7473 phba->io_channel_irqs = io_channel;
7474 if (phba->cfg_fcp_io_channel > io_channel)
7475 phba->cfg_fcp_io_channel = io_channel;
7476 if (phba->cfg_nvme_io_channel > io_channel)
7477 phba->cfg_nvme_io_channel = io_channel;
7478
7479 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7480 "2574 IRQs: %d, IO Channels: fcp %d nvme %d\n",
7481 phba->io_channel_irqs, phba->cfg_fcp_io_channel,
7482 phba->cfg_nvme_io_channel);
James Smartda0436e2009-05-22 14:51:39 -04007483
James Smartda0436e2009-05-22 14:51:39 -04007484 /* Get EQ depth from module parameter, fake the default for now */
7485 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
7486 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
7487
James Smart5350d872011-10-10 21:33:49 -04007488 /* Get CQ depth from module parameter, fake the default for now */
7489 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
7490 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart5350d872011-10-10 21:33:49 -04007491 return 0;
James Smart895427b2017-02-12 13:52:30 -08007492}
7493
7494static int
7495lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx)
7496{
7497 struct lpfc_queue *qdesc;
7498 int cnt;
7499
7500 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7501 phba->sli4_hba.cq_ecount);
7502 if (!qdesc) {
7503 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7504 "0508 Failed allocate fast-path NVME CQ (%d)\n",
7505 wqidx);
7506 return 1;
7507 }
7508 phba->sli4_hba.nvme_cq[wqidx] = qdesc;
7509
7510 cnt = LPFC_NVME_WQSIZE;
7511 qdesc = lpfc_sli4_queue_alloc(phba, LPFC_WQE128_SIZE, cnt);
7512 if (!qdesc) {
7513 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7514 "0509 Failed allocate fast-path NVME WQ (%d)\n",
7515 wqidx);
7516 return 1;
7517 }
7518 phba->sli4_hba.nvme_wq[wqidx] = qdesc;
7519 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
7520 return 0;
7521}
7522
7523static int
7524lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx)
7525{
7526 struct lpfc_queue *qdesc;
7527 uint32_t wqesize;
7528
7529 /* Create Fast Path FCP CQs */
7530 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7531 phba->sli4_hba.cq_ecount);
7532 if (!qdesc) {
7533 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7534 "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx);
7535 return 1;
7536 }
7537 phba->sli4_hba.fcp_cq[wqidx] = qdesc;
7538
7539 /* Create Fast Path FCP WQs */
7540 wqesize = (phba->fcp_embed_io) ?
7541 LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize;
7542 qdesc = lpfc_sli4_queue_alloc(phba, wqesize, phba->sli4_hba.wq_ecount);
7543 if (!qdesc) {
7544 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7545 "0503 Failed allocate fast-path FCP WQ (%d)\n",
7546 wqidx);
7547 return 1;
7548 }
7549 phba->sli4_hba.fcp_wq[wqidx] = qdesc;
7550 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
7551 return 0;
James Smart5350d872011-10-10 21:33:49 -04007552}
7553
7554/**
7555 * lpfc_sli4_queue_create - Create all the SLI4 queues
7556 * @phba: pointer to lpfc hba data structure.
7557 *
7558 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
7559 * operation. For each SLI4 queue type, the parameters such as queue entry
7560 * count (queue depth) shall be taken from the module parameter. For now,
7561 * we just use some constant number as place holder.
7562 *
7563 * Return codes
Anatol Pomozov4907cb72012-09-01 10:31:09 -07007564 * 0 - successful
James Smart5350d872011-10-10 21:33:49 -04007565 * -ENOMEM - No availble memory
7566 * -EIO - The mailbox failed to complete successfully.
7567 **/
7568int
7569lpfc_sli4_queue_create(struct lpfc_hba *phba)
7570{
7571 struct lpfc_queue *qdesc;
James Smart895427b2017-02-12 13:52:30 -08007572 int idx, io_channel;
James Smart5350d872011-10-10 21:33:49 -04007573
7574 /*
James Smart67d12732012-08-03 12:36:13 -04007575 * Create HBA Record arrays.
James Smart895427b2017-02-12 13:52:30 -08007576 * Both NVME and FCP will share that same vectors / EQs
James Smart5350d872011-10-10 21:33:49 -04007577 */
James Smart895427b2017-02-12 13:52:30 -08007578 io_channel = phba->io_channel_irqs;
7579 if (!io_channel)
James Smart67d12732012-08-03 12:36:13 -04007580 return -ERANGE;
James Smart5350d872011-10-10 21:33:49 -04007581
James Smart67d12732012-08-03 12:36:13 -04007582 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
7583 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
7584 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
7585 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
7586 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
7587 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
James Smart895427b2017-02-12 13:52:30 -08007588 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
7589 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
7590 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
7591 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
James Smart67d12732012-08-03 12:36:13 -04007592
James Smart895427b2017-02-12 13:52:30 -08007593 phba->sli4_hba.hba_eq = kcalloc(io_channel,
7594 sizeof(struct lpfc_queue *),
7595 GFP_KERNEL);
James Smart67d12732012-08-03 12:36:13 -04007596 if (!phba->sli4_hba.hba_eq) {
James Smartda0436e2009-05-22 14:51:39 -04007597 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007598 "2576 Failed allocate memory for "
7599 "fast-path EQ record array\n");
James Smartda0436e2009-05-22 14:51:39 -04007600 goto out_error;
7601 }
James Smart67d12732012-08-03 12:36:13 -04007602
James Smart895427b2017-02-12 13:52:30 -08007603 if (phba->cfg_fcp_io_channel) {
7604 phba->sli4_hba.fcp_cq = kcalloc(phba->cfg_fcp_io_channel,
7605 sizeof(struct lpfc_queue *),
7606 GFP_KERNEL);
7607 if (!phba->sli4_hba.fcp_cq) {
7608 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7609 "2577 Failed allocate memory for "
7610 "fast-path CQ record array\n");
7611 goto out_error;
7612 }
7613 phba->sli4_hba.fcp_wq = kcalloc(phba->cfg_fcp_io_channel,
7614 sizeof(struct lpfc_queue *),
7615 GFP_KERNEL);
7616 if (!phba->sli4_hba.fcp_wq) {
7617 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7618 "2578 Failed allocate memory for "
7619 "fast-path FCP WQ record array\n");
7620 goto out_error;
7621 }
7622 /*
7623 * Since the first EQ can have multiple CQs associated with it,
7624 * this array is used to quickly see if we have a FCP fast-path
7625 * CQ match.
7626 */
7627 phba->sli4_hba.fcp_cq_map = kcalloc(phba->cfg_fcp_io_channel,
7628 sizeof(uint16_t),
7629 GFP_KERNEL);
7630 if (!phba->sli4_hba.fcp_cq_map) {
7631 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7632 "2545 Failed allocate memory for "
7633 "fast-path CQ map\n");
7634 goto out_error;
7635 }
James Smart67d12732012-08-03 12:36:13 -04007636 }
7637
James Smart895427b2017-02-12 13:52:30 -08007638 if (phba->cfg_nvme_io_channel) {
7639 phba->sli4_hba.nvme_cq = kcalloc(phba->cfg_nvme_io_channel,
7640 sizeof(struct lpfc_queue *),
7641 GFP_KERNEL);
7642 if (!phba->sli4_hba.nvme_cq) {
7643 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7644 "6077 Failed allocate memory for "
7645 "fast-path CQ record array\n");
7646 goto out_error;
7647 }
7648
7649
7650 phba->sli4_hba.nvme_wq = kcalloc(phba->cfg_nvme_io_channel,
7651 sizeof(struct lpfc_queue *),
7652 GFP_KERNEL);
7653 if (!phba->sli4_hba.nvme_wq) {
7654 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7655 "2581 Failed allocate memory for "
7656 "fast-path NVME WQ record array\n");
7657 goto out_error;
7658 }
7659
7660 /*
7661 * Since the first EQ can have multiple CQs associated with it,
7662 * this array is used to quickly see if we have a NVME fast-path
7663 * CQ match.
7664 */
7665 phba->sli4_hba.nvme_cq_map = kcalloc(phba->cfg_nvme_io_channel,
7666 sizeof(uint16_t),
7667 GFP_KERNEL);
7668 if (!phba->sli4_hba.nvme_cq_map) {
7669 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7670 "6078 Failed allocate memory for "
7671 "fast-path CQ map\n");
7672 goto out_error;
7673 }
James Smart67d12732012-08-03 12:36:13 -04007674 }
James Smartda0436e2009-05-22 14:51:39 -04007675
James Smart895427b2017-02-12 13:52:30 -08007676 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
James Smart67d12732012-08-03 12:36:13 -04007677
James Smart895427b2017-02-12 13:52:30 -08007678 /* Create HBA Event Queues (EQs) */
7679 for (idx = 0; idx < io_channel; idx++) {
James Smart67d12732012-08-03 12:36:13 -04007680 /* Create EQs */
James Smartda0436e2009-05-22 14:51:39 -04007681 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
7682 phba->sli4_hba.eq_ecount);
7683 if (!qdesc) {
7684 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart67d12732012-08-03 12:36:13 -04007685 "0497 Failed allocate EQ (%d)\n", idx);
7686 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007687 }
James Smart67d12732012-08-03 12:36:13 -04007688 phba->sli4_hba.hba_eq[idx] = qdesc;
James Smartda0436e2009-05-22 14:51:39 -04007689 }
7690
James Smart895427b2017-02-12 13:52:30 -08007691 /* FCP and NVME io channels are not required to be balanced */
7692
7693 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
7694 if (lpfc_alloc_fcp_wq_cq(phba, idx))
7695 goto out_error;
7696
7697 for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++)
7698 if (lpfc_alloc_nvme_wq_cq(phba, idx))
7699 goto out_error;
James Smart67d12732012-08-03 12:36:13 -04007700
James Smartda0436e2009-05-22 14:51:39 -04007701 /*
James Smart67d12732012-08-03 12:36:13 -04007702 * Create Slow Path Completion Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04007703 */
7704
James Smartda0436e2009-05-22 14:51:39 -04007705 /* Create slow-path Mailbox Command Complete Queue */
7706 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7707 phba->sli4_hba.cq_ecount);
7708 if (!qdesc) {
7709 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7710 "0500 Failed allocate slow-path mailbox CQ\n");
James Smart67d12732012-08-03 12:36:13 -04007711 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007712 }
7713 phba->sli4_hba.mbx_cq = qdesc;
7714
7715 /* Create slow-path ELS Complete Queue */
7716 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7717 phba->sli4_hba.cq_ecount);
7718 if (!qdesc) {
7719 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7720 "0501 Failed allocate slow-path ELS CQ\n");
James Smart67d12732012-08-03 12:36:13 -04007721 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007722 }
7723 phba->sli4_hba.els_cq = qdesc;
7724
James Smartda0436e2009-05-22 14:51:39 -04007725
James Smart5350d872011-10-10 21:33:49 -04007726 /*
James Smart67d12732012-08-03 12:36:13 -04007727 * Create Slow Path Work Queues (WQs)
James Smart5350d872011-10-10 21:33:49 -04007728 */
James Smartda0436e2009-05-22 14:51:39 -04007729
7730 /* Create Mailbox Command Queue */
James Smartda0436e2009-05-22 14:51:39 -04007731
7732 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
7733 phba->sli4_hba.mq_ecount);
7734 if (!qdesc) {
7735 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7736 "0505 Failed allocate slow-path MQ\n");
James Smart67d12732012-08-03 12:36:13 -04007737 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007738 }
7739 phba->sli4_hba.mbx_wq = qdesc;
7740
7741 /*
James Smart67d12732012-08-03 12:36:13 -04007742 * Create ELS Work Queues
James Smartda0436e2009-05-22 14:51:39 -04007743 */
James Smartda0436e2009-05-22 14:51:39 -04007744
7745 /* Create slow-path ELS Work Queue */
7746 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
7747 phba->sli4_hba.wq_ecount);
7748 if (!qdesc) {
7749 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7750 "0504 Failed allocate slow-path ELS WQ\n");
James Smart67d12732012-08-03 12:36:13 -04007751 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007752 }
7753 phba->sli4_hba.els_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -08007754 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
7755
7756 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
7757 /* Create NVME LS Complete Queue */
7758 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
7759 phba->sli4_hba.cq_ecount);
7760 if (!qdesc) {
7761 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7762 "6079 Failed allocate NVME LS CQ\n");
7763 goto out_error;
7764 }
7765 phba->sli4_hba.nvmels_cq = qdesc;
7766
7767 /* Create NVME LS Work Queue */
7768 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
7769 phba->sli4_hba.wq_ecount);
7770 if (!qdesc) {
7771 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7772 "6080 Failed allocate NVME LS WQ\n");
7773 goto out_error;
7774 }
7775 phba->sli4_hba.nvmels_wq = qdesc;
7776 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
7777 }
James Smartda0436e2009-05-22 14:51:39 -04007778
James Smartda0436e2009-05-22 14:51:39 -04007779 /*
7780 * Create Receive Queue (RQ)
7781 */
James Smartda0436e2009-05-22 14:51:39 -04007782
7783 /* Create Receive Queue for header */
7784 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
7785 phba->sli4_hba.rq_ecount);
7786 if (!qdesc) {
7787 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7788 "0506 Failed allocate receive HRQ\n");
James Smart67d12732012-08-03 12:36:13 -04007789 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007790 }
7791 phba->sli4_hba.hdr_rq = qdesc;
7792
7793 /* Create Receive Queue for data */
7794 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
7795 phba->sli4_hba.rq_ecount);
7796 if (!qdesc) {
7797 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7798 "0507 Failed allocate receive DRQ\n");
James Smart67d12732012-08-03 12:36:13 -04007799 goto out_error;
James Smartda0436e2009-05-22 14:51:39 -04007800 }
7801 phba->sli4_hba.dat_rq = qdesc;
7802
James Smart1ba981f2014-02-20 09:56:45 -05007803 /* Create the Queues needed for Flash Optimized Fabric operations */
7804 if (phba->cfg_fof)
7805 lpfc_fof_queue_create(phba);
James Smartda0436e2009-05-22 14:51:39 -04007806 return 0;
7807
James Smartda0436e2009-05-22 14:51:39 -04007808out_error:
James Smart67d12732012-08-03 12:36:13 -04007809 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -04007810 return -ENOMEM;
7811}
7812
James Smart895427b2017-02-12 13:52:30 -08007813static inline void
7814__lpfc_sli4_release_queue(struct lpfc_queue **qp)
7815{
7816 if (*qp != NULL) {
7817 lpfc_sli4_queue_free(*qp);
7818 *qp = NULL;
7819 }
7820}
7821
7822static inline void
7823lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max)
7824{
7825 int idx;
7826
7827 if (*qs == NULL)
7828 return;
7829
7830 for (idx = 0; idx < max; idx++)
7831 __lpfc_sli4_release_queue(&(*qs)[idx]);
7832
7833 kfree(*qs);
7834 *qs = NULL;
7835}
7836
7837static inline void
7838lpfc_sli4_release_queue_map(uint16_t **qmap)
7839{
7840 if (*qmap != NULL) {
7841 kfree(*qmap);
7842 *qmap = NULL;
7843 }
7844}
7845
James Smartda0436e2009-05-22 14:51:39 -04007846/**
7847 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
7848 * @phba: pointer to lpfc hba data structure.
7849 *
7850 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
7851 * operation.
7852 *
7853 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02007854 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007855 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04007856 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04007857 **/
James Smart5350d872011-10-10 21:33:49 -04007858void
James Smartda0436e2009-05-22 14:51:39 -04007859lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
7860{
James Smart1ba981f2014-02-20 09:56:45 -05007861 if (phba->cfg_fof)
7862 lpfc_fof_queue_destroy(phba);
7863
James Smart895427b2017-02-12 13:52:30 -08007864 /* Release HBA eqs */
7865 lpfc_sli4_release_queues(&phba->sli4_hba.hba_eq, phba->io_channel_irqs);
James Smart67d12732012-08-03 12:36:13 -04007866
James Smart895427b2017-02-12 13:52:30 -08007867 /* Release FCP cqs */
7868 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_cq,
7869 phba->cfg_fcp_io_channel);
James Smart67d12732012-08-03 12:36:13 -04007870
James Smart895427b2017-02-12 13:52:30 -08007871 /* Release FCP wqs */
7872 lpfc_sli4_release_queues(&phba->sli4_hba.fcp_wq,
7873 phba->cfg_fcp_io_channel);
James Smart67d12732012-08-03 12:36:13 -04007874
7875 /* Release FCP CQ mapping array */
James Smart895427b2017-02-12 13:52:30 -08007876 lpfc_sli4_release_queue_map(&phba->sli4_hba.fcp_cq_map);
7877
7878 /* Release NVME cqs */
7879 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_cq,
7880 phba->cfg_nvme_io_channel);
7881
7882 /* Release NVME wqs */
7883 lpfc_sli4_release_queues(&phba->sli4_hba.nvme_wq,
7884 phba->cfg_nvme_io_channel);
7885
7886 /* Release NVME CQ mapping array */
7887 lpfc_sli4_release_queue_map(&phba->sli4_hba.nvme_cq_map);
James Smartda0436e2009-05-22 14:51:39 -04007888
7889 /* Release mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08007890 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq);
James Smartda0436e2009-05-22 14:51:39 -04007891
7892 /* Release ELS work queue */
James Smart895427b2017-02-12 13:52:30 -08007893 __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq);
7894
7895 /* Release ELS work queue */
7896 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq);
James Smartda0436e2009-05-22 14:51:39 -04007897
7898 /* Release unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08007899 __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq);
7900 __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq);
James Smartda0436e2009-05-22 14:51:39 -04007901
James Smartda0436e2009-05-22 14:51:39 -04007902 /* Release ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08007903 __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq);
7904
7905 /* Release NVME LS complete queue */
7906 __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq);
James Smartda0436e2009-05-22 14:51:39 -04007907
7908 /* Release mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08007909 __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq);
7910
7911 /* Everything on this list has been freed */
7912 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list);
7913}
7914
7915int
7916lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq,
7917 struct lpfc_queue *drq, int count)
7918{
7919 int rc, i;
7920 struct lpfc_rqe hrqe;
7921 struct lpfc_rqe drqe;
7922 struct lpfc_rqb *rqbp;
7923 struct rqb_dmabuf *rqb_buffer;
7924 LIST_HEAD(rqb_buf_list);
7925
7926 rqbp = hrq->rqbp;
7927 for (i = 0; i < count; i++) {
7928 rqb_buffer = (rqbp->rqb_alloc_buffer)(phba);
7929 if (!rqb_buffer)
7930 break;
7931 rqb_buffer->hrq = hrq;
7932 rqb_buffer->drq = drq;
7933 list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list);
7934 }
7935 while (!list_empty(&rqb_buf_list)) {
7936 list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf,
7937 hbuf.list);
7938
7939 hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys);
7940 hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys);
7941 drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys);
7942 drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys);
7943 rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe);
7944 if (rc < 0) {
7945 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
7946 } else {
7947 list_add_tail(&rqb_buffer->hbuf.list,
7948 &rqbp->rqb_buffer_list);
7949 rqbp->buffer_count++;
7950 }
7951 }
7952 return 1;
7953}
7954
7955int
7956lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq)
7957{
7958 struct lpfc_rqb *rqbp;
7959 struct lpfc_dmabuf *h_buf;
7960 struct rqb_dmabuf *rqb_buffer;
7961
7962 rqbp = rq->rqbp;
7963 while (!list_empty(&rqbp->rqb_buffer_list)) {
7964 list_remove_head(&rqbp->rqb_buffer_list, h_buf,
7965 struct lpfc_dmabuf, list);
7966
7967 rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf);
7968 (rqbp->rqb_free_buffer)(phba, rqb_buffer);
7969 rqbp->buffer_count--;
7970 }
7971 return 1;
7972}
7973
7974static int
7975lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq,
7976 struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map,
7977 int qidx, uint32_t qtype)
7978{
7979 struct lpfc_sli_ring *pring;
7980 int rc;
7981
7982 if (!eq || !cq || !wq) {
7983 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7984 "6085 Fast-path %s (%d) not allocated\n",
7985 ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx);
7986 return -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04007987 }
James Smartda0436e2009-05-22 14:51:39 -04007988
James Smart895427b2017-02-12 13:52:30 -08007989 /* create the Cq first */
7990 rc = lpfc_cq_create(phba, cq, eq,
7991 (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype);
7992 if (rc) {
7993 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7994 "6086 Failed setup of CQ (%d), rc = 0x%x\n",
7995 qidx, (uint32_t)rc);
7996 return rc;
7997 }
7998
7999 if (qtype != LPFC_MBOX) {
8000 /* Setup nvme_cq_map for fast lookup */
8001 if (cq_map)
8002 *cq_map = cq->queue_id;
8003
8004 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8005 "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n",
8006 qidx, cq->queue_id, qidx, eq->queue_id);
8007
8008 /* create the wq */
8009 rc = lpfc_wq_create(phba, wq, cq, qtype);
8010 if (rc) {
8011 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8012 "6123 Fail setup fastpath WQ (%d), rc = 0x%x\n",
8013 qidx, (uint32_t)rc);
8014 /* no need to tear down cq - caller will do so */
8015 return rc;
8016 }
8017
8018 /* Bind this CQ/WQ to the NVME ring */
8019 pring = wq->pring;
8020 pring->sli.sli4.wqp = (void *)wq;
8021 cq->pring = pring;
8022
8023 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8024 "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n",
8025 qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id);
8026 } else {
8027 rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX);
8028 if (rc) {
8029 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8030 "0539 Failed setup of slow-path MQ: "
8031 "rc = 0x%x\n", rc);
8032 /* no need to tear down cq - caller will do so */
8033 return rc;
8034 }
8035
8036 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8037 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
8038 phba->sli4_hba.mbx_wq->queue_id,
8039 phba->sli4_hba.mbx_cq->queue_id);
8040 }
8041
8042 return 0;
James Smartda0436e2009-05-22 14:51:39 -04008043}
8044
8045/**
8046 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
8047 * @phba: pointer to lpfc hba data structure.
8048 *
8049 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
8050 * operation.
8051 *
8052 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008053 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008054 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008055 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008056 **/
8057int
8058lpfc_sli4_queue_setup(struct lpfc_hba *phba)
8059{
James Smart962bc512013-01-03 15:44:00 -05008060 uint32_t shdr_status, shdr_add_status;
8061 union lpfc_sli4_cfg_shdr *shdr;
8062 LPFC_MBOXQ_t *mboxq;
James Smart895427b2017-02-12 13:52:30 -08008063 int qidx;
8064 uint32_t length, io_channel;
8065 int rc = -ENOMEM;
James Smart962bc512013-01-03 15:44:00 -05008066
8067 /* Check for dual-ULP support */
8068 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8069 if (!mboxq) {
8070 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8071 "3249 Unable to allocate memory for "
8072 "QUERY_FW_CFG mailbox command\n");
8073 return -ENOMEM;
8074 }
8075 length = (sizeof(struct lpfc_mbx_query_fw_config) -
8076 sizeof(struct lpfc_sli4_cfg_mhdr));
8077 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8078 LPFC_MBOX_OPCODE_QUERY_FW_CFG,
8079 length, LPFC_SLI4_MBX_EMBED);
8080
8081 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8082
8083 shdr = (union lpfc_sli4_cfg_shdr *)
8084 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
8085 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8086 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
8087 if (shdr_status || shdr_add_status || rc) {
8088 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8089 "3250 QUERY_FW_CFG mailbox failed with status "
8090 "x%x add_status x%x, mbx status x%x\n",
8091 shdr_status, shdr_add_status, rc);
8092 if (rc != MBX_TIMEOUT)
8093 mempool_free(mboxq, phba->mbox_mem_pool);
8094 rc = -ENXIO;
8095 goto out_error;
8096 }
8097
8098 phba->sli4_hba.fw_func_mode =
8099 mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode;
8100 phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode;
8101 phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode;
James Smart8b017a32015-05-21 13:55:18 -04008102 phba->sli4_hba.physical_port =
8103 mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port;
James Smart962bc512013-01-03 15:44:00 -05008104 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8105 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
8106 "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode,
8107 phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode);
8108
8109 if (rc != MBX_TIMEOUT)
8110 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartda0436e2009-05-22 14:51:39 -04008111
8112 /*
James Smart67d12732012-08-03 12:36:13 -04008113 * Set up HBA Event Queues (EQs)
James Smartda0436e2009-05-22 14:51:39 -04008114 */
James Smart895427b2017-02-12 13:52:30 -08008115 io_channel = phba->io_channel_irqs;
James Smartda0436e2009-05-22 14:51:39 -04008116
James Smart67d12732012-08-03 12:36:13 -04008117 /* Set up HBA event queue */
James Smart895427b2017-02-12 13:52:30 -08008118 if (io_channel && !phba->sli4_hba.hba_eq) {
James Smart2e90f4b2011-12-13 13:22:37 -05008119 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8120 "3147 Fast-path EQs not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05008121 rc = -ENOMEM;
James Smart67d12732012-08-03 12:36:13 -04008122 goto out_error;
James Smart2e90f4b2011-12-13 13:22:37 -05008123 }
James Smart895427b2017-02-12 13:52:30 -08008124 for (qidx = 0; qidx < io_channel; qidx++) {
8125 if (!phba->sli4_hba.hba_eq[qidx]) {
James Smartda0436e2009-05-22 14:51:39 -04008126 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8127 "0522 Fast-path EQ (%d) not "
James Smart895427b2017-02-12 13:52:30 -08008128 "allocated\n", qidx);
James Smart1b511972011-12-13 13:23:09 -05008129 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008130 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008131 }
James Smart895427b2017-02-12 13:52:30 -08008132 rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[qidx],
8133 phba->cfg_fcp_imax);
James Smartda0436e2009-05-22 14:51:39 -04008134 if (rc) {
8135 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8136 "0523 Failed setup of fast-path EQ "
James Smart895427b2017-02-12 13:52:30 -08008137 "(%d), rc = 0x%x\n", qidx,
James Smarta2fc4aef2014-09-03 12:57:55 -04008138 (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08008139 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008140 }
8141 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008142 "2584 HBA EQ setup: queue[%d]-id=%d\n",
8143 qidx, phba->sli4_hba.hba_eq[qidx]->queue_id);
James Smartda0436e2009-05-22 14:51:39 -04008144 }
8145
James Smart895427b2017-02-12 13:52:30 -08008146 if (phba->cfg_nvme_io_channel) {
8147 if (!phba->sli4_hba.nvme_cq || !phba->sli4_hba.nvme_wq) {
James Smart67d12732012-08-03 12:36:13 -04008148 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008149 "6084 Fast-path NVME %s array not allocated\n",
8150 (phba->sli4_hba.nvme_cq) ? "CQ" : "WQ");
James Smart67d12732012-08-03 12:36:13 -04008151 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008152 goto out_destroy;
James Smart67d12732012-08-03 12:36:13 -04008153 }
8154
James Smart895427b2017-02-12 13:52:30 -08008155 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) {
8156 rc = lpfc_create_wq_cq(phba,
8157 phba->sli4_hba.hba_eq[
8158 qidx % io_channel],
8159 phba->sli4_hba.nvme_cq[qidx],
8160 phba->sli4_hba.nvme_wq[qidx],
8161 &phba->sli4_hba.nvme_cq_map[qidx],
8162 qidx, LPFC_NVME);
8163 if (rc) {
8164 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8165 "6123 Failed to setup fastpath "
8166 "NVME WQ/CQ (%d), rc = 0x%x\n",
8167 qidx, (uint32_t)rc);
8168 goto out_destroy;
8169 }
8170 }
James Smart67d12732012-08-03 12:36:13 -04008171 }
8172
James Smart895427b2017-02-12 13:52:30 -08008173 if (phba->cfg_fcp_io_channel) {
8174 /* Set up fast-path FCP Response Complete Queue */
8175 if (!phba->sli4_hba.fcp_cq || !phba->sli4_hba.fcp_wq) {
James Smart67d12732012-08-03 12:36:13 -04008176 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008177 "3148 Fast-path FCP %s array not allocated\n",
8178 phba->sli4_hba.fcp_cq ? "WQ" : "CQ");
James Smart67d12732012-08-03 12:36:13 -04008179 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008180 goto out_destroy;
James Smart67d12732012-08-03 12:36:13 -04008181 }
8182
James Smart895427b2017-02-12 13:52:30 -08008183 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) {
8184 rc = lpfc_create_wq_cq(phba,
8185 phba->sli4_hba.hba_eq[
8186 qidx % io_channel],
8187 phba->sli4_hba.fcp_cq[qidx],
8188 phba->sli4_hba.fcp_wq[qidx],
8189 &phba->sli4_hba.fcp_cq_map[qidx],
8190 qidx, LPFC_FCP);
8191 if (rc) {
8192 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8193 "0535 Failed to setup fastpath "
8194 "FCP WQ/CQ (%d), rc = 0x%x\n",
8195 qidx, (uint32_t)rc);
8196 goto out_destroy;
8197 }
8198 }
James Smart67d12732012-08-03 12:36:13 -04008199 }
James Smartda0436e2009-05-22 14:51:39 -04008200
8201 /*
James Smart895427b2017-02-12 13:52:30 -08008202 * Set up Slow Path Complete Queues (CQs)
James Smartda0436e2009-05-22 14:51:39 -04008203 */
8204
James Smart895427b2017-02-12 13:52:30 -08008205 /* Set up slow-path MBOX CQ/MQ */
8206
8207 if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) {
James Smartda0436e2009-05-22 14:51:39 -04008208 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008209 "0528 %s not allocated\n",
8210 phba->sli4_hba.mbx_cq ?
8211 "Mailbox WQ" : "Mailbox CQ");
James Smart1b511972011-12-13 13:23:09 -05008212 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008213 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008214 }
James Smart895427b2017-02-12 13:52:30 -08008215
8216 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8217 phba->sli4_hba.mbx_cq,
8218 phba->sli4_hba.mbx_wq,
8219 NULL, 0, LPFC_MBOX);
James Smartda0436e2009-05-22 14:51:39 -04008220 if (rc) {
8221 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008222 "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n",
8223 (uint32_t)rc);
8224 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008225 }
James Smartda0436e2009-05-22 14:51:39 -04008226
James Smart895427b2017-02-12 13:52:30 -08008227 /* Set up slow-path ELS WQ/CQ */
8228 if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) {
James Smartda0436e2009-05-22 14:51:39 -04008229 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008230 "0530 ELS %s not allocated\n",
8231 phba->sli4_hba.els_cq ? "WQ" : "CQ");
James Smart1b511972011-12-13 13:23:09 -05008232 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008233 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008234 }
James Smart895427b2017-02-12 13:52:30 -08008235 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8236 phba->sli4_hba.els_cq,
8237 phba->sli4_hba.els_wq,
8238 NULL, 0, LPFC_ELS);
James Smartda0436e2009-05-22 14:51:39 -04008239 if (rc) {
8240 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart895427b2017-02-12 13:52:30 -08008241 "0529 Failed setup of ELS WQ/CQ: rc = 0x%x\n",
8242 (uint32_t)rc);
8243 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008244 }
8245 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8246 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
8247 phba->sli4_hba.els_wq->queue_id,
8248 phba->sli4_hba.els_cq->queue_id);
8249
James Smart895427b2017-02-12 13:52:30 -08008250 if (phba->cfg_nvme_io_channel) {
8251 /* Set up NVME LS Complete Queue */
8252 if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) {
8253 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8254 "6091 LS %s not allocated\n",
8255 phba->sli4_hba.nvmels_cq ? "WQ" : "CQ");
8256 rc = -ENOMEM;
8257 goto out_destroy;
8258 }
8259 rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0],
8260 phba->sli4_hba.nvmels_cq,
8261 phba->sli4_hba.nvmels_wq,
8262 NULL, 0, LPFC_NVME_LS);
8263 if (rc) {
8264 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8265 "0529 Failed setup of NVVME LS WQ/CQ: "
8266 "rc = 0x%x\n", (uint32_t)rc);
8267 goto out_destroy;
8268 }
8269
8270 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8271 "6096 ELS WQ setup: wq-id=%d, "
8272 "parent cq-id=%d\n",
8273 phba->sli4_hba.nvmels_wq->queue_id,
8274 phba->sli4_hba.nvmels_cq->queue_id);
8275 }
8276
James Smartda0436e2009-05-22 14:51:39 -04008277 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
8278 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8279 "0540 Receive Queue not allocated\n");
James Smart1b511972011-12-13 13:23:09 -05008280 rc = -ENOMEM;
James Smart895427b2017-02-12 13:52:30 -08008281 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008282 }
James Smart73d91e52011-10-10 21:32:10 -04008283
8284 lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ);
8285 lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ);
8286
James Smartda0436e2009-05-22 14:51:39 -04008287 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
James Smart4d9ab992009-10-02 15:16:39 -04008288 phba->sli4_hba.els_cq, LPFC_USOL);
James Smartda0436e2009-05-22 14:51:39 -04008289 if (rc) {
8290 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8291 "0541 Failed setup of Receive Queue: "
James Smarta2fc4aef2014-09-03 12:57:55 -04008292 "rc = 0x%x\n", (uint32_t)rc);
James Smart895427b2017-02-12 13:52:30 -08008293 goto out_destroy;
James Smartda0436e2009-05-22 14:51:39 -04008294 }
James Smart73d91e52011-10-10 21:32:10 -04008295
James Smartda0436e2009-05-22 14:51:39 -04008296 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8297 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
8298 "parent cq-id=%d\n",
8299 phba->sli4_hba.hdr_rq->queue_id,
8300 phba->sli4_hba.dat_rq->queue_id,
James Smart4d9ab992009-10-02 15:16:39 -04008301 phba->sli4_hba.els_cq->queue_id);
James Smart1ba981f2014-02-20 09:56:45 -05008302
8303 if (phba->cfg_fof) {
8304 rc = lpfc_fof_queue_setup(phba);
8305 if (rc) {
8306 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8307 "0549 Failed setup of FOF Queues: "
8308 "rc = 0x%x\n", rc);
James Smart895427b2017-02-12 13:52:30 -08008309 goto out_destroy;
James Smart1ba981f2014-02-20 09:56:45 -05008310 }
8311 }
James Smart2c9c5a02015-04-07 15:07:15 -04008312
8313 /*
8314 * Configure EQ delay multipier for interrupt coalescing using
8315 * MODIFY_EQ_DELAY for all EQs created, LPFC_MAX_EQ_DELAY at a time.
8316 */
James Smart895427b2017-02-12 13:52:30 -08008317 for (qidx = 0; qidx < io_channel; qidx += LPFC_MAX_EQ_DELAY)
8318 lpfc_modify_hba_eq_delay(phba, qidx);
James Smartda0436e2009-05-22 14:51:39 -04008319 return 0;
8320
James Smart895427b2017-02-12 13:52:30 -08008321out_destroy:
8322 lpfc_sli4_queue_unset(phba);
James Smartda0436e2009-05-22 14:51:39 -04008323out_error:
8324 return rc;
8325}
8326
8327/**
8328 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
8329 * @phba: pointer to lpfc hba data structure.
8330 *
8331 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
8332 * operation.
8333 *
8334 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008335 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008336 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008337 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008338 **/
8339void
8340lpfc_sli4_queue_unset(struct lpfc_hba *phba)
8341{
James Smart895427b2017-02-12 13:52:30 -08008342 int qidx;
James Smartda0436e2009-05-22 14:51:39 -04008343
James Smart1ba981f2014-02-20 09:56:45 -05008344 /* Unset the queues created for Flash Optimized Fabric operations */
8345 if (phba->cfg_fof)
8346 lpfc_fof_queue_destroy(phba);
James Smart895427b2017-02-12 13:52:30 -08008347
James Smartda0436e2009-05-22 14:51:39 -04008348 /* Unset mailbox command work queue */
James Smart895427b2017-02-12 13:52:30 -08008349 if (phba->sli4_hba.mbx_wq)
8350 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
8351
8352 /* Unset NVME LS work queue */
8353 if (phba->sli4_hba.nvmels_wq)
8354 lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq);
8355
James Smartda0436e2009-05-22 14:51:39 -04008356 /* Unset ELS work queue */
James Smart895427b2017-02-12 13:52:30 -08008357 if (phba->sli4_hba.els_cq)
8358 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
8359
James Smartda0436e2009-05-22 14:51:39 -04008360 /* Unset unsolicited receive queue */
James Smart895427b2017-02-12 13:52:30 -08008361 if (phba->sli4_hba.hdr_rq)
8362 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq,
8363 phba->sli4_hba.dat_rq);
8364
James Smartda0436e2009-05-22 14:51:39 -04008365 /* Unset FCP work queue */
James Smart895427b2017-02-12 13:52:30 -08008366 if (phba->sli4_hba.fcp_wq)
8367 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
8368 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[qidx]);
8369
8370 /* Unset NVME work queue */
8371 if (phba->sli4_hba.nvme_wq) {
8372 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
8373 lpfc_wq_destroy(phba, phba->sli4_hba.nvme_wq[qidx]);
James Smart67d12732012-08-03 12:36:13 -04008374 }
James Smart895427b2017-02-12 13:52:30 -08008375
James Smartda0436e2009-05-22 14:51:39 -04008376 /* Unset mailbox command complete queue */
James Smart895427b2017-02-12 13:52:30 -08008377 if (phba->sli4_hba.mbx_cq)
8378 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
8379
James Smartda0436e2009-05-22 14:51:39 -04008380 /* Unset ELS complete queue */
James Smart895427b2017-02-12 13:52:30 -08008381 if (phba->sli4_hba.els_cq)
8382 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
8383
8384 /* Unset NVME LS complete queue */
8385 if (phba->sli4_hba.nvmels_cq)
8386 lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq);
8387
8388 /* Unset NVME response complete queue */
8389 if (phba->sli4_hba.nvme_cq)
8390 for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++)
8391 lpfc_cq_destroy(phba, phba->sli4_hba.nvme_cq[qidx]);
8392
James Smartda0436e2009-05-22 14:51:39 -04008393 /* Unset FCP response complete queue */
James Smart895427b2017-02-12 13:52:30 -08008394 if (phba->sli4_hba.fcp_cq)
8395 for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++)
8396 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[qidx]);
8397
James Smartda0436e2009-05-22 14:51:39 -04008398 /* Unset fast-path event queue */
James Smart895427b2017-02-12 13:52:30 -08008399 if (phba->sli4_hba.hba_eq)
8400 for (qidx = 0; qidx < phba->io_channel_irqs; qidx++)
8401 lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[qidx]);
James Smartda0436e2009-05-22 14:51:39 -04008402}
8403
8404/**
8405 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
8406 * @phba: pointer to lpfc hba data structure.
8407 *
8408 * This routine is invoked to allocate and set up a pool of completion queue
8409 * events. The body of the completion queue event is a completion queue entry
8410 * CQE. For now, this pool is used for the interrupt service routine to queue
8411 * the following HBA completion queue events for the worker thread to process:
8412 * - Mailbox asynchronous events
8413 * - Receive queue completion unsolicited events
8414 * Later, this can be used for all the slow-path events.
8415 *
8416 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008417 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008418 * -ENOMEM - No available memory
James Smartda0436e2009-05-22 14:51:39 -04008419 **/
8420static int
8421lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
8422{
8423 struct lpfc_cq_event *cq_event;
8424 int i;
8425
8426 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
8427 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
8428 if (!cq_event)
8429 goto out_pool_create_fail;
8430 list_add_tail(&cq_event->list,
8431 &phba->sli4_hba.sp_cqe_event_pool);
8432 }
8433 return 0;
8434
8435out_pool_create_fail:
8436 lpfc_sli4_cq_event_pool_destroy(phba);
8437 return -ENOMEM;
8438}
8439
8440/**
8441 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
8442 * @phba: pointer to lpfc hba data structure.
8443 *
8444 * This routine is invoked to free the pool of completion queue events at
8445 * driver unload time. Note that, it is the responsibility of the driver
8446 * cleanup routine to free all the outstanding completion-queue events
8447 * allocated from this pool back into the pool before invoking this routine
8448 * to destroy the pool.
8449 **/
8450static void
8451lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
8452{
8453 struct lpfc_cq_event *cq_event, *next_cq_event;
8454
8455 list_for_each_entry_safe(cq_event, next_cq_event,
8456 &phba->sli4_hba.sp_cqe_event_pool, list) {
8457 list_del(&cq_event->list);
8458 kfree(cq_event);
8459 }
8460}
8461
8462/**
8463 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
8464 * @phba: pointer to lpfc hba data structure.
8465 *
8466 * This routine is the lock free version of the API invoked to allocate a
8467 * completion-queue event from the free pool.
8468 *
8469 * Return: Pointer to the newly allocated completion-queue event if successful
8470 * NULL otherwise.
8471 **/
8472struct lpfc_cq_event *
8473__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
8474{
8475 struct lpfc_cq_event *cq_event = NULL;
8476
8477 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
8478 struct lpfc_cq_event, list);
8479 return cq_event;
8480}
8481
8482/**
8483 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
8484 * @phba: pointer to lpfc hba data structure.
8485 *
8486 * This routine is the lock version of the API invoked to allocate a
8487 * completion-queue event from the free pool.
8488 *
8489 * Return: Pointer to the newly allocated completion-queue event if successful
8490 * NULL otherwise.
8491 **/
8492struct lpfc_cq_event *
8493lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
8494{
8495 struct lpfc_cq_event *cq_event;
8496 unsigned long iflags;
8497
8498 spin_lock_irqsave(&phba->hbalock, iflags);
8499 cq_event = __lpfc_sli4_cq_event_alloc(phba);
8500 spin_unlock_irqrestore(&phba->hbalock, iflags);
8501 return cq_event;
8502}
8503
8504/**
8505 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
8506 * @phba: pointer to lpfc hba data structure.
8507 * @cq_event: pointer to the completion queue event to be freed.
8508 *
8509 * This routine is the lock free version of the API invoked to release a
8510 * completion-queue event back into the free pool.
8511 **/
8512void
8513__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
8514 struct lpfc_cq_event *cq_event)
8515{
8516 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
8517}
8518
8519/**
8520 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
8521 * @phba: pointer to lpfc hba data structure.
8522 * @cq_event: pointer to the completion queue event to be freed.
8523 *
8524 * This routine is the lock version of the API invoked to release a
8525 * completion-queue event back into the free pool.
8526 **/
8527void
8528lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
8529 struct lpfc_cq_event *cq_event)
8530{
8531 unsigned long iflags;
8532 spin_lock_irqsave(&phba->hbalock, iflags);
8533 __lpfc_sli4_cq_event_release(phba, cq_event);
8534 spin_unlock_irqrestore(&phba->hbalock, iflags);
8535}
8536
8537/**
8538 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
8539 * @phba: pointer to lpfc hba data structure.
8540 *
8541 * This routine is to free all the pending completion-queue events to the
8542 * back into the free pool for device reset.
8543 **/
8544static void
8545lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
8546{
8547 LIST_HEAD(cqelist);
8548 struct lpfc_cq_event *cqe;
8549 unsigned long iflags;
8550
8551 /* Retrieve all the pending WCQEs from pending WCQE lists */
8552 spin_lock_irqsave(&phba->hbalock, iflags);
8553 /* Pending FCP XRI abort events */
8554 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
8555 &cqelist);
8556 /* Pending ELS XRI abort events */
8557 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
8558 &cqelist);
8559 /* Pending asynnc events */
8560 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
8561 &cqelist);
8562 spin_unlock_irqrestore(&phba->hbalock, iflags);
8563
8564 while (!list_empty(&cqelist)) {
8565 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
8566 lpfc_sli4_cq_event_release(phba, cqe);
8567 }
8568}
8569
8570/**
8571 * lpfc_pci_function_reset - Reset pci function.
8572 * @phba: pointer to lpfc hba data structure.
8573 *
8574 * This routine is invoked to request a PCI function reset. It will destroys
8575 * all resources assigned to the PCI function which originates this request.
8576 *
8577 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008578 * 0 - successful
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008579 * -ENOMEM - No available memory
James Smartd439d282010-09-29 11:18:45 -04008580 * -EIO - The mailbox failed to complete successfully.
James Smartda0436e2009-05-22 14:51:39 -04008581 **/
8582int
8583lpfc_pci_function_reset(struct lpfc_hba *phba)
8584{
8585 LPFC_MBOXQ_t *mboxq;
James Smart2fcee4b2010-12-15 17:57:46 -05008586 uint32_t rc = 0, if_type;
James Smartda0436e2009-05-22 14:51:39 -04008587 uint32_t shdr_status, shdr_add_status;
James Smart2f6fa2c2014-09-03 12:57:08 -04008588 uint32_t rdy_chk;
8589 uint32_t port_reset = 0;
James Smartda0436e2009-05-22 14:51:39 -04008590 union lpfc_sli4_cfg_shdr *shdr;
James Smart2fcee4b2010-12-15 17:57:46 -05008591 struct lpfc_register reg_data;
James Smart2b81f942012-03-01 22:37:18 -05008592 uint16_t devid;
James Smartda0436e2009-05-22 14:51:39 -04008593
James Smart2fcee4b2010-12-15 17:57:46 -05008594 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8595 switch (if_type) {
8596 case LPFC_SLI_INTF_IF_TYPE_0:
8597 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
8598 GFP_KERNEL);
8599 if (!mboxq) {
8600 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8601 "0494 Unable to allocate memory for "
8602 "issuing SLI_FUNCTION_RESET mailbox "
8603 "command\n");
8604 return -ENOMEM;
8605 }
8606
8607 /* Setup PCI function reset mailbox-ioctl command */
8608 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
8609 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
8610 LPFC_SLI4_MBX_EMBED);
8611 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
8612 shdr = (union lpfc_sli4_cfg_shdr *)
8613 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
8614 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
8615 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
8616 &shdr->response);
8617 if (rc != MBX_TIMEOUT)
8618 mempool_free(mboxq, phba->mbox_mem_pool);
8619 if (shdr_status || shdr_add_status || rc) {
8620 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8621 "0495 SLI_FUNCTION_RESET mailbox "
8622 "failed with status x%x add_status x%x,"
8623 " mbx status x%x\n",
8624 shdr_status, shdr_add_status, rc);
8625 rc = -ENXIO;
8626 }
8627 break;
8628 case LPFC_SLI_INTF_IF_TYPE_2:
James Smart2f6fa2c2014-09-03 12:57:08 -04008629wait:
8630 /*
8631 * Poll the Port Status Register and wait for RDY for
8632 * up to 30 seconds. If the port doesn't respond, treat
8633 * it as an error.
8634 */
James Smart77d093f2015-04-07 15:07:08 -04008635 for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) {
James Smart2f6fa2c2014-09-03 12:57:08 -04008636 if (lpfc_readl(phba->sli4_hba.u.if_type2.
8637 STATUSregaddr, &reg_data.word0)) {
8638 rc = -ENODEV;
8639 goto out;
8640 }
8641 if (bf_get(lpfc_sliport_status_rdy, &reg_data))
8642 break;
8643 msleep(20);
8644 }
8645
8646 if (!bf_get(lpfc_sliport_status_rdy, &reg_data)) {
8647 phba->work_status[0] = readl(
8648 phba->sli4_hba.u.if_type2.ERR1regaddr);
8649 phba->work_status[1] = readl(
8650 phba->sli4_hba.u.if_type2.ERR2regaddr);
8651 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8652 "2890 Port not ready, port status reg "
8653 "0x%x error 1=0x%x, error 2=0x%x\n",
8654 reg_data.word0,
8655 phba->work_status[0],
8656 phba->work_status[1]);
8657 rc = -ENODEV;
8658 goto out;
8659 }
8660
8661 if (!port_reset) {
8662 /*
8663 * Reset the port now
8664 */
James Smart2fcee4b2010-12-15 17:57:46 -05008665 reg_data.word0 = 0;
8666 bf_set(lpfc_sliport_ctrl_end, &reg_data,
8667 LPFC_SLIPORT_LITTLE_ENDIAN);
8668 bf_set(lpfc_sliport_ctrl_ip, &reg_data,
8669 LPFC_SLIPORT_INIT_PORT);
8670 writel(reg_data.word0, phba->sli4_hba.u.if_type2.
8671 CTRLregaddr);
James Smart8fcb8ac2012-03-01 22:35:58 -05008672 /* flush */
James Smart2b81f942012-03-01 22:37:18 -05008673 pci_read_config_word(phba->pcidev,
8674 PCI_DEVICE_ID, &devid);
James Smart2fcee4b2010-12-15 17:57:46 -05008675
James Smart2f6fa2c2014-09-03 12:57:08 -04008676 port_reset = 1;
8677 msleep(20);
8678 goto wait;
8679 } else if (bf_get(lpfc_sliport_status_rn, &reg_data)) {
8680 rc = -ENODEV;
8681 goto out;
James Smart2fcee4b2010-12-15 17:57:46 -05008682 }
8683 break;
James Smart2f6fa2c2014-09-03 12:57:08 -04008684
James Smart2fcee4b2010-12-15 17:57:46 -05008685 case LPFC_SLI_INTF_IF_TYPE_1:
8686 default:
8687 break;
James Smartda0436e2009-05-22 14:51:39 -04008688 }
8689
James Smart73d91e52011-10-10 21:32:10 -04008690out:
James Smart2fcee4b2010-12-15 17:57:46 -05008691 /* Catch the not-ready port failure after a port reset. */
James Smart2f6fa2c2014-09-03 12:57:08 -04008692 if (rc) {
James Smart229adb02013-04-17 20:16:51 -04008693 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8694 "3317 HBA not functional: IP Reset Failed "
James Smart2f6fa2c2014-09-03 12:57:08 -04008695 "try: echo fw_reset > board_mode\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008696 rc = -ENODEV;
James Smart229adb02013-04-17 20:16:51 -04008697 }
James Smart2fcee4b2010-12-15 17:57:46 -05008698
James Smartda0436e2009-05-22 14:51:39 -04008699 return rc;
8700}
8701
8702/**
James Smartda0436e2009-05-22 14:51:39 -04008703 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
8704 * @phba: pointer to lpfc hba data structure.
8705 *
8706 * This routine is invoked to set up the PCI device memory space for device
8707 * with SLI-4 interface spec.
8708 *
8709 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008710 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04008711 * other values - error
8712 **/
8713static int
8714lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
8715{
8716 struct pci_dev *pdev;
8717 unsigned long bar0map_len, bar1map_len, bar2map_len;
8718 int error = -ENODEV;
James Smart2fcee4b2010-12-15 17:57:46 -05008719 uint32_t if_type;
James Smartda0436e2009-05-22 14:51:39 -04008720
8721 /* Obtain PCI device reference */
8722 if (!phba->pcidev)
8723 return error;
8724 else
8725 pdev = phba->pcidev;
8726
8727 /* Set the device DMA mask size */
Michael Reed8e685972009-09-18 12:02:05 -05008728 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
8729 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
8730 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
8731 || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
James Smartda0436e2009-05-22 14:51:39 -04008732 return error;
Michael Reed8e685972009-09-18 12:02:05 -05008733 }
8734 }
James Smartda0436e2009-05-22 14:51:39 -04008735
James Smart2fcee4b2010-12-15 17:57:46 -05008736 /*
8737 * The BARs and register set definitions and offset locations are
8738 * dependent on the if_type.
8739 */
8740 if (pci_read_config_dword(pdev, LPFC_SLI_INTF,
8741 &phba->sli4_hba.sli_intf.word0)) {
8742 return error;
8743 }
8744
8745 /* There is no SLI3 failback for SLI4 devices. */
8746 if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) !=
8747 LPFC_SLI_INTF_VALID) {
8748 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8749 "2894 SLI_INTF reg contents invalid "
8750 "sli_intf reg 0x%x\n",
8751 phba->sli4_hba.sli_intf.word0);
8752 return error;
8753 }
8754
8755 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
8756 /*
8757 * Get the bus address of SLI4 device Bar regions and the
8758 * number of bytes required by each mapping. The mapping of the
8759 * particular PCI BARs regions is dependent on the type of
8760 * SLI4 device.
James Smartda0436e2009-05-22 14:51:39 -04008761 */
James Smartf5ca6f22013-09-06 12:21:09 -04008762 if (pci_resource_start(pdev, PCI_64BIT_BAR0)) {
8763 phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0);
8764 bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0);
James Smart2fcee4b2010-12-15 17:57:46 -05008765
8766 /*
8767 * Map SLI4 PCI Config Space Register base to a kernel virtual
8768 * addr
8769 */
8770 phba->sli4_hba.conf_regs_memmap_p =
8771 ioremap(phba->pci_bar0_map, bar0map_len);
8772 if (!phba->sli4_hba.conf_regs_memmap_p) {
8773 dev_printk(KERN_ERR, &pdev->dev,
8774 "ioremap failed for SLI4 PCI config "
8775 "registers.\n");
8776 goto out;
8777 }
James Smartf5ca6f22013-09-06 12:21:09 -04008778 phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008779 /* Set up BAR0 PCI config space register memory map */
8780 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smart1dfb5a42010-02-12 14:40:50 -05008781 } else {
8782 phba->pci_bar0_map = pci_resource_start(pdev, 1);
8783 bar0map_len = pci_resource_len(pdev, 1);
James Smart2fcee4b2010-12-15 17:57:46 -05008784 if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
8785 dev_printk(KERN_ERR, &pdev->dev,
8786 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
8787 goto out;
8788 }
8789 phba->sli4_hba.conf_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008790 ioremap(phba->pci_bar0_map, bar0map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008791 if (!phba->sli4_hba.conf_regs_memmap_p) {
8792 dev_printk(KERN_ERR, &pdev->dev,
8793 "ioremap failed for SLI4 PCI config "
8794 "registers.\n");
8795 goto out;
8796 }
8797 lpfc_sli4_bar0_register_memmap(phba, if_type);
James Smartda0436e2009-05-22 14:51:39 -04008798 }
8799
James Smartc31098c2011-04-16 11:03:33 -04008800 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04008801 (pci_resource_start(pdev, PCI_64BIT_BAR2))) {
James Smart2fcee4b2010-12-15 17:57:46 -05008802 /*
8803 * Map SLI4 if type 0 HBA Control Register base to a kernel
8804 * virtual address and setup the registers.
8805 */
James Smartf5ca6f22013-09-06 12:21:09 -04008806 phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2);
8807 bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2);
James Smart2fcee4b2010-12-15 17:57:46 -05008808 phba->sli4_hba.ctrl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008809 ioremap(phba->pci_bar1_map, bar1map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008810 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
8811 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04008812 "ioremap failed for SLI4 HBA control registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008813 goto out_iounmap_conf;
8814 }
James Smartf5ca6f22013-09-06 12:21:09 -04008815 phba->pci_bar2_memmap_p = phba->sli4_hba.ctrl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008816 lpfc_sli4_bar1_register_memmap(phba);
James Smartda0436e2009-05-22 14:51:39 -04008817 }
8818
James Smartc31098c2011-04-16 11:03:33 -04008819 if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) &&
James Smartf5ca6f22013-09-06 12:21:09 -04008820 (pci_resource_start(pdev, PCI_64BIT_BAR4))) {
James Smart2fcee4b2010-12-15 17:57:46 -05008821 /*
8822 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
8823 * virtual address and setup the registers.
8824 */
James Smartf5ca6f22013-09-06 12:21:09 -04008825 phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4);
8826 bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4);
James Smart2fcee4b2010-12-15 17:57:46 -05008827 phba->sli4_hba.drbl_regs_memmap_p =
James Smartda0436e2009-05-22 14:51:39 -04008828 ioremap(phba->pci_bar2_map, bar2map_len);
James Smart2fcee4b2010-12-15 17:57:46 -05008829 if (!phba->sli4_hba.drbl_regs_memmap_p) {
8830 dev_printk(KERN_ERR, &pdev->dev,
James Smartda0436e2009-05-22 14:51:39 -04008831 "ioremap failed for SLI4 HBA doorbell registers.\n");
James Smart2fcee4b2010-12-15 17:57:46 -05008832 goto out_iounmap_ctrl;
8833 }
James Smartf5ca6f22013-09-06 12:21:09 -04008834 phba->pci_bar4_memmap_p = phba->sli4_hba.drbl_regs_memmap_p;
James Smart2fcee4b2010-12-15 17:57:46 -05008835 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
8836 if (error)
8837 goto out_iounmap_all;
James Smartda0436e2009-05-22 14:51:39 -04008838 }
8839
James Smartda0436e2009-05-22 14:51:39 -04008840 return 0;
8841
8842out_iounmap_all:
8843 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
8844out_iounmap_ctrl:
8845 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
8846out_iounmap_conf:
8847 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8848out:
8849 return error;
8850}
8851
8852/**
8853 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
8854 * @phba: pointer to lpfc hba data structure.
8855 *
8856 * This routine is invoked to unset the PCI device memory space for device
8857 * with SLI-4 interface spec.
8858 **/
8859static void
8860lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
8861{
James Smart2e90f4b2011-12-13 13:22:37 -05008862 uint32_t if_type;
8863 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smartda0436e2009-05-22 14:51:39 -04008864
James Smart2e90f4b2011-12-13 13:22:37 -05008865 switch (if_type) {
8866 case LPFC_SLI_INTF_IF_TYPE_0:
8867 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
8868 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
8869 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8870 break;
8871 case LPFC_SLI_INTF_IF_TYPE_2:
8872 iounmap(phba->sli4_hba.conf_regs_memmap_p);
8873 break;
8874 case LPFC_SLI_INTF_IF_TYPE_1:
8875 default:
8876 dev_printk(KERN_ERR, &phba->pcidev->dev,
8877 "FATAL - unsupported SLI4 interface type - %d\n",
8878 if_type);
8879 break;
8880 }
James Smartda0436e2009-05-22 14:51:39 -04008881}
8882
8883/**
James Smart3772a992009-05-22 14:50:54 -04008884 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
8885 * @phba: pointer to lpfc hba data structure.
8886 *
8887 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -08008888 * with SLI-3 interface specs.
James Smart3772a992009-05-22 14:50:54 -04008889 *
8890 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008891 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008892 * other values - error
8893 **/
8894static int
8895lpfc_sli_enable_msix(struct lpfc_hba *phba)
8896{
Christoph Hellwig45ffac12017-02-12 13:52:26 -08008897 int rc;
James Smart3772a992009-05-22 14:50:54 -04008898 LPFC_MBOXQ_t *pmb;
8899
8900 /* Set up MSI-X multi-message vectors */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08008901 rc = pci_alloc_irq_vectors(phba->pcidev,
8902 LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX);
8903 if (rc < 0) {
James Smart3772a992009-05-22 14:50:54 -04008904 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8905 "0420 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02008906 goto vec_fail_out;
James Smart3772a992009-05-22 14:50:54 -04008907 }
Christoph Hellwig45ffac12017-02-12 13:52:26 -08008908
James Smart3772a992009-05-22 14:50:54 -04008909 /*
8910 * Assign MSI-X vectors to interrupt handlers
8911 */
8912
8913 /* vector-0 is associated to slow-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08008914 rc = request_irq(pci_irq_vector(phba->pcidev, 0),
James Smarted243d32015-05-21 13:55:25 -04008915 &lpfc_sli_sp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04008916 LPFC_SP_DRIVER_HANDLER_NAME, phba);
8917 if (rc) {
8918 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8919 "0421 MSI-X slow-path request_irq failed "
8920 "(%d)\n", rc);
8921 goto msi_fail_out;
8922 }
8923
8924 /* vector-1 is associated to fast-path handler */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08008925 rc = request_irq(pci_irq_vector(phba->pcidev, 1),
James Smarted243d32015-05-21 13:55:25 -04008926 &lpfc_sli_fp_intr_handler, 0,
James Smart3772a992009-05-22 14:50:54 -04008927 LPFC_FP_DRIVER_HANDLER_NAME, phba);
8928
8929 if (rc) {
8930 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
8931 "0429 MSI-X fast-path request_irq failed "
8932 "(%d)\n", rc);
8933 goto irq_fail_out;
8934 }
8935
8936 /*
8937 * Configure HBA MSI-X attention conditions to messages
8938 */
8939 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8940
8941 if (!pmb) {
8942 rc = -ENOMEM;
8943 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8944 "0474 Unable to allocate memory for issuing "
8945 "MBOX_CONFIG_MSI command\n");
8946 goto mem_fail_out;
8947 }
8948 rc = lpfc_config_msi(phba, pmb);
8949 if (rc)
8950 goto mbx_fail_out;
8951 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
8952 if (rc != MBX_SUCCESS) {
8953 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
8954 "0351 Config MSI mailbox command failed, "
8955 "mbxCmd x%x, mbxStatus x%x\n",
8956 pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
8957 goto mbx_fail_out;
8958 }
8959
8960 /* Free memory allocated for mailbox command */
8961 mempool_free(pmb, phba->mbox_mem_pool);
8962 return rc;
8963
8964mbx_fail_out:
8965 /* Free memory allocated for mailbox command */
8966 mempool_free(pmb, phba->mbox_mem_pool);
8967
8968mem_fail_out:
8969 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08008970 free_irq(pci_irq_vector(phba->pcidev, 1), phba);
James Smart3772a992009-05-22 14:50:54 -04008971
8972irq_fail_out:
8973 /* free the irq already requested */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08008974 free_irq(pci_irq_vector(phba->pcidev, 0), phba);
James Smart3772a992009-05-22 14:50:54 -04008975
8976msi_fail_out:
8977 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08008978 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02008979
8980vec_fail_out:
James Smart3772a992009-05-22 14:50:54 -04008981 return rc;
8982}
8983
8984/**
James Smart3772a992009-05-22 14:50:54 -04008985 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
8986 * @phba: pointer to lpfc hba data structure.
8987 *
8988 * This routine is invoked to enable the MSI interrupt mode to device with
8989 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
8990 * enable the MSI vector. The device driver is responsible for calling the
8991 * request_irq() to register MSI vector with a interrupt the handler, which
8992 * is done in this function.
8993 *
8994 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02008995 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04008996 * other values - error
8997 */
8998static int
8999lpfc_sli_enable_msi(struct lpfc_hba *phba)
9000{
9001 int rc;
9002
9003 rc = pci_enable_msi(phba->pcidev);
9004 if (!rc)
9005 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9006 "0462 PCI enable MSI mode success.\n");
9007 else {
9008 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9009 "0471 PCI enable MSI mode failed (%d)\n", rc);
9010 return rc;
9011 }
9012
9013 rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04009014 0, LPFC_DRIVER_NAME, phba);
James Smart3772a992009-05-22 14:50:54 -04009015 if (rc) {
9016 pci_disable_msi(phba->pcidev);
9017 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9018 "0478 MSI request_irq failed (%d)\n", rc);
9019 }
9020 return rc;
9021}
9022
9023/**
James Smart3772a992009-05-22 14:50:54 -04009024 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
9025 * @phba: pointer to lpfc hba data structure.
9026 *
9027 * This routine is invoked to enable device interrupt and associate driver's
9028 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
9029 * spec. Depends on the interrupt mode configured to the driver, the driver
9030 * will try to fallback from the configured interrupt mode to an interrupt
9031 * mode which is supported by the platform, kernel, and device in the order
9032 * of:
9033 * MSI-X -> MSI -> IRQ.
9034 *
9035 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009036 * 0 - successful
James Smart3772a992009-05-22 14:50:54 -04009037 * other values - error
9038 **/
9039static uint32_t
9040lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9041{
9042 uint32_t intr_mode = LPFC_INTR_ERROR;
9043 int retval;
9044
9045 if (cfg_mode == 2) {
9046 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
9047 retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
9048 if (!retval) {
9049 /* Now, try to enable MSI-X interrupt mode */
9050 retval = lpfc_sli_enable_msix(phba);
9051 if (!retval) {
9052 /* Indicate initialization to MSI-X mode */
9053 phba->intr_type = MSIX;
9054 intr_mode = 2;
9055 }
9056 }
9057 }
9058
9059 /* Fallback to MSI if MSI-X initialization failed */
9060 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9061 retval = lpfc_sli_enable_msi(phba);
9062 if (!retval) {
9063 /* Indicate initialization to MSI mode */
9064 phba->intr_type = MSI;
9065 intr_mode = 1;
9066 }
9067 }
9068
9069 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9070 if (phba->intr_type == NONE) {
9071 retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
9072 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9073 if (!retval) {
9074 /* Indicate initialization to INTx mode */
9075 phba->intr_type = INTx;
9076 intr_mode = 0;
9077 }
9078 }
9079 return intr_mode;
9080}
9081
9082/**
9083 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
9084 * @phba: pointer to lpfc hba data structure.
9085 *
9086 * This routine is invoked to disable device interrupt and disassociate the
9087 * driver's interrupt handler(s) from interrupt vector(s) to device with
9088 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
9089 * release the interrupt vector(s) for the message signaled interrupt.
9090 **/
9091static void
9092lpfc_sli_disable_intr(struct lpfc_hba *phba)
9093{
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009094 int nr_irqs, i;
9095
James Smart3772a992009-05-22 14:50:54 -04009096 if (phba->intr_type == MSIX)
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009097 nr_irqs = LPFC_MSIX_VECTORS;
9098 else
9099 nr_irqs = 1;
9100
9101 for (i = 0; i < nr_irqs; i++)
9102 free_irq(pci_irq_vector(phba->pcidev, i), phba);
9103 pci_free_irq_vectors(phba->pcidev);
James Smart3772a992009-05-22 14:50:54 -04009104
9105 /* Reset interrupt management states */
9106 phba->intr_type = NONE;
9107 phba->sli.slistat.sli_intr = 0;
James Smart3772a992009-05-22 14:50:54 -04009108}
9109
9110/**
James Smart895427b2017-02-12 13:52:30 -08009111 * lpfc_cpu_affinity_check - Check vector CPU affinity mappings
James Smart7bb03bb2013-04-17 20:19:16 -04009112 * @phba: pointer to lpfc hba data structure.
James Smart895427b2017-02-12 13:52:30 -08009113 * @vectors: number of msix vectors allocated.
James Smart7bb03bb2013-04-17 20:19:16 -04009114 *
James Smart895427b2017-02-12 13:52:30 -08009115 * The routine will figure out the CPU affinity assignment for every
9116 * MSI-X vector allocated for the HBA. The hba_eq_hdl will be updated
9117 * with a pointer to the CPU mask that defines ALL the CPUs this vector
9118 * can be associated with. If the vector can be unquely associated with
9119 * a single CPU, that CPU will be recorded in hba_eq_hdl[index].cpu.
9120 * In addition, the CPU to IO channel mapping will be calculated
9121 * and the phba->sli4_hba.cpu_map array will reflect this.
James Smart7bb03bb2013-04-17 20:19:16 -04009122 */
James Smart895427b2017-02-12 13:52:30 -08009123static void
9124lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors)
James Smart7bb03bb2013-04-17 20:19:16 -04009125{
9126 struct lpfc_vector_map_info *cpup;
James Smart895427b2017-02-12 13:52:30 -08009127 int index = 0;
9128 int vec = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04009129 int cpu;
James Smart7bb03bb2013-04-17 20:19:16 -04009130#ifdef CONFIG_X86
9131 struct cpuinfo_x86 *cpuinfo;
9132#endif
James Smart7bb03bb2013-04-17 20:19:16 -04009133
9134 /* Init cpu_map array */
9135 memset(phba->sli4_hba.cpu_map, 0xff,
9136 (sizeof(struct lpfc_vector_map_info) *
James Smart895427b2017-02-12 13:52:30 -08009137 phba->sli4_hba.num_present_cpu));
James Smart7bb03bb2013-04-17 20:19:16 -04009138
9139 /* Update CPU map with physical id and core id of each CPU */
9140 cpup = phba->sli4_hba.cpu_map;
9141 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
9142#ifdef CONFIG_X86
9143 cpuinfo = &cpu_data(cpu);
9144 cpup->phys_id = cpuinfo->phys_proc_id;
9145 cpup->core_id = cpuinfo->cpu_core_id;
9146#else
9147 /* No distinction between CPUs for other platforms */
9148 cpup->phys_id = 0;
9149 cpup->core_id = 0;
9150#endif
James Smart895427b2017-02-12 13:52:30 -08009151 cpup->channel_id = index; /* For now round robin */
9152 cpup->irq = pci_irq_vector(phba->pcidev, vec);
9153 vec++;
9154 if (vec >= vectors)
9155 vec = 0;
9156 index++;
9157 if (index >= phba->cfg_fcp_io_channel)
9158 index = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04009159 cpup++;
9160 }
James Smart7bb03bb2013-04-17 20:19:16 -04009161}
9162
9163
9164/**
James Smartda0436e2009-05-22 14:51:39 -04009165 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
9166 * @phba: pointer to lpfc hba data structure.
9167 *
9168 * This routine is invoked to enable the MSI-X interrupt vectors to device
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009169 * with SLI-4 interface spec.
James Smartda0436e2009-05-22 14:51:39 -04009170 *
9171 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009172 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009173 * other values - error
9174 **/
9175static int
9176lpfc_sli4_enable_msix(struct lpfc_hba *phba)
9177{
James Smart75baf692010-06-08 18:31:21 -04009178 int vectors, rc, index;
James Smartda0436e2009-05-22 14:51:39 -04009179
9180 /* Set up MSI-X multi-message vectors */
James Smart895427b2017-02-12 13:52:30 -08009181 vectors = phba->io_channel_irqs;
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009182 if (phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05009183 vectors++;
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009184
James Smart895427b2017-02-12 13:52:30 -08009185 rc = pci_alloc_irq_vectors(phba->pcidev, 2, vectors,
9186 PCI_IRQ_MSIX | PCI_IRQ_AFFINITY);
Alexander Gordeev4f871e12014-09-03 12:56:29 -04009187 if (rc < 0) {
James Smartda0436e2009-05-22 14:51:39 -04009188 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9189 "0484 PCI enable MSI-X failed (%d)\n", rc);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009190 goto vec_fail_out;
James Smartda0436e2009-05-22 14:51:39 -04009191 }
Alexander Gordeev4f871e12014-09-03 12:56:29 -04009192 vectors = rc;
James Smart75baf692010-06-08 18:31:21 -04009193
James Smart7bb03bb2013-04-17 20:19:16 -04009194 /* Assign MSI-X vectors to interrupt handlers */
James Smart67d12732012-08-03 12:36:13 -04009195 for (index = 0; index < vectors; index++) {
James Smart4305f182012-08-03 12:36:33 -04009196 memset(&phba->sli4_hba.handler_name[index], 0, 16);
James Smarta2fc4aef2014-09-03 12:57:55 -04009197 snprintf((char *)&phba->sli4_hba.handler_name[index],
9198 LPFC_SLI4_HANDLER_NAME_SZ,
James Smart4305f182012-08-03 12:36:33 -04009199 LPFC_DRIVER_HANDLER_NAME"%d", index);
James Smartda0436e2009-05-22 14:51:39 -04009200
James Smart895427b2017-02-12 13:52:30 -08009201 phba->sli4_hba.hba_eq_hdl[index].idx = index;
9202 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
9203 atomic_set(&phba->sli4_hba.hba_eq_hdl[index].hba_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -05009204 if (phba->cfg_fof && (index == (vectors - 1)))
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009205 rc = request_irq(pci_irq_vector(phba->pcidev, index),
James Smarted243d32015-05-21 13:55:25 -04009206 &lpfc_sli4_fof_intr_handler, 0,
James Smart1ba981f2014-02-20 09:56:45 -05009207 (char *)&phba->sli4_hba.handler_name[index],
James Smart895427b2017-02-12 13:52:30 -08009208 &phba->sli4_hba.hba_eq_hdl[index]);
James Smart1ba981f2014-02-20 09:56:45 -05009209 else
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009210 rc = request_irq(pci_irq_vector(phba->pcidev, index),
James Smarted243d32015-05-21 13:55:25 -04009211 &lpfc_sli4_hba_intr_handler, 0,
James Smart4305f182012-08-03 12:36:33 -04009212 (char *)&phba->sli4_hba.handler_name[index],
James Smart895427b2017-02-12 13:52:30 -08009213 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -04009214 if (rc) {
9215 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9216 "0486 MSI-X fast-path (%d) "
9217 "request_irq failed (%d)\n", index, rc);
9218 goto cfg_fail_out;
9219 }
9220 }
9221
James Smart1ba981f2014-02-20 09:56:45 -05009222 if (phba->cfg_fof)
9223 vectors--;
9224
James Smart895427b2017-02-12 13:52:30 -08009225 if (vectors != phba->io_channel_irqs) {
James Smart82c3e9b2012-09-29 11:29:50 -04009226 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9227 "3238 Reducing IO channels to match number of "
9228 "MSI-X vectors, requested %d got %d\n",
James Smart895427b2017-02-12 13:52:30 -08009229 phba->io_channel_irqs, vectors);
9230 if (phba->cfg_fcp_io_channel > vectors)
9231 phba->cfg_fcp_io_channel = vectors;
9232 if (phba->cfg_nvme_io_channel > vectors)
9233 phba->cfg_nvme_io_channel = vectors;
9234 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
9235 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
9236 else
9237 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
James Smart82c3e9b2012-09-29 11:29:50 -04009238 }
James Smart895427b2017-02-12 13:52:30 -08009239 lpfc_cpu_affinity_check(phba, vectors);
James Smart7bb03bb2013-04-17 20:19:16 -04009240
James Smartda0436e2009-05-22 14:51:39 -04009241 return rc;
9242
9243cfg_fail_out:
9244 /* free the irq already requested */
James Smart895427b2017-02-12 13:52:30 -08009245 for (--index; index >= 0; index--)
9246 free_irq(pci_irq_vector(phba->pcidev, index),
9247 &phba->sli4_hba.hba_eq_hdl[index]);
James Smartda0436e2009-05-22 14:51:39 -04009248
James Smartda0436e2009-05-22 14:51:39 -04009249 /* Unconfigure MSI-X capability structure */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009250 pci_free_irq_vectors(phba->pcidev);
Alexander Gordeev029165a2014-07-16 20:05:15 +02009251
9252vec_fail_out:
James Smartda0436e2009-05-22 14:51:39 -04009253 return rc;
9254}
9255
9256/**
James Smartda0436e2009-05-22 14:51:39 -04009257 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
9258 * @phba: pointer to lpfc hba data structure.
9259 *
9260 * This routine is invoked to enable the MSI interrupt mode to device with
9261 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
9262 * to enable the MSI vector. The device driver is responsible for calling
9263 * the request_irq() to register MSI vector with a interrupt the handler,
9264 * which is done in this function.
9265 *
9266 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009267 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009268 * other values - error
9269 **/
9270static int
9271lpfc_sli4_enable_msi(struct lpfc_hba *phba)
9272{
9273 int rc, index;
9274
9275 rc = pci_enable_msi(phba->pcidev);
9276 if (!rc)
9277 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9278 "0487 PCI enable MSI mode success.\n");
9279 else {
9280 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9281 "0488 PCI enable MSI mode failed (%d)\n", rc);
9282 return rc;
9283 }
9284
9285 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
James Smarted243d32015-05-21 13:55:25 -04009286 0, LPFC_DRIVER_NAME, phba);
James Smartda0436e2009-05-22 14:51:39 -04009287 if (rc) {
9288 pci_disable_msi(phba->pcidev);
9289 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
9290 "0490 MSI request_irq failed (%d)\n", rc);
James Smart75baf692010-06-08 18:31:21 -04009291 return rc;
James Smartda0436e2009-05-22 14:51:39 -04009292 }
9293
James Smart895427b2017-02-12 13:52:30 -08009294 for (index = 0; index < phba->io_channel_irqs; index++) {
9295 phba->sli4_hba.hba_eq_hdl[index].idx = index;
9296 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smartda0436e2009-05-22 14:51:39 -04009297 }
9298
James Smart1ba981f2014-02-20 09:56:45 -05009299 if (phba->cfg_fof) {
James Smart895427b2017-02-12 13:52:30 -08009300 phba->sli4_hba.hba_eq_hdl[index].idx = index;
9301 phba->sli4_hba.hba_eq_hdl[index].phba = phba;
James Smart1ba981f2014-02-20 09:56:45 -05009302 }
James Smart75baf692010-06-08 18:31:21 -04009303 return 0;
James Smartda0436e2009-05-22 14:51:39 -04009304}
9305
9306/**
James Smartda0436e2009-05-22 14:51:39 -04009307 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
9308 * @phba: pointer to lpfc hba data structure.
9309 *
9310 * This routine is invoked to enable device interrupt and associate driver's
9311 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
9312 * interface spec. Depends on the interrupt mode configured to the driver,
9313 * the driver will try to fallback from the configured interrupt mode to an
9314 * interrupt mode which is supported by the platform, kernel, and device in
9315 * the order of:
9316 * MSI-X -> MSI -> IRQ.
9317 *
9318 * Return codes
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02009319 * 0 - successful
James Smartda0436e2009-05-22 14:51:39 -04009320 * other values - error
9321 **/
9322static uint32_t
9323lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
9324{
9325 uint32_t intr_mode = LPFC_INTR_ERROR;
James Smart895427b2017-02-12 13:52:30 -08009326 int retval, idx;
James Smartda0436e2009-05-22 14:51:39 -04009327
9328 if (cfg_mode == 2) {
9329 /* Preparation before conf_msi mbox cmd */
9330 retval = 0;
9331 if (!retval) {
9332 /* Now, try to enable MSI-X interrupt mode */
9333 retval = lpfc_sli4_enable_msix(phba);
9334 if (!retval) {
9335 /* Indicate initialization to MSI-X mode */
9336 phba->intr_type = MSIX;
9337 intr_mode = 2;
9338 }
9339 }
9340 }
9341
9342 /* Fallback to MSI if MSI-X initialization failed */
9343 if (cfg_mode >= 1 && phba->intr_type == NONE) {
9344 retval = lpfc_sli4_enable_msi(phba);
9345 if (!retval) {
9346 /* Indicate initialization to MSI mode */
9347 phba->intr_type = MSI;
9348 intr_mode = 1;
9349 }
9350 }
9351
9352 /* Fallback to INTx if both MSI-X/MSI initalization failed */
9353 if (phba->intr_type == NONE) {
9354 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
9355 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
9356 if (!retval) {
James Smart895427b2017-02-12 13:52:30 -08009357 struct lpfc_hba_eq_hdl *eqhdl;
9358
James Smartda0436e2009-05-22 14:51:39 -04009359 /* Indicate initialization to INTx mode */
9360 phba->intr_type = INTx;
9361 intr_mode = 0;
James Smart895427b2017-02-12 13:52:30 -08009362
9363 for (idx = 0; idx < phba->io_channel_irqs; idx++) {
9364 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
9365 eqhdl->idx = idx;
9366 eqhdl->phba = phba;
9367 atomic_set(&eqhdl->hba_eq_in_use, 1);
James Smartda0436e2009-05-22 14:51:39 -04009368 }
James Smart1ba981f2014-02-20 09:56:45 -05009369 if (phba->cfg_fof) {
James Smart895427b2017-02-12 13:52:30 -08009370 eqhdl = &phba->sli4_hba.hba_eq_hdl[idx];
9371 eqhdl->idx = idx;
9372 eqhdl->phba = phba;
9373 atomic_set(&eqhdl->hba_eq_in_use, 1);
James Smart1ba981f2014-02-20 09:56:45 -05009374 }
James Smartda0436e2009-05-22 14:51:39 -04009375 }
9376 }
9377 return intr_mode;
9378}
9379
9380/**
9381 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
9382 * @phba: pointer to lpfc hba data structure.
9383 *
9384 * This routine is invoked to disable device interrupt and disassociate
9385 * the driver's interrupt handler(s) from interrupt vector(s) to device
9386 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
9387 * will release the interrupt vector(s) for the message signaled interrupt.
9388 **/
9389static void
9390lpfc_sli4_disable_intr(struct lpfc_hba *phba)
9391{
9392 /* Disable the currently initialized interrupt mode */
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009393 if (phba->intr_type == MSIX) {
9394 int index;
9395
9396 /* Free up MSI-X multi-message vectors */
James Smart895427b2017-02-12 13:52:30 -08009397 for (index = 0; index < phba->io_channel_irqs; index++)
9398 free_irq(pci_irq_vector(phba->pcidev, index),
9399 &phba->sli4_hba.hba_eq_hdl[index]);
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009400
9401 if (phba->cfg_fof)
James Smart895427b2017-02-12 13:52:30 -08009402 free_irq(pci_irq_vector(phba->pcidev, index),
9403 &phba->sli4_hba.hba_eq_hdl[index]);
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009404 } else {
James Smartda0436e2009-05-22 14:51:39 -04009405 free_irq(phba->pcidev->irq, phba);
Christoph Hellwig45ffac12017-02-12 13:52:26 -08009406 }
9407
9408 pci_free_irq_vectors(phba->pcidev);
James Smartda0436e2009-05-22 14:51:39 -04009409
9410 /* Reset interrupt management states */
9411 phba->intr_type = NONE;
9412 phba->sli.slistat.sli_intr = 0;
James Smartda0436e2009-05-22 14:51:39 -04009413}
9414
9415/**
James Smart3772a992009-05-22 14:50:54 -04009416 * lpfc_unset_hba - Unset SLI3 hba device initialization
9417 * @phba: pointer to lpfc hba data structure.
9418 *
9419 * This routine is invoked to unset the HBA device initialization steps to
9420 * a device with SLI-3 interface spec.
9421 **/
9422static void
9423lpfc_unset_hba(struct lpfc_hba *phba)
9424{
9425 struct lpfc_vport *vport = phba->pport;
9426 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9427
9428 spin_lock_irq(shost->host_lock);
9429 vport->load_flag |= FC_UNLOADING;
9430 spin_unlock_irq(shost->host_lock);
9431
James Smart72859902012-01-18 16:25:38 -05009432 kfree(phba->vpi_bmask);
9433 kfree(phba->vpi_ids);
9434
James Smart3772a992009-05-22 14:50:54 -04009435 lpfc_stop_hba_timers(phba);
9436
9437 phba->pport->work_port_events = 0;
9438
9439 lpfc_sli_hba_down(phba);
9440
9441 lpfc_sli_brdrestart(phba);
9442
9443 lpfc_sli_disable_intr(phba);
9444
9445 return;
9446}
9447
9448/**
James Smart5af5eee2010-10-22 11:06:38 -04009449 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
9450 * @phba: Pointer to HBA context object.
9451 *
9452 * This function is called in the SLI4 code path to wait for completion
9453 * of device's XRIs exchange busy. It will check the XRI exchange busy
9454 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
9455 * that, it will check the XRI exchange busy on outstanding FCP and ELS
9456 * I/Os every 30 seconds, log error message, and wait forever. Only when
9457 * all XRI exchange busy complete, the driver unload shall proceed with
9458 * invoking the function reset ioctl mailbox command to the CNA and the
9459 * the rest of the driver unload resource release.
9460 **/
9461static void
9462lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba)
9463{
9464 int wait_time = 0;
James Smart895427b2017-02-12 13:52:30 -08009465 int nvme_xri_cmpl = 1;
9466 int fcp_xri_cmpl = 1;
James Smart5af5eee2010-10-22 11:06:38 -04009467 int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9468
James Smart895427b2017-02-12 13:52:30 -08009469 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
9470 fcp_xri_cmpl =
9471 list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
9472 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
9473 nvme_xri_cmpl =
9474 list_empty(&phba->sli4_hba.lpfc_abts_nvme_buf_list);
9475
9476 while (!fcp_xri_cmpl || !els_xri_cmpl || !nvme_xri_cmpl) {
James Smart5af5eee2010-10-22 11:06:38 -04009477 if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) {
James Smart895427b2017-02-12 13:52:30 -08009478 if (!nvme_xri_cmpl)
9479 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9480 "6100 NVME XRI exchange busy "
9481 "wait time: %d seconds.\n",
9482 wait_time/1000);
James Smart5af5eee2010-10-22 11:06:38 -04009483 if (!fcp_xri_cmpl)
9484 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9485 "2877 FCP XRI exchange busy "
9486 "wait time: %d seconds.\n",
9487 wait_time/1000);
9488 if (!els_xri_cmpl)
9489 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9490 "2878 ELS XRI exchange busy "
9491 "wait time: %d seconds.\n",
9492 wait_time/1000);
9493 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2);
9494 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2;
9495 } else {
9496 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1);
9497 wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1;
9498 }
James Smart895427b2017-02-12 13:52:30 -08009499 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
9500 nvme_xri_cmpl = list_empty(
9501 &phba->sli4_hba.lpfc_abts_nvme_buf_list);
9502
9503 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
9504 fcp_xri_cmpl = list_empty(
9505 &phba->sli4_hba.lpfc_abts_scsi_buf_list);
9506
James Smart5af5eee2010-10-22 11:06:38 -04009507 els_xri_cmpl =
9508 list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list);
9509 }
9510}
9511
9512/**
James Smartda0436e2009-05-22 14:51:39 -04009513 * lpfc_sli4_hba_unset - Unset the fcoe hba
9514 * @phba: Pointer to HBA context object.
9515 *
9516 * This function is called in the SLI4 code path to reset the HBA's FCoE
9517 * function. The caller is not required to hold any lock. This routine
9518 * issues PCI function reset mailbox command to reset the FCoE function.
9519 * At the end of the function, it calls lpfc_hba_down_post function to
9520 * free any pending commands.
9521 **/
9522static void
9523lpfc_sli4_hba_unset(struct lpfc_hba *phba)
9524{
9525 int wait_cnt = 0;
9526 LPFC_MBOXQ_t *mboxq;
James Smart912e3ac2011-05-24 11:42:11 -04009527 struct pci_dev *pdev = phba->pcidev;
James Smartda0436e2009-05-22 14:51:39 -04009528
9529 lpfc_stop_hba_timers(phba);
9530 phba->sli4_hba.intr_enable = 0;
9531
9532 /*
9533 * Gracefully wait out the potential current outstanding asynchronous
9534 * mailbox command.
9535 */
9536
9537 /* First, block any pending async mailbox command from posted */
9538 spin_lock_irq(&phba->hbalock);
9539 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
9540 spin_unlock_irq(&phba->hbalock);
9541 /* Now, trying to wait it out if we can */
9542 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9543 msleep(10);
9544 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
9545 break;
9546 }
9547 /* Forcefully release the outstanding mailbox command if timed out */
9548 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
9549 spin_lock_irq(&phba->hbalock);
9550 mboxq = phba->sli.mbox_active;
9551 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
9552 __lpfc_mbox_cmpl_put(phba, mboxq);
9553 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
9554 phba->sli.mbox_active = NULL;
9555 spin_unlock_irq(&phba->hbalock);
9556 }
9557
James Smart5af5eee2010-10-22 11:06:38 -04009558 /* Abort all iocbs associated with the hba */
9559 lpfc_sli_hba_iocb_abort(phba);
9560
9561 /* Wait for completion of device XRI exchange busy */
9562 lpfc_sli4_xri_exchange_busy_wait(phba);
9563
James Smartda0436e2009-05-22 14:51:39 -04009564 /* Disable PCI subsystem interrupt */
9565 lpfc_sli4_disable_intr(phba);
9566
James Smart912e3ac2011-05-24 11:42:11 -04009567 /* Disable SR-IOV if enabled */
9568 if (phba->cfg_sriov_nr_virtfn)
9569 pci_disable_sriov(pdev);
9570
James Smartda0436e2009-05-22 14:51:39 -04009571 /* Stop kthread signal shall trigger work_done one more time */
9572 kthread_stop(phba->worker_thread);
9573
James Smart3677a3a2010-09-29 11:19:14 -04009574 /* Reset SLI4 HBA FCoE function */
9575 lpfc_pci_function_reset(phba);
James Smart5350d872011-10-10 21:33:49 -04009576 lpfc_sli4_queue_destroy(phba);
James Smart3677a3a2010-09-29 11:19:14 -04009577
James Smartda0436e2009-05-22 14:51:39 -04009578 /* Stop the SLI4 device port */
9579 phba->pport->work_port_events = 0;
9580}
9581
James Smart28baac72010-02-12 14:42:03 -05009582 /**
9583 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
9584 * @phba: Pointer to HBA context object.
9585 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9586 *
9587 * This function is called in the SLI4 code path to read the port's
9588 * sli4 capabilities.
9589 *
9590 * This function may be be called from any context that can block-wait
9591 * for the completion. The expectation is that this routine is called
9592 * typically from probe_one or from the online routine.
9593 **/
9594int
9595lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9596{
9597 int rc;
9598 struct lpfc_mqe *mqe;
9599 struct lpfc_pc_sli4_params *sli4_params;
9600 uint32_t mbox_tmo;
9601
9602 rc = 0;
9603 mqe = &mboxq->u.mqe;
9604
9605 /* Read the port's SLI4 Parameters port capabilities */
James Smartfedd3b72011-02-16 12:39:24 -05009606 lpfc_pc_sli4_params(mboxq);
James Smart28baac72010-02-12 14:42:03 -05009607 if (!phba->sli4_hba.intr_enable)
9608 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
9609 else {
James Smarta183a152011-10-10 21:32:43 -04009610 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
James Smart28baac72010-02-12 14:42:03 -05009611 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
9612 }
9613
9614 if (unlikely(rc))
9615 return 1;
9616
9617 sli4_params = &phba->sli4_hba.pc_sli4_params;
9618 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
9619 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
9620 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
9621 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
9622 &mqe->un.sli4_params);
9623 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
9624 &mqe->un.sli4_params);
9625 sli4_params->proto_types = mqe->un.sli4_params.word3;
9626 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
9627 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
9628 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
9629 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
9630 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
9631 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
9632 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
9633 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
9634 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
9635 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
9636 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
9637 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
9638 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
9639 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
9640 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
9641 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
9642 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
9643 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
9644 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
9645 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
James Smart05580562011-05-24 11:40:48 -04009646
9647 /* Make sure that sge_supp_len can be handled by the driver */
9648 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
9649 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
9650
James Smart28baac72010-02-12 14:42:03 -05009651 return rc;
9652}
9653
James Smartda0436e2009-05-22 14:51:39 -04009654/**
James Smartfedd3b72011-02-16 12:39:24 -05009655 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
9656 * @phba: Pointer to HBA context object.
9657 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9658 *
9659 * This function is called in the SLI4 code path to read the port's
9660 * sli4 capabilities.
9661 *
9662 * This function may be be called from any context that can block-wait
9663 * for the completion. The expectation is that this routine is called
9664 * typically from probe_one or from the online routine.
9665 **/
9666int
9667lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
9668{
9669 int rc;
9670 struct lpfc_mqe *mqe = &mboxq->u.mqe;
9671 struct lpfc_pc_sli4_params *sli4_params;
James Smarta183a152011-10-10 21:32:43 -04009672 uint32_t mbox_tmo;
James Smartfedd3b72011-02-16 12:39:24 -05009673 int length;
9674 struct lpfc_sli4_parameters *mbx_sli4_parameters;
9675
James Smart6d368e52011-05-24 11:44:12 -04009676 /*
9677 * By default, the driver assumes the SLI4 port requires RPI
9678 * header postings. The SLI4_PARAM response will correct this
9679 * assumption.
9680 */
9681 phba->sli4_hba.rpi_hdrs_in_use = 1;
9682
James Smartfedd3b72011-02-16 12:39:24 -05009683 /* Read the port's SLI4 Config Parameters */
9684 length = (sizeof(struct lpfc_mbx_get_sli4_parameters) -
9685 sizeof(struct lpfc_sli4_cfg_mhdr));
9686 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
9687 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS,
9688 length, LPFC_SLI4_MBX_EMBED);
9689 if (!phba->sli4_hba.intr_enable)
9690 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
James Smarta183a152011-10-10 21:32:43 -04009691 else {
9692 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
9693 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
9694 }
James Smartfedd3b72011-02-16 12:39:24 -05009695 if (unlikely(rc))
9696 return rc;
9697 sli4_params = &phba->sli4_hba.pc_sli4_params;
9698 mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters;
9699 sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters);
9700 sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters);
9701 sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters);
9702 sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1,
9703 mbx_sli4_parameters);
9704 sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2,
9705 mbx_sli4_parameters);
9706 if (bf_get(cfg_phwq, mbx_sli4_parameters))
9707 phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED;
9708 else
9709 phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED;
9710 sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len;
9711 sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters);
James Smart1ba981f2014-02-20 09:56:45 -05009712 sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -05009713 sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters);
9714 sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters);
9715 sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters);
9716 sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters);
James Smart0c651872013-07-15 18:33:23 -04009717 sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -05009718 sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt,
9719 mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -08009720 sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters);
James Smartfedd3b72011-02-16 12:39:24 -05009721 sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align,
9722 mbx_sli4_parameters);
James Smart6d368e52011-05-24 11:44:12 -04009723 phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters);
9724 phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters);
James Smart895427b2017-02-12 13:52:30 -08009725 phba->nvme_support = (bf_get(cfg_nvme, mbx_sli4_parameters) &&
9726 bf_get(cfg_xib, mbx_sli4_parameters));
9727
9728 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) ||
9729 !phba->nvme_support) {
9730 phba->nvme_support = 0;
9731 phba->nvmet_support = 0;
9732 phba->cfg_nvme_io_channel = 0;
9733 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
9734 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME,
9735 "6101 Disabling NVME support: "
9736 "Not supported by firmware: %d %d\n",
9737 bf_get(cfg_nvme, mbx_sli4_parameters),
9738 bf_get(cfg_xib, mbx_sli4_parameters));
9739
9740 /* If firmware doesn't support NVME, just use SCSI support */
9741 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
9742 return -ENODEV;
9743 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
9744 }
James Smart05580562011-05-24 11:40:48 -04009745
9746 /* Make sure that sge_supp_len can be handled by the driver */
9747 if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE)
9748 sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE;
9749
James Smartb5c53952016-03-31 14:12:30 -07009750 /*
9751 * Issue IOs with CDB embedded in WQE to minimized the number
9752 * of DMAs the firmware has to do. Setting this to 1 also forces
9753 * the driver to use 128 bytes WQEs for FCP IOs.
9754 */
9755 if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters))
9756 phba->fcp_embed_io = 1;
9757 else
9758 phba->fcp_embed_io = 0;
James Smart7bdedb32016-07-06 12:36:00 -07009759
9760 /*
9761 * Check if the SLI port supports MDS Diagnostics
9762 */
9763 if (bf_get(cfg_mds_diags, mbx_sli4_parameters))
9764 phba->mds_diags_support = 1;
9765 else
9766 phba->mds_diags_support = 0;
James Smartfedd3b72011-02-16 12:39:24 -05009767 return 0;
9768}
9769
9770/**
James Smart3772a992009-05-22 14:50:54 -04009771 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
9772 * @pdev: pointer to PCI device
9773 * @pid: pointer to PCI device identifier
9774 *
9775 * This routine is to be called to attach a device with SLI-3 interface spec
9776 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9777 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
9778 * information of the device and driver to see if the driver state that it can
9779 * support this kind of device. If the match is successful, the driver core
9780 * invokes this routine. If this routine determines it can claim the HBA, it
9781 * does all the initialization that it needs to do to handle the HBA properly.
9782 *
9783 * Return code
9784 * 0 - driver can claim the device
9785 * negative value - driver can not claim the device
9786 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009787static int
James Smart3772a992009-05-22 14:50:54 -04009788lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
9789{
9790 struct lpfc_hba *phba;
9791 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -04009792 struct Scsi_Host *shost = NULL;
James Smart3772a992009-05-22 14:50:54 -04009793 int error;
9794 uint32_t cfg_mode, intr_mode;
9795
9796 /* Allocate memory for HBA structure */
9797 phba = lpfc_hba_alloc(pdev);
9798 if (!phba)
9799 return -ENOMEM;
9800
9801 /* Perform generic PCI device enabling operation */
9802 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -04009803 if (error)
James Smart3772a992009-05-22 14:50:54 -04009804 goto out_free_phba;
James Smart3772a992009-05-22 14:50:54 -04009805
9806 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
9807 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
9808 if (error)
9809 goto out_disable_pci_dev;
9810
9811 /* Set up SLI-3 specific device PCI memory space */
9812 error = lpfc_sli_pci_mem_setup(phba);
9813 if (error) {
9814 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9815 "1402 Failed to set up pci memory space.\n");
9816 goto out_disable_pci_dev;
9817 }
9818
James Smart3772a992009-05-22 14:50:54 -04009819 /* Set up SLI-3 specific device driver resources */
9820 error = lpfc_sli_driver_resource_setup(phba);
9821 if (error) {
9822 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9823 "1404 Failed to set up driver resource.\n");
9824 goto out_unset_pci_mem_s3;
9825 }
9826
9827 /* Initialize and populate the iocb list per host */
9828 error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
9829 if (error) {
9830 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9831 "1405 Failed to initialize iocb list.\n");
9832 goto out_unset_driver_resource_s3;
9833 }
9834
9835 /* Set up common device driver resources */
9836 error = lpfc_setup_driver_resource_phase2(phba);
9837 if (error) {
9838 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9839 "1406 Failed to set up driver resource.\n");
9840 goto out_free_iocb_list;
9841 }
9842
James Smart079b5c92011-08-21 21:48:49 -04009843 /* Get the default values for Model Name and Description */
9844 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
9845
James Smart3772a992009-05-22 14:50:54 -04009846 /* Create SCSI host to the physical port */
9847 error = lpfc_create_shost(phba);
9848 if (error) {
9849 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9850 "1407 Failed to create scsi host.\n");
9851 goto out_unset_driver_resource;
9852 }
9853
9854 /* Configure sysfs attributes */
9855 vport = phba->pport;
9856 error = lpfc_alloc_sysfs_attr(vport);
9857 if (error) {
9858 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9859 "1476 Failed to allocate sysfs attr\n");
9860 goto out_destroy_shost;
9861 }
9862
James Smart6669f9b2009-10-02 15:16:45 -04009863 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smart3772a992009-05-22 14:50:54 -04009864 /* Now, trying to enable interrupt and bring up the device */
9865 cfg_mode = phba->cfg_use_msi;
9866 while (true) {
9867 /* Put device to a known state before enabling interrupt */
9868 lpfc_stop_port(phba);
9869 /* Configure and enable interrupt */
9870 intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
9871 if (intr_mode == LPFC_INTR_ERROR) {
9872 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9873 "0431 Failed to enable interrupt.\n");
9874 error = -ENODEV;
9875 goto out_free_sysfs_attr;
9876 }
9877 /* SLI-3 HBA setup */
9878 if (lpfc_sli_hba_setup(phba)) {
9879 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
9880 "1477 Failed to set up hba\n");
9881 error = -ENODEV;
9882 goto out_remove_device;
9883 }
9884
9885 /* Wait 50ms for the interrupts of previous mailbox commands */
9886 msleep(50);
9887 /* Check active interrupts on message signaled interrupts */
9888 if (intr_mode == 0 ||
9889 phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
9890 /* Log the current active interrupt mode */
9891 phba->intr_mode = intr_mode;
9892 lpfc_log_intr_mode(phba, intr_mode);
9893 break;
9894 } else {
9895 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
9896 "0447 Configure interrupt mode (%d) "
9897 "failed active interrupt test.\n",
9898 intr_mode);
9899 /* Disable the current interrupt mode */
9900 lpfc_sli_disable_intr(phba);
9901 /* Try next level of interrupt mode */
9902 cfg_mode = --intr_mode;
9903 }
9904 }
9905
9906 /* Perform post initialization setup */
9907 lpfc_post_init_setup(phba);
9908
9909 /* Check if there are static vports to be created. */
9910 lpfc_create_static_vport(phba);
9911
9912 return 0;
9913
9914out_remove_device:
9915 lpfc_unset_hba(phba);
9916out_free_sysfs_attr:
9917 lpfc_free_sysfs_attr(vport);
9918out_destroy_shost:
9919 lpfc_destroy_shost(phba);
9920out_unset_driver_resource:
9921 lpfc_unset_driver_resource_phase2(phba);
9922out_free_iocb_list:
9923 lpfc_free_iocb_list(phba);
9924out_unset_driver_resource_s3:
9925 lpfc_sli_driver_resource_unset(phba);
9926out_unset_pci_mem_s3:
9927 lpfc_sli_pci_mem_unset(phba);
9928out_disable_pci_dev:
9929 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -04009930 if (shost)
9931 scsi_host_put(shost);
James Smart3772a992009-05-22 14:50:54 -04009932out_free_phba:
9933 lpfc_hba_free(phba);
9934 return error;
9935}
9936
9937/**
9938 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
James Smarte59058c2008-08-24 21:49:00 -04009939 * @pdev: pointer to PCI device
9940 *
James Smart3772a992009-05-22 14:50:54 -04009941 * This routine is to be called to disattach a device with SLI-3 interface
9942 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9943 * removed from PCI bus, it performs all the necessary cleanup for the HBA
9944 * device to be removed from the PCI subsystem properly.
James Smarte59058c2008-08-24 21:49:00 -04009945 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009946static void
James Smart3772a992009-05-22 14:50:54 -04009947lpfc_pci_remove_one_s3(struct pci_dev *pdev)
dea31012005-04-17 16:05:31 -05009948{
James Smart2e0fef82007-06-17 19:56:36 -05009949 struct Scsi_Host *shost = pci_get_drvdata(pdev);
9950 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarteada2722008-12-04 22:39:13 -05009951 struct lpfc_vport **vports;
James Smart2e0fef82007-06-17 19:56:36 -05009952 struct lpfc_hba *phba = vport->phba;
James Smarteada2722008-12-04 22:39:13 -05009953 int i;
Tomohiro Kusumi8a4df1202008-01-11 01:53:00 -05009954
James Smart549e55c2007-08-02 11:09:51 -04009955 spin_lock_irq(&phba->hbalock);
James Smart51ef4c22007-08-02 11:10:31 -04009956 vport->load_flag |= FC_UNLOADING;
James Smart549e55c2007-08-02 11:09:51 -04009957 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05009958
James Smart858c9f62007-06-17 19:56:39 -05009959 lpfc_free_sysfs_attr(vport);
9960
James Smarteada2722008-12-04 22:39:13 -05009961 /* Release all the vports against this physical port */
9962 vports = lpfc_create_vport_work_array(phba);
9963 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -04009964 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9965 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
9966 continue;
James Smarteada2722008-12-04 22:39:13 -05009967 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -04009968 }
James Smarteada2722008-12-04 22:39:13 -05009969 lpfc_destroy_vport_work_array(phba, vports);
9970
9971 /* Remove FC host and then SCSI host with the physical port */
James Smart858c9f62007-06-17 19:56:39 -05009972 fc_remove_host(shost);
9973 scsi_remove_host(shost);
James Smart87af33f2007-10-27 13:37:43 -04009974 lpfc_cleanup(vport);
9975
James Smart2e0fef82007-06-17 19:56:36 -05009976 /*
9977 * Bring down the SLI Layer. This step disable all interrupts,
9978 * clears the rings, discards all mailbox commands, and resets
9979 * the HBA.
9980 */
James Smarta257bf92009-04-06 18:48:10 -04009981
Justin P. Mattock48e34d02010-12-30 15:07:58 -08009982 /* HBA interrupt will be disabled after this call */
James Smart2e0fef82007-06-17 19:56:36 -05009983 lpfc_sli_hba_down(phba);
James Smarta257bf92009-04-06 18:48:10 -04009984 /* Stop kthread signal shall trigger work_done one more time */
9985 kthread_stop(phba->worker_thread);
9986 /* Final cleanup of txcmplq and reset the HBA */
James Smart2e0fef82007-06-17 19:56:36 -05009987 lpfc_sli_brdrestart(phba);
9988
James Smart72859902012-01-18 16:25:38 -05009989 kfree(phba->vpi_bmask);
9990 kfree(phba->vpi_ids);
9991
James Smart3772a992009-05-22 14:50:54 -04009992 lpfc_stop_hba_timers(phba);
James Smart858c9f62007-06-17 19:56:39 -05009993 spin_lock_irq(&phba->hbalock);
9994 list_del_init(&vport->listentry);
9995 spin_unlock_irq(&phba->hbalock);
9996
James Smart858c9f62007-06-17 19:56:39 -05009997 lpfc_debugfs_terminate(vport);
James Smart2e0fef82007-06-17 19:56:36 -05009998
James Smart912e3ac2011-05-24 11:42:11 -04009999 /* Disable SR-IOV if enabled */
10000 if (phba->cfg_sriov_nr_virtfn)
10001 pci_disable_sriov(pdev);
10002
James Smart5b75da22008-12-04 22:39:35 -050010003 /* Disable interrupt */
James Smart3772a992009-05-22 14:50:54 -040010004 lpfc_sli_disable_intr(phba);
dea31012005-04-17 16:05:31 -050010005
James Smart858c9f62007-06-17 19:56:39 -050010006 scsi_host_put(shost);
James Smart2e0fef82007-06-17 19:56:36 -050010007
10008 /*
10009 * Call scsi_free before mem_free since scsi bufs are released to their
10010 * corresponding pools here.
10011 */
10012 lpfc_scsi_free(phba);
James Smart3772a992009-05-22 14:50:54 -040010013 lpfc_mem_free_all(phba);
James Smart2e0fef82007-06-17 19:56:36 -050010014
James Smart34b02dc2008-08-24 21:49:55 -040010015 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
10016 phba->hbqslimp.virt, phba->hbqslimp.phys);
James Smarted957682007-06-17 19:56:37 -050010017
James Smart2e0fef82007-06-17 19:56:36 -050010018 /* Free resources associated with SLI2 interface */
10019 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
James Smart34b02dc2008-08-24 21:49:55 -040010020 phba->slim2p.virt, phba->slim2p.phys);
James Smart2e0fef82007-06-17 19:56:36 -050010021
10022 /* unmap adapter SLIM and Control Registers */
10023 iounmap(phba->ctrl_regs_memmap_p);
10024 iounmap(phba->slim_memmap_p);
10025
James Smart3772a992009-05-22 14:50:54 -040010026 lpfc_hba_free(phba);
James Smart2e0fef82007-06-17 19:56:36 -050010027
Johannes Thumshirne0c04832016-06-07 09:44:03 +020010028 pci_release_mem_regions(pdev);
James Smart2e0fef82007-06-17 19:56:36 -050010029 pci_disable_device(pdev);
dea31012005-04-17 16:05:31 -050010030}
10031
Linas Vepstas8d63f372007-02-14 14:28:36 -060010032/**
James Smart3772a992009-05-22 14:50:54 -040010033 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050010034 * @pdev: pointer to PCI device
10035 * @msg: power management message
10036 *
James Smart3772a992009-05-22 14:50:54 -040010037 * This routine is to be called from the kernel's PCI subsystem to support
10038 * system Power Management (PM) to device with SLI-3 interface spec. When
10039 * PM invokes this method, it quiesces the device by stopping the driver's
10040 * worker thread for the device, turning off device's interrupt and DMA,
10041 * and bring the device offline. Note that as the driver implements the
10042 * minimum PM requirements to a power-aware driver's PM support for the
10043 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10044 * to the suspend() method call will be treated as SUSPEND and the driver will
10045 * fully reinitialize its device during resume() method call, the driver will
10046 * set device to PCI_D3hot state in PCI config space instead of setting it
10047 * according to the @msg provided by the PM.
James Smart3a55b532008-12-04 22:38:54 -050010048 *
10049 * Return code
James Smart3772a992009-05-22 14:50:54 -040010050 * 0 - driver suspended the device
10051 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050010052 **/
10053static int
James Smart3772a992009-05-22 14:50:54 -040010054lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
James Smart3a55b532008-12-04 22:38:54 -050010055{
10056 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10057 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10058
10059 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10060 "0473 PCI device Power Management suspend.\n");
10061
10062 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040010063 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart3a55b532008-12-04 22:38:54 -050010064 lpfc_offline(phba);
10065 kthread_stop(phba->worker_thread);
10066
10067 /* Disable interrupt from device */
James Smart3772a992009-05-22 14:50:54 -040010068 lpfc_sli_disable_intr(phba);
James Smart3a55b532008-12-04 22:38:54 -050010069
10070 /* Save device state to PCI config space */
10071 pci_save_state(pdev);
10072 pci_set_power_state(pdev, PCI_D3hot);
10073
10074 return 0;
10075}
10076
10077/**
James Smart3772a992009-05-22 14:50:54 -040010078 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
James Smart3a55b532008-12-04 22:38:54 -050010079 * @pdev: pointer to PCI device
10080 *
James Smart3772a992009-05-22 14:50:54 -040010081 * This routine is to be called from the kernel's PCI subsystem to support
10082 * system Power Management (PM) to device with SLI-3 interface spec. When PM
10083 * invokes this method, it restores the device's PCI config space state and
10084 * fully reinitializes the device and brings it online. Note that as the
10085 * driver implements the minimum PM requirements to a power-aware driver's
10086 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
10087 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
10088 * driver will fully reinitialize its device during resume() method call,
10089 * the device will be set to PCI_D0 directly in PCI config space before
10090 * restoring the state.
James Smart3a55b532008-12-04 22:38:54 -050010091 *
10092 * Return code
James Smart3772a992009-05-22 14:50:54 -040010093 * 0 - driver suspended the device
10094 * Error otherwise
James Smart3a55b532008-12-04 22:38:54 -050010095 **/
10096static int
James Smart3772a992009-05-22 14:50:54 -040010097lpfc_pci_resume_one_s3(struct pci_dev *pdev)
James Smart3a55b532008-12-04 22:38:54 -050010098{
10099 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10100 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smart5b75da22008-12-04 22:39:35 -050010101 uint32_t intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050010102 int error;
10103
10104 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10105 "0452 PCI device Power Management resume.\n");
10106
10107 /* Restore device state from PCI config space */
10108 pci_set_power_state(pdev, PCI_D0);
10109 pci_restore_state(pdev);
James Smart0d878412009-10-02 15:16:56 -040010110
James Smart1dfb5a42010-02-12 14:40:50 -050010111 /*
10112 * As the new kernel behavior of pci_restore_state() API call clears
10113 * device saved_state flag, need to save the restored state again.
10114 */
10115 pci_save_state(pdev);
10116
James Smart3a55b532008-12-04 22:38:54 -050010117 if (pdev->is_busmaster)
10118 pci_set_master(pdev);
10119
10120 /* Startup the kernel thread for this host adapter. */
10121 phba->worker_thread = kthread_run(lpfc_do_work, phba,
10122 "lpfc_worker_%d", phba->brd_no);
10123 if (IS_ERR(phba->worker_thread)) {
10124 error = PTR_ERR(phba->worker_thread);
10125 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10126 "0434 PM resume failed to start worker "
10127 "thread: error=x%x.\n", error);
10128 return error;
10129 }
10130
James Smart5b75da22008-12-04 22:39:35 -050010131 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040010132 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050010133 if (intr_mode == LPFC_INTR_ERROR) {
James Smart3a55b532008-12-04 22:38:54 -050010134 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart5b75da22008-12-04 22:39:35 -050010135 "0430 PM resume Failed to enable interrupt\n");
10136 return -EIO;
10137 } else
10138 phba->intr_mode = intr_mode;
James Smart3a55b532008-12-04 22:38:54 -050010139
10140 /* Restart HBA and bring it online */
10141 lpfc_sli_brdrestart(phba);
10142 lpfc_online(phba);
10143
James Smart5b75da22008-12-04 22:39:35 -050010144 /* Log the current active interrupt mode */
10145 lpfc_log_intr_mode(phba, phba->intr_mode);
10146
James Smart3a55b532008-12-04 22:38:54 -050010147 return 0;
10148}
10149
10150/**
James Smart891478a2009-11-18 15:40:23 -050010151 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
10152 * @phba: pointer to lpfc hba data structure.
10153 *
10154 * This routine is called to prepare the SLI3 device for PCI slot recover. It
James Smarte2af0d22010-03-15 11:25:32 -040010155 * aborts all the outstanding SCSI I/Os to the pci device.
James Smart891478a2009-11-18 15:40:23 -050010156 **/
10157static void
10158lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
10159{
10160 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10161 "2723 PCI channel I/O abort preparing for recovery\n");
James Smarte2af0d22010-03-15 11:25:32 -040010162
10163 /*
10164 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10165 * and let the SCSI mid-layer to retry them to recover.
10166 */
James Smartdb55fba2014-04-04 13:52:02 -040010167 lpfc_sli_abort_fcp_rings(phba);
James Smart891478a2009-11-18 15:40:23 -050010168}
10169
10170/**
James Smart0d878412009-10-02 15:16:56 -040010171 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
10172 * @phba: pointer to lpfc hba data structure.
10173 *
10174 * This routine is called to prepare the SLI3 device for PCI slot reset. It
10175 * disables the device interrupt and pci device, and aborts the internal FCP
10176 * pending I/Os.
10177 **/
10178static void
10179lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
10180{
James Smart0d878412009-10-02 15:16:56 -040010181 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050010182 "2710 PCI channel disable preparing for reset\n");
James Smarte2af0d22010-03-15 11:25:32 -040010183
James Smart75baf692010-06-08 18:31:21 -040010184 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040010185 lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010186
James Smarte2af0d22010-03-15 11:25:32 -040010187 /* Block all SCSI devices' I/Os on the host */
10188 lpfc_scsi_dev_block(phba);
10189
James Smartea714f32013-04-17 20:18:47 -040010190 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10191 lpfc_sli_flush_fcp_rings(phba);
10192
James Smarte2af0d22010-03-15 11:25:32 -040010193 /* stop all timers */
10194 lpfc_stop_hba_timers(phba);
10195
James Smart0d878412009-10-02 15:16:56 -040010196 /* Disable interrupt and pci device */
10197 lpfc_sli_disable_intr(phba);
10198 pci_disable_device(phba->pcidev);
James Smart0d878412009-10-02 15:16:56 -040010199}
10200
10201/**
10202 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
10203 * @phba: pointer to lpfc hba data structure.
10204 *
10205 * This routine is called to prepare the SLI3 device for PCI slot permanently
10206 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10207 * pending I/Os.
10208 **/
10209static void
James Smart75baf692010-06-08 18:31:21 -040010210lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba)
James Smart0d878412009-10-02 15:16:56 -040010211{
10212 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart891478a2009-11-18 15:40:23 -050010213 "2711 PCI channel permanent disable for failure\n");
James Smarte2af0d22010-03-15 11:25:32 -040010214 /* Block all SCSI devices' I/Os on the host */
10215 lpfc_scsi_dev_block(phba);
10216
10217 /* stop all timers */
10218 lpfc_stop_hba_timers(phba);
10219
James Smart0d878412009-10-02 15:16:56 -040010220 /* Clean up all driver's outstanding SCSI I/Os */
10221 lpfc_sli_flush_fcp_rings(phba);
10222}
10223
10224/**
James Smart3772a992009-05-22 14:50:54 -040010225 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
James Smarte59058c2008-08-24 21:49:00 -040010226 * @pdev: pointer to PCI device.
10227 * @state: the current PCI connection state.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010228 *
James Smart3772a992009-05-22 14:50:54 -040010229 * This routine is called from the PCI subsystem for I/O error handling to
10230 * device with SLI-3 interface spec. This function is called by the PCI
10231 * subsystem after a PCI bus error affecting this device has been detected.
10232 * When this function is invoked, it will need to stop all the I/Os and
10233 * interrupt(s) to the device. Once that is done, it will return
10234 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
10235 * as desired.
James Smarte59058c2008-08-24 21:49:00 -040010236 *
10237 * Return codes
James Smart0d878412009-10-02 15:16:56 -040010238 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
James Smart3772a992009-05-22 14:50:54 -040010239 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10240 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
James Smarte59058c2008-08-24 21:49:00 -040010241 **/
James Smart3772a992009-05-22 14:50:54 -040010242static pci_ers_result_t
10243lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010244{
James Smart51ef4c22007-08-02 11:10:31 -040010245 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10246 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010247
James Smart0d878412009-10-02 15:16:56 -040010248 switch (state) {
10249 case pci_channel_io_normal:
James Smart891478a2009-11-18 15:40:23 -050010250 /* Non-fatal error, prepare for recovery */
10251 lpfc_sli_prep_dev_for_recover(phba);
James Smart0d878412009-10-02 15:16:56 -040010252 return PCI_ERS_RESULT_CAN_RECOVER;
10253 case pci_channel_io_frozen:
10254 /* Fatal error, prepare for slot reset */
10255 lpfc_sli_prep_dev_for_reset(phba);
10256 return PCI_ERS_RESULT_NEED_RESET;
10257 case pci_channel_io_perm_failure:
10258 /* Permanent failure, prepare for device down */
James Smart75baf692010-06-08 18:31:21 -040010259 lpfc_sli_prep_dev_for_perm_failure(phba);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010260 return PCI_ERS_RESULT_DISCONNECT;
James Smart0d878412009-10-02 15:16:56 -040010261 default:
10262 /* Unknown state, prepare and request slot reset */
10263 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10264 "0472 Unknown PCI error state: x%x\n", state);
10265 lpfc_sli_prep_dev_for_reset(phba);
10266 return PCI_ERS_RESULT_NEED_RESET;
James Smarta8e497d2008-08-24 21:50:11 -040010267 }
Linas Vepstas8d63f372007-02-14 14:28:36 -060010268}
10269
10270/**
James Smart3772a992009-05-22 14:50:54 -040010271 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
James Smarte59058c2008-08-24 21:49:00 -040010272 * @pdev: pointer to PCI device.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010273 *
James Smart3772a992009-05-22 14:50:54 -040010274 * This routine is called from the PCI subsystem for error handling to
10275 * device with SLI-3 interface spec. This is called after PCI bus has been
10276 * reset to restart the PCI card from scratch, as if from a cold-boot.
10277 * During the PCI subsystem error recovery, after driver returns
10278 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10279 * recovery and then call this routine before calling the .resume method
10280 * to recover the device. This function will initialize the HBA device,
10281 * enable the interrupt, but it will just put the HBA to offline state
10282 * without passing any I/O traffic.
James Smarte59058c2008-08-24 21:49:00 -040010283 *
10284 * Return codes
James Smart3772a992009-05-22 14:50:54 -040010285 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10286 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
Linas Vepstas8d63f372007-02-14 14:28:36 -060010287 */
James Smart3772a992009-05-22 14:50:54 -040010288static pci_ers_result_t
10289lpfc_io_slot_reset_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010290{
James Smart51ef4c22007-08-02 11:10:31 -040010291 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10292 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010293 struct lpfc_sli *psli = &phba->sli;
James Smart5b75da22008-12-04 22:39:35 -050010294 uint32_t intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010295
10296 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +110010297 if (pci_enable_device_mem(pdev)) {
Linas Vepstas8d63f372007-02-14 14:28:36 -060010298 printk(KERN_ERR "lpfc: Cannot re-enable "
10299 "PCI device after reset.\n");
10300 return PCI_ERS_RESULT_DISCONNECT;
10301 }
10302
James Smart97207482008-12-04 22:39:19 -050010303 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050010304
10305 /*
10306 * As the new kernel behavior of pci_restore_state() API call clears
10307 * device saved_state flag, need to save the restored state again.
10308 */
10309 pci_save_state(pdev);
10310
James Smart97207482008-12-04 22:39:19 -050010311 if (pdev->is_busmaster)
10312 pci_set_master(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010313
James Smart92d7f7b2007-06-17 19:56:38 -050010314 spin_lock_irq(&phba->hbalock);
James Smart3772a992009-05-22 14:50:54 -040010315 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
James Smart92d7f7b2007-06-17 19:56:38 -050010316 spin_unlock_irq(&phba->hbalock);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010317
James Smart5b75da22008-12-04 22:39:35 -050010318 /* Configure and enable interrupt */
James Smart3772a992009-05-22 14:50:54 -040010319 intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
James Smart5b75da22008-12-04 22:39:35 -050010320 if (intr_mode == LPFC_INTR_ERROR) {
10321 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10322 "0427 Cannot re-enable interrupt after "
10323 "slot reset.\n");
10324 return PCI_ERS_RESULT_DISCONNECT;
10325 } else
10326 phba->intr_mode = intr_mode;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010327
James Smart75baf692010-06-08 18:31:21 -040010328 /* Take device offline, it will perform cleanup */
James Smart618a5232012-06-12 13:54:36 -040010329 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010330 lpfc_offline(phba);
10331 lpfc_sli_brdrestart(phba);
10332
James Smart5b75da22008-12-04 22:39:35 -050010333 /* Log the current active interrupt mode */
10334 lpfc_log_intr_mode(phba, phba->intr_mode);
10335
Linas Vepstas8d63f372007-02-14 14:28:36 -060010336 return PCI_ERS_RESULT_RECOVERED;
10337}
10338
10339/**
James Smart3772a992009-05-22 14:50:54 -040010340 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
James Smarte59058c2008-08-24 21:49:00 -040010341 * @pdev: pointer to PCI device
Linas Vepstas8d63f372007-02-14 14:28:36 -060010342 *
James Smart3772a992009-05-22 14:50:54 -040010343 * This routine is called from the PCI subsystem for error handling to device
10344 * with SLI-3 interface spec. It is called when kernel error recovery tells
10345 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10346 * error recovery. After this call, traffic can start to flow from this device
10347 * again.
Linas Vepstas8d63f372007-02-14 14:28:36 -060010348 */
James Smart3772a992009-05-22 14:50:54 -040010349static void
10350lpfc_io_resume_s3(struct pci_dev *pdev)
Linas Vepstas8d63f372007-02-14 14:28:36 -060010351{
James Smart51ef4c22007-08-02 11:10:31 -040010352 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10353 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
Linas Vepstas8d63f372007-02-14 14:28:36 -060010354
James Smarte2af0d22010-03-15 11:25:32 -040010355 /* Bring device online, it will be no-op for non-fatal error resume */
James Smart58da1ff2008-04-07 10:15:56 -040010356 lpfc_online(phba);
James Smart0d878412009-10-02 15:16:56 -040010357
10358 /* Clean up Advanced Error Reporting (AER) if needed */
10359 if (phba->hba_flag & HBA_AER_ENABLED)
10360 pci_cleanup_aer_uncorrect_error_status(pdev);
Linas Vepstas8d63f372007-02-14 14:28:36 -060010361}
10362
James Smart3772a992009-05-22 14:50:54 -040010363/**
James Smartda0436e2009-05-22 14:51:39 -040010364 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
10365 * @phba: pointer to lpfc hba data structure.
10366 *
10367 * returns the number of ELS/CT IOCBs to reserve
10368 **/
10369int
10370lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
10371{
10372 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
10373
James Smartf1126682009-06-10 17:22:44 -040010374 if (phba->sli_rev == LPFC_SLI_REV4) {
10375 if (max_xri <= 100)
James Smart6a9c52c2009-10-02 15:16:51 -040010376 return 10;
James Smartf1126682009-06-10 17:22:44 -040010377 else if (max_xri <= 256)
James Smart6a9c52c2009-10-02 15:16:51 -040010378 return 25;
James Smartf1126682009-06-10 17:22:44 -040010379 else if (max_xri <= 512)
James Smart6a9c52c2009-10-02 15:16:51 -040010380 return 50;
James Smartf1126682009-06-10 17:22:44 -040010381 else if (max_xri <= 1024)
James Smart6a9c52c2009-10-02 15:16:51 -040010382 return 100;
James Smart8a9d2e82012-05-09 21:16:12 -040010383 else if (max_xri <= 1536)
James Smart6a9c52c2009-10-02 15:16:51 -040010384 return 150;
James Smart8a9d2e82012-05-09 21:16:12 -040010385 else if (max_xri <= 2048)
10386 return 200;
10387 else
10388 return 250;
James Smartf1126682009-06-10 17:22:44 -040010389 } else
10390 return 0;
James Smartda0436e2009-05-22 14:51:39 -040010391}
10392
10393/**
James Smart895427b2017-02-12 13:52:30 -080010394 * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve
10395 * @phba: pointer to lpfc hba data structure.
10396 *
10397 * returns the number of ELS/CT
10398 **/
10399int
10400lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba)
10401{
10402 int max_xri = lpfc_sli4_get_els_iocb_cnt(phba);
10403
10404 return max_xri;
10405}
10406
10407
10408/**
James Smart52d52442011-05-24 11:42:45 -040010409 * lpfc_write_firmware - attempt to write a firmware image to the port
James Smart52d52442011-05-24 11:42:45 -040010410 * @fw: pointer to firmware image returned from request_firmware.
James Smartce396282012-09-29 11:30:56 -040010411 * @phba: pointer to lpfc hba data structure.
James Smart52d52442011-05-24 11:42:45 -040010412 *
James Smart52d52442011-05-24 11:42:45 -040010413 **/
James Smartce396282012-09-29 11:30:56 -040010414static void
10415lpfc_write_firmware(const struct firmware *fw, void *context)
James Smart52d52442011-05-24 11:42:45 -040010416{
James Smartce396282012-09-29 11:30:56 -040010417 struct lpfc_hba *phba = (struct lpfc_hba *)context;
James Smart6b5151f2012-01-18 16:24:06 -050010418 char fwrev[FW_REV_STR_SIZE];
James Smartce396282012-09-29 11:30:56 -040010419 struct lpfc_grp_hdr *image;
James Smart52d52442011-05-24 11:42:45 -040010420 struct list_head dma_buffer_list;
10421 int i, rc = 0;
10422 struct lpfc_dmabuf *dmabuf, *next;
10423 uint32_t offset = 0, temp_offset = 0;
James Smart6b6ef5d2016-10-13 15:06:17 -070010424 uint32_t magic_number, ftype, fid, fsize;
James Smart52d52442011-05-24 11:42:45 -040010425
James Smartc71ab862012-10-31 14:44:33 -040010426 /* It can be null in no-wait mode, sanity check */
James Smartce396282012-09-29 11:30:56 -040010427 if (!fw) {
10428 rc = -ENXIO;
10429 goto out;
10430 }
10431 image = (struct lpfc_grp_hdr *)fw->data;
10432
James Smart6b6ef5d2016-10-13 15:06:17 -070010433 magic_number = be32_to_cpu(image->magic_number);
10434 ftype = bf_get_be32(lpfc_grp_hdr_file_type, image);
10435 fid = bf_get_be32(lpfc_grp_hdr_id, image),
10436 fsize = be32_to_cpu(image->size);
10437
James Smart52d52442011-05-24 11:42:45 -040010438 INIT_LIST_HEAD(&dma_buffer_list);
James Smart6b6ef5d2016-10-13 15:06:17 -070010439 if ((magic_number != LPFC_GROUP_OJECT_MAGIC_G5 &&
10440 magic_number != LPFC_GROUP_OJECT_MAGIC_G6) ||
10441 ftype != LPFC_FILE_TYPE_GROUP || fsize != fw->size) {
James Smart52d52442011-05-24 11:42:45 -040010442 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10443 "3022 Invalid FW image found. "
Arnd Bergmannefe583c2016-10-17 14:35:46 +020010444 "Magic:%x Type:%x ID:%x Size %d %zd\n",
James Smart6b6ef5d2016-10-13 15:06:17 -070010445 magic_number, ftype, fid, fsize, fw->size);
James Smartce396282012-09-29 11:30:56 -040010446 rc = -EINVAL;
10447 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010448 }
10449 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart88a2cfb2011-07-22 18:36:33 -040010450 if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) {
James Smart52d52442011-05-24 11:42:45 -040010451 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartce396282012-09-29 11:30:56 -040010452 "3023 Updating Firmware, Current Version:%s "
James Smart52d52442011-05-24 11:42:45 -040010453 "New Version:%s\n",
James Smart88a2cfb2011-07-22 18:36:33 -040010454 fwrev, image->revision);
James Smart52d52442011-05-24 11:42:45 -040010455 for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) {
10456 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
10457 GFP_KERNEL);
10458 if (!dmabuf) {
10459 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040010460 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010461 }
10462 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
10463 SLI4_PAGE_SIZE,
10464 &dmabuf->phys,
10465 GFP_KERNEL);
10466 if (!dmabuf->virt) {
10467 kfree(dmabuf);
10468 rc = -ENOMEM;
James Smartce396282012-09-29 11:30:56 -040010469 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010470 }
10471 list_add_tail(&dmabuf->list, &dma_buffer_list);
10472 }
10473 while (offset < fw->size) {
10474 temp_offset = offset;
10475 list_for_each_entry(dmabuf, &dma_buffer_list, list) {
James Smart079b5c92011-08-21 21:48:49 -040010476 if (temp_offset + SLI4_PAGE_SIZE > fw->size) {
James Smart52d52442011-05-24 11:42:45 -040010477 memcpy(dmabuf->virt,
10478 fw->data + temp_offset,
James Smart079b5c92011-08-21 21:48:49 -040010479 fw->size - temp_offset);
10480 temp_offset = fw->size;
James Smart52d52442011-05-24 11:42:45 -040010481 break;
10482 }
James Smart52d52442011-05-24 11:42:45 -040010483 memcpy(dmabuf->virt, fw->data + temp_offset,
10484 SLI4_PAGE_SIZE);
James Smart88a2cfb2011-07-22 18:36:33 -040010485 temp_offset += SLI4_PAGE_SIZE;
James Smart52d52442011-05-24 11:42:45 -040010486 }
10487 rc = lpfc_wr_object(phba, &dma_buffer_list,
10488 (fw->size - offset), &offset);
James Smartce396282012-09-29 11:30:56 -040010489 if (rc)
10490 goto release_out;
James Smart52d52442011-05-24 11:42:45 -040010491 }
10492 rc = offset;
10493 }
James Smartce396282012-09-29 11:30:56 -040010494
10495release_out:
James Smart52d52442011-05-24 11:42:45 -040010496 list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) {
10497 list_del(&dmabuf->list);
10498 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
10499 dmabuf->virt, dmabuf->phys);
10500 kfree(dmabuf);
10501 }
James Smartce396282012-09-29 11:30:56 -040010502 release_firmware(fw);
10503out:
10504 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartc71ab862012-10-31 14:44:33 -040010505 "3024 Firmware update done: %d.\n", rc);
James Smartce396282012-09-29 11:30:56 -040010506 return;
James Smart52d52442011-05-24 11:42:45 -040010507}
10508
10509/**
James Smartc71ab862012-10-31 14:44:33 -040010510 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
10511 * @phba: pointer to lpfc hba data structure.
10512 *
10513 * This routine is called to perform Linux generic firmware upgrade on device
10514 * that supports such feature.
10515 **/
10516int
10517lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade)
10518{
10519 uint8_t file_name[ELX_MODEL_NAME_SIZE];
10520 int ret;
10521 const struct firmware *fw;
10522
10523 /* Only supported on SLI4 interface type 2 for now */
10524 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
10525 LPFC_SLI_INTF_IF_TYPE_2)
10526 return -EPERM;
10527
10528 snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName);
10529
10530 if (fw_upgrade == INT_FW_UPGRADE) {
10531 ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
10532 file_name, &phba->pcidev->dev,
10533 GFP_KERNEL, (void *)phba,
10534 lpfc_write_firmware);
10535 } else if (fw_upgrade == RUN_FW_UPGRADE) {
10536 ret = request_firmware(&fw, file_name, &phba->pcidev->dev);
10537 if (!ret)
10538 lpfc_write_firmware(fw, (void *)phba);
10539 } else {
10540 ret = -EINVAL;
10541 }
10542
10543 return ret;
10544}
10545
10546/**
James Smartda0436e2009-05-22 14:51:39 -040010547 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
10548 * @pdev: pointer to PCI device
10549 * @pid: pointer to PCI device identifier
10550 *
10551 * This routine is called from the kernel's PCI subsystem to device with
10552 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10553 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
10554 * information of the device and driver to see if the driver state that it
10555 * can support this kind of device. If the match is successful, the driver
10556 * core invokes this routine. If this routine determines it can claim the HBA,
10557 * it does all the initialization that it needs to do to handle the HBA
10558 * properly.
10559 *
10560 * Return code
10561 * 0 - driver can claim the device
10562 * negative value - driver can not claim the device
10563 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010564static int
James Smartda0436e2009-05-22 14:51:39 -040010565lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
10566{
10567 struct lpfc_hba *phba;
10568 struct lpfc_vport *vport = NULL;
James Smart6669f9b2009-10-02 15:16:45 -040010569 struct Scsi_Host *shost = NULL;
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040010570 int error;
James Smartda0436e2009-05-22 14:51:39 -040010571 uint32_t cfg_mode, intr_mode;
James Smartda0436e2009-05-22 14:51:39 -040010572
10573 /* Allocate memory for HBA structure */
10574 phba = lpfc_hba_alloc(pdev);
10575 if (!phba)
10576 return -ENOMEM;
10577
10578 /* Perform generic PCI device enabling operation */
10579 error = lpfc_enable_pci_dev(phba);
James Smart079b5c92011-08-21 21:48:49 -040010580 if (error)
James Smartda0436e2009-05-22 14:51:39 -040010581 goto out_free_phba;
James Smartda0436e2009-05-22 14:51:39 -040010582
10583 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
10584 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
10585 if (error)
10586 goto out_disable_pci_dev;
10587
10588 /* Set up SLI-4 specific device PCI memory space */
10589 error = lpfc_sli4_pci_mem_setup(phba);
10590 if (error) {
10591 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10592 "1410 Failed to set up pci memory space.\n");
10593 goto out_disable_pci_dev;
10594 }
10595
James Smartda0436e2009-05-22 14:51:39 -040010596 /* Set up SLI-4 Specific device driver resources */
10597 error = lpfc_sli4_driver_resource_setup(phba);
10598 if (error) {
10599 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10600 "1412 Failed to set up driver resource.\n");
10601 goto out_unset_pci_mem_s4;
10602 }
10603
10604 /* Initialize and populate the iocb list per host */
James Smart2a9bf3d2010-06-07 15:24:45 -040010605
10606 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10607 "2821 initialize iocb list %d.\n",
10608 phba->cfg_iocb_cnt*1024);
10609 error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024);
10610
James Smartda0436e2009-05-22 14:51:39 -040010611 if (error) {
10612 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10613 "1413 Failed to initialize iocb list.\n");
10614 goto out_unset_driver_resource_s4;
10615 }
10616
James Smart19ca7602010-11-20 23:11:55 -050010617 INIT_LIST_HEAD(&phba->active_rrq_list);
James Smart7d791df2011-07-22 18:37:52 -040010618 INIT_LIST_HEAD(&phba->fcf.fcf_pri_list);
James Smart19ca7602010-11-20 23:11:55 -050010619
James Smartda0436e2009-05-22 14:51:39 -040010620 /* Set up common device driver resources */
10621 error = lpfc_setup_driver_resource_phase2(phba);
10622 if (error) {
10623 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10624 "1414 Failed to set up driver resource.\n");
10625 goto out_free_iocb_list;
10626 }
10627
James Smart079b5c92011-08-21 21:48:49 -040010628 /* Get the default values for Model Name and Description */
10629 lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
10630
James Smartda0436e2009-05-22 14:51:39 -040010631 /* Create SCSI host to the physical port */
10632 error = lpfc_create_shost(phba);
10633 if (error) {
10634 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10635 "1415 Failed to create scsi host.\n");
10636 goto out_unset_driver_resource;
10637 }
10638
10639 /* Configure sysfs attributes */
10640 vport = phba->pport;
10641 error = lpfc_alloc_sysfs_attr(vport);
10642 if (error) {
10643 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10644 "1416 Failed to allocate sysfs attr\n");
10645 goto out_destroy_shost;
10646 }
10647
James Smart6669f9b2009-10-02 15:16:45 -040010648 shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
James Smartda0436e2009-05-22 14:51:39 -040010649 /* Now, trying to enable interrupt and bring up the device */
10650 cfg_mode = phba->cfg_use_msi;
James Smartda0436e2009-05-22 14:51:39 -040010651
James Smart7b15db32013-01-03 15:43:29 -050010652 /* Put device to a known state before enabling interrupt */
10653 lpfc_stop_port(phba);
James Smart895427b2017-02-12 13:52:30 -080010654
James Smart7b15db32013-01-03 15:43:29 -050010655 /* Configure and enable interrupt */
10656 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
10657 if (intr_mode == LPFC_INTR_ERROR) {
10658 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10659 "0426 Failed to enable interrupt.\n");
10660 error = -ENODEV;
10661 goto out_free_sysfs_attr;
James Smartda0436e2009-05-22 14:51:39 -040010662 }
James Smart7b15db32013-01-03 15:43:29 -050010663 /* Default to single EQ for non-MSI-X */
James Smart895427b2017-02-12 13:52:30 -080010664 if (phba->intr_type != MSIX) {
10665 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)
10666 phba->cfg_fcp_io_channel = 1;
10667 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
10668 phba->cfg_nvme_io_channel = 1;
10669 phba->io_channel_irqs = 1;
10670 }
10671
10672
James Smart7b15db32013-01-03 15:43:29 -050010673 /* Set up SLI-4 HBA */
10674 if (lpfc_sli4_hba_setup(phba)) {
10675 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10676 "1421 Failed to set up hba\n");
10677 error = -ENODEV;
10678 goto out_disable_intr;
10679 }
10680
10681 /* Log the current active interrupt mode */
10682 phba->intr_mode = intr_mode;
10683 lpfc_log_intr_mode(phba, intr_mode);
James Smartda0436e2009-05-22 14:51:39 -040010684
10685 /* Perform post initialization setup */
10686 lpfc_post_init_setup(phba);
10687
James Smart895427b2017-02-12 13:52:30 -080010688 /* todo: init: register port with nvme */
10689
James Smartc71ab862012-10-31 14:44:33 -040010690 /* check for firmware upgrade or downgrade */
10691 if (phba->cfg_request_firmware_upgrade)
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -040010692 lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE);
James Smart52d52442011-05-24 11:42:45 -040010693
James Smart1c6834a2009-07-19 10:01:26 -040010694 /* Check if there are static vports to be created. */
10695 lpfc_create_static_vport(phba);
James Smartda0436e2009-05-22 14:51:39 -040010696 return 0;
10697
10698out_disable_intr:
10699 lpfc_sli4_disable_intr(phba);
10700out_free_sysfs_attr:
10701 lpfc_free_sysfs_attr(vport);
10702out_destroy_shost:
10703 lpfc_destroy_shost(phba);
10704out_unset_driver_resource:
10705 lpfc_unset_driver_resource_phase2(phba);
10706out_free_iocb_list:
10707 lpfc_free_iocb_list(phba);
10708out_unset_driver_resource_s4:
10709 lpfc_sli4_driver_resource_unset(phba);
10710out_unset_pci_mem_s4:
10711 lpfc_sli4_pci_mem_unset(phba);
10712out_disable_pci_dev:
10713 lpfc_disable_pci_dev(phba);
James Smart6669f9b2009-10-02 15:16:45 -040010714 if (shost)
10715 scsi_host_put(shost);
James Smartda0436e2009-05-22 14:51:39 -040010716out_free_phba:
10717 lpfc_hba_free(phba);
10718 return error;
10719}
10720
10721/**
10722 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
10723 * @pdev: pointer to PCI device
10724 *
10725 * This routine is called from the kernel's PCI subsystem to device with
10726 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10727 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10728 * device to be removed from the PCI subsystem properly.
10729 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010730static void
James Smartda0436e2009-05-22 14:51:39 -040010731lpfc_pci_remove_one_s4(struct pci_dev *pdev)
10732{
10733 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10734 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
10735 struct lpfc_vport **vports;
10736 struct lpfc_hba *phba = vport->phba;
10737 int i;
10738
10739 /* Mark the device unloading flag */
10740 spin_lock_irq(&phba->hbalock);
10741 vport->load_flag |= FC_UNLOADING;
10742 spin_unlock_irq(&phba->hbalock);
10743
10744 /* Free the HBA sysfs attributes */
10745 lpfc_free_sysfs_attr(vport);
10746
10747 /* Release all the vports against this physical port */
10748 vports = lpfc_create_vport_work_array(phba);
10749 if (vports != NULL)
James Smart587a37f2012-05-09 21:16:03 -040010750 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
10751 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
10752 continue;
James Smartda0436e2009-05-22 14:51:39 -040010753 fc_vport_terminate(vports[i]->fc_vport);
James Smart587a37f2012-05-09 21:16:03 -040010754 }
James Smartda0436e2009-05-22 14:51:39 -040010755 lpfc_destroy_vport_work_array(phba, vports);
10756
10757 /* Remove FC host and then SCSI host with the physical port */
10758 fc_remove_host(shost);
10759 scsi_remove_host(shost);
10760
James Smart895427b2017-02-12 13:52:30 -080010761 /* Perform ndlp cleanup on the physical port. The nvme localport
10762 * is destroyed after to ensure all rports are io-disabled.
10763 */
James Smartda0436e2009-05-22 14:51:39 -040010764 lpfc_cleanup(vport);
James Smart895427b2017-02-12 13:52:30 -080010765 /* todo: init: unregister port with nvme */
James Smartda0436e2009-05-22 14:51:39 -040010766
10767 /*
10768 * Bring down the SLI Layer. This step disables all interrupts,
10769 * clears the rings, discards all mailbox commands, and resets
10770 * the HBA FCoE function.
10771 */
10772 lpfc_debugfs_terminate(vport);
10773 lpfc_sli4_hba_unset(phba);
10774
10775 spin_lock_irq(&phba->hbalock);
10776 list_del_init(&vport->listentry);
10777 spin_unlock_irq(&phba->hbalock);
10778
James Smart3677a3a2010-09-29 11:19:14 -040010779 /* Perform scsi free before driver resource_unset since scsi
James Smartda0436e2009-05-22 14:51:39 -040010780 * buffers are released to their corresponding pools here.
10781 */
10782 lpfc_scsi_free(phba);
James Smart895427b2017-02-12 13:52:30 -080010783 lpfc_nvme_free(phba);
James Smart67d12732012-08-03 12:36:13 -040010784
James Smartda0436e2009-05-22 14:51:39 -040010785 lpfc_sli4_driver_resource_unset(phba);
10786
10787 /* Unmap adapter Control and Doorbell registers */
10788 lpfc_sli4_pci_mem_unset(phba);
10789
10790 /* Release PCI resources and disable device's PCI function */
10791 scsi_host_put(shost);
10792 lpfc_disable_pci_dev(phba);
10793
10794 /* Finally, free the driver's device data structure */
10795 lpfc_hba_free(phba);
10796
10797 return;
10798}
10799
10800/**
10801 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
10802 * @pdev: pointer to PCI device
10803 * @msg: power management message
10804 *
10805 * This routine is called from the kernel's PCI subsystem to support system
10806 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
10807 * this method, it quiesces the device by stopping the driver's worker
10808 * thread for the device, turning off device's interrupt and DMA, and bring
10809 * the device offline. Note that as the driver implements the minimum PM
10810 * requirements to a power-aware driver's PM support for suspend/resume -- all
10811 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
10812 * method call will be treated as SUSPEND and the driver will fully
10813 * reinitialize its device during resume() method call, the driver will set
10814 * device to PCI_D3hot state in PCI config space instead of setting it
10815 * according to the @msg provided by the PM.
10816 *
10817 * Return code
10818 * 0 - driver suspended the device
10819 * Error otherwise
10820 **/
10821static int
10822lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
10823{
10824 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10825 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10826
10827 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smart75baf692010-06-08 18:31:21 -040010828 "2843 PCI device Power Management suspend.\n");
James Smartda0436e2009-05-22 14:51:39 -040010829
10830 /* Bring down the device */
James Smart618a5232012-06-12 13:54:36 -040010831 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smartda0436e2009-05-22 14:51:39 -040010832 lpfc_offline(phba);
10833 kthread_stop(phba->worker_thread);
10834
10835 /* Disable interrupt from device */
10836 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040010837 lpfc_sli4_queue_destroy(phba);
James Smartda0436e2009-05-22 14:51:39 -040010838
10839 /* Save device state to PCI config space */
10840 pci_save_state(pdev);
10841 pci_set_power_state(pdev, PCI_D3hot);
10842
10843 return 0;
10844}
10845
10846/**
10847 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
10848 * @pdev: pointer to PCI device
10849 *
10850 * This routine is called from the kernel's PCI subsystem to support system
10851 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
10852 * this method, it restores the device's PCI config space state and fully
10853 * reinitializes the device and brings it online. Note that as the driver
10854 * implements the minimum PM requirements to a power-aware driver's PM for
10855 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10856 * to the suspend() method call will be treated as SUSPEND and the driver
10857 * will fully reinitialize its device during resume() method call, the device
10858 * will be set to PCI_D0 directly in PCI config space before restoring the
10859 * state.
10860 *
10861 * Return code
10862 * 0 - driver suspended the device
10863 * Error otherwise
10864 **/
10865static int
10866lpfc_pci_resume_one_s4(struct pci_dev *pdev)
10867{
10868 struct Scsi_Host *shost = pci_get_drvdata(pdev);
10869 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
10870 uint32_t intr_mode;
10871 int error;
10872
10873 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
10874 "0292 PCI device Power Management resume.\n");
10875
10876 /* Restore device state from PCI config space */
10877 pci_set_power_state(pdev, PCI_D0);
10878 pci_restore_state(pdev);
James Smart1dfb5a42010-02-12 14:40:50 -050010879
10880 /*
10881 * As the new kernel behavior of pci_restore_state() API call clears
10882 * device saved_state flag, need to save the restored state again.
10883 */
10884 pci_save_state(pdev);
10885
James Smartda0436e2009-05-22 14:51:39 -040010886 if (pdev->is_busmaster)
10887 pci_set_master(pdev);
10888
10889 /* Startup the kernel thread for this host adapter. */
10890 phba->worker_thread = kthread_run(lpfc_do_work, phba,
10891 "lpfc_worker_%d", phba->brd_no);
10892 if (IS_ERR(phba->worker_thread)) {
10893 error = PTR_ERR(phba->worker_thread);
10894 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10895 "0293 PM resume failed to start worker "
10896 "thread: error=x%x.\n", error);
10897 return error;
10898 }
10899
10900 /* Configure and enable interrupt */
10901 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
10902 if (intr_mode == LPFC_INTR_ERROR) {
10903 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10904 "0294 PM resume Failed to enable interrupt\n");
10905 return -EIO;
10906 } else
10907 phba->intr_mode = intr_mode;
10908
10909 /* Restart HBA and bring it online */
10910 lpfc_sli_brdrestart(phba);
10911 lpfc_online(phba);
10912
10913 /* Log the current active interrupt mode */
10914 lpfc_log_intr_mode(phba, phba->intr_mode);
10915
10916 return 0;
10917}
10918
10919/**
James Smart75baf692010-06-08 18:31:21 -040010920 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
10921 * @phba: pointer to lpfc hba data structure.
10922 *
10923 * This routine is called to prepare the SLI4 device for PCI slot recover. It
10924 * aborts all the outstanding SCSI I/Os to the pci device.
10925 **/
10926static void
10927lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba)
10928{
James Smart75baf692010-06-08 18:31:21 -040010929 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10930 "2828 PCI channel I/O abort preparing for recovery\n");
10931 /*
10932 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10933 * and let the SCSI mid-layer to retry them to recover.
10934 */
James Smartdb55fba2014-04-04 13:52:02 -040010935 lpfc_sli_abort_fcp_rings(phba);
James Smart75baf692010-06-08 18:31:21 -040010936}
10937
10938/**
10939 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
10940 * @phba: pointer to lpfc hba data structure.
10941 *
10942 * This routine is called to prepare the SLI4 device for PCI slot reset. It
10943 * disables the device interrupt and pci device, and aborts the internal FCP
10944 * pending I/Os.
10945 **/
10946static void
10947lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
10948{
10949 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10950 "2826 PCI channel disable preparing for reset\n");
10951
10952 /* Block any management I/Os to the device */
James Smart618a5232012-06-12 13:54:36 -040010953 lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT);
James Smart75baf692010-06-08 18:31:21 -040010954
10955 /* Block all SCSI devices' I/Os on the host */
10956 lpfc_scsi_dev_block(phba);
10957
James Smartea714f32013-04-17 20:18:47 -040010958 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10959 lpfc_sli_flush_fcp_rings(phba);
10960
James Smart75baf692010-06-08 18:31:21 -040010961 /* stop all timers */
10962 lpfc_stop_hba_timers(phba);
10963
10964 /* Disable interrupt and pci device */
10965 lpfc_sli4_disable_intr(phba);
James Smart5350d872011-10-10 21:33:49 -040010966 lpfc_sli4_queue_destroy(phba);
James Smart75baf692010-06-08 18:31:21 -040010967 pci_disable_device(phba->pcidev);
James Smart75baf692010-06-08 18:31:21 -040010968}
10969
10970/**
10971 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
10972 * @phba: pointer to lpfc hba data structure.
10973 *
10974 * This routine is called to prepare the SLI4 device for PCI slot permanently
10975 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10976 * pending I/Os.
10977 **/
10978static void
10979lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba)
10980{
10981 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
10982 "2827 PCI channel permanent disable for failure\n");
10983
10984 /* Block all SCSI devices' I/Os on the host */
10985 lpfc_scsi_dev_block(phba);
10986
10987 /* stop all timers */
10988 lpfc_stop_hba_timers(phba);
10989
10990 /* Clean up all driver's outstanding SCSI I/Os */
10991 lpfc_sli_flush_fcp_rings(phba);
10992}
10993
10994/**
James Smartda0436e2009-05-22 14:51:39 -040010995 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
10996 * @pdev: pointer to PCI device.
10997 * @state: the current PCI connection state.
10998 *
10999 * This routine is called from the PCI subsystem for error handling to device
11000 * with SLI-4 interface spec. This function is called by the PCI subsystem
11001 * after a PCI bus error affecting this device has been detected. When this
11002 * function is invoked, it will need to stop all the I/Os and interrupt(s)
11003 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
11004 * for the PCI subsystem to perform proper recovery as desired.
11005 *
11006 * Return codes
11007 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11008 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11009 **/
11010static pci_ers_result_t
11011lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
11012{
James Smart75baf692010-06-08 18:31:21 -040011013 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11014 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11015
11016 switch (state) {
11017 case pci_channel_io_normal:
11018 /* Non-fatal error, prepare for recovery */
11019 lpfc_sli4_prep_dev_for_recover(phba);
11020 return PCI_ERS_RESULT_CAN_RECOVER;
11021 case pci_channel_io_frozen:
11022 /* Fatal error, prepare for slot reset */
11023 lpfc_sli4_prep_dev_for_reset(phba);
11024 return PCI_ERS_RESULT_NEED_RESET;
11025 case pci_channel_io_perm_failure:
11026 /* Permanent failure, prepare for device down */
11027 lpfc_sli4_prep_dev_for_perm_failure(phba);
11028 return PCI_ERS_RESULT_DISCONNECT;
11029 default:
11030 /* Unknown state, prepare and request slot reset */
11031 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11032 "2825 Unknown PCI error state: x%x\n", state);
11033 lpfc_sli4_prep_dev_for_reset(phba);
11034 return PCI_ERS_RESULT_NEED_RESET;
11035 }
James Smartda0436e2009-05-22 14:51:39 -040011036}
11037
11038/**
11039 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
11040 * @pdev: pointer to PCI device.
11041 *
11042 * This routine is called from the PCI subsystem for error handling to device
11043 * with SLI-4 interface spec. It is called after PCI bus has been reset to
11044 * restart the PCI card from scratch, as if from a cold-boot. During the
11045 * PCI subsystem error recovery, after the driver returns
11046 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
11047 * recovery and then call this routine before calling the .resume method to
11048 * recover the device. This function will initialize the HBA device, enable
11049 * the interrupt, but it will just put the HBA to offline state without
11050 * passing any I/O traffic.
11051 *
11052 * Return codes
11053 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11054 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11055 */
11056static pci_ers_result_t
11057lpfc_io_slot_reset_s4(struct pci_dev *pdev)
11058{
James Smart75baf692010-06-08 18:31:21 -040011059 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11060 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11061 struct lpfc_sli *psli = &phba->sli;
11062 uint32_t intr_mode;
11063
11064 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
11065 if (pci_enable_device_mem(pdev)) {
11066 printk(KERN_ERR "lpfc: Cannot re-enable "
11067 "PCI device after reset.\n");
11068 return PCI_ERS_RESULT_DISCONNECT;
11069 }
11070
11071 pci_restore_state(pdev);
James Smart0a96e972011-07-22 18:37:28 -040011072
11073 /*
11074 * As the new kernel behavior of pci_restore_state() API call clears
11075 * device saved_state flag, need to save the restored state again.
11076 */
11077 pci_save_state(pdev);
11078
James Smart75baf692010-06-08 18:31:21 -040011079 if (pdev->is_busmaster)
11080 pci_set_master(pdev);
11081
11082 spin_lock_irq(&phba->hbalock);
11083 psli->sli_flag &= ~LPFC_SLI_ACTIVE;
11084 spin_unlock_irq(&phba->hbalock);
11085
11086 /* Configure and enable interrupt */
11087 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
11088 if (intr_mode == LPFC_INTR_ERROR) {
11089 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11090 "2824 Cannot re-enable interrupt after "
11091 "slot reset.\n");
11092 return PCI_ERS_RESULT_DISCONNECT;
11093 } else
11094 phba->intr_mode = intr_mode;
11095
11096 /* Log the current active interrupt mode */
11097 lpfc_log_intr_mode(phba, phba->intr_mode);
11098
James Smartda0436e2009-05-22 14:51:39 -040011099 return PCI_ERS_RESULT_RECOVERED;
11100}
11101
11102/**
11103 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
11104 * @pdev: pointer to PCI device
11105 *
11106 * This routine is called from the PCI subsystem for error handling to device
11107 * with SLI-4 interface spec. It is called when kernel error recovery tells
11108 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
11109 * error recovery. After this call, traffic can start to flow from this device
11110 * again.
11111 **/
11112static void
11113lpfc_io_resume_s4(struct pci_dev *pdev)
11114{
James Smart75baf692010-06-08 18:31:21 -040011115 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11116 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11117
11118 /*
11119 * In case of slot reset, as function reset is performed through
11120 * mailbox command which needs DMA to be enabled, this operation
11121 * has to be moved to the io resume phase. Taking device offline
11122 * will perform the necessary cleanup.
11123 */
11124 if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) {
11125 /* Perform device reset */
James Smart618a5232012-06-12 13:54:36 -040011126 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart75baf692010-06-08 18:31:21 -040011127 lpfc_offline(phba);
11128 lpfc_sli_brdrestart(phba);
11129 /* Bring the device back online */
11130 lpfc_online(phba);
11131 }
11132
11133 /* Clean up Advanced Error Reporting (AER) if needed */
11134 if (phba->hba_flag & HBA_AER_ENABLED)
11135 pci_cleanup_aer_uncorrect_error_status(pdev);
James Smartda0436e2009-05-22 14:51:39 -040011136}
11137
11138/**
James Smart3772a992009-05-22 14:50:54 -040011139 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
11140 * @pdev: pointer to PCI device
11141 * @pid: pointer to PCI device identifier
11142 *
11143 * This routine is to be registered to the kernel's PCI subsystem. When an
11144 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
11145 * at PCI device-specific information of the device and driver to see if the
11146 * driver state that it can support this kind of device. If the match is
11147 * successful, the driver core invokes this routine. This routine dispatches
11148 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
11149 * do all the initialization that it needs to do to handle the HBA device
11150 * properly.
11151 *
11152 * Return code
11153 * 0 - driver can claim the device
11154 * negative value - driver can not claim the device
11155 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011156static int
James Smart3772a992009-05-22 14:50:54 -040011157lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
11158{
11159 int rc;
James Smart8fa38512009-07-19 10:01:03 -040011160 struct lpfc_sli_intf intf;
James Smart3772a992009-05-22 14:50:54 -040011161
James Smart28baac72010-02-12 14:42:03 -050011162 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
James Smart3772a992009-05-22 14:50:54 -040011163 return -ENODEV;
11164
James Smart8fa38512009-07-19 10:01:03 -040011165 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
James Smart28baac72010-02-12 14:42:03 -050011166 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
James Smartda0436e2009-05-22 14:51:39 -040011167 rc = lpfc_pci_probe_one_s4(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040011168 else
James Smart3772a992009-05-22 14:50:54 -040011169 rc = lpfc_pci_probe_one_s3(pdev, pid);
James Smart8fa38512009-07-19 10:01:03 -040011170
James Smart3772a992009-05-22 14:50:54 -040011171 return rc;
11172}
11173
11174/**
11175 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
11176 * @pdev: pointer to PCI device
11177 *
11178 * This routine is to be registered to the kernel's PCI subsystem. When an
11179 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
11180 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
11181 * remove routine, which will perform all the necessary cleanup for the
11182 * device to be removed from the PCI subsystem properly.
11183 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011184static void
James Smart3772a992009-05-22 14:50:54 -040011185lpfc_pci_remove_one(struct pci_dev *pdev)
11186{
11187 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11188 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11189
11190 switch (phba->pci_dev_grp) {
11191 case LPFC_PCI_DEV_LP:
11192 lpfc_pci_remove_one_s3(pdev);
11193 break;
James Smartda0436e2009-05-22 14:51:39 -040011194 case LPFC_PCI_DEV_OC:
11195 lpfc_pci_remove_one_s4(pdev);
11196 break;
James Smart3772a992009-05-22 14:50:54 -040011197 default:
11198 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11199 "1424 Invalid PCI device group: 0x%x\n",
11200 phba->pci_dev_grp);
11201 break;
11202 }
11203 return;
11204}
11205
11206/**
11207 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
11208 * @pdev: pointer to PCI device
11209 * @msg: power management message
11210 *
11211 * This routine is to be registered to the kernel's PCI subsystem to support
11212 * system Power Management (PM). When PM invokes this method, it dispatches
11213 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
11214 * suspend the device.
11215 *
11216 * Return code
11217 * 0 - driver suspended the device
11218 * Error otherwise
11219 **/
11220static int
11221lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
11222{
11223 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11224 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11225 int rc = -ENODEV;
11226
11227 switch (phba->pci_dev_grp) {
11228 case LPFC_PCI_DEV_LP:
11229 rc = lpfc_pci_suspend_one_s3(pdev, msg);
11230 break;
James Smartda0436e2009-05-22 14:51:39 -040011231 case LPFC_PCI_DEV_OC:
11232 rc = lpfc_pci_suspend_one_s4(pdev, msg);
11233 break;
James Smart3772a992009-05-22 14:50:54 -040011234 default:
11235 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11236 "1425 Invalid PCI device group: 0x%x\n",
11237 phba->pci_dev_grp);
11238 break;
11239 }
11240 return rc;
11241}
11242
11243/**
11244 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
11245 * @pdev: pointer to PCI device
11246 *
11247 * This routine is to be registered to the kernel's PCI subsystem to support
11248 * system Power Management (PM). When PM invokes this method, it dispatches
11249 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
11250 * resume the device.
11251 *
11252 * Return code
11253 * 0 - driver suspended the device
11254 * Error otherwise
11255 **/
11256static int
11257lpfc_pci_resume_one(struct pci_dev *pdev)
11258{
11259 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11260 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11261 int rc = -ENODEV;
11262
11263 switch (phba->pci_dev_grp) {
11264 case LPFC_PCI_DEV_LP:
11265 rc = lpfc_pci_resume_one_s3(pdev);
11266 break;
James Smartda0436e2009-05-22 14:51:39 -040011267 case LPFC_PCI_DEV_OC:
11268 rc = lpfc_pci_resume_one_s4(pdev);
11269 break;
James Smart3772a992009-05-22 14:50:54 -040011270 default:
11271 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11272 "1426 Invalid PCI device group: 0x%x\n",
11273 phba->pci_dev_grp);
11274 break;
11275 }
11276 return rc;
11277}
11278
11279/**
11280 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
11281 * @pdev: pointer to PCI device.
11282 * @state: the current PCI connection state.
11283 *
11284 * This routine is registered to the PCI subsystem for error handling. This
11285 * function is called by the PCI subsystem after a PCI bus error affecting
11286 * this device has been detected. When this routine is invoked, it dispatches
11287 * the action to the proper SLI-3 or SLI-4 device error detected handling
11288 * routine, which will perform the proper error detected operation.
11289 *
11290 * Return codes
11291 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
11292 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11293 **/
11294static pci_ers_result_t
11295lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
11296{
11297 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11298 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11299 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11300
11301 switch (phba->pci_dev_grp) {
11302 case LPFC_PCI_DEV_LP:
11303 rc = lpfc_io_error_detected_s3(pdev, state);
11304 break;
James Smartda0436e2009-05-22 14:51:39 -040011305 case LPFC_PCI_DEV_OC:
11306 rc = lpfc_io_error_detected_s4(pdev, state);
11307 break;
James Smart3772a992009-05-22 14:50:54 -040011308 default:
11309 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11310 "1427 Invalid PCI device group: 0x%x\n",
11311 phba->pci_dev_grp);
11312 break;
11313 }
11314 return rc;
11315}
11316
11317/**
11318 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
11319 * @pdev: pointer to PCI device.
11320 *
11321 * This routine is registered to the PCI subsystem for error handling. This
11322 * function is called after PCI bus has been reset to restart the PCI card
11323 * from scratch, as if from a cold-boot. When this routine is invoked, it
11324 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
11325 * routine, which will perform the proper device reset.
11326 *
11327 * Return codes
11328 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
11329 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
11330 **/
11331static pci_ers_result_t
11332lpfc_io_slot_reset(struct pci_dev *pdev)
11333{
11334 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11335 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11336 pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
11337
11338 switch (phba->pci_dev_grp) {
11339 case LPFC_PCI_DEV_LP:
11340 rc = lpfc_io_slot_reset_s3(pdev);
11341 break;
James Smartda0436e2009-05-22 14:51:39 -040011342 case LPFC_PCI_DEV_OC:
11343 rc = lpfc_io_slot_reset_s4(pdev);
11344 break;
James Smart3772a992009-05-22 14:50:54 -040011345 default:
11346 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11347 "1428 Invalid PCI device group: 0x%x\n",
11348 phba->pci_dev_grp);
11349 break;
11350 }
11351 return rc;
11352}
11353
11354/**
11355 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
11356 * @pdev: pointer to PCI device
11357 *
11358 * This routine is registered to the PCI subsystem for error handling. It
11359 * is called when kernel error recovery tells the lpfc driver that it is
11360 * OK to resume normal PCI operation after PCI bus error recovery. When
11361 * this routine is invoked, it dispatches the action to the proper SLI-3
11362 * or SLI-4 device io_resume routine, which will resume the device operation.
11363 **/
11364static void
11365lpfc_io_resume(struct pci_dev *pdev)
11366{
11367 struct Scsi_Host *shost = pci_get_drvdata(pdev);
11368 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
11369
11370 switch (phba->pci_dev_grp) {
11371 case LPFC_PCI_DEV_LP:
11372 lpfc_io_resume_s3(pdev);
11373 break;
James Smartda0436e2009-05-22 14:51:39 -040011374 case LPFC_PCI_DEV_OC:
11375 lpfc_io_resume_s4(pdev);
11376 break;
James Smart3772a992009-05-22 14:50:54 -040011377 default:
11378 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11379 "1429 Invalid PCI device group: 0x%x\n",
11380 phba->pci_dev_grp);
11381 break;
11382 }
11383 return;
11384}
11385
James Smart1ba981f2014-02-20 09:56:45 -050011386/**
11387 * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter
11388 * @phba: pointer to lpfc hba data structure.
11389 *
11390 * This routine checks to see if OAS is supported for this adapter. If
11391 * supported, the configure Flash Optimized Fabric flag is set. Otherwise,
11392 * the enable oas flag is cleared and the pool created for OAS device data
11393 * is destroyed.
11394 *
11395 **/
11396void
11397lpfc_sli4_oas_verify(struct lpfc_hba *phba)
11398{
11399
11400 if (!phba->cfg_EnableXLane)
11401 return;
11402
11403 if (phba->sli4_hba.pc_sli4_params.oas_supported) {
11404 phba->cfg_fof = 1;
11405 } else {
James Smartf38fa0b2014-04-04 13:52:21 -040011406 phba->cfg_fof = 0;
James Smart1ba981f2014-02-20 09:56:45 -050011407 if (phba->device_data_mem_pool)
11408 mempool_destroy(phba->device_data_mem_pool);
11409 phba->device_data_mem_pool = NULL;
11410 }
11411
11412 return;
11413}
11414
11415/**
11416 * lpfc_fof_queue_setup - Set up all the fof queues
11417 * @phba: pointer to lpfc hba data structure.
11418 *
11419 * This routine is invoked to set up all the fof queues for the FC HBA
11420 * operation.
11421 *
11422 * Return codes
11423 * 0 - successful
11424 * -ENOMEM - No available memory
11425 **/
11426int
11427lpfc_fof_queue_setup(struct lpfc_hba *phba)
11428{
James Smart895427b2017-02-12 13:52:30 -080011429 struct lpfc_sli_ring *pring;
James Smart1ba981f2014-02-20 09:56:45 -050011430 int rc;
11431
11432 rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX);
11433 if (rc)
11434 return -ENOMEM;
11435
James Smartf38fa0b2014-04-04 13:52:21 -040011436 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050011437
11438 rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq,
11439 phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP);
11440 if (rc)
11441 goto out_oas_cq;
11442
11443 rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq,
11444 phba->sli4_hba.oas_cq, LPFC_FCP);
11445 if (rc)
11446 goto out_oas_wq;
11447
James Smart895427b2017-02-12 13:52:30 -080011448 /* Bind this CQ/WQ to the NVME ring */
11449 pring = phba->sli4_hba.oas_wq->pring;
11450 pring->sli.sli4.wqp =
11451 (void *)phba->sli4_hba.oas_wq;
11452 phba->sli4_hba.oas_cq->pring = pring;
James Smart1ba981f2014-02-20 09:56:45 -050011453 }
11454
11455 return 0;
11456
11457out_oas_wq:
James Smartf38fa0b2014-04-04 13:52:21 -040011458 lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq);
James Smart1ba981f2014-02-20 09:56:45 -050011459out_oas_cq:
11460 lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq);
11461 return rc;
11462
11463}
11464
11465/**
11466 * lpfc_fof_queue_create - Create all the fof queues
11467 * @phba: pointer to lpfc hba data structure.
11468 *
11469 * This routine is invoked to allocate all the fof queues for the FC HBA
11470 * operation. For each SLI4 queue type, the parameters such as queue entry
11471 * count (queue depth) shall be taken from the module parameter. For now,
11472 * we just use some constant number as place holder.
11473 *
11474 * Return codes
11475 * 0 - successful
11476 * -ENOMEM - No availble memory
11477 * -EIO - The mailbox failed to complete successfully.
11478 **/
11479int
11480lpfc_fof_queue_create(struct lpfc_hba *phba)
11481{
11482 struct lpfc_queue *qdesc;
11483
11484 /* Create FOF EQ */
11485 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
11486 phba->sli4_hba.eq_ecount);
11487 if (!qdesc)
11488 goto out_error;
11489
11490 phba->sli4_hba.fof_eq = qdesc;
11491
James Smartf38fa0b2014-04-04 13:52:21 -040011492 if (phba->cfg_fof) {
James Smart1ba981f2014-02-20 09:56:45 -050011493
11494 /* Create OAS CQ */
11495 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
11496 phba->sli4_hba.cq_ecount);
11497 if (!qdesc)
11498 goto out_error;
11499
11500 phba->sli4_hba.oas_cq = qdesc;
11501
11502 /* Create OAS WQ */
11503 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
11504 phba->sli4_hba.wq_ecount);
11505 if (!qdesc)
11506 goto out_error;
11507
11508 phba->sli4_hba.oas_wq = qdesc;
James Smart895427b2017-02-12 13:52:30 -080011509 list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list);
James Smart1ba981f2014-02-20 09:56:45 -050011510
11511 }
11512 return 0;
11513
11514out_error:
11515 lpfc_fof_queue_destroy(phba);
11516 return -ENOMEM;
11517}
11518
11519/**
11520 * lpfc_fof_queue_destroy - Destroy all the fof queues
11521 * @phba: pointer to lpfc hba data structure.
11522 *
11523 * This routine is invoked to release all the SLI4 queues with the FC HBA
11524 * operation.
11525 *
11526 * Return codes
11527 * 0 - successful
11528 **/
11529int
11530lpfc_fof_queue_destroy(struct lpfc_hba *phba)
11531{
11532 /* Release FOF Event queue */
11533 if (phba->sli4_hba.fof_eq != NULL) {
11534 lpfc_sli4_queue_free(phba->sli4_hba.fof_eq);
11535 phba->sli4_hba.fof_eq = NULL;
11536 }
11537
11538 /* Release OAS Completion queue */
11539 if (phba->sli4_hba.oas_cq != NULL) {
11540 lpfc_sli4_queue_free(phba->sli4_hba.oas_cq);
11541 phba->sli4_hba.oas_cq = NULL;
11542 }
11543
11544 /* Release OAS Work queue */
11545 if (phba->sli4_hba.oas_wq != NULL) {
11546 lpfc_sli4_queue_free(phba->sli4_hba.oas_wq);
11547 phba->sli4_hba.oas_wq = NULL;
11548 }
11549 return 0;
11550}
11551
dea31012005-04-17 16:05:31 -050011552MODULE_DEVICE_TABLE(pci, lpfc_id_table);
11553
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070011554static const struct pci_error_handlers lpfc_err_handler = {
Linas Vepstas8d63f372007-02-14 14:28:36 -060011555 .error_detected = lpfc_io_error_detected,
11556 .slot_reset = lpfc_io_slot_reset,
11557 .resume = lpfc_io_resume,
11558};
11559
dea31012005-04-17 16:05:31 -050011560static struct pci_driver lpfc_driver = {
11561 .name = LPFC_DRIVER_NAME,
11562 .id_table = lpfc_id_table,
11563 .probe = lpfc_pci_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080011564 .remove = lpfc_pci_remove_one,
James Smart3a55b532008-12-04 22:38:54 -050011565 .suspend = lpfc_pci_suspend_one,
James Smart3772a992009-05-22 14:50:54 -040011566 .resume = lpfc_pci_resume_one,
James Smart2e0fef82007-06-17 19:56:36 -050011567 .err_handler = &lpfc_err_handler,
dea31012005-04-17 16:05:31 -050011568};
11569
James Smart3ef6d242012-01-18 16:23:48 -050011570static const struct file_operations lpfc_mgmt_fop = {
Al Viro858feac2013-04-14 22:39:37 -040011571 .owner = THIS_MODULE,
James Smart3ef6d242012-01-18 16:23:48 -050011572};
11573
11574static struct miscdevice lpfc_mgmt_dev = {
11575 .minor = MISC_DYNAMIC_MINOR,
11576 .name = "lpfcmgmt",
11577 .fops = &lpfc_mgmt_fop,
11578};
11579
James Smarte59058c2008-08-24 21:49:00 -040011580/**
James Smart3621a712009-04-06 18:47:14 -040011581 * lpfc_init - lpfc module initialization routine
James Smarte59058c2008-08-24 21:49:00 -040011582 *
11583 * This routine is to be invoked when the lpfc module is loaded into the
11584 * kernel. The special kernel macro module_init() is used to indicate the
11585 * role of this routine to the kernel as lpfc module entry point.
11586 *
11587 * Return codes
11588 * 0 - successful
11589 * -ENOMEM - FC attach transport failed
11590 * all others - failed
11591 */
dea31012005-04-17 16:05:31 -050011592static int __init
11593lpfc_init(void)
11594{
11595 int error = 0;
11596
11597 printk(LPFC_MODULE_DESC "\n");
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040011598 printk(LPFC_COPYRIGHT "\n");
dea31012005-04-17 16:05:31 -050011599
James Smart3ef6d242012-01-18 16:23:48 -050011600 error = misc_register(&lpfc_mgmt_dev);
11601 if (error)
11602 printk(KERN_ERR "Could not register lpfcmgmt device, "
11603 "misc_register returned with status %d", error);
11604
James Smart458c0832016-07-06 12:36:07 -070011605 lpfc_transport_functions.vport_create = lpfc_vport_create;
11606 lpfc_transport_functions.vport_delete = lpfc_vport_delete;
dea31012005-04-17 16:05:31 -050011607 lpfc_transport_template =
11608 fc_attach_transport(&lpfc_transport_functions);
James Smart7ee5d432007-10-27 13:37:17 -040011609 if (lpfc_transport_template == NULL)
dea31012005-04-17 16:05:31 -050011610 return -ENOMEM;
James Smart458c0832016-07-06 12:36:07 -070011611 lpfc_vport_transport_template =
11612 fc_attach_transport(&lpfc_vport_transport_functions);
11613 if (lpfc_vport_transport_template == NULL) {
11614 fc_release_transport(lpfc_transport_template);
11615 return -ENOMEM;
James Smart7ee5d432007-10-27 13:37:17 -040011616 }
James Smart7bb03bb2013-04-17 20:19:16 -040011617
11618 /* Initialize in case vector mapping is needed */
James Smartb246de12013-05-31 17:03:07 -040011619 lpfc_used_cpu = NULL;
James Smart2ea259e2017-02-12 13:52:27 -080011620 lpfc_present_cpu = num_present_cpus();
James Smart7bb03bb2013-04-17 20:19:16 -040011621
dea31012005-04-17 16:05:31 -050011622 error = pci_register_driver(&lpfc_driver);
James Smart92d7f7b2007-06-17 19:56:38 -050011623 if (error) {
dea31012005-04-17 16:05:31 -050011624 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070011625 fc_release_transport(lpfc_vport_transport_template);
James Smart92d7f7b2007-06-17 19:56:38 -050011626 }
dea31012005-04-17 16:05:31 -050011627
11628 return error;
11629}
11630
James Smarte59058c2008-08-24 21:49:00 -040011631/**
James Smart3621a712009-04-06 18:47:14 -040011632 * lpfc_exit - lpfc module removal routine
James Smarte59058c2008-08-24 21:49:00 -040011633 *
11634 * This routine is invoked when the lpfc module is removed from the kernel.
11635 * The special kernel macro module_exit() is used to indicate the role of
11636 * this routine to the kernel as lpfc module exit point.
11637 */
dea31012005-04-17 16:05:31 -050011638static void __exit
11639lpfc_exit(void)
11640{
James Smart3ef6d242012-01-18 16:23:48 -050011641 misc_deregister(&lpfc_mgmt_dev);
dea31012005-04-17 16:05:31 -050011642 pci_unregister_driver(&lpfc_driver);
11643 fc_release_transport(lpfc_transport_template);
James Smart458c0832016-07-06 12:36:07 -070011644 fc_release_transport(lpfc_vport_transport_template);
James Smart81301a92008-12-04 22:39:46 -050011645 if (_dump_buf_data) {
James Smart6a9c52c2009-10-02 15:16:51 -040011646 printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
11647 "_dump_buf_data at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050011648 (1L << _dump_buf_data_order), _dump_buf_data);
11649 free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
11650 }
11651
11652 if (_dump_buf_dif) {
James Smart6a9c52c2009-10-02 15:16:51 -040011653 printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
11654 "_dump_buf_dif at 0x%p\n",
James Smart81301a92008-12-04 22:39:46 -050011655 (1L << _dump_buf_dif_order), _dump_buf_dif);
11656 free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
11657 }
James Smartb246de12013-05-31 17:03:07 -040011658 kfree(lpfc_used_cpu);
Johannes Thumshirn79739672015-08-31 16:48:11 -040011659 idr_destroy(&lpfc_hba_index);
dea31012005-04-17 16:05:31 -050011660}
11661
11662module_init(lpfc_init);
11663module_exit(lpfc_exit);
11664MODULE_LICENSE("GPL");
11665MODULE_DESCRIPTION(LPFC_MODULE_DESC);
11666MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
11667MODULE_VERSION("0:" LPFC_DRIVER_VERSION);